01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.forms.widgets;
11:
12: import java.util.Hashtable;
13:
14: import org.eclipse.swt.graphics.*;
15: import org.eclipse.ui.forms.HyperlinkSettings;
16:
17: /**
18: * @version 1.0
19: * @author
20: */
21: public class TextHyperlinkSegment extends TextSegment implements
22: IHyperlinkSegment {
23: private String href;
24:
25: private String tooltipText;
26:
27: //private static final String LINK_FG = "c.___link_fg";
28:
29: private HyperlinkSettings settings;
30:
31: public TextHyperlinkSegment(String text,
32: HyperlinkSettings settings, String fontId) {
33: super (text, fontId);
34: this .settings = settings;
35: underline = settings.getHyperlinkUnderlineMode() == HyperlinkSettings.UNDERLINE_ALWAYS;
36: }
37:
38: /*
39: * @see IObjectReference#getObjectId()
40: */
41: public String getHref() {
42: return href;
43: }
44:
45: public void setHref(String href) {
46: this .href = href;
47: }
48:
49: /*
50: * public void paint(GC gc, int width, Locator locator, Hashtable
51: * resourceTable, boolean selected, SelectionData selData) {
52: * resourceTable.put(LINK_FG, settings.getForeground());
53: * setColorId(LINK_FG); super.paint(gc, width, locator, resourceTable,
54: * selected, selData); }
55: */
56:
57: public void paint(GC gc, boolean hover, Hashtable resourceTable,
58: boolean selected, SelectionData selData,
59: Rectangle repaintRegion) {
60: boolean rolloverMode = settings.getHyperlinkUnderlineMode() == HyperlinkSettings.UNDERLINE_HOVER;
61: Color savedFg = gc.getForeground();
62: Color newFg = hover ? settings.getActiveForeground() : settings
63: .getForeground();
64: if (newFg != null)
65: gc.setForeground(newFg);
66: super .paint(gc, hover, resourceTable, selected, rolloverMode,
67: selData, repaintRegion);
68: gc.setForeground(savedFg);
69: }
70:
71: public String getTooltipText() {
72: return tooltipText;
73: }
74:
75: public void setTooltipText(String tooltip) {
76: this .tooltipText = tooltip;
77: }
78:
79: public boolean isSelectable() {
80: return true;
81: }
82:
83: public boolean isFocusSelectable(Hashtable resourceTable) {
84: return true;
85: }
86:
87: public boolean setFocus(Hashtable resourceTable, boolean direction) {
88: return true;
89: }
90: }
|