KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 import org.eclipse.swt.graphics.*;
16 import org.eclipse.ui.forms.HyperlinkSettings;
17
18 /**
19  * @version 1.0
20  * @author
21  */

22 public class TextHyperlinkSegment extends TextSegment implements
23         IHyperlinkSegment {
24     private String JavaDoc href;
25
26     private String JavaDoc tooltipText;
27
28     //private static final String LINK_FG = "c.___link_fg";
29

30     private HyperlinkSettings settings;
31
32     public TextHyperlinkSegment(String JavaDoc text, HyperlinkSettings settings,
33             String JavaDoc fontId) {
34         super(text, fontId);
35         this.settings = settings;
36         underline = settings.getHyperlinkUnderlineMode() == HyperlinkSettings.UNDERLINE_ALWAYS;
37     }
38
39     /*
40      * @see IObjectReference#getObjectId()
41      */

42     public String JavaDoc getHref() {
43         return href;
44     }
45
46     public void setHref(String JavaDoc href) {
47         this.href = href;
48     }
49
50     /*
51      * public void paint(GC gc, int width, Locator locator, Hashtable
52      * resourceTable, boolean selected, SelectionData selData) {
53      * resourceTable.put(LINK_FG, settings.getForeground());
54      * setColorId(LINK_FG); super.paint(gc, width, locator, resourceTable,
55      * selected, selData); }
56      */

57
58     public void paint(GC gc, boolean hover, Hashtable JavaDoc resourceTable,
59             boolean selected, SelectionData selData, 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, selData,
67                 repaintRegion);
68         gc.setForeground(savedFg);
69     }
70
71     public String JavaDoc getTooltipText() {
72         return tooltipText;
73     }
74
75     public void setTooltipText(String JavaDoc tooltip) {
76         this.tooltipText = tooltip;
77     }
78     
79     public boolean isSelectable() {
80         return true;
81     }
82
83     public boolean isFocusSelectable(Hashtable JavaDoc resourceTable) {
84         return true;
85     }
86
87     public boolean setFocus(Hashtable JavaDoc resourceTable, boolean direction) {
88         return true;
89     }
90 }
Popular Tags