Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jconsole/AboutDialog.java
38918 views
/*1* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jconsole;2627import java.awt.*;28import java.awt.event.*;29import java.beans.PropertyVetoException;30import java.net.URI;3132import javax.swing.*;33import javax.swing.border.*;34import javax.swing.event.*;3536import static sun.misc.Version.jdkMinorVersion;3738import static java.awt.BorderLayout.*;39import static sun.tools.jconsole.Utilities.*;4041@SuppressWarnings("serial")42public class AboutDialog extends InternalDialog {4344private static final Color textColor = new Color(87, 88, 89);45private static final Color bgColor = new Color(232, 237, 241);46private static final Color borderColor = Color.black;4748private Icon mastheadIcon =49new MastheadIcon(Messages.HELP_ABOUT_DIALOG_MASTHEAD_TITLE);5051private static AboutDialog aboutDialog;5253private JLabel statusBar;54private Action closeAction;5556public AboutDialog(JConsole jConsole) {57super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false);5859setAccessibleDescription(this, Messages.HELP_ABOUT_DIALOG_ACCESSIBLE_DESCRIPTION);60setDefaultCloseOperation(HIDE_ON_CLOSE);61setResizable(false);62JComponent cp = (JComponent)getContentPane();6364createActions();6566JLabel mastheadLabel = new JLabel(mastheadIcon);67setAccessibleName(mastheadLabel,68Messages.HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);6970JPanel mainPanel = new TPanel(0, 0);71mainPanel.add(mastheadLabel, NORTH);7273String jConsoleVersion = Version.getVersion();74String vmName = System.getProperty("java.vm.name");75String vmVersion = System.getProperty("java.vm.version");76String urlStr = getOnlineDocUrl();77if (isBrowseSupported()) {78urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";79}8081JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));82infoAndLogoPanel.setBackground(bgColor);8384String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);85JEditorPane helpLink = new JEditorPane("text/html",86"<html><font color=#"+ colorStr + ">" +87Resources.format(Messages.HELP_ABOUT_DIALOG_JCONSOLE_VERSION, jConsoleVersion) +88"<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) +89"<p>" + urlStr + "</html>");90helpLink.setOpaque(false);91helpLink.setEditable(false);92helpLink.setForeground(textColor);93mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));94infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));95helpLink.addHyperlinkListener(new HyperlinkListener() {96public void hyperlinkUpdate(HyperlinkEvent e) {97if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {98browse(e.getDescription());99}100}101});102infoAndLogoPanel.add(helpLink, NORTH);103104ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));105JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);106107JButton closeButton = new JButton(closeAction);108109JPanel bottomPanel = new TPanel(0, 0);110JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));111buttonPanel.setOpaque(false);112113mainPanel.add(infoAndLogoPanel, CENTER);114cp.add(bottomPanel, SOUTH);115116infoAndLogoPanel.add(brandLogo, SOUTH);117118buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));119buttonPanel.add(closeButton);120bottomPanel.add(buttonPanel, NORTH);121122statusBar = new JLabel(" ");123bottomPanel.add(statusBar, SOUTH);124125cp.add(mainPanel, NORTH);126127pack();128setLocationRelativeTo(jConsole);129Utilities.updateTransparency(this);130}131132public void showDialog() {133statusBar.setText(" ");134setVisible(true);135try {136// Bring to front of other dialogs137setSelected(true);138} catch (PropertyVetoException e) {139// ignore140}141}142143private static AboutDialog getAboutDialog(JConsole jConsole) {144if (aboutDialog == null) {145aboutDialog = new AboutDialog(jConsole);146}147return aboutDialog;148}149150static void showAboutDialog(JConsole jConsole) {151getAboutDialog(jConsole).showDialog();152}153154static void browseUserGuide(JConsole jConsole) {155getAboutDialog(jConsole).browse(getOnlineDocUrl());156}157158static boolean isBrowseSupported() {159return (Desktop.isDesktopSupported() &&160Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));161}162163void browse(String urlStr) {164try {165Desktop.getDesktop().browse(new URI(urlStr));166} catch (Exception ex) {167showDialog();168statusBar.setText(ex.getLocalizedMessage());169if (JConsole.isDebug()) {170ex.printStackTrace();171}172}173}174175private void createActions() {176closeAction = new AbstractAction(Messages.CLOSE) {177public void actionPerformed(ActionEvent ev) {178setVisible(false);179statusBar.setText("");180}181};182}183184private static String getOnlineDocUrl() {185String version = Integer.toString(jdkMinorVersion());186return Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL,187version);188}189190private static class TPanel extends JPanel {191TPanel(int hgap, int vgap) {192super(new BorderLayout(hgap, vgap));193setOpaque(false);194}195}196}197198199