J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 27 | package com.sun.java.swing.plaf.windows; |
| 28 | |
| 29 | import javax.swing.DefaultDesktopManager; |
| 30 | import javax.swing.JInternalFrame; |
| 31 | import javax.swing.JLayeredPane; |
| 32 | import java.awt.Component; |
| 33 | import java.awt.Container; |
| 34 | import java.awt.Dimension; |
| 35 | import java.beans.PropertyVetoException; |
| 36 | import java.util.Vector; |
| 37 | import 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 | */ |
| 54 | public 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 | } |