jdk/src/share/classes/sun/tools/jconsole/SheetDialog.java
author nloodin
Mon, 27 May 2013 17:10:32 +0200
changeset 17719 ba3677303a76
parent 5506 202f599c92aa
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
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, 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.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
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.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static javax.swing.JOptionPane.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public final class SheetDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // Reusable objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static Rectangle iconR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static Rectangle textR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static Rectangle viewR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static Insets viewInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /** Don't let anyone instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private SheetDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static JOptionPane showOptionDialog(final VMPanel vmPanel, Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                        int optionType, int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                        Icon icon, Object[] options, Object initialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        JRootPane rootPane = SwingUtilities.getRootPane(vmPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        JPanel glassPane = (JPanel)rootPane.getGlassPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (!(glassPane instanceof SlideAndFadeGlassPane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            glassPane = new SlideAndFadeGlassPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            glassPane.setName(rootPane.getName()+".glassPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            rootPane.setGlassPane(glassPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            rootPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        final SlideAndFadeGlassPane safGlassPane = (SlideAndFadeGlassPane)glassPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        // Workaround for the fact that JOptionPane does not handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        // limiting the width when using multi-line html messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // See Swing bug 5074006 and JConsole bug 6426317
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        message = fixWrapping(message, rootPane.getWidth() - 75); // Leave room for icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        final SheetOptionPane optionPane = new SheetOptionPane(message, messageType, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                                           icon, options, initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        optionPane.setComponentOrientation(vmPanel.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                if (event.getPropertyName().equals(VALUE_PROPERTY) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    event.getNewValue() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    event.getNewValue() != UNINITIALIZED_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    ((SlideAndFadeGlassPane)optionPane.getParent()).hide(optionPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Delay this (even though we're already on the EDT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                safGlassPane.show(optionPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return optionPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static Object fixWrapping(Object message, final int maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (message instanceof Object[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            Object[] arr = (Object[])message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            for (int i = 0; i < arr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                arr[i] = fixWrapping(arr[i], maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        } else if (message instanceof String &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                   ((String)message).startsWith("<html>")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            message = new JLabel((String)message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    String text = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    Insets insets = getInsets(viewInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    FontMetrics fm = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    Dimension pref = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    Dimension min = getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    iconR.x = iconR.y = iconR.width = iconR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    textR.x = textR.y = textR.width = textR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    int dx = insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    int dy = insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    viewR.x = dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    viewR.y = dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    viewR.width = viewR.height = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    View v = (View)getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        // Use pref width if less than 300, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        // min width up to size of window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        int w = Math.min(maxWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                         Math.min(pref.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                                  Math.max(min.width, 300)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        v.setSize((float)w, 0F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        SwingUtilities.layoutCompoundLabel(this, fm, text, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                           getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                                           getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                                           getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                                           getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                                           viewR, iconR, textR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                                           getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        return new Dimension(textR.width + dx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                             textR.height + dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        return pref; //  Should not happen
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
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static class SlideAndFadeGlassPane extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        SheetOptionPane optionPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        int fade = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        boolean slideIn = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        SlideAndFadeGlassPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // Grab mouse input, making the dialog modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            addMouseListener(new MouseAdapter() {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        public void show(SheetOptionPane optionPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            this.optionPane = optionPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            add(optionPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            slideIn = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            doSlide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public void hide(SheetOptionPane optionPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (optionPane != this.optionPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            slideIn = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            doSlide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        private void doSlide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (optionPane.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (optionPane.getWidth() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                optionPane.setSize(optionPane.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            int glassPaneWidth = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (glassPaneWidth == 0 && getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                glassPaneWidth = getParent().getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            int x = (glassPaneWidth - optionPane.getWidth()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (!slideIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    remove(optionPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    optionPane.setLocation(x, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    setGrayLevel(fade);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    return;
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
        public void setGrayLevel(int gray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            gray = gray * 255 / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            setBackground(new Color(0, 0, 0, gray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    static class SheetOptionPane extends JOptionPane {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        SheetOptionPane(Object message, int messageType, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        Icon icon, Object[] options, Object initialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            super(message, messageType, optionType, icon, options, initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            setBorder(new CompoundBorder(new LineBorder(new Color(204, 204, 204), 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                         new EmptyBorder(4, 4, 4, 4)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        private static Composite comp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        private static Color bgColor = new Color(241, 239, 239);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        public void setVisible(boolean visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            SlideAndFadeGlassPane glassPane = (SlideAndFadeGlassPane)getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (glassPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    glassPane.show(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    glassPane.hide(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Graphics2D g2d = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            Composite oldComp = g2d.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            g2d.setComposite(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            Color oldColor = g2d.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            g2d.setColor(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            g2d.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            g2d.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            g2d.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}