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