jdk/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 21259 4780cf380d96
child 22574 7f8ce0c8c20a
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     2
 * Copyright (c) 1997, 2008, 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 javax.swing.plaf.basic;
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
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.accessibility.AccessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.InternalFrameEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.beans.VetoableChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The class that manages a basic title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20169
diff changeset
    53
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class BasicInternalFrameTitlePane extends JComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected JMenuBar menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected JButton iconButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected JButton maxButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected JButton closeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected JMenu windowMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected Color selectedTitleColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected Color selectedTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected Color notSelectedTitleColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected Color notSelectedTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected Icon maxIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected Icon minIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected Icon iconIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected Icon closeIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected Action closeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected Action maximizeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected Action iconifyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected Action restoreAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected Action moveAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected Action sizeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
    89
    // These constants are not used in JDK code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected static final String CLOSE_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        UIManager.getString("InternalFrameTitlePane.closeButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected static final String ICONIFY_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        UIManager.getString("InternalFrameTitlePane.minimizeButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected static final String RESTORE_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        UIManager.getString("InternalFrameTitlePane.restoreButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected static final String MAXIMIZE_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        UIManager.getString("InternalFrameTitlePane.maximizeButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected static final String MOVE_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        UIManager.getString("InternalFrameTitlePane.moveButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected static final String SIZE_CMD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        UIManager.getString("InternalFrameTitlePane.sizeButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String closeButtonToolTip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private String iconButtonToolTip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private String restoreButtonToolTip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private String maxButtonToolTip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public BasicInternalFrameTitlePane(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        frame = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        installTitlePane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected void installTitlePane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        createActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        createActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        setLayout(createLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        assembleSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        createButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        addSubComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected void addSubComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        add(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        add(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        add(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void createActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        maximizeAction = new MaximizeAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        iconifyAction = new IconifyAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        closeAction = new CloseAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        restoreAction = new RestoreAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        moveAction = new MoveAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        sizeAction = new SizeAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    ActionMap createActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        ActionMap map = new ActionMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        map.put("showSystemMenu", new ShowSystemMenuAction(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        map.put("hideSystemMenu", new ShowSystemMenuAction(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if( propertyChangeListener == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            propertyChangeListener = createPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        frame.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        frame.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        setFont(UIManager.getFont("InternalFrame.titleFont"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        closeButtonToolTip =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                UIManager.getString("InternalFrame.closeButtonToolTip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        iconButtonToolTip =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                UIManager.getString("InternalFrame.iconButtonToolTip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        restoreButtonToolTip =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                UIManager.getString("InternalFrame.restoreButtonToolTip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        maxButtonToolTip =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                UIManager.getString("InternalFrame.maxButtonToolTip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected void createButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        iconButton = new NoFocusButton(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                     "InternalFrameTitlePane.iconifyButtonAccessibleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                     "InternalFrameTitlePane.iconifyButtonOpacity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        iconButton.addActionListener(iconifyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            iconButton.setToolTipText(iconButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        maxButton = new NoFocusButton(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        "InternalFrameTitlePane.maximizeButtonAccessibleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        "InternalFrameTitlePane.maximizeButtonOpacity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        maxButton.addActionListener(maximizeAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        closeButton = new NoFocusButton(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                      "InternalFrameTitlePane.closeButtonAccessibleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                      "InternalFrameTitlePane.closeButtonOpacity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        closeButton.addActionListener(closeAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            closeButton.setToolTipText(closeButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        setButtonIcons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    protected void setButtonIcons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if(frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (minIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                iconButton.setIcon(minIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (restoreButtonToolTip != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    restoreButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                iconButton.setToolTipText(restoreButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (maxIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                maxButton.setIcon(maxIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                maxButton.setToolTipText(maxButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } else if (frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (iconIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                iconButton.setIcon(iconIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                iconButton.setToolTipText(iconButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            if (minIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                maxButton.setIcon(minIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (restoreButtonToolTip != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    restoreButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                maxButton.setToolTipText(restoreButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (iconIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                iconButton.setIcon(iconIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                iconButton.setToolTipText(iconButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (maxIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                maxButton.setIcon(maxIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                maxButton.setToolTipText(maxButtonToolTip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (closeIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            closeButton.setIcon(closeIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected void assembleSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        menuBar = createSystemMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        windowMenu = createSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        menuBar.add(windowMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        addSystemMenuItems(windowMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    protected void addSystemMenuItems(JMenu systemMenu) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   272
        JMenuItem mi = systemMenu.add(restoreAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   273
        mi.setMnemonic(getButtonMnemonic("restore"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   274
        mi = systemMenu.add(moveAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   275
        mi.setMnemonic(getButtonMnemonic("move"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   276
        mi = systemMenu.add(sizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   277
        mi.setMnemonic(getButtonMnemonic("size"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   278
        mi = systemMenu.add(iconifyAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   279
        mi.setMnemonic(getButtonMnemonic("minimize"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   280
        mi = systemMenu.add(maximizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   281
        mi.setMnemonic(getButtonMnemonic("maximize"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        systemMenu.add(new JSeparator());
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   283
        mi = systemMenu.add(closeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   284
        mi.setMnemonic(getButtonMnemonic("close"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   285
    }
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   286
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   287
    private static int getButtonMnemonic(String button) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   288
        try {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   289
            return Integer.parseInt(UIManager.getString(
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   290
                    "InternalFrameTitlePane." + button + "Button.mnemonic"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   291
        } catch (NumberFormatException e) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   292
            return -1;
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 20458
diff changeset
   293
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    protected JMenu createSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return new JMenu("    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    protected JMenuBar createSystemMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        menuBar = new SystemMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        menuBar.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected void showSystemMenu(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        //      windowMenu.setPopupMenuVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      //      windowMenu.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      windowMenu.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void paintComponent(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        paintTitleBackground(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if(frame.getTitle() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            Font f = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if(isSelected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                g.setColor(selectedTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                g.setColor(notSelectedTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // Center text vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    fm.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            int titleX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Rectangle r = new Rectangle(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (frame.isIconifiable())  r = iconButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            else if (frame.isMaximizable())  r = maxButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            else if (frame.isClosable())  r = closeButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            int titleW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if( BasicGraphicsUtils.isLeftToRight(frame) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
              if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
              titleX = menuBar.getX() + menuBar.getWidth() + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
              titleW = r.x - titleX - 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
              title = getTitle(frame.getTitle(), fm, titleW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                titleX = menuBar.getX() - 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                         - SwingUtilities2.stringWidth(frame,fm,title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            SwingUtilities2.drawString(frame, g, title, titleX, baseline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    * Invoked from paintComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    * Paints the background of the titlepane.  All text and icons will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    * then be rendered on top of this background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    * @param g the graphics to use to render the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    protected void paintTitleBackground(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if(isSelected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            g.setColor(selectedTitleColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            g.setColor(notSelectedTitleColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return SwingUtilities2.clipStringIfNecessary(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                           frame, fm, text, availTextWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Post a WINDOW_CLOSING-like event to the frame, so that it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * be treated like a regular Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    protected void postClosingEvent(JInternalFrame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        InternalFrameEvent e = new InternalFrameEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        // Try posting event, unless there's a SecurityManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (JInternalFrame.class.getClassLoader() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                // Use dispatchEvent instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        frame.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    protected void enableActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        restoreAction.setEnabled(frame.isMaximum() || frame.isIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        maximizeAction.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            (frame.isMaximizable() && frame.isIcon()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        closeAction.setEnabled(frame.isClosable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        sizeAction.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        moveAction.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private class Handler implements LayoutManager, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        public void propertyChange(PropertyChangeEvent evt) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   426
            String prop = evt.getPropertyName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (prop == JInternalFrame.IS_ICON_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                setButtonIcons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if ("closable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   441
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    remove(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            } else if ("maximizable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   447
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    add(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    remove(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            } else if ("iconable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   453
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    add(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    remove(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        public Dimension preferredLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            // Calculate width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            int width = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            FontMetrics fm = frame.getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                               frame, fm, frameTitle) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            int title_length = frameTitle != null ? frameTitle.length() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            // Leave room for three characters in the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (title_length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                int subtitle_w = SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    frame, fm, frameTitle.substring(0, 3) + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                width += (title_w < subtitle_w) ? title_w : subtitle_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                width += title_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            // Calculate height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            int fontHeight = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            fontHeight += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            int iconHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                // SystemMenuBar forces the icon to be 16x16 or less.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                iconHeight = Math.min(icon.getIconHeight(), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            iconHeight += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            int height = Math.max( fontHeight, iconHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            Dimension dim = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            // Take into account the border insets if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (getBorder() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                Insets insets = getBorder().getBorderInsets(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            int h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            int buttonHeight = closeButton.getIcon().getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            int iconHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                iconHeight = icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            x = (leftToRight) ? 2 : w - 16 - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            x = (leftToRight) ? w - 16 - 2 : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                x += (leftToRight) ? -(16 + 2) : 16 + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                x += (leftToRight) ? -(16 + 2) : 16 + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   565
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public class PropertyChangeHandler implements PropertyChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21259
diff changeset
   568
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            getHandler().propertyChange(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   579
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public class TitlePaneLayout implements LayoutManager {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21259
diff changeset
   582
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        public void addLayoutComponent(String name, Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            getHandler().addLayoutComponent(name, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public void removeLayoutComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            getHandler().removeLayoutComponent(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            return getHandler().preferredLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            return getHandler().minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            getHandler().layoutContainer(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   609
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public class CloseAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        public CloseAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   613
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   614
                    "InternalFrameTitlePane.closeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if(frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                frame.doDefaultCloseAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    } // end CloseAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   626
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public class MaximizeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        public MaximizeAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   630
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   631
                    "InternalFrameTitlePane.maximizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                if (frame.isMaximum() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                } else if (!frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                        frame.setMaximum(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                        frame.setMaximum(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   655
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public class IconifyAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        public IconifyAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   659
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   660
                    "InternalFrameTitlePane.minimizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if(frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
              if(!frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
              } else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    } // end IconifyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   676
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public class RestoreAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public RestoreAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   680
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   681
                    "InternalFrameTitlePane.restoreButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            } else if (frame.isMaximizable() && frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    frame.setMaximum(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            } else if (frame.isIconifiable() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   703
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public class MoveAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        public MoveAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   707
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   708
                    "InternalFrameTitlePane.moveButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            // This action is currently undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    } // end MoveAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Handles showing and hiding the system menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    private class ShowSystemMenuAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        private boolean show;   // whether to show the menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        public ShowSystemMenuAction(boolean show) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            this.show = show;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (show) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                windowMenu.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                windowMenu.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   737
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public class SizeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        public SizeAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   741
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   742
                    "InternalFrameTitlePane.sizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            // This action is currently undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    } // end SizeAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   753
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public class SystemMenuBar extends JMenuBar {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        public boolean isFocusTraversable() { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        public void requestFocus() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
              icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                      "InternalFrame.icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                // Resize to 16x16 if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    Image img = ((ImageIcon)icon).getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                icon.paintIcon(this, g, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    } // end SystemMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private class NoFocusButton extends JButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        private String uiKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        public NoFocusButton(String uiKey, String opacityKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            setMargin(new Insets(0,0,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            this.uiKey = uiKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            Object opacity = UIManager.get(opacityKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            if (opacity instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                setOpaque(((Boolean)opacity).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        public boolean isFocusTraversable() { return false; }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   793
        public void requestFocus() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            AccessibleContext ac = super.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            if (uiKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                ac.setAccessibleName(UIManager.getString(uiKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                uiKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            return ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   802
    }  // end NoFocusButton
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
}   // End Title Pane Class