KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > forms > widgets > AggregateHyperlinkSegment


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.forms.widgets;
12
13 import java.util.Hashtable JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.graphics.GC;
18 import org.eclipse.swt.graphics.Rectangle;
19
20 /**
21  * This segment contains a collection of images and links that all belong to one
22  * logical hyperlink.
23  */

24 public class AggregateHyperlinkSegment extends ParagraphSegment implements
25         IHyperlinkSegment {
26     private String JavaDoc href;
27
28     private Vector JavaDoc segments = new Vector JavaDoc();
29
30     public AggregateHyperlinkSegment() {
31     }
32
33     public void add(TextHyperlinkSegment segment) {
34         segments.add(segment);
35     }
36
37     public void add(ImageHyperlinkSegment segment) {
38         segments.add(segment);
39     }
40
41     /*
42      * (non-Javadoc)
43      *
44      * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#advanceLocator(org.eclipse.swt.graphics.GC,
45      * int, org.eclipse.ui.internal.forms.widgets.Locator,
46      * java.util.Hashtable, boolean)
47      */

48     public boolean advanceLocator(GC gc, int wHint, Locator loc,
49             Hashtable JavaDoc objectTable, boolean computeHeightOnly) {
50         boolean newLine = false;
51         for (int i = 0; i < segments.size(); i++) {
52             ParagraphSegment segment = (ParagraphSegment) segments.get(i);
53             if (segment.advanceLocator(gc, wHint, loc, objectTable,
54                     computeHeightOnly))
55                 newLine = true;
56         }
57         return newLine;
58     }
59
60     /**
61      * @return Returns the href.
62      */

63     public String JavaDoc getHref() {
64         return href;
65     }
66
67     /**
68      * @param href
69      * The href to set.
70      */

71     public void setHref(String JavaDoc href) {
72         this.href = href;
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#repaint(org.eclipse.swt.graphics.GC,
79      * boolean)
80      */

81     public void paint(GC gc, boolean hover, Hashtable JavaDoc resourceTable,
82             boolean selected, SelectionData selData, Rectangle repaintRegion) {
83         for (int i = 0; i < segments.size(); i++) {
84             ParagraphSegment segment = (ParagraphSegment) segments.get(i);
85             segment.paint(gc, hover, resourceTable, selected, selData,
86                     repaintRegion);
87         }
88     }
89
90     public String JavaDoc getText() {
91         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
92         for (int i = 0; i < segments.size(); i++) {
93             IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
94             buf.append(segment.getText());
95         }
96         return buf.toString();
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#paintFocus(org.eclipse.swt.graphics.GC,
103      * org.eclipse.swt.graphics.Color, org.eclipse.swt.graphics.Color,
104      * boolean)
105      */

106     public void paintFocus(GC gc, Color bg, Color fg, boolean selected,
107             Rectangle repaintRegion) {
108         for (int i = 0; i < segments.size(); i++) {
109             IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
110             segment.paintFocus(gc, bg, fg, selected, repaintRegion);
111         }
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#getBounds()
118      */

119     public Rectangle getBounds() {
120         Rectangle bounds = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE,
121                 0, 0);
122         // TODO this is wrong
123
for (int i = 0; i < segments.size(); i++) {
124             IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
125             Rectangle sbounds = segment.getBounds();
126             bounds.x = Math.min(bounds.x, sbounds.x);
127             bounds.y = Math.min(bounds.y, sbounds.y);
128             bounds.width = Math.max(bounds.width, sbounds.width);
129             bounds.height = Math.max(bounds.height, sbounds.height);
130         }
131         return bounds;
132     }
133
134     public boolean contains(int x, int y) {
135         for (int i = 0; i < segments.size(); i++) {
136             IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
137             if (segment.contains(x, y))
138                 return true;
139         }
140         return false;
141     }
142
143     public boolean intersects(Rectangle rect) {
144         for (int i = 0; i < segments.size(); i++) {
145             IHyperlinkSegment segment = (IHyperlinkSegment) segments.get(i);
146             if (segment.intersects(rect))
147                 return true;
148         }
149         return false;
150     }
151
152     /*
153      * (non-Javadoc)
154      *
155      * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#layout(org.eclipse.swt.graphics.GC,
156      * int, org.eclipse.ui.internal.forms.widgets.Locator,
157      * java.util.Hashtable, boolean,
158      * org.eclipse.ui.internal.forms.widgets.SelectionData)
159      */

160     public void layout(GC gc, int width, Locator locator,
161             Hashtable JavaDoc resourceTable, boolean selected) {
162         for (int i = 0; i < segments.size(); i++) {
163             ParagraphSegment segment = (ParagraphSegment) segments.get(i);
164             segment.layout(gc, width, locator, resourceTable, selected);
165         }
166     }
167
168     /*
169      * (non-Javadoc)
170      *
171      * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#computeSelection(org.eclipse.swt.graphics.GC,
172      * java.util.Hashtable, boolean,
173      * org.eclipse.ui.internal.forms.widgets.SelectionData)
174      */

175     public void computeSelection(GC gc, Hashtable JavaDoc resourceTable,
176             SelectionData selData) {
177         for (int i = 0; i < segments.size(); i++) {
178             ParagraphSegment segment = (ParagraphSegment) segments.get(i);
179             segment.computeSelection(gc, resourceTable, selData);
180         }
181     }
182
183     public void clearCache(String JavaDoc fontId) {
184         for (int i = 0; i < segments.size(); i++) {
185             ParagraphSegment segment = (ParagraphSegment) segments.get(i);
186             segment.clearCache(fontId);
187         }
188     }
189
190     public String JavaDoc getTooltipText() {
191         if (segments.size() > 0)
192             return ((ParagraphSegment) segments.get(0)).getTooltipText();
193         return super.getTooltipText();
194     }
195
196     public boolean isFocusSelectable(Hashtable JavaDoc resourceTable) {
197         return true;
198     }
199
200     public boolean setFocus(Hashtable JavaDoc resourceTable, boolean direction) {
201         return true;
202     }
203 }
204
Popular Tags