author | weijun |
Thu, 11 Dec 2014 15:19:12 +0800 | |
changeset 28228 | be83f404724d |
parent 25859 | 3317bb8137f4 |
child 28991 | c9b7acf9062d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.basic; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.plaf.*; |
|
30 |
||
31 |
import java.beans.*; |
|
32 |
||
33 |
import java.awt.event.*; |
|
34 |
import java.awt.Dimension; |
|
35 |
import java.awt.Insets; |
|
36 |
import java.awt.Graphics; |
|
37 |
import java.awt.KeyboardFocusManager; |
|
38 |
import java.awt.*; |
|
39 |
import java.util.Vector; |
|
40 |
import sun.swing.DefaultLookup; |
|
41 |
import sun.swing.UIAction; |
|
42 |
import sun.awt.AppContext; |
|
43 |
||
44 |
/** |
|
20169 | 45 |
* Basic L&F for a desktop. |
2 | 46 |
* |
47 |
* @author Steve Wilson |
|
48 |
*/ |
|
49 |
public class BasicDesktopPaneUI extends DesktopPaneUI { |
|
50 |
// Old actions forward to an instance of this. |
|
51 |
private static final Actions SHARED_ACTION = new Actions(); |
|
52 |
private static Dimension minSize = new Dimension(0,0); |
|
53 |
private static Dimension maxSize = new Dimension(Integer.MAX_VALUE, |
|
54 |
Integer.MAX_VALUE); |
|
55 |
private Handler handler; |
|
56 |
private PropertyChangeListener pcl; |
|
57 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
58 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
59 |
* The instance of {@code JDesktopPane}. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
60 |
*/ |
2 | 61 |
protected JDesktopPane desktop; |
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
62 |
|
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
63 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
64 |
* The instance of {@code DesktopManager}. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
65 |
*/ |
2 | 66 |
protected DesktopManager desktopManager; |
67 |
||
68 |
/** |
|
69 |
* As of Java 2 platform v1.3 this previously undocumented field is no |
|
70 |
* longer used. |
|
71 |
* Key bindings are now defined by the LookAndFeel, please refer to |
|
72 |
* the key bindings specification for further details. |
|
73 |
* |
|
74 |
* @deprecated As of 1.3. |
|
75 |
*/ |
|
76 |
@Deprecated |
|
77 |
protected KeyStroke minimizeKey; |
|
78 |
/** |
|
79 |
* As of Java 2 platform v1.3 this previously undocumented field is no |
|
80 |
* longer used. |
|
81 |
* Key bindings are now defined by the LookAndFeel, please refer to |
|
82 |
* the key bindings specification for further details. |
|
83 |
* |
|
84 |
* @deprecated As of 1.3. |
|
85 |
*/ |
|
86 |
@Deprecated |
|
87 |
protected KeyStroke maximizeKey; |
|
88 |
/** |
|
89 |
* As of Java 2 platform v1.3 this previously undocumented field is no |
|
90 |
* longer used. |
|
91 |
* Key bindings are now defined by the LookAndFeel, please refer to |
|
92 |
* the key bindings specification for further details. |
|
93 |
* |
|
94 |
* @deprecated As of 1.3. |
|
95 |
*/ |
|
96 |
@Deprecated |
|
97 |
protected KeyStroke closeKey; |
|
98 |
/** |
|
99 |
* As of Java 2 platform v1.3 this previously undocumented field is no |
|
100 |
* longer used. |
|
101 |
* Key bindings are now defined by the LookAndFeel, please refer to |
|
102 |
* the key bindings specification for further details. |
|
103 |
* |
|
104 |
* @deprecated As of 1.3. |
|
105 |
*/ |
|
106 |
@Deprecated |
|
107 |
protected KeyStroke navigateKey; |
|
108 |
/** |
|
109 |
* As of Java 2 platform v1.3 this previously undocumented field is no |
|
110 |
* longer used. |
|
111 |
* Key bindings are now defined by the LookAndFeel, please refer to |
|
112 |
* the key bindings specification for further details. |
|
113 |
* |
|
114 |
* @deprecated As of 1.3. |
|
115 |
*/ |
|
116 |
@Deprecated |
|
117 |
protected KeyStroke navigateKey2; |
|
118 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
119 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
120 |
* Constructs a new instance of {@code BasicDesktopPaneUI}. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
121 |
* |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
122 |
* @param c a component |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
123 |
* @return a new instance of {@code BasicDesktopPaneUI} |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
124 |
*/ |
2 | 125 |
public static ComponentUI createUI(JComponent c) { |
126 |
return new BasicDesktopPaneUI(); |
|
127 |
} |
|
128 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
129 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
130 |
* Constructs a new instance of {@code BasicDesktopPaneUI}. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
131 |
*/ |
2 | 132 |
public BasicDesktopPaneUI() { |
133 |
} |
|
134 |
||
135 |
public void installUI(JComponent c) { |
|
136 |
desktop = (JDesktopPane)c; |
|
137 |
installDefaults(); |
|
138 |
installDesktopManager(); |
|
139 |
installListeners(); |
|
140 |
installKeyboardActions(); |
|
141 |
} |
|
142 |
||
143 |
public void uninstallUI(JComponent c) { |
|
144 |
uninstallKeyboardActions(); |
|
145 |
uninstallListeners(); |
|
146 |
uninstallDesktopManager(); |
|
147 |
uninstallDefaults(); |
|
148 |
desktop = null; |
|
149 |
handler = null; |
|
150 |
} |
|
151 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
152 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
153 |
* Installs default properties. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
154 |
*/ |
2 | 155 |
protected void installDefaults() { |
156 |
if (desktop.getBackground() == null || |
|
157 |
desktop.getBackground() instanceof UIResource) { |
|
158 |
desktop.setBackground(UIManager.getColor("Desktop.background")); |
|
159 |
} |
|
160 |
LookAndFeel.installProperty(desktop, "opaque", Boolean.TRUE); |
|
161 |
} |
|
162 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
163 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
164 |
* Uninstalls default properties. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
165 |
*/ |
2 | 166 |
protected void uninstallDefaults() { } |
167 |
||
168 |
/** |
|
169 |
* Installs the <code>PropertyChangeListener</code> returned from |
|
170 |
* <code>createPropertyChangeListener</code> on the |
|
171 |
* <code>JDesktopPane</code>. |
|
172 |
* |
|
173 |
* @since 1.5 |
|
174 |
* @see #createPropertyChangeListener |
|
175 |
*/ |
|
176 |
protected void installListeners() { |
|
177 |
pcl = createPropertyChangeListener(); |
|
178 |
desktop.addPropertyChangeListener(pcl); |
|
179 |
} |
|
180 |
||
181 |
/** |
|
182 |
* Uninstalls the <code>PropertyChangeListener</code> returned from |
|
183 |
* <code>createPropertyChangeListener</code> from the |
|
184 |
* <code>JDesktopPane</code>. |
|
185 |
* |
|
186 |
* @since 1.5 |
|
187 |
* @see #createPropertyChangeListener |
|
188 |
*/ |
|
189 |
protected void uninstallListeners() { |
|
190 |
desktop.removePropertyChangeListener(pcl); |
|
191 |
pcl = null; |
|
192 |
} |
|
193 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
194 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
195 |
* Installs desktop manager. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
196 |
*/ |
2 | 197 |
protected void installDesktopManager() { |
198 |
desktopManager = desktop.getDesktopManager(); |
|
199 |
if(desktopManager == null) { |
|
200 |
desktopManager = new BasicDesktopManager(); |
|
201 |
desktop.setDesktopManager(desktopManager); |
|
202 |
} |
|
203 |
} |
|
204 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
205 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
206 |
* Uninstalls desktop manager. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
207 |
*/ |
2 | 208 |
protected void uninstallDesktopManager() { |
209 |
if(desktop.getDesktopManager() instanceof UIResource) { |
|
210 |
desktop.setDesktopManager(null); |
|
211 |
} |
|
212 |
desktopManager = null; |
|
213 |
} |
|
214 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
215 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
216 |
* Installs keyboard actions. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
217 |
*/ |
2 | 218 |
protected void installKeyboardActions(){ |
219 |
InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); |
|
220 |
if (inputMap != null) { |
|
221 |
SwingUtilities.replaceUIInputMap(desktop, |
|
222 |
JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap); |
|
223 |
} |
|
224 |
inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); |
|
225 |
if (inputMap != null) { |
|
226 |
SwingUtilities.replaceUIInputMap(desktop, |
|
227 |
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, |
|
228 |
inputMap); |
|
229 |
} |
|
230 |
||
231 |
LazyActionMap.installLazyActionMap(desktop, BasicDesktopPaneUI.class, |
|
232 |
"DesktopPane.actionMap"); |
|
233 |
registerKeyboardActions(); |
|
234 |
} |
|
235 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
236 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
237 |
* Registers keyboard actions. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
238 |
*/ |
2 | 239 |
protected void registerKeyboardActions(){ |
240 |
} |
|
241 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
242 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
243 |
* Unregisters keyboard actions. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
244 |
*/ |
2 | 245 |
protected void unregisterKeyboardActions(){ |
246 |
} |
|
247 |
||
248 |
InputMap getInputMap(int condition) { |
|
249 |
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { |
|
250 |
return createInputMap(condition); |
|
251 |
} |
|
252 |
else if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { |
|
253 |
return (InputMap)DefaultLookup.get(desktop, this, |
|
254 |
"Desktop.ancestorInputMap"); |
|
255 |
} |
|
256 |
return null; |
|
257 |
} |
|
258 |
||
259 |
InputMap createInputMap(int condition) { |
|
260 |
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { |
|
261 |
Object[] bindings = (Object[])DefaultLookup.get(desktop, |
|
262 |
this, "Desktop.windowBindings"); |
|
263 |
||
264 |
if (bindings != null) { |
|
265 |
return LookAndFeel.makeComponentInputMap(desktop, bindings); |
|
266 |
} |
|
267 |
} |
|
268 |
return null; |
|
269 |
} |
|
270 |
||
271 |
static void loadActionMap(LazyActionMap map) { |
|
272 |
map.put(new Actions(Actions.RESTORE)); |
|
273 |
map.put(new Actions(Actions.CLOSE)); |
|
274 |
map.put(new Actions(Actions.MOVE)); |
|
275 |
map.put(new Actions(Actions.RESIZE)); |
|
276 |
map.put(new Actions(Actions.LEFT)); |
|
277 |
map.put(new Actions(Actions.SHRINK_LEFT)); |
|
278 |
map.put(new Actions(Actions.RIGHT)); |
|
279 |
map.put(new Actions(Actions.SHRINK_RIGHT)); |
|
280 |
map.put(new Actions(Actions.UP)); |
|
281 |
map.put(new Actions(Actions.SHRINK_UP)); |
|
282 |
map.put(new Actions(Actions.DOWN)); |
|
283 |
map.put(new Actions(Actions.SHRINK_DOWN)); |
|
284 |
map.put(new Actions(Actions.ESCAPE)); |
|
285 |
map.put(new Actions(Actions.MINIMIZE)); |
|
286 |
map.put(new Actions(Actions.MAXIMIZE)); |
|
287 |
map.put(new Actions(Actions.NEXT_FRAME)); |
|
288 |
map.put(new Actions(Actions.PREVIOUS_FRAME)); |
|
289 |
map.put(new Actions(Actions.NAVIGATE_NEXT)); |
|
290 |
map.put(new Actions(Actions.NAVIGATE_PREVIOUS)); |
|
291 |
} |
|
292 |
||
25761
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
293 |
/** |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
294 |
* Unregisters keyboard actions. |
c408b10ef757
8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents:
23697
diff
changeset
|
295 |
*/ |
2 | 296 |
protected void uninstallKeyboardActions(){ |
297 |
unregisterKeyboardActions(); |
|
298 |
SwingUtilities.replaceUIInputMap(desktop, JComponent. |
|
299 |
WHEN_IN_FOCUSED_WINDOW, null); |
|
300 |
SwingUtilities.replaceUIInputMap(desktop, JComponent. |
|
301 |
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); |
|
302 |
SwingUtilities.replaceUIActionMap(desktop, null); |
|
303 |
} |
|
304 |
||
305 |
public void paint(Graphics g, JComponent c) {} |
|
306 |
||
307 |
public Dimension getPreferredSize(JComponent c) {return null;} |
|
308 |
||
309 |
public Dimension getMinimumSize(JComponent c) { |
|
310 |
return minSize; |
|
311 |
} |
|
312 |
public Dimension getMaximumSize(JComponent c){ |
|
313 |
return maxSize; |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Returns the <code>PropertyChangeListener</code> to install on |
|
318 |
* the <code>JDesktopPane</code>. |
|
319 |
* |
|
320 |
* @since 1.5 |
|
321 |
* @return The PropertyChangeListener that will be added to track |
|
322 |
* changes in the desktop pane. |
|
323 |
*/ |
|
324 |
protected PropertyChangeListener createPropertyChangeListener() { |
|
325 |
return getHandler(); |
|
326 |
} |
|
327 |
||
328 |
private Handler getHandler() { |
|
329 |
if (handler == null) { |
|
330 |
handler = new Handler(); |
|
331 |
} |
|
332 |
return handler; |
|
333 |
} |
|
334 |
||
335 |
private class Handler implements PropertyChangeListener { |
|
336 |
public void propertyChange(PropertyChangeEvent evt) { |
|
337 |
String propertyName = evt.getPropertyName(); |
|
338 |
if ("desktopManager" == propertyName) { |
|
339 |
installDesktopManager(); |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
/** |
|
345 |
* The default DesktopManager installed by the UI. |
|
346 |
*/ |
|
23697 | 347 |
@SuppressWarnings("serial") // JDK-implementation class |
2 | 348 |
private class BasicDesktopManager extends DefaultDesktopManager |
349 |
implements UIResource { |
|
350 |
} |
|
351 |
||
352 |
private static class Actions extends UIAction { |
|
353 |
private static String CLOSE = "close"; |
|
354 |
private static String ESCAPE = "escape"; |
|
355 |
private static String MAXIMIZE = "maximize"; |
|
356 |
private static String MINIMIZE = "minimize"; |
|
357 |
private static String MOVE = "move"; |
|
358 |
private static String RESIZE = "resize"; |
|
359 |
private static String RESTORE = "restore"; |
|
360 |
private static String LEFT = "left"; |
|
361 |
private static String RIGHT = "right"; |
|
362 |
private static String UP = "up"; |
|
363 |
private static String DOWN = "down"; |
|
364 |
private static String SHRINK_LEFT = "shrinkLeft"; |
|
365 |
private static String SHRINK_RIGHT = "shrinkRight"; |
|
366 |
private static String SHRINK_UP = "shrinkUp"; |
|
367 |
private static String SHRINK_DOWN = "shrinkDown"; |
|
368 |
private static String NEXT_FRAME = "selectNextFrame"; |
|
369 |
private static String PREVIOUS_FRAME = "selectPreviousFrame"; |
|
370 |
private static String NAVIGATE_NEXT = "navigateNext"; |
|
371 |
private static String NAVIGATE_PREVIOUS = "navigatePrevious"; |
|
372 |
private final int MOVE_RESIZE_INCREMENT = 10; |
|
373 |
private static boolean moving = false; |
|
374 |
private static boolean resizing = false; |
|
375 |
private static JInternalFrame sourceFrame = null; |
|
376 |
private static Component focusOwner = null; |
|
377 |
||
378 |
Actions() { |
|
379 |
super(null); |
|
380 |
} |
|
381 |
||
382 |
Actions(String name) { |
|
383 |
super(name); |
|
384 |
} |
|
385 |
||
386 |
public void actionPerformed(ActionEvent e) { |
|
387 |
JDesktopPane dp = (JDesktopPane)e.getSource(); |
|
388 |
String key = getName(); |
|
389 |
||
390 |
if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key || |
|
391 |
RESTORE == key) { |
|
392 |
setState(dp, key); |
|
393 |
} |
|
394 |
else if (ESCAPE == key) { |
|
395 |
if (sourceFrame == dp.getSelectedFrame() && |
|
396 |
focusOwner != null) { |
|
397 |
focusOwner.requestFocus(); |
|
398 |
} |
|
399 |
moving = false; |
|
400 |
resizing = false; |
|
401 |
sourceFrame = null; |
|
402 |
focusOwner = null; |
|
403 |
} |
|
404 |
else if (MOVE == key || RESIZE == key) { |
|
405 |
sourceFrame = dp.getSelectedFrame(); |
|
406 |
if (sourceFrame == null) { |
|
407 |
return; |
|
408 |
} |
|
409 |
moving = (key == MOVE) ? true : false; |
|
410 |
resizing = (key == RESIZE) ? true : false; |
|
411 |
||
412 |
focusOwner = KeyboardFocusManager. |
|
413 |
getCurrentKeyboardFocusManager().getFocusOwner(); |
|
414 |
if (!SwingUtilities.isDescendingFrom(focusOwner, sourceFrame)) { |
|
415 |
focusOwner = null; |
|
416 |
} |
|
417 |
sourceFrame.requestFocus(); |
|
418 |
} |
|
419 |
else if (LEFT == key || |
|
420 |
RIGHT == key || |
|
421 |
UP == key || |
|
422 |
DOWN == key || |
|
423 |
SHRINK_RIGHT == key || |
|
424 |
SHRINK_LEFT == key || |
|
425 |
SHRINK_UP == key || |
|
426 |
SHRINK_DOWN == key) { |
|
427 |
JInternalFrame c = dp.getSelectedFrame(); |
|
428 |
if (sourceFrame == null || c != sourceFrame || |
|
429 |
KeyboardFocusManager. |
|
430 |
getCurrentKeyboardFocusManager().getFocusOwner() != |
|
431 |
sourceFrame) { |
|
432 |
return; |
|
433 |
} |
|
434 |
Insets minOnScreenInsets = |
|
435 |
UIManager.getInsets("Desktop.minOnScreenInsets"); |
|
436 |
Dimension size = c.getSize(); |
|
437 |
Dimension minSize = c.getMinimumSize(); |
|
438 |
int dpWidth = dp.getWidth(); |
|
439 |
int dpHeight = dp.getHeight(); |
|
440 |
int delta; |
|
441 |
Point loc = c.getLocation(); |
|
442 |
if (LEFT == key) { |
|
443 |
if (moving) { |
|
444 |
c.setLocation( |
|
445 |
loc.x + size.width - MOVE_RESIZE_INCREMENT < |
|
446 |
minOnScreenInsets.right ? |
|
447 |
-size.width + minOnScreenInsets.right : |
|
448 |
loc.x - MOVE_RESIZE_INCREMENT, |
|
449 |
loc.y); |
|
450 |
} else if (resizing) { |
|
451 |
c.setLocation(loc.x - MOVE_RESIZE_INCREMENT, loc.y); |
|
452 |
c.setSize(size.width + MOVE_RESIZE_INCREMENT, |
|
453 |
size.height); |
|
454 |
} |
|
455 |
} else if (RIGHT == key) { |
|
456 |
if (moving) { |
|
457 |
c.setLocation( |
|
458 |
loc.x + MOVE_RESIZE_INCREMENT > |
|
459 |
dpWidth - minOnScreenInsets.left ? |
|
460 |
dpWidth - minOnScreenInsets.left : |
|
461 |
loc.x + MOVE_RESIZE_INCREMENT, |
|
462 |
loc.y); |
|
463 |
} else if (resizing) { |
|
464 |
c.setSize(size.width + MOVE_RESIZE_INCREMENT, |
|
465 |
size.height); |
|
466 |
} |
|
467 |
} else if (UP == key) { |
|
468 |
if (moving) { |
|
469 |
c.setLocation(loc.x, |
|
470 |
loc.y + size.height - MOVE_RESIZE_INCREMENT < |
|
471 |
minOnScreenInsets.bottom ? |
|
472 |
-size.height + |
|
473 |
minOnScreenInsets.bottom : |
|
474 |
loc.y - MOVE_RESIZE_INCREMENT); |
|
475 |
} else if (resizing) { |
|
476 |
c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT); |
|
477 |
c.setSize(size.width, |
|
478 |
size.height + MOVE_RESIZE_INCREMENT); |
|
479 |
} |
|
480 |
} else if (DOWN == key) { |
|
481 |
if (moving) { |
|
482 |
c.setLocation(loc.x, |
|
483 |
loc.y + MOVE_RESIZE_INCREMENT > |
|
484 |
dpHeight - minOnScreenInsets.top ? |
|
485 |
dpHeight - minOnScreenInsets.top : |
|
486 |
loc.y + MOVE_RESIZE_INCREMENT); |
|
487 |
} else if (resizing) { |
|
488 |
c.setSize(size.width, |
|
489 |
size.height + MOVE_RESIZE_INCREMENT); |
|
490 |
} |
|
491 |
} else if (SHRINK_LEFT == key && resizing) { |
|
492 |
// Make sure we don't resize less than minimum size. |
|
493 |
if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { |
|
494 |
delta = MOVE_RESIZE_INCREMENT; |
|
495 |
} else { |
|
496 |
delta = size.width - minSize.width; |
|
497 |
} |
|
498 |
||
499 |
// Ensure that we keep the internal frame on the desktop. |
|
500 |
if (loc.x + size.width - delta < minOnScreenInsets.left) { |
|
501 |
delta = loc.x + size.width - minOnScreenInsets.left; |
|
502 |
} |
|
503 |
c.setSize(size.width - delta, size.height); |
|
504 |
} else if (SHRINK_RIGHT == key && resizing) { |
|
505 |
// Make sure we don't resize less than minimum size. |
|
506 |
if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { |
|
507 |
delta = MOVE_RESIZE_INCREMENT; |
|
508 |
} else { |
|
509 |
delta = size.width - minSize.width; |
|
510 |
} |
|
511 |
||
512 |
// Ensure that we keep the internal frame on the desktop. |
|
513 |
if (loc.x + delta > dpWidth - minOnScreenInsets.right) { |
|
514 |
delta = (dpWidth - minOnScreenInsets.right) - loc.x; |
|
515 |
} |
|
516 |
||
517 |
c.setLocation(loc.x + delta, loc.y); |
|
518 |
c.setSize(size.width - delta, size.height); |
|
519 |
} else if (SHRINK_UP == key && resizing) { |
|
520 |
// Make sure we don't resize less than minimum size. |
|
521 |
if (minSize.height < |
|
522 |
(size.height - MOVE_RESIZE_INCREMENT)) { |
|
523 |
delta = MOVE_RESIZE_INCREMENT; |
|
524 |
} else { |
|
525 |
delta = size.height - minSize.height; |
|
526 |
} |
|
527 |
||
528 |
// Ensure that we keep the internal frame on the desktop. |
|
529 |
if (loc.y + size.height - delta < |
|
530 |
minOnScreenInsets.bottom) { |
|
531 |
delta = loc.y + size.height - minOnScreenInsets.bottom; |
|
532 |
} |
|
533 |
||
534 |
c.setSize(size.width, size.height - delta); |
|
535 |
} else if (SHRINK_DOWN == key && resizing) { |
|
536 |
// Make sure we don't resize less than minimum size. |
|
537 |
if (minSize.height < |
|
538 |
(size.height - MOVE_RESIZE_INCREMENT)) { |
|
539 |
delta = MOVE_RESIZE_INCREMENT; |
|
540 |
} else { |
|
541 |
delta = size.height - minSize.height; |
|
542 |
} |
|
543 |
||
544 |
// Ensure that we keep the internal frame on the desktop. |
|
545 |
if (loc.y + delta > dpHeight - minOnScreenInsets.top) { |
|
546 |
delta = (dpHeight - minOnScreenInsets.top) - loc.y; |
|
547 |
} |
|
548 |
||
549 |
c.setLocation(loc.x, loc.y + delta); |
|
550 |
c.setSize(size.width, size.height - delta); |
|
551 |
} |
|
552 |
} |
|
553 |
else if (NEXT_FRAME == key || PREVIOUS_FRAME == key) { |
|
554 |
dp.selectFrame((key == NEXT_FRAME) ? true : false); |
|
555 |
} |
|
556 |
else if (NAVIGATE_NEXT == key || |
|
557 |
NAVIGATE_PREVIOUS == key) { |
|
558 |
boolean moveForward = true; |
|
559 |
if (NAVIGATE_PREVIOUS == key) { |
|
560 |
moveForward = false; |
|
561 |
} |
|
562 |
Container cycleRoot = dp.getFocusCycleRootAncestor(); |
|
563 |
||
564 |
if (cycleRoot != null) { |
|
565 |
FocusTraversalPolicy policy = |
|
566 |
cycleRoot.getFocusTraversalPolicy(); |
|
567 |
if (policy != null && policy instanceof |
|
568 |
SortingFocusTraversalPolicy) { |
|
569 |
SortingFocusTraversalPolicy sPolicy = |
|
570 |
(SortingFocusTraversalPolicy)policy; |
|
571 |
boolean idc = sPolicy.getImplicitDownCycleTraversal(); |
|
572 |
try { |
|
573 |
sPolicy.setImplicitDownCycleTraversal(false); |
|
574 |
if (moveForward) { |
|
575 |
KeyboardFocusManager. |
|
576 |
getCurrentKeyboardFocusManager(). |
|
577 |
focusNextComponent(dp); |
|
578 |
} else { |
|
579 |
KeyboardFocusManager. |
|
580 |
getCurrentKeyboardFocusManager(). |
|
581 |
focusPreviousComponent(dp); |
|
582 |
} |
|
583 |
} finally { |
|
584 |
sPolicy.setImplicitDownCycleTraversal(idc); |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
} |
|
589 |
} |
|
590 |
||
591 |
private void setState(JDesktopPane dp, String state) { |
|
592 |
if (state == CLOSE) { |
|
593 |
JInternalFrame f = dp.getSelectedFrame(); |
|
594 |
if (f == null) { |
|
595 |
return; |
|
596 |
} |
|
597 |
f.doDefaultCloseAction(); |
|
598 |
} else if (state == MAXIMIZE) { |
|
599 |
// maximize the selected frame |
|
600 |
JInternalFrame f = dp.getSelectedFrame(); |
|
601 |
if (f == null) { |
|
602 |
return; |
|
603 |
} |
|
604 |
if (!f.isMaximum()) { |
|
605 |
if (f.isIcon()) { |
|
606 |
try { |
|
607 |
f.setIcon(false); |
|
608 |
f.setMaximum(true); |
|
609 |
} catch (PropertyVetoException pve) {} |
|
610 |
} else { |
|
611 |
try { |
|
612 |
f.setMaximum(true); |
|
613 |
} catch (PropertyVetoException pve) { |
|
614 |
} |
|
615 |
} |
|
616 |
} |
|
617 |
} else if (state == MINIMIZE) { |
|
618 |
// minimize the selected frame |
|
619 |
JInternalFrame f = dp.getSelectedFrame(); |
|
620 |
if (f == null) { |
|
621 |
return; |
|
622 |
} |
|
623 |
if (!f.isIcon()) { |
|
624 |
try { |
|
625 |
f.setIcon(true); |
|
626 |
} catch (PropertyVetoException pve) { |
|
627 |
} |
|
628 |
} |
|
629 |
} else if (state == RESTORE) { |
|
630 |
// restore the selected minimized or maximized frame |
|
631 |
JInternalFrame f = dp.getSelectedFrame(); |
|
632 |
if (f == null) { |
|
633 |
return; |
|
634 |
} |
|
635 |
try { |
|
636 |
if (f.isIcon()) { |
|
637 |
f.setIcon(false); |
|
638 |
} else if (f.isMaximum()) { |
|
639 |
f.setMaximum(false); |
|
640 |
} |
|
641 |
f.setSelected(true); |
|
642 |
} catch (PropertyVetoException pve) { |
|
643 |
} |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
public boolean isEnabled(Object sender) { |
|
648 |
if (sender instanceof JDesktopPane) { |
|
649 |
JDesktopPane dp = (JDesktopPane)sender; |
|
650 |
String action = getName(); |
|
651 |
if (action == Actions.NEXT_FRAME || |
|
652 |
action == Actions.PREVIOUS_FRAME) { |
|
653 |
return true; |
|
654 |
} |
|
655 |
JInternalFrame iFrame = dp.getSelectedFrame(); |
|
656 |
if (iFrame == null) { |
|
657 |
return false; |
|
658 |
} else if (action == Actions.CLOSE) { |
|
659 |
return iFrame.isClosable(); |
|
660 |
} else if (action == Actions.MINIMIZE) { |
|
661 |
return iFrame.isIconifiable(); |
|
662 |
} else if (action == Actions.MAXIMIZE) { |
|
663 |
return iFrame.isMaximizable(); |
|
664 |
} |
|
665 |
return true; |
|
666 |
} |
|
667 |
return false; |
|
668 |
} |
|
669 |
} |
|
670 |
||
671 |
||
672 |
/** |
|
673 |
* Handles restoring a minimized or maximized internal frame. |
|
674 |
* @since 1.3 |
|
675 |
*/ |
|
23697 | 676 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 677 |
protected class OpenAction extends AbstractAction { |
678 |
public void actionPerformed(ActionEvent evt) { |
|
679 |
JDesktopPane dp = (JDesktopPane)evt.getSource(); |
|
680 |
SHARED_ACTION.setState(dp, Actions.RESTORE); |
|
681 |
} |
|
682 |
||
683 |
public boolean isEnabled() { |
|
684 |
return true; |
|
685 |
} |
|
686 |
} |
|
687 |
||
688 |
/** |
|
689 |
* Handles closing an internal frame. |
|
690 |
*/ |
|
23697 | 691 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 692 |
protected class CloseAction extends AbstractAction { |
693 |
public void actionPerformed(ActionEvent evt) { |
|
694 |
JDesktopPane dp = (JDesktopPane)evt.getSource(); |
|
695 |
SHARED_ACTION.setState(dp, Actions.CLOSE); |
|
696 |
} |
|
697 |
||
698 |
public boolean isEnabled() { |
|
699 |
JInternalFrame iFrame = desktop.getSelectedFrame(); |
|
700 |
if (iFrame != null) { |
|
701 |
return iFrame.isClosable(); |
|
702 |
} |
|
703 |
return false; |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
/** |
|
708 |
* Handles minimizing an internal frame. |
|
709 |
*/ |
|
23697 | 710 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 711 |
protected class MinimizeAction extends AbstractAction { |
712 |
public void actionPerformed(ActionEvent evt) { |
|
713 |
JDesktopPane dp = (JDesktopPane)evt.getSource(); |
|
714 |
SHARED_ACTION.setState(dp, Actions.MINIMIZE); |
|
715 |
} |
|
716 |
||
717 |
public boolean isEnabled() { |
|
718 |
JInternalFrame iFrame = desktop.getSelectedFrame(); |
|
719 |
if (iFrame != null) { |
|
720 |
return iFrame.isIconifiable(); |
|
721 |
} |
|
722 |
return false; |
|
723 |
} |
|
724 |
} |
|
725 |
||
726 |
/** |
|
727 |
* Handles maximizing an internal frame. |
|
728 |
*/ |
|
23697 | 729 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 730 |
protected class MaximizeAction extends AbstractAction { |
731 |
public void actionPerformed(ActionEvent evt) { |
|
732 |
JDesktopPane dp = (JDesktopPane)evt.getSource(); |
|
733 |
SHARED_ACTION.setState(dp, Actions.MAXIMIZE); |
|
734 |
} |
|
735 |
||
736 |
public boolean isEnabled() { |
|
737 |
JInternalFrame iFrame = desktop.getSelectedFrame(); |
|
738 |
if (iFrame != null) { |
|
739 |
return iFrame.isMaximizable(); |
|
740 |
} |
|
741 |
return false; |
|
742 |
} |
|
743 |
} |
|
744 |
||
745 |
/** |
|
746 |
* Handles navigating to the next internal frame. |
|
747 |
*/ |
|
23697 | 748 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 749 |
protected class NavigateAction extends AbstractAction { |
750 |
public void actionPerformed(ActionEvent evt) { |
|
751 |
JDesktopPane dp = (JDesktopPane)evt.getSource(); |
|
752 |
dp.selectFrame(true); |
|
753 |
} |
|
754 |
||
755 |
public boolean isEnabled() { |
|
756 |
return true; |
|
757 |
} |
|
758 |
} |
|
759 |
} |