1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import java.util.Hashtable ; 14 import java.util.Vector ; 15 16 import org.eclipse.swt.graphics.Color; 17 import org.eclipse.swt.graphics.GC; 18 import org.eclipse.swt.graphics.Rectangle; 19 20 24 public class AggregateHyperlinkSegment extends ParagraphSegment implements 25 IHyperlinkSegment { 26 private String href; 27 28 private Vector segments = new Vector (); 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 48 public boolean advanceLocator(GC gc, int wHint, Locator loc, 49 Hashtable 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 63 public String getHref() { 64 return href; 65 } 66 67 71 public void setHref(String href) { 72 this.href = href; 73 } 74 75 81 public void paint(GC gc, boolean hover, Hashtable 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 getText() { 91 StringBuffer buf = new StringBuffer (); 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 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 119 public Rectangle getBounds() { 120 Rectangle bounds = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE, 121 0, 0); 122 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 160 public void layout(GC gc, int width, Locator locator, 161 Hashtable 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 175 public void computeSelection(GC gc, Hashtable 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 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 getTooltipText() { 191 if (segments.size() > 0) 192 return ((ParagraphSegment) segments.get(0)).getTooltipText(); 193 return super.getTooltipText(); 194 } 195 196 public boolean isFocusSelectable(Hashtable resourceTable) { 197 return true; 198 } 199 200 public boolean setFocus(Hashtable resourceTable, boolean direction) { 201 return true; 202 } 203 } 204 | Popular Tags |