src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameUI.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) 1997, 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 package com.sun.java.swing.plaf.windows;
       
    27 
       
    28 import java.awt.*;
       
    29 import java.beans.*;
       
    30 import javax.swing.*;
       
    31 import javax.swing.border.*;
       
    32 import javax.swing.plaf.basic.*;
       
    33 import javax.swing.plaf.ComponentUI;
       
    34 
       
    35 import static com.sun.java.swing.plaf.windows.TMSchema.*;
       
    36 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
       
    37 
       
    38 /**
       
    39  * Windows rendition of the component.
       
    40  * <p>
       
    41  * <strong>Warning:</strong>
       
    42  * Serialized objects of this class will not be compatible with
       
    43  * future Swing releases.  The current serialization support is appropriate
       
    44  * for short term storage or RMI between applications running the same
       
    45  * version of Swing.  A future release of Swing will provide support for
       
    46  * long term persistence.
       
    47  */
       
    48 public class WindowsInternalFrameUI extends BasicInternalFrameUI
       
    49 {
       
    50     XPStyle xp = XPStyle.getXP();
       
    51 
       
    52     public void installDefaults() {
       
    53         super.installDefaults();
       
    54 
       
    55         if (xp != null) {
       
    56             frame.setBorder(new XPBorder());
       
    57         } else {
       
    58             frame.setBorder(UIManager.getBorder("InternalFrame.border"));
       
    59         }
       
    60     }
       
    61 
       
    62     public void installUI(JComponent c)   {
       
    63         super.installUI(c);
       
    64 
       
    65         LookAndFeel.installProperty(c, "opaque",
       
    66                                     xp == null? Boolean.TRUE : Boolean.FALSE);
       
    67     }
       
    68 
       
    69     public void uninstallDefaults() {
       
    70         frame.setBorder(null);
       
    71         super.uninstallDefaults();
       
    72     }
       
    73 
       
    74     public static ComponentUI createUI(JComponent b)    {
       
    75         return new WindowsInternalFrameUI((JInternalFrame)b);
       
    76     }
       
    77 
       
    78     public WindowsInternalFrameUI(JInternalFrame w){
       
    79         super(w);
       
    80     }
       
    81 
       
    82     protected DesktopManager createDesktopManager(){
       
    83         return new WindowsDesktopManager();
       
    84     }
       
    85 
       
    86     protected JComponent createNorthPane(JInternalFrame w) {
       
    87         titlePane = new WindowsInternalFrameTitlePane(w);
       
    88         return titlePane;
       
    89     }
       
    90 
       
    91     @SuppressWarnings("serial") // Superclass is not serializable across versions
       
    92     private class XPBorder extends AbstractBorder {
       
    93         private Skin leftSkin   = xp.getSkin(frame, Part.WP_FRAMELEFT);
       
    94         private Skin rightSkin  = xp.getSkin(frame, Part.WP_FRAMERIGHT);
       
    95         private Skin bottomSkin = xp.getSkin(frame, Part.WP_FRAMEBOTTOM);
       
    96 
       
    97         /**
       
    98          * @param x the x position of the painted border
       
    99          * @param y the y position of the painted border
       
   100          * @param width the width of the painted border
       
   101          * @param height the height of the painted border
       
   102          */
       
   103         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
       
   104             State state = ((JInternalFrame)c).isSelected() ? State.ACTIVE : State.INACTIVE;
       
   105             int topBorderHeight  = (titlePane != null) ? titlePane.getSize().height : 0;
       
   106 
       
   107             bottomSkin.paintSkin(g, 0, height-bottomSkin.getHeight(),
       
   108                                  width, bottomSkin.getHeight(),
       
   109                                  state);
       
   110 
       
   111             leftSkin.paintSkin(g, 0, topBorderHeight-1,
       
   112                                leftSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
       
   113                                state);
       
   114 
       
   115             rightSkin.paintSkin(g, width-rightSkin.getWidth(), topBorderHeight-1,
       
   116                                 rightSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
       
   117                                 state);
       
   118 
       
   119         }
       
   120 
       
   121         public Insets getBorderInsets(Component c, Insets insets) {
       
   122             insets.top    = 4;
       
   123             insets.left   = leftSkin.getWidth();
       
   124             insets.right  = rightSkin.getWidth();
       
   125             insets.bottom = bottomSkin.getHeight();
       
   126 
       
   127             return insets;
       
   128         }
       
   129 
       
   130         public boolean isBorderOpaque() {
       
   131             return true;
       
   132         }
       
   133     }
       
   134 
       
   135 }