jdk/src/share/classes/sun/tools/jconsole/MaximizableInternalFrame.java
author nloodin
Mon, 27 May 2013 17:10:32 +0200
changeset 17719 ba3677303a76
parent 14342 8435a30053c1
permissions -rw-r--r--
6470730: Disconnect button leads to wrong popup message Reviewed-by: dcubed, sla, egahlin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12851
diff changeset
     2
 * Copyright (c) 2006, 2012, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 sun.tools.jconsole;
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.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class is a temporary workaround for bug 4834918:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Win L&F: JInternalFrame should merge with JMenuBar when maximized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * It is not a general solution, but intended for use within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * limited scope of JConsole when running with XP/Vista styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class MaximizableInternalFrame extends JInternalFrame {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private boolean isXP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private JFrame mainFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private JMenuBar mainMenuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private String mainTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private JComponent titlePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private Border normalBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private PropertyChangeListener pcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public MaximizableInternalFrame(String title, boolean resizable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                    boolean closable, boolean maximizable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                    boolean iconifiable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super(title, resizable, closable, maximizable, iconifiable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        normalBorder = getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        isXP = normalBorder.getClass().getName().endsWith("XPBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (isXP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            setRootPaneCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            titlePane = ((BasicInternalFrameUI)getUI()).getNorthPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if (pcl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                pcl = new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                        String prop = ev.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        if (prop.equals("icon") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                            prop.equals("maximum") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                            prop.equals("closed")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                            updateFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                addPropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } else if (pcl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            removePropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            pcl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private void updateFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        JFrame mainFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (!isXP || (mainFrame = getMainFrame()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        JMenuBar menuBar = getMainMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        BasicInternalFrameUI ui = (BasicInternalFrameUI)getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (isMaximum() && !isIcon() && !isClosed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            if (ui.getNorthPane() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // Merge title bar into menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                mainTitle = mainFrame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                mainFrame.setTitle(mainTitle + " - " + getTitle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    // Move buttons to menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    menuBar.add(Box.createGlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    for (Component c : titlePane.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        if (c instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                            menuBar.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        } else if (c instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                            // This is the system menu icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                            menuBar.add(Box.createHorizontalStrut(3), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                            menuBar.add(c, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                            menuBar.add(Box.createHorizontalStrut(3), 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    ui.setNorthPane(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (ui.getNorthPane() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                // Restore title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                mainFrame.setTitle(mainTitle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    // Move buttons back to title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    for (Component c : menuBar.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        if (c instanceof JButton || c instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                            titlePane.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        } else if (c instanceof Box.Filler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                            menuBar.remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    menuBar.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    ui.setNorthPane(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    setBorder(normalBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        boolean isMax = (isXP && getBorder() == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (isMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                setMaximum(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            } catch (PropertyVetoException ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        super.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (isMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                setMaximum(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } catch (PropertyVetoException ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private JFrame getMainFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (mainFrame == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            JDesktopPane desktop = getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                mainFrame = (JFrame)SwingUtilities.getWindowAncestor(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return mainFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private JMenuBar getMainMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (mainMenuBar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            JFrame mainFrame = getMainFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            if (mainFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                mainMenuBar = mainFrame.getJMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (mainMenuBar != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    !(mainMenuBar.getLayout() instanceof FixedMenuBarLayout)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    mainMenuBar.setLayout(new FixedMenuBarLayout(mainMenuBar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                            BoxLayout.X_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return mainMenuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void setTitle(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (isXP && isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (getMainFrame() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                getMainFrame().setTitle(mainTitle + " - " + title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        super.setTitle(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private class FixedMenuBarLayout extends BoxLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        public FixedMenuBarLayout(Container target, int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            super(target, axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            super.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            for (Component c : target.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (c instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    int y = (target.getHeight() - c.getHeight()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    c.setLocation(c.getX(), Math.max(2, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // The rest of this class is messy and should not be relied upon. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // uses reflection to access private, undocumented, and unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    // classes and fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    // Install icon wrappers to display MDI icons when the buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // are in the menubar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // Please note that this will very likely fail in a future version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    // of Swing, but at least it should fail silently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private static Object WP_MINBUTTON, WP_RESTOREBUTTON, WP_CLOSEBUTTON,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                          WP_MDIMINBUTTON, WP_MDIRESTOREBUTTON, WP_MDICLOSEBUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (JConsole.IS_WIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            try {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   225
                Class<?> Part =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    Class.forName("com.sun.java.swing.plaf.windows.TMSchema$Part");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                if (Part != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    WP_MINBUTTON        = Part.getField("WP_MINBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    WP_RESTOREBUTTON    = Part.getField("WP_RESTOREBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    WP_CLOSEBUTTON      = Part.getField("WP_CLOSEBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    WP_MDIMINBUTTON     = Part.getField("WP_MDIMINBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    WP_MDIRESTOREBUTTON = Part.getField("WP_MDIRESTOREBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    WP_MDICLOSEBUTTON   = Part.getField("WP_MDICLOSEBUTTON").get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                for (String str : new String[] { "maximize", "minimize",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                 "iconify", "close" }) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    String key = "InternalFrame." + str + "Icon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    UIManager.put(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                  new MDIButtonIcon(UIManager.getIcon(key)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            } catch (ClassNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            } catch (NoSuchFieldException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // A wrapper class for the title pane button icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    // This code should really go in the WindowsIconsFactory class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static class MDIButtonIcon implements Icon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        Icon windowsIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Field part;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        MDIButtonIcon(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            windowsIcon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (WP_MINBUTTON != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    part = windowsIcon.getClass().getDeclaredField("part");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    part.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                } catch (NoSuchFieldException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (part != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    Object v = part.get(windowsIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    if (c.getParent() instanceof JMenuBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        // Use MDI icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        if (v == WP_MINBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            part.set(windowsIcon, WP_MDIMINBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        } else if (v == WP_RESTOREBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                            part.set(windowsIcon, WP_MDIRESTOREBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        } else if (v == WP_CLOSEBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                            part.set(windowsIcon, WP_MDICLOSEBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        // Use regular icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        if (v == WP_MDIMINBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                            part.set(windowsIcon, WP_MINBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        } else if (v == WP_MDIRESTOREBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                            part.set(windowsIcon, WP_RESTOREBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        } else if (v == WP_MDICLOSEBUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            part.set(windowsIcon, WP_CLOSEBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            windowsIcon.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        public int getIconWidth(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return windowsIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return windowsIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    // Use reflection to invoke protected methods in BasicInternalFrameTitlePane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private Method setButtonIcons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    private Method enableActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private void updateButtonStates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (setButtonIcons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                Class<? extends JComponent> cls = titlePane.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                Class<?> superCls = cls.getSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                setButtonIcons = cls.getDeclaredMethod("setButtonIcons");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                enableActions  = superCls.getDeclaredMethod("enableActions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                setButtonIcons.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                enableActions.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            setButtonIcons.invoke(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            enableActions.invoke(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (JConsole.debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
}