jdk/src/share/classes/sun/tools/jconsole/AboutDialog.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 12851 3334e1c781d0
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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) 2006, 2007, 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.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
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.Resources.*;
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 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        new MastheadIcon(getText("Help.AboutDialog.masthead.title"));
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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(jConsole, Resources.getText("Help.AboutDialog.title"), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        setAccessibleDescription(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                 getText("Help.AboutDialog.accessibleDescription"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        setDefaultCloseOperation(HIDE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        JComponent cp = (JComponent)getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        createActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        JLabel mastheadLabel = new JLabel(mastheadIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        setAccessibleName(mastheadLabel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                          getText("Help.AboutDialog.masthead.accessibleName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        JPanel mainPanel = new TPanel(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        mainPanel.add(mastheadLabel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        String jConsoleVersion = Version.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        String vmName = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        String vmVersion = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        String urlStr = getText("Help.AboutDialog.userGuideLink.url");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (isBrowseSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        infoAndLogoPanel.setBackground(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        JEditorPane helpLink = new JEditorPane("text/html",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                "<html><font color=#"+ colorStr + ">" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        getText("Help.AboutDialog.jConsoleVersion", jConsoleVersion) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                "<p>" + getText("Help.AboutDialog.javaVersion", (vmName +", "+ vmVersion)) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                "<p>" + getText("Help.AboutDialog.userGuideLink", urlStr) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                                 "</html>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        helpLink.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        helpLink.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        helpLink.setForeground(textColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        helpLink.addHyperlinkListener(new HyperlinkListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            public void hyperlinkUpdate(HyperlinkEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    browse(e.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        infoAndLogoPanel.add(helpLink, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        JButton closeButton = new JButton(closeAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        JPanel bottomPanel = new TPanel(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        buttonPanel.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        mainPanel.add(infoAndLogoPanel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        cp.add(bottomPanel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        infoAndLogoPanel.add(brandLogo, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        buttonPanel.add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        bottomPanel.add(buttonPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        statusBar = new JLabel(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        bottomPanel.add(statusBar, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        cp.add(mainPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        setLocationRelativeTo(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Utilities.updateTransparency(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void showDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        statusBar.setText(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // Bring to front of other dialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } catch (PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
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 AboutDialog getAboutDialog(JConsole jConsole) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (aboutDialog == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            aboutDialog = new AboutDialog(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return aboutDialog;
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 showAboutDialog(JConsole jConsole) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        getAboutDialog(jConsole).showDialog();
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 void browseUserGuide(JConsole jConsole) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        getAboutDialog(jConsole).browse(getText("Help.AboutDialog.userGuideLink.url"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static boolean isBrowseSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return (Desktop.isDesktopSupported() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    void browse(String urlStr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Desktop.getDesktop().browse(new URI(urlStr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            showDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            statusBar.setText(ex.getLocalizedMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private void createActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        closeAction = new AbstractAction(getText("Close")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static class TPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        TPanel(int hgap, int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            super(new BorderLayout(hgap, vgap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}