001: /*
002: * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.swing.plaf.windows;
027:
028: import javax.swing.DefaultDesktopManager;
029: import javax.swing.JInternalFrame;
030: import javax.swing.JLayeredPane;
031: import java.awt.Component;
032: import java.awt.Container;
033: import java.awt.Dimension;
034: import java.beans.PropertyVetoException;
035: import java.util.Vector;
036: import java.lang.ref.WeakReference;
037:
038: /**
039: * This class implements a DesktopManager which more closely follows
040: * the MDI model than the DefaultDesktopManager. Unlike the
041: * DefaultDesktopManager policy, MDI requires that the selected
042: * and activated child frames are the same, and that that frame
043: * always be the top-most window.
044: * <p>
045: * The maximized state is managed by the DesktopManager with MDI,
046: * instead of just being a property of the individual child frame.
047: * This means that if the currently selected window is maximized
048: * and another window is selected, that new window will be maximized.
049: *
050: * @see javax.swing.DefaultDesktopManager
051: * @version 1.27 05/05/07
052: * @author Thomas Ball
053: */
054: public class WindowsDesktopManager extends DefaultDesktopManager
055: implements java.io.Serializable, javax.swing.plaf.UIResource {
056:
057: /* The frame which is currently selected/activated.
058: * We store this value to enforce MDI's single-selection model.
059: */
060: private WeakReference<JInternalFrame> currentFrameRef;
061:
062: public void activateFrame(JInternalFrame f) {
063: JInternalFrame currentFrame = currentFrameRef != null ? currentFrameRef
064: .get()
065: : null;
066: try {
067: super .activateFrame(f);
068: if (currentFrame != null && f != currentFrame) {
069: // If the current frame is maximized, transfer that
070: // attribute to the frame being activated.
071: if (currentFrame.isMaximum()
072: && (f
073: .getClientProperty("JInternalFrame.frameType") != "optionDialog")) {
074: //Special case. If key binding was used to select next
075: //frame instead of minimizing the icon via the minimize
076: //icon.
077: if (!currentFrame.isIcon()) {
078: currentFrame.setMaximum(false);
079: if (f.isMaximizable()) {
080: if (!f.isMaximum()) {
081: f.setMaximum(true);
082: } else if (f.isMaximum() && f.isIcon()) {
083: f.setIcon(false);
084: } else {
085: f.setMaximum(false);
086: }
087: }
088: }
089: }
090: if (currentFrame.isSelected()) {
091: currentFrame.setSelected(false);
092: }
093: }
094:
095: if (!f.isSelected()) {
096: f.setSelected(true);
097: }
098: } catch (PropertyVetoException e) {
099: }
100: if (f != currentFrame) {
101: currentFrameRef = new WeakReference(f);
102: }
103: }
104:
105: }
|