001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.forms.widgets;
011:
012: import java.util.Hashtable;
013: import java.util.Vector;
014:
015: import org.eclipse.swt.graphics.Color;
016: import org.eclipse.swt.graphics.GC;
017: import org.eclipse.swt.graphics.Rectangle;
018:
019: /**
020: * This segment contains a collection of images and links that all belong to one
021: * logical hyperlink.
022: */
023: public class AggregateHyperlinkSegment extends ParagraphSegment
024: implements IHyperlinkSegment {
025: private String href;
026:
027: private Vector segments = new Vector();
028:
029: public AggregateHyperlinkSegment() {
030: }
031:
032: public void add(TextHyperlinkSegment segment) {
033: segments.add(segment);
034: }
035:
036: public void add(ImageHyperlinkSegment segment) {
037: segments.add(segment);
038: }
039:
040: /*
041: * (non-Javadoc)
042: *
043: * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#advanceLocator(org.eclipse.swt.graphics.GC,
044: * int, org.eclipse.ui.internal.forms.widgets.Locator,
045: * java.util.Hashtable, boolean)
046: */
047: public boolean advanceLocator(GC gc, int wHint, Locator loc,
048: Hashtable objectTable, boolean computeHeightOnly) {
049: boolean newLine = false;
050: for (int i = 0; i < segments.size(); i++) {
051: ParagraphSegment segment = (ParagraphSegment) segments
052: .get(i);
053: if (segment.advanceLocator(gc, wHint, loc, objectTable,
054: computeHeightOnly))
055: newLine = true;
056: }
057: return newLine;
058: }
059:
060: /**
061: * @return Returns the href.
062: */
063: public String getHref() {
064: return href;
065: }
066:
067: /**
068: * @param href
069: * The href to set.
070: */
071: public void setHref(String href) {
072: this .href = href;
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#repaint(org.eclipse.swt.graphics.GC,
079: * boolean)
080: */
081: public void paint(GC gc, boolean hover, Hashtable resourceTable,
082: boolean selected, SelectionData selData,
083: Rectangle repaintRegion) {
084: for (int i = 0; i < segments.size(); i++) {
085: ParagraphSegment segment = (ParagraphSegment) segments
086: .get(i);
087: segment.paint(gc, hover, resourceTable, selected, selData,
088: repaintRegion);
089: }
090: }
091:
092: public String getText() {
093: StringBuffer buf = new StringBuffer();
094: for (int i = 0; i < segments.size(); i++) {
095: IHyperlinkSegment segment = (IHyperlinkSegment) segments
096: .get(i);
097: buf.append(segment.getText());
098: }
099: return buf.toString();
100: }
101:
102: /*
103: * (non-Javadoc)
104: *
105: * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#paintFocus(org.eclipse.swt.graphics.GC,
106: * org.eclipse.swt.graphics.Color, org.eclipse.swt.graphics.Color,
107: * boolean)
108: */
109: public void paintFocus(GC gc, Color bg, Color fg, boolean selected,
110: Rectangle repaintRegion) {
111: for (int i = 0; i < segments.size(); i++) {
112: IHyperlinkSegment segment = (IHyperlinkSegment) segments
113: .get(i);
114: segment.paintFocus(gc, bg, fg, selected, repaintRegion);
115: }
116: }
117:
118: /*
119: * (non-Javadoc)
120: *
121: * @see org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment#getBounds()
122: */
123: public Rectangle getBounds() {
124: Rectangle bounds = new Rectangle(Integer.MAX_VALUE,
125: Integer.MAX_VALUE, 0, 0);
126: // TODO this is wrong
127: for (int i = 0; i < segments.size(); i++) {
128: IHyperlinkSegment segment = (IHyperlinkSegment) segments
129: .get(i);
130: Rectangle sbounds = segment.getBounds();
131: bounds.x = Math.min(bounds.x, sbounds.x);
132: bounds.y = Math.min(bounds.y, sbounds.y);
133: bounds.width = Math.max(bounds.width, sbounds.width);
134: bounds.height = Math.max(bounds.height, sbounds.height);
135: }
136: return bounds;
137: }
138:
139: public boolean contains(int x, int y) {
140: for (int i = 0; i < segments.size(); i++) {
141: IHyperlinkSegment segment = (IHyperlinkSegment) segments
142: .get(i);
143: if (segment.contains(x, y))
144: return true;
145: }
146: return false;
147: }
148:
149: public boolean intersects(Rectangle rect) {
150: for (int i = 0; i < segments.size(); i++) {
151: IHyperlinkSegment segment = (IHyperlinkSegment) segments
152: .get(i);
153: if (segment.intersects(rect))
154: return true;
155: }
156: return false;
157: }
158:
159: /*
160: * (non-Javadoc)
161: *
162: * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#layout(org.eclipse.swt.graphics.GC,
163: * int, org.eclipse.ui.internal.forms.widgets.Locator,
164: * java.util.Hashtable, boolean,
165: * org.eclipse.ui.internal.forms.widgets.SelectionData)
166: */
167: public void layout(GC gc, int width, Locator locator,
168: Hashtable resourceTable, boolean selected) {
169: for (int i = 0; i < segments.size(); i++) {
170: ParagraphSegment segment = (ParagraphSegment) segments
171: .get(i);
172: segment.layout(gc, width, locator, resourceTable, selected);
173: }
174: }
175:
176: /*
177: * (non-Javadoc)
178: *
179: * @see org.eclipse.ui.internal.forms.widgets.ParagraphSegment#computeSelection(org.eclipse.swt.graphics.GC,
180: * java.util.Hashtable, boolean,
181: * org.eclipse.ui.internal.forms.widgets.SelectionData)
182: */
183: public void computeSelection(GC gc, Hashtable resourceTable,
184: SelectionData selData) {
185: for (int i = 0; i < segments.size(); i++) {
186: ParagraphSegment segment = (ParagraphSegment) segments
187: .get(i);
188: segment.computeSelection(gc, resourceTable, selData);
189: }
190: }
191:
192: public void clearCache(String fontId) {
193: for (int i = 0; i < segments.size(); i++) {
194: ParagraphSegment segment = (ParagraphSegment) segments
195: .get(i);
196: segment.clearCache(fontId);
197: }
198: }
199:
200: public String getTooltipText() {
201: if (segments.size() > 0)
202: return ((ParagraphSegment) segments.get(0))
203: .getTooltipText();
204: return super .getTooltipText();
205: }
206:
207: public boolean isFocusSelectable(Hashtable resourceTable) {
208: return true;
209: }
210:
211: public boolean setFocus(Hashtable resourceTable, boolean direction) {
212: return true;
213: }
214: }
|