Lines 15-20
Link Here
|
15 |
|
15 |
|
16 |
import java.awt.Image; |
16 |
import java.awt.Image; |
17 |
import java.awt.event.ActionEvent; |
17 |
import java.awt.event.ActionEvent; |
|
|
18 |
import java.awt.event.ActionListener; |
18 |
import java.awt.event.KeyEvent; |
19 |
import java.awt.event.KeyEvent; |
19 |
import java.util.*; |
20 |
import java.util.*; |
20 |
import java.beans.*; |
21 |
import java.beans.*; |
Lines 38-43
Link Here
|
38 |
import javax.swing.JComponent; |
39 |
import javax.swing.JComponent; |
39 |
import javax.swing.KeyStroke; |
40 |
import javax.swing.KeyStroke; |
40 |
import javax.swing.SwingUtilities; |
41 |
import javax.swing.SwingUtilities; |
|
|
42 |
import javax.swing.Timer; |
41 |
import javax.swing.text.Keymap; |
43 |
import javax.swing.text.Keymap; |
42 |
|
44 |
|
43 |
import org.openide.ErrorManager; |
45 |
import org.openide.ErrorManager; |
Lines 98-104
Link Here
|
98 |
private static SystemAction[] DEFAULT_ACTIONS; |
100 |
private static SystemAction[] DEFAULT_ACTIONS; |
99 |
|
101 |
|
100 |
/** a lock for operations in default impl of getLookup */ |
102 |
/** a lock for operations in default impl of getLookup */ |
101 |
private static Object defaultLookupLock = new Object (); |
103 |
private static final Object defaultLookupLock = new Object (); |
|
|
104 |
|
105 |
/** a lock for operations with DelayedSetter */ |
106 |
private static final Object lockDelayer = new Object (); |
107 |
|
108 |
/** Init delay for second change of the activated nodes. */ |
109 |
private static final int INIT_DELAY = 70; |
110 |
|
111 |
/** Maximum delay for repeated change of the activated nodes. */ |
112 |
private static final int MAX_DELAY = 350; |
102 |
|
113 |
|
103 |
/** reference to Lookup with default implementation for the |
114 |
/** reference to Lookup with default implementation for the |
104 |
* component |
115 |
* component |
Lines 174-190
Link Here
|
174 |
* @return the activated nodes for this component |
185 |
* @return the activated nodes for this component |
175 |
*/ |
186 |
*/ |
176 |
public final Node[] getActivatedNodes () { |
187 |
public final Node[] getActivatedNodes () { |
|
|
188 |
synchronized (lockDelayer) { |
189 |
if (delayedSetter != null) { |
190 |
return delayedSetter.getNodesImmediatelly (); |
191 |
} |
192 |
} |
177 |
return getManager ().getActivatedNodes (); |
193 |
return getManager ().getActivatedNodes (); |
178 |
} |
194 |
} |
179 |
|
195 |
|
180 |
/** Set the set of activated nodes in this component. |
196 |
/** Set the set of activated nodes in this component. |
181 |
* @param nodes activated nodes for this component |
197 |
* @param nodes activated nodes for this component |
182 |
*/ |
198 |
*/ |
183 |
public final void setActivatedNodes (Node[] nodes) { |
199 |
public void setActivatedNodes (Node[] nodes) { |
|
|
200 |
scheduleActivatedNodes (nodes); |
201 |
} |
202 |
|
203 |
private void doSetActivatedNodes (Node[] nodes) { |
184 |
getManager ().setActivatedNodes (nodes); |
204 |
getManager ().setActivatedNodes (nodes); |
185 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
205 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
186 |
} |
206 |
} |
187 |
|
207 |
|
|
|
208 |
private class DelayedSetter implements ActionListener { |
209 |
DelayedSetter () {} |
210 |
private Node[] nodes; |
211 |
private Timer timer; |
212 |
private boolean firstChange = true; |
213 |
|
214 |
public void scheduleActivatedNodes (Node[] nodes) { |
215 |
this.nodes = nodes; |
216 |
synchronized (this) { |
217 |
if (timer == null) { |
218 |
// start timer with INIT_DELAY |
219 |
timer = new Timer (INIT_DELAY, this); |
220 |
timer.setCoalesce (true); |
221 |
timer.setRepeats (false); |
222 |
} |
223 |
if (timer.isRunning ()) { |
224 |
// if timer is running then double init delay |
225 |
if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2); |
226 |
firstChange = false; |
227 |
} else { |
228 |
firstChange = true; |
229 |
} |
230 |
// make sure timer is running |
231 |
timer.restart(); |
232 |
} |
233 |
if (firstChange) { |
234 |
// the first change is set immediatelly |
235 |
doSetActivatedNodes (nodes); |
236 |
} |
237 |
} |
238 |
|
239 |
public void actionPerformed (ActionEvent evt) { |
240 |
synchronized (this) { |
241 |
timer.stop (); |
242 |
} |
243 |
// set activated nodes for 2nd and next changes |
244 |
if (!firstChange) { |
245 |
doSetActivatedNodes (nodes); |
246 |
} |
247 |
} |
248 |
|
249 |
public Node[] getNodesImmediatelly () { |
250 |
return nodes; |
251 |
} |
252 |
} |
253 |
|
254 |
private transient DelayedSetter delayedSetter; |
255 |
|
256 |
// schudule activation the nodes |
257 |
private void scheduleActivatedNodes (Node[] nodes) { |
258 |
synchronized (lockDelayer) { |
259 |
if (delayedSetter == null) |
260 |
delayedSetter = new DelayedSetter (); |
261 |
} |
262 |
delayedSetter.scheduleActivatedNodes (nodes); |
263 |
} |
264 |
|
188 |
/** Get the undo/redo support for this component. |
265 |
/** Get the undo/redo support for this component. |
189 |
* The default implementation returns a dummy support that cannot |
266 |
* The default implementation returns a dummy support that cannot |
190 |
* undo anything. |
267 |
* undo anything. |