src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsDesktopManager.java
branchhttp-client-branch
changeset 55982 b6ff245c0db6
parent 55981 907bddce488c
parent 48332 651a95f30dfb
child 55983 e4a1f0c9d4c6
equal deleted inserted replaced
55981:907bddce488c 55982:b6ff245c0db6
     1 /*
       
     2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle 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 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.
       
    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 @SuppressWarnings("serial") // JDK-implementation class
       
    55 public class WindowsDesktopManager extends DefaultDesktopManager
       
    56         implements java.io.Serializable, javax.swing.plaf.UIResource {
       
    57 
       
    58     /* The frame which is currently selected/activated.
       
    59      * We store this value to enforce MDI's single-selection model.
       
    60      */
       
    61     private WeakReference<JInternalFrame> currentFrameRef;
       
    62 
       
    63     public void activateFrame(JInternalFrame f) {
       
    64         JInternalFrame currentFrame = currentFrameRef != null ?
       
    65             currentFrameRef.get() : null;
       
    66         try {
       
    67             super.activateFrame(f);
       
    68             if (currentFrame != null && f != currentFrame) {
       
    69                 // If the current frame is maximized, transfer that
       
    70                 // attribute to the frame being activated.
       
    71                 if (!currentFrame.isClosed() && currentFrame.isMaximum() &&
       
    72                     (f.getClientProperty("JInternalFrame.frameType") !=
       
    73                     "optionDialog") ) {
       
    74                     //Special case.  If key binding was used to select next
       
    75                     //frame instead of minimizing the icon via the minimize
       
    76                     //icon.
       
    77                     if (!currentFrame.isIcon()) {
       
    78                         currentFrame.setMaximum(false);
       
    79                         if (f.isMaximizable()) {
       
    80                             if (!f.isMaximum()) {
       
    81                                 f.setMaximum(true);
       
    82                             } else if (f.isMaximum() && f.isIcon()) {
       
    83                                 f.setIcon(false);
       
    84                             } else {
       
    85                                 f.setMaximum(false);
       
    86                             }
       
    87                         }
       
    88                     }
       
    89                 }
       
    90                 if (currentFrame.isSelected()) {
       
    91                     currentFrame.setSelected(false);
       
    92                 }
       
    93             }
       
    94 
       
    95             if (!f.isSelected()) {
       
    96                 f.setSelected(true);
       
    97             }
       
    98         } catch (PropertyVetoException e) {}
       
    99         if (f != currentFrame) {
       
   100             currentFrameRef = new WeakReference<JInternalFrame>(f);
       
   101         }
       
   102     }
       
   103 
       
   104 }