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 boolean running = false; |
172 |
|
186 |
|
173 |
/** Get the set of activated nodes in this component. |
187 |
/** Get the set of activated nodes in this component. |
174 |
* @return the activated nodes for this component |
188 |
* @return the activated nodes for this component |
175 |
*/ |
189 |
*/ |
176 |
public final Node[] getActivatedNodes () { |
190 |
public final Node[] getActivatedNodes () { |
177 |
return getManager ().getActivatedNodes (); |
191 |
Node[] nodes = null; |
|
|
192 |
synchronized (lockDelayer) { |
193 |
if (delayedSetter != null) { |
194 |
nodes = delayedSetter.getNodesImmediatelly (); |
195 |
} |
196 |
} |
197 |
if (running) return nodes; |
198 |
doSetActivatedNodes (nodes); |
199 |
return nodes; |
178 |
} |
200 |
} |
179 |
|
201 |
|
180 |
/** Set the set of activated nodes in this component. |
202 |
/** Set the set of activated nodes in this component. |
181 |
* @param nodes activated nodes for this component |
203 |
* @param nodes activated nodes for this component |
182 |
*/ |
204 |
*/ |
183 |
public final void setActivatedNodes (Node[] nodes) { |
205 |
public void setActivatedNodes (Node[] nodes) { |
|
|
206 |
scheduleActivatedNodes (nodes); |
207 |
} |
208 |
|
209 |
private void doSetActivatedNodes (Node[] nodes) { |
210 |
running = true; |
184 |
getManager ().setActivatedNodes (nodes); |
211 |
getManager ().setActivatedNodes (nodes); |
185 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
212 |
firePropertyChange ("activatedNodes", null, null); // NOI18N |
|
|
213 |
running = false; |
186 |
} |
214 |
} |
187 |
|
215 |
|
|
|
216 |
private class DelayedSetter implements ActionListener { |
217 |
DelayedSetter () {} |
218 |
private Node[] nodes; |
219 |
private Timer timer; |
220 |
private boolean firstChange = true; |
221 |
|
222 |
public void scheduleActivatedNodes (Node[] nodes) { |
223 |
this.nodes = nodes; |
224 |
synchronized (this) { |
225 |
if (timer == null) { |
226 |
// start timer with INIT_DELAY |
227 |
timer = new Timer (INIT_DELAY, this); |
228 |
timer.setCoalesce (true); |
229 |
timer.setRepeats (false); |
230 |
} |
231 |
if (timer.isRunning ()) { |
232 |
// if timer is running then double init delay |
233 |
if (timer.getInitialDelay () < MAX_DELAY) timer.setInitialDelay (timer.getInitialDelay () * 2); |
234 |
firstChange = false; |
235 |
} else { |
236 |
firstChange = true; |
237 |
} |
238 |
// make sure timer is running |
239 |
timer.restart(); |
240 |
} |
241 |
if (firstChange) { |
242 |
// the first change is set immediatelly |
243 |
doSetActivatedNodes (nodes); |
244 |
} |
245 |
} |
246 |
|
247 |
public void actionPerformed (ActionEvent evt) { |
248 |
synchronized (this) { |
249 |
timer.stop (); |
250 |
} |
251 |
// set activated nodes for 2nd and next changes |
252 |
if (!firstChange) { |
253 |
doSetActivatedNodes (nodes); |
254 |
} |
255 |
} |
256 |
|
257 |
public Node[] getNodesImmediatelly () { |
258 |
return nodes; |
259 |
} |
260 |
} |
261 |
|
262 |
private transient DelayedSetter delayedSetter; |
263 |
|
264 |
// schudule activation the nodes |
265 |
private void scheduleActivatedNodes (Node[] nodes) { |
266 |
synchronized (lockDelayer) { |
267 |
if (delayedSetter == null) |
268 |
delayedSetter = new DelayedSetter (); |
269 |
} |
270 |
delayedSetter.scheduleActivatedNodes (nodes); |
271 |
} |
272 |
|
188 |
/** Get the undo/redo support for this component. |
273 |
/** Get the undo/redo support for this component. |
189 |
* The default implementation returns a dummy support that cannot |
274 |
* The default implementation returns a dummy support that cannot |
190 |
* undo anything. |
275 |
* undo anything. |