jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/AboutDialog.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23010 jdk/src/share/classes/sun/tools/jconsole/AboutDialog.java@6dadb192ad81
child 36011 77231de79e04
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 17711
diff changeset
     2
 * Copyright (c) 2006, 2013, 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
17711
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
    37
import static sun.misc.Version.jdkMinorVersion;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    38
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static java.awt.BorderLayout.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class AboutDialog extends InternalDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final Color textColor     = new Color(87,   88,  89);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final Color bgColor       = new Color(232, 237, 241);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final Color borderColor   = Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private Icon mastheadIcon =
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    50
        new MastheadIcon(Messages.HELP_ABOUT_DIALOG_MASTHEAD_TITLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static AboutDialog aboutDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private JLabel statusBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private Action closeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public AboutDialog(JConsole jConsole) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    58
        super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    60
        setAccessibleDescription(this, Messages.HELP_ABOUT_DIALOG_ACCESSIBLE_DESCRIPTION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        setDefaultCloseOperation(HIDE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        JComponent cp = (JComponent)getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        createActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        JLabel mastheadLabel = new JLabel(mastheadIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        setAccessibleName(mastheadLabel,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    69
                Messages.HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        JPanel mainPanel = new TPanel(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        mainPanel.add(mastheadLabel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        String jConsoleVersion = Version.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        String vmName = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        String vmVersion = System.getProperty("java.vm.version");
17711
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
    77
        String urlStr = getOnlineDocUrl();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (isBrowseSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        infoAndLogoPanel.setBackground(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        JEditorPane helpLink = new JEditorPane("text/html",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                "<html><font color=#"+ colorStr + ">" +
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    88
                        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
    89
                "<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) +
17711
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
    90
                "<p>" + urlStr + "</html>");
2
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) {
17711
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   156
        getAboutDialog(jConsole).browse(getOnlineDocUrl());
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
17711
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   185
    private static String getOnlineDocUrl() {
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   186
        String version = Integer.toString(jdkMinorVersion());
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   187
        return Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL,
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   188
                                version);
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   189
    }
3cb70d5832aa 8014048: Online user guide of jconsole points incorrect link
nloodin
parents: 14342
diff changeset
   190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static class TPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        TPanel(int hgap, int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            super(new BorderLayout(hgap, vgap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
}