jdk/src/share/classes/sun/tools/jconsole/AboutDialog.java
author sla
Tue, 19 Mar 2013 13:26:42 +0100
changeset 18197 ae73e4f50e08
parent 14342 8435a30053c1
child 17711 3cb70d5832aa
permissions -rw-r--r--
8003703: Update RMI connection dialog box Reviewed-by: skoivu, ahgross, mchung, jbachorik
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.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static java.awt.BorderLayout.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class AboutDialog extends InternalDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final Color textColor     = new Color(87,   88,  89);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final Color bgColor       = new Color(232, 237, 241);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final Color borderColor   = Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private Icon mastheadIcon =
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    49
        new MastheadIcon(Messages.HELP_ABOUT_DIALOG_MASTHEAD_TITLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static AboutDialog aboutDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private JLabel statusBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Action closeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public AboutDialog(JConsole jConsole) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    57
        super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    59
        setAccessibleDescription(this, Messages.HELP_ABOUT_DIALOG_ACCESSIBLE_DESCRIPTION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        setDefaultCloseOperation(HIDE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        JComponent cp = (JComponent)getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        createActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        JLabel mastheadLabel = new JLabel(mastheadIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        setAccessibleName(mastheadLabel,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    68
                Messages.HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        JPanel mainPanel = new TPanel(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        mainPanel.add(mastheadLabel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        String jConsoleVersion = Version.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        String vmName = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        String vmVersion = System.getProperty("java.vm.version");
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    76
        String urlStr = Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (isBrowseSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        infoAndLogoPanel.setBackground(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        JEditorPane helpLink = new JEditorPane("text/html",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                "<html><font color=#"+ colorStr + ">" +
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    87
                        Resources.format(Messages.HELP_ABOUT_DIALOG_JCONSOLE_VERSION, jConsoleVersion) +
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    88
                "<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) +
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    89
                "<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK, urlStr) +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                 "</html>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        helpLink.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        helpLink.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        helpLink.setForeground(textColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        helpLink.addHyperlinkListener(new HyperlinkListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            public void hyperlinkUpdate(HyperlinkEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    browse(e.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        infoAndLogoPanel.add(helpLink, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        JButton closeButton = new JButton(closeAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        JPanel bottomPanel = new TPanel(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        buttonPanel.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        mainPanel.add(infoAndLogoPanel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        cp.add(bottomPanel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        infoAndLogoPanel.add(brandLogo, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        buttonPanel.add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        bottomPanel.add(buttonPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        statusBar = new JLabel(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        bottomPanel.add(statusBar, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        cp.add(mainPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        setLocationRelativeTo(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Utilities.updateTransparency(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void showDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        statusBar.setText(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            // Bring to front of other dialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static AboutDialog getAboutDialog(JConsole jConsole) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (aboutDialog == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            aboutDialog = new AboutDialog(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return aboutDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static void showAboutDialog(JConsole jConsole) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        getAboutDialog(jConsole).showDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    static void browseUserGuide(JConsole jConsole) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   156
        getAboutDialog(jConsole).browse(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static boolean isBrowseSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return (Desktop.isDesktopSupported() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    void browse(String urlStr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            Desktop.getDesktop().browse(new URI(urlStr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            showDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            statusBar.setText(ex.getLocalizedMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private void createActions() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   177
        closeAction = new AbstractAction(Messages.CLOSE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static class TPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        TPanel(int hgap, int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            super(new BorderLayout(hgap, vgap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}