Mercurial > projects > dwt-addons
annotate dwtx/ui/forms/HyperlinkGroup.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 5d489b9f966c |
children | c3583c6ec027 |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.ui.forms.HyperlinkGroup; | |
14 | |
15 import dwtx.ui.forms.HyperlinkSettings; | |
16 | |
17 import dwt.DWT; | |
18 import dwt.graphics.Color; | |
19 import dwt.widgets.Display; | |
20 import dwt.widgets.Event; | |
21 import dwt.widgets.Listener; | |
22 import dwtx.ui.forms.events.HyperlinkEvent; | |
23 import dwtx.ui.forms.events.IHyperlinkListener; | |
24 import dwtx.ui.forms.widgets.Hyperlink; | |
25 | |
26 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
27 import dwtx.dwtxhelper.Collection; |
75 | 28 |
29 /** | |
30 * Manages a group of hyperlinks. It tracks activation, updates normal and | |
31 * active colors and updates underline state depending on the underline | |
32 * preference. Hyperlink labels are added to the group after creation and are | |
33 * automatically removed from the group when they are disposed. | |
34 * | |
35 * @since 3.0 | |
36 */ | |
37 | |
38 public final class HyperlinkGroup : HyperlinkSettings { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
39 private ArrayList links; |
75 | 40 private Hyperlink lastActivated; |
41 private Hyperlink lastEntered; | |
42 private GroupListener listener; | |
43 private bool isActiveBackgroundSet; | |
44 private bool isActiveForegroundSet; | |
45 private bool isBackgroundSet; | |
46 private bool isForegroundSet; | |
47 | |
48 private class GroupListener : Listener, IHyperlinkListener { | |
49 | |
50 private Color previousBackground; | |
51 private Color previousForeground; | |
52 | |
53 public void handleEvent(Event e) { | |
54 switch (e.type) { | |
55 case DWT.MouseEnter : | |
56 onMouseEnter(e); | |
57 break; | |
58 case DWT.MouseExit : | |
59 onMouseExit(e); | |
60 break; | |
61 case DWT.MouseDown : | |
62 onMouseDown(e); | |
63 break; | |
64 case DWT.Dispose : | |
65 unhook(cast(Hyperlink) e.widget); | |
66 break; | |
67 } | |
68 } | |
69 private void onMouseEnter(Event e) { | |
70 Hyperlink link = cast(Hyperlink) e.widget; | |
71 previousBackground = link.getBackground(); | |
72 previousForeground = link.getForeground(); | |
73 if (isActiveBackgroundSet) | |
74 link.setBackground(getActiveBackground()); | |
75 if (isActiveForegroundSet) | |
76 link.setForeground(getActiveForeground()); | |
77 if (getHyperlinkUnderlineMode() is UNDERLINE_HOVER) | |
78 link.setUnderlined(true); | |
79 link.setCursor(getHyperlinkCursor()); | |
80 } | |
81 private void onMouseExit(Event e) { | |
82 Hyperlink link = cast(Hyperlink) e.widget; | |
83 if (isActiveBackgroundSet) | |
84 link.setBackground(previousBackground); | |
85 if (isActiveForegroundSet) | |
86 link.setForeground(previousForeground); | |
87 if (getHyperlinkUnderlineMode() is UNDERLINE_HOVER) | |
88 link.setUnderlined(false); | |
89 } | |
90 public void linkActivated(HyperlinkEvent e) { | |
91 } | |
92 | |
93 public void linkEntered(HyperlinkEvent e) { | |
94 Hyperlink link = cast(Hyperlink) e.widget; | |
95 if (lastEntered !is null) { | |
96 linkExited(lastEntered); | |
97 } | |
98 lastEntered = link; | |
99 } | |
100 | |
101 public void linkExited(HyperlinkEvent e) { | |
102 linkExited(cast(Hyperlink) e.widget); | |
103 } | |
104 private void linkExited(Hyperlink link) { | |
105 link.setCursor(null); | |
106 if (lastEntered is link) | |
107 lastEntered = null; | |
108 } | |
109 } | |
110 | |
111 /** | |
112 * Creates a hyperlink group. | |
113 */ | |
114 | |
115 public this(Display display) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
116 links = new ArrayList(); |
75 | 117 super(display); |
118 listener = new GroupListener(); | |
119 } | |
120 | |
121 /** | |
122 * Returns the link that has been active the last, or <code>null</code> | |
123 * if no link has been active yet or the last active link has been | |
124 * disposed. | |
125 * | |
126 * @return the last active link or <code>null</code> | |
127 */ | |
128 public Hyperlink getLastActivated() { | |
129 return lastActivated; | |
130 } | |
131 /** | |
132 * Adds a hyperlink to the group to be jointly managed. Hyperlink will be | |
133 * managed until it is disposed. Settings like colors, cursors and modes | |
134 * will affect all managed hyperlinks. | |
135 * | |
136 * @param link | |
137 */ | |
138 | |
139 public void add(Hyperlink link) { | |
140 if (isBackgroundSet) | |
141 link.setBackground(getBackground()); | |
142 if (isForegroundSet) | |
143 link.setForeground(getForeground()); | |
144 if (getHyperlinkUnderlineMode() is UNDERLINE_ALWAYS) | |
145 link.setUnderlined(true); | |
146 hook(link); | |
147 } | |
148 | |
149 /** | |
150 * Sets the new active hyperlink background for all the links. | |
151 * | |
152 * @param newActiveBackground | |
153 * the new active background | |
154 */ | |
155 public void setActiveBackground(Color newActiveBackground) { | |
156 super.setActiveBackground(newActiveBackground); | |
157 isActiveBackgroundSet = true; | |
158 } | |
159 | |
160 /** | |
161 * Sets the new active hyperlink foreground for all the links. | |
162 * | |
163 * @param newActiveForeground | |
164 * the new active foreground | |
165 */ | |
166 public void setActiveForeground(Color newActiveForeground) { | |
167 super.setActiveForeground(newActiveForeground); | |
168 isActiveForegroundSet = true; | |
169 } | |
170 | |
171 /** | |
172 * Sets the group background and also sets the background of all the | |
173 * currently managed links. | |
174 * | |
175 * @param bg | |
176 * the new background | |
177 */ | |
178 public void setBackground(Color bg) { | |
179 super.setBackground(bg); | |
180 isBackgroundSet = true; | |
181 if (links !is null) { | |
182 for (int i = 0; i < links.size(); i++) { | |
183 Hyperlink label = cast(Hyperlink) links.get(i); | |
184 label.setBackground(bg); | |
185 } | |
186 } | |
187 } | |
188 /** | |
189 * Sets the group foreground and also sets the background of all the | |
190 * currently managed links. | |
191 * | |
192 * @param fg | |
193 * the new foreground | |
194 */ | |
195 public void setForeground(Color fg) { | |
196 super.setForeground(fg); | |
197 isForegroundSet = true; | |
198 if (links !is null) { | |
199 for (int i = 0; i < links.size(); i++) { | |
200 Hyperlink label = cast(Hyperlink) links.get(i); | |
201 label.setForeground(fg); | |
202 } | |
203 } | |
204 } | |
205 /** | |
206 * Sets the hyperlink underline mode. | |
207 * | |
208 * @param mode | |
209 * the new hyperlink underline mode | |
210 * @see HyperlinkSettings | |
211 */ | |
212 public void setHyperlinkUnderlineMode(int mode) { | |
213 super.setHyperlinkUnderlineMode(mode); | |
214 if (links !is null) { | |
215 for (int i = 0; i < links.size(); i++) { | |
216 Hyperlink label = cast(Hyperlink) links.get(i); | |
217 label.setUnderlined(mode is UNDERLINE_ALWAYS); | |
218 } | |
219 } | |
220 } | |
221 | |
222 private void hook(Hyperlink link) { | |
223 link.addListener(DWT.MouseDown, listener); | |
224 link.addHyperlinkListener(listener); | |
225 link.addListener(DWT.Dispose, listener); | |
226 link.addListener(DWT.MouseEnter, listener); | |
227 link.addListener(DWT.MouseExit, listener); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
228 links.add(link); |
75 | 229 } |
230 | |
231 private void unhook(Hyperlink link) { | |
232 link.removeListener(DWT.MouseDown, listener); | |
233 link.removeHyperlinkListener(listener); | |
234 link.removeListener(DWT.MouseEnter, listener); | |
235 link.removeListener(DWT.MouseExit, listener); | |
236 if (lastActivated is link) | |
237 lastActivated = null; | |
238 if (lastEntered is link) | |
239 lastEntered = null; | |
240 links.remove(link); | |
241 } | |
242 | |
243 private void onMouseDown(Event e) { | |
244 if (e.button is 1) | |
245 return; | |
246 lastActivated = cast(Hyperlink) e.widget; | |
247 } | |
248 } |