jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java
author alexsch
Wed, 18 Nov 2015 19:13:42 +0400
changeset 34407 2b40f400a30b
parent 25859 3317bb8137f4
child 37698 4d798c873df0
permissions -rw-r--r--
8081411: Add an API for painting an icon with a SynthContext Reviewed-by: serb, azvegint
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
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        updateStyle(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        SynthContext context = getContext(this, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if(di != null && di.getComponentPopupMenu() == systemPopupMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // Release link to systemMenu from the JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            di.setComponentPopupMenu(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   162
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private static class JPopupMenuUIResource extends JPopupMenu implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        UIResource { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected void assembleSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        systemPopupMenu = new JPopupMenuUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        addSystemMenuItems(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        menuButton = createNoFocusButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        updateMenuIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        menuButton.addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    frame.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                } catch(PropertyVetoException pve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                showSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        JPopupMenu p = frame.getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (p == null || p instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            frame.setComponentPopupMenu(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (frame.getDesktopIcon() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            p = frame.getDesktopIcon().getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (p == null || p instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                frame.getDesktopIcon().setComponentPopupMenu(systemPopupMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        setInheritsPopupMenu(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    protected void addSystemMenuItems(JPopupMenu menu) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   195
        JMenuItem mi = menu.add(restoreAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   196
        mi.setMnemonic(getButtonMnemonic("restore"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   197
        mi = menu.add(moveAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   198
        mi.setMnemonic(getButtonMnemonic("move"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   199
        mi = menu.add(sizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   200
        mi.setMnemonic(getButtonMnemonic("size"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   201
        mi = menu.add(iconifyAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   202
        mi.setMnemonic(getButtonMnemonic("minimize"));
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   203
        mi = menu.add(maximizeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   204
        mi.setMnemonic(getButtonMnemonic("maximize"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        menu.add(new JSeparator());
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   206
        mi = menu.add(closeAction);
21259
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   207
        mi.setMnemonic(getButtonMnemonic("close"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   208
    }
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   209
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   210
    private static int getButtonMnemonic(String button) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   211
        try {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   212
            return Integer.parseInt(UIManager.getString(
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   213
                    "InternalFrameTitlePane." + button + "Button.mnemonic"));
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   214
        } catch (NumberFormatException e) {
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   215
            return -1;
4780cf380d96 8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents: 5506
diff changeset
   216
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected void showSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Insets insets = frame.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        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
   222
            systemPopupMenu.show(frame, menuButton.getX(), getY() + getHeight());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            systemPopupMenu.show(menuButton,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                getX() - insets.left - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                getY() - systemPopupMenu.getPreferredSize().height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    insets.bottom - insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // SynthInternalFrameTitlePane has no UI, we'll invoke paint on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        context.getPainter().paintInternalFrameTitlePaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                          g, 0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            g.setFont(style.getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            // Center text vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            fm.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            JButton lastButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                lastButton = iconButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            else if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                lastButton = maxButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            else if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                lastButton = closeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            int maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            int minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            boolean ltr = SynthLookAndFeel.isLeftToRight(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            int titleAlignment = this.titleAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if (lastButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    maxX = lastButton.getX() - titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    maxX = frame.getWidth() - frame.getInsets().right -
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
                minX = menuButton.getX() + menuButton.getWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                       titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                if (lastButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    minX = lastButton.getX() + lastButton.getWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                           titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    minX = frame.getInsets().left + titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                maxX = menuButton.getX() - titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                if (titleAlignment == SwingConstants.LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    titleAlignment = SwingConstants.TRAILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                else if (titleAlignment == SwingConstants.TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    titleAlignment = SwingConstants.LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            String clippedTitle = getTitle(title, fm, maxX - minX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (clippedTitle == title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                // String fit, align as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                if (titleAlignment == SwingConstants.TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    minX = maxX - style.getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        computeStringWidth(context, g.getFont(), fm, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                else if (titleAlignment == SwingConstants.CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    int width = style.getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                           computeStringWidth(context, g.getFont(), fm, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    minX = Math.max(minX, (getWidth() - width) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    minX = Math.min(maxX - width, minX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            style.getGraphicsUtils(context).paintText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                context, g, clippedTitle, minX, baseline - fm.getAscent(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        context.getPainter().paintInternalFrameTitlePaneBorder(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                            g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        LayoutManager lm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            (LayoutManager)style.get(context, "InternalFrameTitlePane.titlePaneLayout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return (lm != null) ? lm : new SynthTitlePaneLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (evt.getSource() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                updateStyle(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            // Changes for the internal frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (evt.getPropertyName() == JInternalFrame.FRAME_ICON_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                updateMenuIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
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
     * Resets the menuButton icon to match that of the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private void updateMenuIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        Icon frameIcon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        SynthContext context = getContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (frameIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            Dimension maxSize = (Dimension)context.getStyle().get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                "InternalFrameTitlePane.maxFrameIconSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            int maxWidth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            int maxHeight = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (maxSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                maxWidth = maxSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                maxHeight = maxSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if ((frameIcon.getIconWidth() > maxWidth ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                     frameIcon.getIconHeight() > maxHeight) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    (frameIcon instanceof ImageIcon)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                frameIcon = new ImageIcon(((ImageIcon)frameIcon).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                             getImage().getScaledInstance(maxWidth, maxHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                             Image.SCALE_SMOOTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        menuButton.setIcon(frameIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    class SynthTitlePaneLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            SynthContext context = getContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                             SynthInternalFrameTitlePane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            int width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            int buttonCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            Dimension pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                pref = closeButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                pref = maxButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                pref = iconButton.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
                buttonCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            pref = menuButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            width += pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            height = Math.max(pref.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            width += Math.max(0, (buttonCount - 1) * buttonSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            FontMetrics fm = SynthInternalFrameTitlePane.this.getFontMetrics(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                          getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            SynthGraphicsUtils graphicsUtils = context.getStyle().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                       getGraphicsUtils(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            int title_w = frameTitle != null ? graphicsUtils.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                               computeStringWidth(context, fm.getFont(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                               fm, frameTitle) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            int title_length = frameTitle != null ? frameTitle.length() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            // Leave room for three characters in the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (title_length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                int subtitle_w = graphicsUtils.computeStringWidth(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    fm.getFont(), fm, frameTitle.substring(0, 3) + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                width += (title_w < subtitle_w) ? title_w : subtitle_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                width += title_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            height = Math.max(fm.getHeight() + 2, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            width += titleSpacing + titleSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        private int center(Component c, Insets insets, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                           boolean trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Dimension pref = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                x -= pref.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            c.setBounds(x, insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        (getHeight() - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                         pref.height) / 2, pref.width, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (pref.width > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                if (trailing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    return x - buttonSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                return x + pref.width + buttonSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            Dimension pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (SynthLookAndFeel.isLeftToRight(frame)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                center(menuButton, insets, insets.left, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                int x = getWidth() - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    x = center(closeButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    x = center(maxButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    x = center(iconButton, insets, x, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                center(menuButton, insets, getWidth() - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    x = center(closeButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    x = center(maxButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    x = center(iconButton, insets, x, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    private JButton createNoFocusButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        JButton button = new JButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        button.setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        button.setMargin(new Insets(0,0,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
}