blob: e27ac218e113b6f37908e7e9c8a2f00e15c44c78 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26
27package com.sun.java.swing.plaf.windows;
28
29import javax.swing.DefaultDesktopManager;
30import javax.swing.JInternalFrame;
31import javax.swing.JLayeredPane;
32import java.awt.Component;
33import java.awt.Container;
34import java.awt.Dimension;
35import java.beans.PropertyVetoException;
36import java.util.Vector;
37import java.lang.ref.WeakReference;
38
39/**
40 * This class implements a DesktopManager which more closely follows
41 * the MDI model than the DefaultDesktopManager. Unlike the
42 * DefaultDesktopManager policy, MDI requires that the selected
43 * and activated child frames are the same, and that that frame
44 * always be the top-most window.
45 * <p>
46 * The maximized state is managed by the DesktopManager with MDI,
47 * instead of just being a property of the individual child frame.
48 * This means that if the currently selected window is maximized
49 * and another window is selected, that new window will be maximized.
50 *
51 * @see javax.swing.DefaultDesktopManager
52 * @author Thomas Ball
53 */
54public class WindowsDesktopManager extends DefaultDesktopManager
55 implements java.io.Serializable, javax.swing.plaf.UIResource {
56
57 /* The frame which is currently selected/activated.
58 * We store this value to enforce MDI's single-selection model.
59 */
60 private WeakReference<JInternalFrame> currentFrameRef;
61
62 public void activateFrame(JInternalFrame f) {
63 JInternalFrame currentFrame = currentFrameRef != null ?
64 currentFrameRef.get() : null;
65 try {
66 super.activateFrame(f);
67 if (currentFrame != null && f != currentFrame) {
68 // If the current frame is maximized, transfer that
69 // attribute to the frame being activated.
70 if (currentFrame.isMaximum() &&
71 (f.getClientProperty("JInternalFrame.frameType") !=
72 "optionDialog") ) {
73 //Special case. If key binding was used to select next
74 //frame instead of minimizing the icon via the minimize
75 //icon.
76 if (!currentFrame.isIcon()) {
77 currentFrame.setMaximum(false);
78 if (f.isMaximizable()) {
79 if (!f.isMaximum()) {
80 f.setMaximum(true);
81 } else if (f.isMaximum() && f.isIcon()) {
82 f.setIcon(false);
83 } else {
84 f.setMaximum(false);
85 }
86 }
87 }
88 }
89 if (currentFrame.isSelected()) {
90 currentFrame.setSelected(false);
91 }
92 }
93
94 if (!f.isSelected()) {
95 f.setSelected(true);
96 }
97 } catch (PropertyVetoException e) {}
98 if (f != currentFrame) {
99 currentFrameRef = new WeakReference(f);
100 }
101 }
102
103}