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