jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java
author alexsch
Fri, 15 Apr 2016 19:15:12 +0400
changeset 37698 4d798c873df0
parent 25859 3317bb8137f4
permissions -rw-r--r--
8132791: No access to SynthContext.getContext() Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, 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: 4394
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: 4394
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: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
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.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The class that manages a synth title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Joshua Outwater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    45
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        implements SynthUI, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected JPopupMenu systemPopupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected JButton menuButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int buttonSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // Alignment for the title, one of SwingConstants.(LEADING|TRAILING|CENTER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int titleAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public SynthInternalFrameTitlePane(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return "InternalFrameTitlePaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public SynthContext getContext(JComponent c, int state) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
    71
        return SynthContext.getContext(c, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private Region getRegion(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return SynthLookAndFeel.getRegion(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (frame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            if (frame.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                return SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected void addSubComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        menuButton.setName("InternalFrameTitlePane.menuButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        iconButton.setName("InternalFrameTitlePane.iconifyButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        maxButton.setName("InternalFrameTitlePane.maximizeButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        closeButton.setName("InternalFrameTitlePane.closeButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        add(menuButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        add(iconButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        add(maxButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        frame.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        frame.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private void updateStyle(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        SynthContext context = getContext(this, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            maxIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                style.getIcon(context,"InternalFrameTitlePane.maximizeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            minIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                style.getIcon(context,"InternalFrameTitlePane.minimizeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            iconIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                style.getIcon(context,"InternalFrameTitlePane.iconifyIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            closeIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                style.getIcon(context,"InternalFrameTitlePane.closeIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            titleSpacing = style.getInt(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                              "InternalFrameTitlePane.titleSpacing", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            buttonSpacing = style.getInt(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                              "InternalFrameTitlePane.buttonSpacing", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            String alignString = (String)style.get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                              "InternalFrameTitlePane.titleAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            titleAlignment = SwingConstants.LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (alignString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                alignString = alignString.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (alignString.equals("TRAILING")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    titleAlignment = SwingConstants.TRAILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                else if (alignString.equals("CENTER")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    titleAlignment = SwingConstants.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        updateStyle(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        SynthContext context = getContext(this, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if(di != null && di.getComponentPopupMenu() == systemPopupMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // Release link to systemMenu from the JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            di.setComponentPopupMenu(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   160
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static class JPopupMenuUIResource extends JPopupMenu implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        UIResource { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected void assembleSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        systemPopupMenu = new JPopupMenuUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        addSystemMenuItems(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        menuButton = createNoFocusButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        updateMenuIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        menuButton.addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    frame.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                } catch(PropertyVetoException pve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                showSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        JPopupMenu p = frame.getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (p == null || p instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            frame.setComponentPopupMenu(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (frame.getDesktopIcon() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            p = frame.getDesktopIcon().getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (p == null || p instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                frame.getDesktopIcon().setComponentPopupMenu(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        setInheritsPopupMenu(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected void addSystemMenuItems(JPopupMenu menu) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   193
        JMenuItem mi = menu.add(restoreAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   194
        mi.setMnemonic(getButtonMnemonic("restore"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   195
        mi = menu.add(moveAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   196
        mi.setMnemonic(getButtonMnemonic("move"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   197
        mi = menu.add(sizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   198
        mi.setMnemonic(getButtonMnemonic("size"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   199
        mi = menu.add(iconifyAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   200
        mi.setMnemonic(getButtonMnemonic("minimize"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   201
        mi = menu.add(maximizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   202
        mi.setMnemonic(getButtonMnemonic("maximize"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        menu.add(new JSeparator());
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   204
        mi = menu.add(closeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   205
        mi.setMnemonic(getButtonMnemonic("close"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   206
    }
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   207
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   208
    private static int getButtonMnemonic(String button) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   209
        try {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   210
            return Integer.parseInt(UIManager.getString(
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   211
                    "InternalFrameTitlePane." + button + "Button.mnemonic"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   212
        } catch (NumberFormatException e) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   213
            return -1;
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   214
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    protected void showSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Insets insets = frame.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (!frame.isIcon()) {
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 1290
diff changeset
   220
            systemPopupMenu.show(frame, menuButton.getX(), getY() + getHeight());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            systemPopupMenu.show(menuButton,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                getX() - insets.left - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                getY() - systemPopupMenu.getPreferredSize().height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    insets.bottom - insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // SynthInternalFrameTitlePane has no UI, we'll invoke paint on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        context.getPainter().paintInternalFrameTitlePaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                          g, 0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            g.setFont(style.getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // Center text vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            fm.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            JButton lastButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                lastButton = iconButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            else if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                lastButton = maxButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            else if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                lastButton = closeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            int maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            int minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            boolean ltr = SynthLookAndFeel.isLeftToRight(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            int titleAlignment = this.titleAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                if (lastButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    maxX = lastButton.getX() - titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    maxX = frame.getWidth() - frame.getInsets().right -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                           titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                minX = menuButton.getX() + menuButton.getWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                       titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                if (lastButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    minX = lastButton.getX() + lastButton.getWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                           titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    minX = frame.getInsets().left + titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                maxX = menuButton.getX() - titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                if (titleAlignment == SwingConstants.LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    titleAlignment = SwingConstants.TRAILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                else if (titleAlignment == SwingConstants.TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    titleAlignment = SwingConstants.LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            String clippedTitle = getTitle(title, fm, maxX - minX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if (clippedTitle == title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                // String fit, align as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                if (titleAlignment == SwingConstants.TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    minX = maxX - style.getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        computeStringWidth(context, g.getFont(), fm, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                else if (titleAlignment == SwingConstants.CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    int width = style.getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                           computeStringWidth(context, g.getFont(), fm, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    minX = Math.max(minX, (getWidth() - width) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    minX = Math.min(maxX - width, minX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            style.getGraphicsUtils(context).paintText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                context, g, clippedTitle, minX, baseline - fm.getAscent(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        context.getPainter().paintInternalFrameTitlePaneBorder(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                                            g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        LayoutManager lm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            (LayoutManager)style.get(context, "InternalFrameTitlePane.titlePaneLayout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return (lm != null) ? lm : new SynthTitlePaneLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (evt.getSource() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                updateStyle(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // Changes for the internal frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (evt.getPropertyName() == JInternalFrame.FRAME_ICON_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                updateMenuIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Resets the menuButton icon to match that of the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    private void updateMenuIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        Icon frameIcon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (frameIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            Dimension maxSize = (Dimension)context.getStyle().get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                "InternalFrameTitlePane.maxFrameIconSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            int maxWidth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            int maxHeight = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            if (maxSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                maxWidth = maxSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                maxHeight = maxSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if ((frameIcon.getIconWidth() > maxWidth ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                     frameIcon.getIconHeight() > maxHeight) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    (frameIcon instanceof ImageIcon)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                frameIcon = new ImageIcon(((ImageIcon)frameIcon).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                             getImage().getScaledInstance(maxWidth, maxHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                             Image.SCALE_SMOOTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        menuButton.setIcon(frameIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    class SynthTitlePaneLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            SynthContext context = getContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                             SynthInternalFrameTitlePane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            int width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            int buttonCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            Dimension pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                pref = closeButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                pref = maxButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                pref = iconButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            pref = menuButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            width += Math.max(0, (buttonCount - 1) * buttonSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            FontMetrics fm = SynthInternalFrameTitlePane.this.getFontMetrics(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                          getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            SynthGraphicsUtils graphicsUtils = context.getStyle().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                                       getGraphicsUtils(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            int title_w = frameTitle != null ? graphicsUtils.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                               computeStringWidth(context, fm.getFont(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                               fm, frameTitle) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            int title_length = frameTitle != null ? frameTitle.length() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            // Leave room for three characters in the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (title_length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                int subtitle_w = graphicsUtils.computeStringWidth(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    fm.getFont(), fm, frameTitle.substring(0, 3) + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                width += (title_w < subtitle_w) ? title_w : subtitle_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                width += title_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            height = Math.max(fm.getHeight() + 2, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            width += titleSpacing + titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        private int center(Component c, Insets insets, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                           boolean trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            Dimension pref = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                x -= pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            c.setBounds(x, insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        (getHeight() - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                         pref.height) / 2, pref.width, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (pref.width > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                if (trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    return x - buttonSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                return x + pref.width + buttonSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            Dimension pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (SynthLookAndFeel.isLeftToRight(frame)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                center(menuButton, insets, insets.left, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                int x = getWidth() - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    x = center(closeButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    x = center(maxButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    x = center(iconButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                center(menuButton, insets, getWidth() - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    x = center(closeButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    x = center(maxButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    x = center(iconButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    private JButton createNoFocusButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        JButton button = new JButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        button.setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        button.setMargin(new Insets(0,0,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
}