KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > HyperlinkSettings


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.forms;
12 import org.eclipse.jface.resource.JFaceColors;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.*;
15 import org.eclipse.swt.widgets.Display;
16 import org.eclipse.ui.internal.forms.widgets.*;
17 /**
18  * Manages color and underline mode settings for a group of hyperlinks. The
19  * class is extended by HyperlinkGroup but is otwerwise not intended to be
20  * subclassed.
21  *
22  * @since 3.0
23  */

24 public class HyperlinkSettings {
25     /**
26      * Underline mode to be used when hyperlinks should not be underlined.
27      */

28     public static final int UNDERLINE_NEVER = 1;
29     /**
30      * Underline mode to be used when hyperlinks should only be underlined on
31      * mouse hover.
32      */

33     public static final int UNDERLINE_HOVER = 2;
34     /**
35      * Underline mode to be used when hyperlinks should always be underlined.
36      */

37     public static final int UNDERLINE_ALWAYS = 3;
38     private int hyperlinkUnderlineMode = UNDERLINE_ALWAYS;
39     private Color background;
40     private Color foreground;
41     private Color activeBackground;
42     private Color activeForeground;
43     /**
44      * The constructor.
45      *
46      * @param display
47      * the display to use when creating colors.
48      */

49     public HyperlinkSettings(Display display) {
50         initializeDefaultForegrounds(display);
51     }
52     /**
53      * Initializes the hyperlink foregrounds from the JFace defaults set for the
54      * entire workbench.
55      *
56      * @see JFaceColors
57      * @param display
58      * the display to use when creating colors
59      */

60     public void initializeDefaultForegrounds(Display display) {
61         Color fg = JFaceColors.getHyperlinkText(display);
62         Color afg = JFaceColors.getActiveHyperlinkText(display);
63         if (fg==null)
64             fg = display.getSystemColor(SWT.COLOR_BLUE);
65         setForeground(fg);
66         setActiveForeground(afg);
67     }
68     /**
69      * Returns the background to use for the active hyperlink.
70      *
71      * @return active hyperlink background
72      */

73     public Color getActiveBackground() {
74         return activeBackground;
75     }
76     /**
77      * Returns the foreground to use for the active hyperlink.
78      *
79      * @return active hyperlink foreground
80      */

81     public Color getActiveForeground() {
82         return activeForeground;
83     }
84     /**
85      * Returns the background to use for the normal hyperlink.
86      *
87      * @return normal hyperlink background
88      */

89     public Color getBackground() {
90         return background;
91     }
92     /**
93      * Returns the cursor to use when the hyperlink is active. This cursor will
94      * be shown before hyperlink listeners have been notified of hyperlink
95      * activation and hidden when the notification method returns.
96      *
97      * @return the busy cursor
98      */

99     public Cursor getBusyCursor() {
100         return FormsResources.getBusyCursor();
101     }
102     /**
103      * Returns the cursor to use when over text.
104      *
105      * @return the text cursor
106      */

107     public Cursor getTextCursor() {
108         return FormsResources.getTextCursor();
109     }
110     /**
111      * Returns the foreground to use for the normal hyperlink.
112      *
113      * @return the normal hyperlink foreground
114      */

115     public Color getForeground() {
116         return foreground;
117     }
118     /**
119      * Returns the cursor to use when hovering over the hyperlink.
120      *
121      * @return the hyperlink cursor
122      */

123     public Cursor getHyperlinkCursor() {
124         return FormsResources.getHandCursor();
125     }
126     /**
127      * Returns the underline mode to be used for all the hyperlinks in this
128      * group.
129      *
130      * @return one of UNDERLINE_NEVER, UNDERLINE_ALWAYS, UNDERLINE_HOVER
131      */

132     public int getHyperlinkUnderlineMode() {
133         return hyperlinkUnderlineMode;
134     }
135     /**
136      * Sets the new active hyperlink background for all the links.
137      *
138      * @param newActiveBackground
139      * the new active background
140      */

141     public void setActiveBackground(Color newActiveBackground) {
142         activeBackground = newActiveBackground;
143     }
144     /**
145      * Sets the new active hyperlink foreground for all the links.
146      *
147      * @param newActiveForeground
148      * the new active foreground
149      */

150     public void setActiveForeground(Color newActiveForeground) {
151         activeForeground = newActiveForeground;
152     }
153     /**
154      * Sets the new hyperlink background for all the links.
155      *
156      * @param newBackground
157      * the new hyperlink background
158      */

159     public void setBackground(Color newBackground) {
160         background = newBackground;
161     }
162     /**
163      * Sets the new hyperlink foreground for all the links.
164      *
165      * @param newForeground
166      * the new hyperlink foreground
167      */

168     public void setForeground(Color newForeground) {
169         foreground = newForeground;
170     }
171     /**
172      * Sets the new hyperlink underline mode for all the links in this group.
173      *
174      * @param mode
175      * one of <code>UNDERLINE_NEVER</code>,
176      * <code>UNDERLINE_HOVER</code> and
177      * <code>UNDERLINE_ALWAYS</code>.
178      */

179     public void setHyperlinkUnderlineMode(int mode) {
180         hyperlinkUnderlineMode = mode;
181     }
182 }
183
Popular Tags