jdk/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1639 a97859015238
child 20169 d7fa6d7586c9
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        mi.setMnemonic('R');
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   274
        mi = systemMenu.add(moveAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        mi.setMnemonic('M');
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   276
        mi = systemMenu.add(sizeAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        mi.setMnemonic('S');
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   278
        mi = systemMenu.add(iconifyAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        mi.setMnemonic('n');
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   280
        mi = systemMenu.add(maximizeAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        mi.setMnemonic('x');
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);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        mi.setMnemonic('C');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    protected JMenu createSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return new JMenu("    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    protected JMenuBar createSystemMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        menuBar = new SystemMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        menuBar.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected void showSystemMenu(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        //      windowMenu.setPopupMenuVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      //      windowMenu.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      windowMenu.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public void paintComponent(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        paintTitleBackground(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if(frame.getTitle() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            Font f = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if(isSelected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                g.setColor(selectedTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                g.setColor(notSelectedTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // Center text vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    fm.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            int titleX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            Rectangle r = new Rectangle(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (frame.isIconifiable())  r = iconButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            else if (frame.isMaximizable())  r = maxButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            else if (frame.isClosable())  r = closeButton.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            int titleW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if( BasicGraphicsUtils.isLeftToRight(frame) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
              if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
              titleX = menuBar.getX() + menuBar.getWidth() + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
              titleW = r.x - titleX - 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
              title = getTitle(frame.getTitle(), fm, titleW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                titleX = menuBar.getX() - 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                         - SwingUtilities2.stringWidth(frame,fm,title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            SwingUtilities2.drawString(frame, g, title, titleX, baseline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    * Invoked from paintComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    * Paints the background of the titlepane.  All text and icons will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    * then be rendered on top of this background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    * @param g the graphics to use to render the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    protected void paintTitleBackground(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        boolean isSelected = frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if(isSelected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            g.setColor(selectedTitleColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            g.setColor(notSelectedTitleColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return SwingUtilities2.clipStringIfNecessary(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                           frame, fm, text, availTextWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Post a WINDOW_CLOSING-like event to the frame, so that it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * be treated like a regular Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    protected void postClosingEvent(JInternalFrame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        InternalFrameEvent e = new InternalFrameEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // Try posting event, unless there's a SecurityManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (JInternalFrame.class.getClassLoader() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                // Use dispatchEvent instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        frame.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    protected void enableActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        restoreAction.setEnabled(frame.isMaximum() || frame.isIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        maximizeAction.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            (frame.isMaximizable() && frame.isIcon()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        closeAction.setEnabled(frame.isClosable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        sizeAction.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        moveAction.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private class Handler implements LayoutManager, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public void propertyChange(PropertyChangeEvent evt) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   417
            String prop = evt.getPropertyName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (prop == JInternalFrame.IS_ICON_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                setButtonIcons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if ("closable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   432
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    remove(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            } else if ("maximizable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   438
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    add(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    remove(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            } else if ("iconable" == prop) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   444
                if (evt.getNewValue() == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    add(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    remove(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        public Dimension preferredLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            // Calculate width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            int width = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                width += 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            FontMetrics fm = frame.getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                               frame, fm, frameTitle) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            int title_length = frameTitle != null ? frameTitle.length() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            // Leave room for three characters in the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (title_length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                int subtitle_w = SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    frame, fm, frameTitle.substring(0, 3) + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                width += (title_w < subtitle_w) ? title_w : subtitle_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                width += title_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            // Calculate height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            int fontHeight = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            fontHeight += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            int iconHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                // SystemMenuBar forces the icon to be 16x16 or less.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                iconHeight = Math.min(icon.getIconHeight(), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            iconHeight += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            int height = Math.max( fontHeight, iconHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            Dimension dim = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            // Take into account the border insets if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            if (getBorder() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                Insets insets = getBorder().getBorderInsets(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            int h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            int buttonHeight = closeButton.getIcon().getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            int iconHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                iconHeight = icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            x = (leftToRight) ? 2 : w - 16 - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            x = (leftToRight) ? w - 16 - 2 : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                x += (leftToRight) ? -(16 + 2) : 16 + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                x += (leftToRight) ? -(16 + 2) : 16 + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public class PropertyChangeHandler implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            getHandler().propertyChange(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public class TitlePaneLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        public void addLayoutComponent(String name, Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            getHandler().addLayoutComponent(name, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        public void removeLayoutComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            getHandler().removeLayoutComponent(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            return getHandler().preferredLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            return getHandler().minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            getHandler().layoutContainer(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public class CloseAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        public CloseAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   604
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   605
                    "InternalFrameTitlePane.closeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            if(frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                frame.doDefaultCloseAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    } // end CloseAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public class MaximizeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        public MaximizeAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   621
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   622
                    "InternalFrameTitlePane.maximizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                if (frame.isMaximum() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                } else if (!frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        frame.setMaximum(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        frame.setMaximum(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public class IconifyAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        public IconifyAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   650
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   651
                    "InternalFrameTitlePane.minimizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            if(frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
              if(!frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
              } else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    } // end IconifyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public class RestoreAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        public RestoreAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   671
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   672
                    "InternalFrameTitlePane.restoreButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            } else if (frame.isMaximizable() && frame.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    frame.setMaximum(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            } else if (frame.isIconifiable() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    frame.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                } catch (PropertyVetoException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    public class MoveAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        public MoveAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   698
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   699
                    "InternalFrameTitlePane.moveButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // This action is currently undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    } // end MoveAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Handles showing and hiding the system menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    private class ShowSystemMenuAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        private boolean show;   // whether to show the menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        public ShowSystemMenuAction(boolean show) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            this.show = show;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (show) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                windowMenu.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                windowMenu.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public class SizeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        public SizeAction() {
1285
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   732
            super(UIManager.getString(
d2d433263986 6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents: 2
diff changeset
   733
                    "InternalFrameTitlePane.sizeButtonText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            // This action is currently undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    } // end SizeAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public class SystemMenuBar extends JMenuBar {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        public boolean isFocusTraversable() { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        public void requestFocus() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
              icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                      "InternalFrame.icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                // Resize to 16x16 if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    Image img = ((ImageIcon)icon).getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                icon.paintIcon(this, g, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    } // end SystemMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    private class NoFocusButton extends JButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        private String uiKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        public NoFocusButton(String uiKey, String opacityKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            setMargin(new Insets(0,0,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            this.uiKey = uiKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            Object opacity = UIManager.get(opacityKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            if (opacity instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                setOpaque(((Boolean)opacity).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        public boolean isFocusTraversable() { return false; }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   784
        public void requestFocus() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            AccessibleContext ac = super.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (uiKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                ac.setAccessibleName(UIManager.getString(uiKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                uiKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            return ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 1285
diff changeset
   793
    }  // end NoFocusButton
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
}   // End Title Pane Class