1 /* 2 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.tools.jconsole; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import java.beans.PropertyVetoException; 31 import java.net.URI; 32 33 import javax.swing.*; 34 import javax.swing.border.*; 35 import javax.swing.event.*; 36 37 import sun.tools.jconsole.resources.Messages; 38 39 import static java.awt.BorderLayout.*; 40 import static sun.tools.jconsole.Utilities.*; 41 42 @SuppressWarnings("serial") 43 public class AboutDialog extends InternalDialog { 44 45 private static final Color textColor = new Color(87, 88, 89); 46 private static final Color bgColor = new Color(232, 237, 241); 47 private static final Color borderColor = Color.black; 48 49 private Icon mastheadIcon = 50 new MastheadIcon(Messages.HELP_ABOUT_DIALOG_MASTHEAD_TITLE); 51 52 private static AboutDialog aboutDialog; 53 54 private JLabel statusBar; 55 private Action closeAction; 56 57 public AboutDialog(JConsole jConsole) { 58 super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false); 59 60 setAccessibleDescription(this, Messages.HELP_ABOUT_DIALOG_ACCESSIBLE_DESCRIPTION); 61 setDefaultCloseOperation(HIDE_ON_CLOSE); 62 setResizable(false); 63 JComponent cp = (JComponent)getContentPane(); 64 65 createActions(); 66 67 JLabel mastheadLabel = new JLabel(mastheadIcon); 68 setAccessibleName(mastheadLabel, 69 Messages.HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME); 70 71 JPanel mainPanel = new TPanel(0, 0); 72 mainPanel.add(mastheadLabel, NORTH); 73 74 String jConsoleVersion = Version.getVersion(); 75 String vmName = System.getProperty("java.vm.name"); 76 String vmVersion = System.getProperty("java.vm.version"); 77 String urlStr = Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL; 78 if (isBrowseSupported()) { 79 urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>"; 80 } 81 82 JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10)); 83 infoAndLogoPanel.setBackground(bgColor); 84 85 String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF); 86 JEditorPane helpLink = new JEditorPane("text/html", 87 "<html><font color=#"+ colorStr + ">" + 88 Resources.format(Messages.HELP_ABOUT_DIALOG_JCONSOLE_VERSION, jConsoleVersion) + 89 "<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) + 90 "<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK, urlStr) + 91 "</html>"); 92 helpLink.setOpaque(false); 93 helpLink.setEditable(false); 94 helpLink.setForeground(textColor); 95 mainPanel.setBorder(BorderFactory.createLineBorder(borderColor)); 96 infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 97 helpLink.addHyperlinkListener(new HyperlinkListener() { 98 public void hyperlinkUpdate(HyperlinkEvent e) { 99 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 100 browse(e.getDescription()); 101 } 102 } 103 }); 104 infoAndLogoPanel.add(helpLink, NORTH); 105 106 ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png")); 107 JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING); 108 109 JButton closeButton = new JButton(closeAction); 110 111 JPanel bottomPanel = new TPanel(0, 0); 112 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); 113 buttonPanel.setOpaque(false); 114 115 mainPanel.add(infoAndLogoPanel, CENTER); 116 cp.add(bottomPanel, SOUTH); 117 118 infoAndLogoPanel.add(brandLogo, SOUTH); 119 120 buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12)); 121 buttonPanel.add(closeButton); 122 bottomPanel.add(buttonPanel, NORTH); 123 124 statusBar = new JLabel(" "); 125 bottomPanel.add(statusBar, SOUTH); 126 127 cp.add(mainPanel, NORTH); 128 129 pack(); 130 setLocationRelativeTo(jConsole); 131 Utilities.updateTransparency(this); 132 } 133 134 public void showDialog() { 135 statusBar.setText(" "); 136 setVisible(true); 137 try { 138 // Bring to front of other dialogs 139 setSelected(true); 140 } catch (PropertyVetoException e) { 141 // ignore 142 } 143 } 144 145 private static AboutDialog getAboutDialog(JConsole jConsole) { 146 if (aboutDialog == null) { 147 aboutDialog = new AboutDialog(jConsole); 148 } 149 return aboutDialog; 150 } 151 152 static void showAboutDialog(JConsole jConsole) { 153 getAboutDialog(jConsole).showDialog(); 154 } 155 156 static void browseUserGuide(JConsole jConsole) { 157 getAboutDialog(jConsole).browse(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL); 158 } 159 160 static boolean isBrowseSupported() { 161 return (Desktop.isDesktopSupported() && 162 Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)); 163 } 164 165 void browse(String urlStr) { 166 try { 167 Desktop.getDesktop().browse(new URI(urlStr)); 168 } catch (Exception ex) { 169 showDialog(); 170 statusBar.setText(ex.getLocalizedMessage()); 171 if (JConsole.isDebug()) { 172 ex.printStackTrace(); 173 } 174 } 175 } 176 177 private void createActions() { 178 closeAction = new AbstractAction(Messages.CLOSE) { 179 public void actionPerformed(ActionEvent ev) { 180 setVisible(false); 181 statusBar.setText(""); 182 } 183 }; 184 } 185 186 private static class TPanel extends JPanel { 187 TPanel(int hgap, int vgap) { 188 super(new BorderLayout(hgap, vgap)); 189 setOpaque(false); 190 } 191 } 192 }