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 56-61
Link Here
|
56 |
|
58 |
|
57 |
import org.openide.modules.Dependency; |
59 |
import org.openide.modules.Dependency; |
58 |
import org.openide.modules.SpecificationVersion; |
60 |
import org.openide.modules.SpecificationVersion; |
|
|
61 |
import org.openide.util.RequestProcessor; |
59 |
|
62 |
|
60 |
/** Embeddable visual component to be displayed in the IDE. |
63 |
/** Embeddable visual component to be displayed in the IDE. |
61 |
* This is the basic unit of display in the IDE--windows should not be |
64 |
* This is the basic unit of display in the IDE--windows should not be |
Lines 98-104
Link Here
|
98 |
private static SystemAction[] DEFAULT_ACTIONS; |
101 |
private static SystemAction[] DEFAULT_ACTIONS; |
99 |
|
102 |
|
100 |
/** a lock for operations in default impl of getLookup */ |
103 |
/** a lock for operations in default impl of getLookup */ |
101 |
private static Object defaultLookupLock = new Object (); |
104 |
private static final Object defaultLookupLock = new Object (); |
|
|
105 |
|
106 |
/** a lock for operations with DelayedSetter */ |
107 |
private static final Object lockDelayer = new Object (); |
108 |
|
109 |
/** Init delay for second change of the activated nodes. */ |
110 |
private static final int INIT_DELAY = 70; |
111 |
|
112 |
/** Maximum delay for repeated change of the activated nodes. */ |
113 |
private static final int MAX_DELAY = 350; |
102 |
|
114 |
|
103 |
/** reference to Lookup with default implementation for the |
115 |
/** reference to Lookup with default implementation for the |
104 |
* component |
116 |
* component |
Lines 169-190
Link Here
|
169 |
public static final Registry getRegistry () { |
181 |
public static final Registry getRegistry () { |
170 |
return WindowManager.getDefault().getRegistry(); |
182 |
return WindowManager.getDefault().getRegistry(); |
171 |
} |
183 |
} |
|
|
184 |
|
185 |
private transient boolean runningSetter = false; |
186 |
|
187 |
private synchronized void setRunnigSetter (boolean running) { |
188 |
runningSetter = running; |
189 |
} |
190 |
|
191 |
private synchronized boolean isRunnigSetter () { |
192 |
return runningSetter; |
193 |
} |
172 |
|
194 |
|
173 |
/** Get the set of activated nodes in this component. |
195 |
/** Get the set of activated nodes in this component. |
174 |
* @return the activated nodes for this component |
196 |
* @return the activated nodes for this component |
175 |
*/ |
197 |
*/ |
176 |
public final Node[] getActivatedNodes () { |
198 |
public final Node[] getActivatedNodes () { |
177 |
return getManager ().getActivatedNodes (); |
199 |
Node[] nodes = null; |
|
|
200 |
synchronized (lockDelayer) { |
201 |
if (delayedSetter != null) { |
202 |
nodes = delayedSetter.getNodesImmediatelly (); |
203 |
} |
204 |
} |
205 |
if (isRunnigSetter ()) return nodes; |
206 |
doSetActivatedNodes (nodes); |
207 |
return nodes; |
178 |
} |
208 |
} |
179 |
|
209 |
|
180 |
/** Set the set of activated nodes in this component. |
210 |
/** Set the set of activated nodes in this component. |
181 |
* @param nodes activated nodes for this component |
211 |
* @param nodes activated nodes for this component |
182 |
*/ |
212 |
*/ |
183 |
public final void setActivatedNodes (Node[] nodes) { |
213 |
public void setActivatedNodes (Node[] nodes) { |
|
|
214 |
scheduleActivatedNodes (nodes); |
215 |
} |
216 |
|
217 |
private void doSetActivatedNodes (Node[] nodes) { |
218 |
setRunnigSetter (true); |
184 |
getManager ().setActivatedNodes (nodes); |
219 |
getManager ().setActivatedNodes (nodes); |
185 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
220 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
|
|
221 |
setRunnigSetter (false); |
186 |
} |
222 |
} |
187 |
|
223 |
|
|
|
224 |
private class DelayedSetter implements ActionListener { |
225 |
DelayedSetter () {} |
226 |
private Node[] nodes; |
227 |
private Timer timer; |
228 |
private boolean firstChange = true; |
229 |
|
230 |
public void scheduleActivatedNodes (Node[] nodes) { |
231 |
this.nodes = nodes; |
232 |
synchronized (this) { |
233 |
if (timer == null) { |
234 |
// start timer with INIT_DELAY |
235 |
timer = new Timer (INIT_DELAY, this); |
236 |
timer.setCoalesce (true); |
237 |
timer.setRepeats (false); |
238 |
} |
239 |
if (timer.isRunning ()) { |
240 |
// if timer is running then double init delay |
241 |
if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2); |
242 |
firstChange = false; |
243 |
} else { |
244 |
firstChange = true; |
245 |
} |
246 |
// make sure timer is running |
247 |
timer.restart(); |
248 |
} |
249 |
if (firstChange) { |
250 |
// the first change is set immediatelly |
251 |
doSetActivatedNodes (nodes); |
252 |
} |
253 |
} |
254 |
|
255 |
public void actionPerformed (ActionEvent evt) { |
256 |
synchronized (this) { |
257 |
timer.stop (); |
258 |
} |
259 |
// set activated nodes for 2nd and next changes |
260 |
if (!firstChange) { |
261 |
doSetActivatedNodes (nodes); |
262 |
} |
263 |
} |
264 |
|
265 |
public Node[] getNodesImmediatelly () { |
266 |
return nodes; |
267 |
} |
268 |
} |
269 |
|
270 |
private transient DelayedSetter delayedSetter; |
271 |
|
272 |
// schudule activation the nodes |
273 |
private void scheduleActivatedNodes (Node[] nodes) { |
274 |
synchronized (lockDelayer) { |
275 |
if (delayedSetter == null) |
276 |
delayedSetter = new DelayedSetter (); |
277 |
} |
278 |
delayedSetter.scheduleActivatedNodes (nodes); |
279 |
} |
280 |
|
188 |
/** Get the undo/redo support for this component. |
281 |
/** Get the undo/redo support for this component. |
189 |
* The default implementation returns a dummy support that cannot |
282 |
* The default implementation returns a dummy support that cannot |
190 |
* undo anything. |
283 |
* undo anything. |