Lines 13-19
Link Here
|
13 |
|
13 |
|
14 |
package org.netbeans.core; |
14 |
package org.netbeans.core; |
15 |
|
15 |
|
|
|
16 |
import java.awt.event.ActionEvent; |
16 |
import java.util.*; |
17 |
import java.util.*; |
|
|
18 |
import javax.swing.Action; |
17 |
|
19 |
|
18 |
import org.openide.actions.ActionManager; |
20 |
import org.openide.actions.ActionManager; |
19 |
import org.openide.util.actions.SystemAction; |
21 |
import org.openide.util.actions.SystemAction; |
Lines 35-40
Link Here
|
35 |
private static Map map = new HashMap (7); |
37 |
private static Map map = new HashMap (7); |
36 |
/** current module */ |
38 |
/** current module */ |
37 |
private static Object module = null; |
39 |
private static Object module = null; |
|
|
40 |
/** Map of currently running actions, (maps action event to action) */ |
41 |
private Map runningActions = new HashMap(); |
38 |
|
42 |
|
39 |
public static ModuleActions getDefaultInstance() { |
43 |
public static ModuleActions getDefaultInstance() { |
40 |
return (ModuleActions)ActionManager.getDefault(); |
44 |
return (ModuleActions)ActionManager.getDefault(); |
Lines 52-64
Link Here
|
52 |
return a; |
56 |
return a; |
53 |
} |
57 |
} |
54 |
|
58 |
|
|
|
59 |
/** Invokes action in a RequestPrecessor dedicated to performing |
60 |
* actions. |
61 |
*/ |
62 |
public void invokeAction(final Action a, final ActionEvent e) { |
63 |
try { |
64 |
java.awt.EventQueue.invokeLater(new Runnable() { |
65 |
public void run() { |
66 |
showWaitCursor(e); |
67 |
} |
68 |
}); |
69 |
addRunningAction(a, e); |
70 |
|
71 |
a.actionPerformed (e); |
72 |
} finally { |
73 |
removeRunningAction(e); |
74 |
java.awt.EventQueue.invokeLater(new Runnable() { |
75 |
public void run() { |
76 |
hideWaitCursor(e); |
77 |
} |
78 |
}); |
79 |
} |
80 |
} |
81 |
|
55 |
/** Listens on change of modules and if changed, |
82 |
/** Listens on change of modules and if changed, |
56 |
* fires change to all listeners. |
83 |
* fires change to all listeners. |
57 |
*/ |
84 |
*/ |
58 |
private void fireChange () { |
85 |
private void fireChange () { |
59 |
firePropertyChange(PROP_CONTEXT_ACTIONS, null, null); |
86 |
firePropertyChange(PROP_CONTEXT_ACTIONS, null, null); |
60 |
} |
87 |
} |
|
|
88 |
|
89 |
/** Adds action to <code>runningAction</code> map using event as a key. |
90 |
* @param rp <code>RequestProcessor</code> which runs the actio task |
91 |
* @param action action to put in map |
92 |
* @param evt action event used as key in the map */ |
93 |
private void addRunningAction(Action action, ActionEvent evt) { |
94 |
synchronized(runningActions) { |
95 |
runningActions.put(evt, action); |
96 |
} |
97 |
} |
98 |
|
99 |
/** Removes action from <code>runningAction</code> map for key. |
100 |
* @param evt action event used as a key in map */ |
101 |
private void removeRunningAction(ActionEvent evt) { |
102 |
synchronized(runningActions) { |
103 |
runningActions.remove(evt); |
104 |
} |
105 |
} |
61 |
|
106 |
|
|
|
107 |
/** Gets collection of currently running actions. */ |
108 |
public Collection getRunningActions() { |
109 |
synchronized(runningActions) { |
110 |
return new ArrayList(runningActions.values()); |
111 |
} |
112 |
} |
113 |
|
62 |
/** Change enabled property of an action |
114 |
/** Change enabled property of an action |
63 |
* |
115 |
* |
64 |
public void propertyChange (PropertyChangeEvent ev) { |
116 |
public void propertyChange (PropertyChangeEvent ev) { |
Lines 142-147
Link Here
|
142 |
|
194 |
|
143 |
return (SystemAction[])arr.toArray (new SystemAction[arr.size ()]); |
195 |
return (SystemAction[])arr.toArray (new SystemAction[arr.size ()]); |
144 |
} |
196 |
} |
|
|
197 |
|
198 |
|
199 |
private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.actions.MouseCursorUtils"); // NOI18N |
200 |
|
201 |
/** |
202 |
* Running show/hide count for glass panes in use. |
203 |
* Maps arbitrary keys to glass panes. |
204 |
* Several keys may map to the same glass pane - the wait cursor is shown |
205 |
* so long as there are any. |
206 |
*/ |
207 |
private static final Map glassPaneUses = new HashMap(); // Map<Object,Component> |
208 |
|
209 |
/** |
210 |
* Try to find the active window's glass pane. |
211 |
* @return a glass pane, or null |
212 |
*/ |
213 |
private static java.awt.Component activeGlassPane() { |
214 |
java.awt.Window w = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); |
215 |
if (w instanceof javax.swing.RootPaneContainer) { |
216 |
return ((javax.swing.RootPaneContainer)w).getGlassPane(); |
217 |
} else { |
218 |
return null; |
219 |
} |
220 |
} |
221 |
|
222 |
/** |
223 |
* Sets wait cursor visible on the window associated with an event, if any. |
224 |
* @param key something to pass to {@link #hideWaitCursor} to turn it off |
225 |
*/ |
226 |
public static void showWaitCursor(Object key) { |
227 |
assert java.awt.EventQueue.isDispatchThread(); |
228 |
assert !glassPaneUses.containsKey(key); |
229 |
java.awt.Component c = activeGlassPane(); |
230 |
if (c == null) { |
231 |
if (err.isLoggable(ErrorManager.WARNING)) { |
232 |
err.log(ErrorManager.WARNING, "showWaitCursor could not find a suitable glass pane; key=" + key); |
233 |
} |
234 |
return; |
235 |
} |
236 |
if (glassPaneUses.values().contains(c)) { |
237 |
if (err.isLoggable(ErrorManager.INFORMATIONAL)) { |
238 |
err.log("wait cursor already displayed on " + c); |
239 |
} |
240 |
} else { |
241 |
if (err.isLoggable(ErrorManager.INFORMATIONAL)) { |
242 |
err.log("wait cursor will be displayed on " + c); |
243 |
} |
244 |
c.setCursor(org.openide.util.Utilities.createProgressCursor(c)); |
245 |
c.setVisible(true); |
246 |
} |
247 |
glassPaneUses.put(key, c); |
248 |
} |
249 |
|
250 |
/** |
251 |
* Resets cursor to default. |
252 |
* @param key the same key passed to {@link #showWaitCursor} |
253 |
*/ |
254 |
public static void hideWaitCursor(Object key) { |
255 |
assert java.awt.EventQueue.isDispatchThread(); |
256 |
java.awt.Component c = (java.awt.Component)glassPaneUses.get(key); |
257 |
if (c == null) { |
258 |
return; |
259 |
} |
260 |
glassPaneUses.remove(key); |
261 |
if (glassPaneUses.values().contains(c)) { |
262 |
if (err.isLoggable(ErrorManager.INFORMATIONAL)) { |
263 |
err.log("wait cursor still displayed on " + c); |
264 |
} |
265 |
} else { |
266 |
if (err.isLoggable(ErrorManager.INFORMATIONAL)) { |
267 |
err.log("wait cursor will be hidden on " + c); |
268 |
} |
269 |
c.setVisible(false); |
270 |
c.setCursor(null); |
271 |
} |
272 |
} |
273 |
|
145 |
|
274 |
|
146 |
} |
275 |
} |
147 |
|
276 |
|