jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java
author darcy
Mon, 10 Mar 2014 13:54:25 -0700
changeset 23632 cd7a34d12e8c
parent 23010 6dadb192ad81
child 25135 cd4631f0afdc
permissions -rw-r--r--
8033908: Fix serial lint warnings in com.sun.java.swing.plaf Reviewed-by: serb, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21259
diff changeset
     2
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.UIManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static com.sun.java.swing.plaf.windows.TMSchema.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
    44
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private Color selectedTitleGradientColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private Color notSelectedTitleGradientColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private JPopupMenu systemPopupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private JLabel systemLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private Font titleFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int titlePaneHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int buttonWidth, buttonHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private boolean hotTrackingOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public WindowsInternalFrameTitlePane(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected void addSubComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        add(systemLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        add(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        add(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        titlePaneHeight = UIManager.getInt("InternalFrame.titlePaneHeight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        buttonWidth     = UIManager.getInt("InternalFrame.titleButtonWidth")  - 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        buttonHeight    = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Object obj      = UIManager.get("InternalFrame.titleButtonToolTipsOn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            // Fix for XP bug where sometimes these sizes aren't updated properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            // Assume for now that height is correct and derive width using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            // ratio from the uxtheme part
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            buttonWidth = buttonHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (d != null && d.width != 0 && d.height != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                buttonWidth = (int) ((float) buttonWidth * d.width / d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            buttonWidth += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            selectedTitleGradientColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    UIManager.getColor("InternalFrame.activeTitleGradient");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            notSelectedTitleGradientColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    UIManager.getColor("InternalFrame.inactiveTitleGradient");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            Color activeBorderColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    UIManager.getColor("InternalFrame.activeBorderColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            setBorder(BorderFactory.createLineBorder(activeBorderColor, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // Get around protected method in superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected void createButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        super.createButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            iconButton.setContentAreaFilled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            maxButton.setContentAreaFilled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            closeButton.setContentAreaFilled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected void setButtonIcons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super.setButtonIcons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (!hotTrackingOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            iconButton.setToolTipText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            maxButton.setToolTipText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            closeButton.setToolTipText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void paintComponent(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        paintTitleBackground(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Font oldFont = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            Font newFont = (titleFont != null) ? titleFont : getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            g.setFont(newFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // Center text vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, newFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    fm.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   141
            Rectangle lastIconBounds = new Rectangle(0, 0, 0, 0);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   142
            if (frame.isIconifiable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   143
                lastIconBounds = iconButton.getBounds();
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   144
            } else if (frame.isMaximizable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   145
                lastIconBounds = maxButton.getBounds();
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   146
            } else if (frame.isClosable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   147
                lastIconBounds = closeButton.getBounds();
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   148
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   150
            int titleX;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   151
            int titleW;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   152
            int gap = 2;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   153
            if (WindowsGraphicsUtils.isLeftToRight(frame)) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   154
                if (lastIconBounds.x == 0) { // There are no icons
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   155
                    lastIconBounds.x = frame.getWidth() - frame.getInsets().right;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   156
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   157
                titleX = systemLabel.getX() + systemLabel.getWidth() + gap;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   158
                if (xp != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   159
                    titleX += 2;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   160
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   161
                titleW = lastIconBounds.x - titleX - gap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            } else {
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   163
                if (lastIconBounds.x == 0) { // There are no icons
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   164
                    lastIconBounds.x = frame.getInsets().left;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   165
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   166
                titleW = SwingUtilities2.stringWidth(frame, fm, title);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   167
                int minTitleX = lastIconBounds.x + lastIconBounds.width + gap;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   168
                if (xp != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   169
                    minTitleX += 2;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   170
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   171
                int availableWidth = systemLabel.getX() - gap - minTitleX;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   172
                if (availableWidth > titleW) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   173
                    titleX = systemLabel.getX() - gap - titleW;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   174
                } else {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   175
                    titleX = minTitleX;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   176
                    titleW = availableWidth;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   177
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   179
            title = getTitle(frame.getTitle(), fm, titleW);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   180
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                String shadowType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    shadowType = xp.getString(this, Part.WP_CAPTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                              State.ACTIVE, Prop.TEXTSHADOWTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                if ("single".equalsIgnoreCase(shadowType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    Point shadowOffset = xp.getPoint(this, Part.WP_WINDOW, State.ACTIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                                     Prop.TEXTSHADOWOFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    Color shadowColor  = xp.getColor(this, Part.WP_WINDOW, State.ACTIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                     Prop.TEXTSHADOWCOLOR, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    if (shadowOffset != null && shadowColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        g.setColor(shadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        SwingUtilities2.drawString(frame, g, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                     titleX + shadowOffset.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                     baseline + shadowOffset.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            g.setColor(isSelected ? selectedTextColor : notSelectedTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            SwingUtilities2.drawString(frame, g, title, titleX, baseline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            g.setFont(oldFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        Dimension d = new Dimension(super.getMinimumSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        d.height = titlePaneHeight + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // Note: Don't know how to calculate height on XP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // the captionbarheight is 25 but native caption is 30 (maximized 26)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                d.height -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                d.height += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    protected void paintTitleBackground(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Part part = frame.isIcon() ? Part.WP_MINCAPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                       : (frame.isMaximum() ? Part.WP_MAXCAPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                                            : Part.WP_CAPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            State state = frame.isSelected() ? State.ACTIVE : State.INACTIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Skin skin = xp.getSkin(this, part);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            skin.paintSkin(g, 0,  0, getWidth(), getHeight(), state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Boolean gradientsOn = (Boolean)LookAndFeel.getDesktopPropertyValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                "win.frame.captionGradientsOn", Boolean.valueOf(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (gradientsOn.booleanValue() && g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                Paint savePaint = g2.getPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    GradientPaint titleGradient = new GradientPaint(0,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            selectedTitleColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            (int)(w*.75),0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            selectedTitleGradientColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    g2.setPaint(titleGradient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    GradientPaint titleGradient = new GradientPaint(0,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                            notSelectedTitleColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            (int)(w*.75),0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            notSelectedTitleGradientColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    g2.setPaint(titleGradient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                g2.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                g2.setPaint(savePaint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                super.paintTitleBackground(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    protected void assembleSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        systemPopupMenu = new JPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        addSystemMenuItems(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        enableActions();
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
   271
        @SuppressWarnings("serial") // anonymous class
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
   272
        JLabel tmp = new JLabel(frame.getFrameIcon()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                int h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                g = g.create();  // Create scratch graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                Icon icon = getIcon();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   284
                int iconWidth;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   285
                int iconHeight;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (icon != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    (iconWidth = icon.getIconWidth()) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    (iconHeight = icon.getIconHeight()) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    // Set drawing scale to make icon scale to our desired size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    double drawScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    if (iconWidth > iconHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        // Center icon vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        y = (h - w*iconHeight/iconWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        drawScale = w / (double)iconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        // Center icon horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        x = (w - h*iconWidth/iconHeight) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        drawScale = h / (double)iconHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    ((Graphics2D)g).translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    ((Graphics2D)g).scale(drawScale, drawScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    icon.paintIcon(this, g, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        };
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
   308
        systemLabel = tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        systemLabel.addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                if (e.getClickCount() == 2 && frame.isClosable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    !frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    systemPopupMenu.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    frame.doDefaultCloseAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    super.mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    frame.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                } catch(PropertyVetoException pve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                showSystemPopupMenu(e.getComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    protected void addSystemMenuItems(JPopupMenu menu) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   331
        JMenuItem mi = menu.add(restoreAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   332
        mi.setMnemonic(getButtonMnemonic("restore"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   333
        mi = menu.add(moveAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   334
        mi.setMnemonic(getButtonMnemonic("move"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   335
        mi = menu.add(sizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   336
        mi.setMnemonic(getButtonMnemonic("size"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   337
        mi = menu.add(iconifyAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   338
        mi.setMnemonic(getButtonMnemonic("minimize"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   339
        mi = menu.add(maximizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   340
        mi.setMnemonic(getButtonMnemonic("maximize"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   341
        menu.add(new JSeparator());
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   342
        mi = menu.add(closeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   343
        mi.setMnemonic(getButtonMnemonic("close"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   344
    }
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   345
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   346
    private static int getButtonMnemonic(String button) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   347
        try {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   348
            return Integer.parseInt(UIManager.getString(
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   349
                    "InternalFrameTitlePane." + button + "Button.mnemonic"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   350
        } catch (NumberFormatException e) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   351
            return -1;
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   352
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    protected void showSystemMenu(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        showSystemPopupMenu(systemLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private void showSystemPopupMenu(Component invoker){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Dimension dim = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        Border border = frame.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            dim.width += border.getBorderInsets(frame).left +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                border.getBorderInsets(frame).right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            dim.height += border.getBorderInsets(frame).bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                border.getBorderInsets(frame).top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (!frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            systemPopupMenu.show(invoker,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                getX() - dim.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                getY() + getHeight() - dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            systemPopupMenu.show(invoker,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                getX() - dim.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                getY() - systemPopupMenu.getPreferredSize().height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                     dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return new WindowsPropertyChangeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return new WindowsTitlePaneLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public class WindowsTitlePaneLayout extends BasicInternalFrameTitlePane.TitlePaneLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        private Insets captionMargin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        private Insets contentMargin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        private XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        WindowsTitlePaneLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                Component c = WindowsInternalFrameTitlePane.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                captionMargin = xp.getMargin(c, Part.WP_CAPTION, null, Prop.CAPTIONMARGINS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                contentMargin = xp.getMargin(c, Part.WP_CAPTION, null, Prop.CONTENTMARGINS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (captionMargin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                captionMargin = new Insets(0, 2, 0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (contentMargin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                contentMargin = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        private int layoutButton(JComponent button, Part part,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                                 int x, int y, int w, int h, int gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                 boolean leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (!leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            button.setBounds(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                x += w + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                x -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            boolean leftToRight = WindowsGraphicsUtils.isLeftToRight(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            int x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            int h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            // System button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            // Note: this icon is square, but the buttons aren't always.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            int iconSize = (xp != null) ? (h-2)*6/10 : h-4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                x = (leftToRight) ? captionMargin.left + 2 : w - captionMargin.right - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                x = (leftToRight) ? captionMargin.left : w - captionMargin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            y = (h - iconSize) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            layoutButton(systemLabel, Part.WP_SYSBUTTON,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                         x, y, iconSize, iconSize, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                         leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            // Right hand buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                x = (leftToRight) ? w - captionMargin.right - 2 : captionMargin.left + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                y = 1;  // XP seems to ignore margins and offset here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    y += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                x = (leftToRight) ? w - captionMargin.right : captionMargin.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                y = (h - buttonHeight) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if(frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                x = layoutButton(closeButton, Part.WP_CLOSEBUTTON,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                 x, y, buttonWidth, buttonHeight, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                 !leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if(frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                x = layoutButton(maxButton, Part.WP_MAXBUTTON,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                 x, y, buttonWidth, buttonHeight, (xp != null) ? 2 : 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                 !leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if(frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                layoutButton(iconButton, Part.WP_MINBUTTON,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                             x, y, buttonWidth, buttonHeight, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                             !leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    } // end WindowsTitlePaneLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public class WindowsPropertyChangeHandler extends PropertyChangeHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        public void propertyChange(PropertyChangeEvent evt) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   477
            String prop = evt.getPropertyName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // Update the internal frame icon for the system menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    systemLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                systemLabel.setIcon(frame.getFrameIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            super.propertyChange(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * A versatile Icon implementation which can take an array of Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * instances (typically <code>ImageIcon</code>s) and choose one that gives the best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * quality for a given Graphics2D scale factor when painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * The class is public so it can be instantiated by UIDefaults.ProxyLazyValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Note: We assume here that icons are square.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public static class ScalableIconUIResource implements Icon, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // We can use an arbitrary size here because we scale to it in paintIcon()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        private static final int SIZE = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        private Icon[] icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * @params objects an array of Icon or UIDefaults.LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * The constructor is public so it can be called by UIDefaults.ProxyLazyValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public ScalableIconUIResource(Object[] objects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            this.icons = new Icon[objects.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            for (int i = 0; i < objects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                if (objects[i] instanceof UIDefaults.LazyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    icons[i] = (Icon)((UIDefaults.LazyValue)objects[i]).createValue(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    icons[i] = (Icon)objects[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * @return the <code>Icon</code> closest to the requested size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        protected Icon getBestIcon(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (icons != null && icons.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                int bestIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                int minDiff = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                for (int i=0; i < icons.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    Icon icon = icons[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    int iconSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    if (icon != null && (iconSize = icon.getIconWidth()) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                        int diff = Math.abs(iconSize - size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                        if (diff < minDiff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                            minDiff = diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                            bestIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                return icons[bestIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            Graphics2D g2d = (Graphics2D)g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            // Calculate how big our drawing area is in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            // Assume we are square
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            int size = getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            double scale = g2d.getTransform().getScaleX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            Icon icon = getBestIcon((int)(size * scale));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            int iconSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (icon != null && (iconSize = icon.getIconWidth()) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                // Set drawing scale to make icon act true to our reported size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                double drawScale = size / (double)iconSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                g2d.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                g2d.scale(drawScale, drawScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                icon.paintIcon(c, g2d, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            g2d.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            return SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
}