1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.swt.graphics.*; 16 import org.eclipse.ui.forms.HyperlinkSettings; 17 18 22 public class HyperlinkSegment 23 extends TextSegment { 24 private String href; 25 private static final String LINK_FG = "c.___link_fg"; 26 private HyperlinkSettings settings; 27 28 public HyperlinkSegment(String text, HyperlinkSettings settings, String fontId) { 29 super(text, fontId); 30 this.settings = settings; 31 underline = settings.getHyperlinkUnderlineMode()==HyperlinkSettings.UNDERLINE_ALWAYS; 32 } 33 34 37 public String getHref() { 38 return href; 39 } 40 41 void setHref(String href) { 42 this.href = href; 43 } 44 public void paint(GC gc, int width, Locator locator, Hashtable resourceTable, boolean selected) { 45 resourceTable.put(LINK_FG, settings.getForeground()); 46 setColorId(LINK_FG); 47 super.paint(gc, width, locator, resourceTable, selected); 48 } 49 50 public void repaint(GC gc, boolean hover) { 51 FontMetrics fm = gc.getFontMetrics(); 52 int lineHeight = fm.getHeight(); 53 int descent = fm.getDescent(); 54 boolean rolloverMode = settings.getHyperlinkUnderlineMode()==HyperlinkSettings.UNDERLINE_HOVER; 55 for (int i=0; i<areaRectangles.size(); i++) { 56 AreaRectangle areaRectangle = (AreaRectangle)areaRectangles.get(i); 57 Rectangle rect = areaRectangle.rect; 58 String text = areaRectangle.getText(); 59 Point extent = gc.textExtent(text); 60 int textX = rect.x + 1; 61 gc.drawString(text, textX, rect.y, false); 62 if (underline || hover || rolloverMode) { 63 int lineY = rect.y + lineHeight - descent + 1; 64 Color saved=null; 65 if (rolloverMode && !hover) { 66 saved = gc.getForeground(); 67 gc.setForeground(gc.getBackground()); 68 } 69 gc.drawLine(textX, lineY, textX+extent.x, lineY); 70 if (saved!=null) 71 gc.setForeground(saved); 72 } 73 } 74 } 75 } 76 | Popular Tags |