view dwtx/ui/internal/forms/widgets/AggregateHyperlinkSegment.d @ 75:5d489b9f966c

Fix continue porting
author Frank Benoit <benoit@tionex.de>
date Sat, 24 May 2008 05:11:16 +0200
parents
children e193036d82c9
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/
module dwtx.ui.internal.forms.widgets.AggregateHyperlinkSegment;

import java.util.Hashtable;
import java.util.Vector;

import dwt.graphics.Color;
import dwt.graphics.GC;
import dwt.graphics.Rectangle;

/**
 * This segment contains a collection of images and links that all belong to one
 * logical hyperlink.
 */
public class AggregateHyperlinkSegment extends ParagraphSegment implements
        IHyperlinkSegment {
    private String href;

    private Vector segments = new Vector();

    public AggregateHyperlinkSegment() {
    }

    public void add(TextHyperlinkSegment segment) {
        segments.add(segment);
    }

    public void add(ImageHyperlinkSegment segment) {
        segments.add(segment);
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#advanceLocator(dwt.graphics.GC,
     *      int, dwtx.ui.internal.forms.widgets.Locator,
     *      java.util.Hashtable, bool)
     */
    public bool advanceLocator(GC gc, int wHint, Locator loc,
            Hashtable objectTable, bool computeHeightOnly) {
        bool newLine = false;
        for (int i = 0; i < segments.size(); i++) {
            ParagraphSegment segment = (ParagraphSegment) segments.get(i);
            if (segment.advanceLocator(gc, wHint, loc, objectTable,
                    computeHeightOnly))
                newLine = true;
        }
        return newLine;
    }

    /**
     * @return Returns the href.
     */
    public String getHref() {
        return href;
    }

    /**
     * @param href
     *            The href to set.
     */
    public void setHref(String href) {
        this.href = href;
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.IHyperlinkSegment#repaint(dwt.graphics.GC,
     *      bool)
     */
    public void paint(GC gc, bool hover, Hashtable resourceTable,
            bool selected, SelectionData selData, Rectangle repaintRegion) {
        for (int i = 0; i < segments.size(); i++) {
            ParagraphSegment segment = (ParagraphSegment) segments.get(i);
            segment.paint(gc, hover, resourceTable, selected, selData,
                    repaintRegion);
        }
    }

    public String getText() {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < segments.size(); i++) {
            IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
            buf.append(segment.getText());
        }
        return buf.toString();
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.IHyperlinkSegment#paintFocus(dwt.graphics.GC,
     *      dwt.graphics.Color, dwt.graphics.Color,
     *      bool)
     */
    public void paintFocus(GC gc, Color bg, Color fg, bool selected,
            Rectangle repaintRegion) {
        for (int i = 0; i < segments.size(); i++) {
            IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
            segment.paintFocus(gc, bg, fg, selected, repaintRegion);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.IHyperlinkSegment#getBounds()
     */
    public Rectangle getBounds() {
        Rectangle bounds = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE,
                0, 0);
        // TODO this is wrong
        for (int i = 0; i < segments.size(); i++) {
            IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
            Rectangle sbounds = segment.getBounds();
            bounds.x = Math.min(bounds.x, sbounds.x);
            bounds.y = Math.min(bounds.y, sbounds.y);
            bounds.width = Math.max(bounds.width, sbounds.width);
            bounds.height = Math.max(bounds.height, sbounds.height);
        }
        return bounds;
    }

    public bool contains(int x, int y) {
        for (int i = 0; i < segments.size(); i++) {
            IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
            if (segment.contains(x, y))
                return true;
        }
        return false;
    }

    public bool intersects(Rectangle rect) {
        for (int i = 0; i < segments.size(); i++) {
            IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
            if (segment.intersects(rect))
                return true;
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#layout(dwt.graphics.GC,
     *      int, dwtx.ui.internal.forms.widgets.Locator,
     *      java.util.Hashtable, bool,
     *      dwtx.ui.internal.forms.widgets.SelectionData)
     */
    public void layout(GC gc, int width, Locator locator,
            Hashtable resourceTable, bool selected) {
        for (int i = 0; i < segments.size(); i++) {
            ParagraphSegment segment = (ParagraphSegment) segments.get(i);
            segment.layout(gc, width, locator, resourceTable, selected);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#computeSelection(dwt.graphics.GC,
     *      java.util.Hashtable, bool,
     *      dwtx.ui.internal.forms.widgets.SelectionData)
     */
    public void computeSelection(GC gc, Hashtable resourceTable,
            SelectionData selData) {
        for (int i = 0; i < segments.size(); i++) {
            ParagraphSegment segment = (ParagraphSegment) segments.get(i);
            segment.computeSelection(gc, resourceTable, selData);
        }
    }

    public void clearCache(String fontId) {
        for (int i = 0; i < segments.size(); i++) {
            ParagraphSegment segment = (ParagraphSegment) segments.get(i);
            segment.clearCache(fontId);
        }
    }

    public String getTooltipText() {
        if (segments.size() > 0)
            return ((ParagraphSegment) segments.get(0)).getTooltipText();
        return super.getTooltipText();
    }

    public bool isFocusSelectable(Hashtable resourceTable) {
        return true;
    }

    public bool setFocus(Hashtable resourceTable, bool direction) {
        return true;
    }
}