001: /*
002: * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.tools.jconsole;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.beans.PropertyVetoException;
031: import java.net.URI;
032:
033: import javax.accessibility.*;
034: import javax.swing.*;
035: import javax.swing.border.*;
036: import javax.swing.event.*;
037:
038: import static java.awt.BorderLayout.*;
039: import static sun.tools.jconsole.Resources.*;
040: import static sun.tools.jconsole.Utilities.*;
041:
042: @SuppressWarnings("serial")
043: public class AboutDialog extends InternalDialog {
044:
045: private static final Color textColor = new Color(87, 88, 89);
046: private static final Color bgColor = new Color(232, 237, 241);
047: private static final Color borderColor = Color.black;
048:
049: private Icon mastheadIcon = new MastheadIcon(
050: getText("Help.AboutDialog.masthead.title"));
051:
052: private static AboutDialog aboutDialog;
053:
054: private JLabel statusBar;
055: private Action closeAction;
056:
057: public AboutDialog(JConsole jConsole) {
058: super (jConsole, Resources.getText("Help.AboutDialog.title"),
059: false);
060:
061: setAccessibleDescription(this ,
062: getText("Help.AboutDialog.accessibleDescription"));
063: setDefaultCloseOperation(HIDE_ON_CLOSE);
064: setResizable(false);
065: JComponent cp = (JComponent) getContentPane();
066:
067: createActions();
068:
069: JLabel mastheadLabel = new JLabel(mastheadIcon);
070: setAccessibleName(mastheadLabel,
071: getText("Help.AboutDialog.masthead.accessibleName"));
072:
073: JPanel mainPanel = new TPanel(0, 0);
074: mainPanel.add(mastheadLabel, NORTH);
075:
076: String jConsoleVersion = Version.getVersion();
077: String vmName = System.getProperty("java.vm.name");
078: String vmVersion = System.getProperty("java.vm.version");
079: String urlStr = getText("Help.AboutDialog.userGuideLink.url");
080: if (isBrowseSupported()) {
081: urlStr = "<a style='color:#35556b' href=\"" + urlStr
082: + "\">" + urlStr + "</a>";
083: }
084:
085: JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
086: infoAndLogoPanel.setBackground(bgColor);
087:
088: String colorStr = String.format("%06x",
089: textColor.getRGB() & 0xFFFFFF);
090: JEditorPane helpLink = new JEditorPane("text/html",
091: "<html><font color=#"
092: + colorStr
093: + ">"
094: + getText("Help.AboutDialog.jConsoleVersion",
095: jConsoleVersion)
096: + "<p>"
097: + getText("Help.AboutDialog.javaVersion",
098: (vmName + ", " + vmVersion))
099: + "<p>"
100: + getText("Help.AboutDialog.userGuideLink",
101: urlStr) + "</html>");
102: helpLink.setOpaque(false);
103: helpLink.setEditable(false);
104: helpLink.setForeground(textColor);
105: mainPanel
106: .setBorder(BorderFactory.createLineBorder(borderColor));
107: infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10,
108: 10, 10, 10));
109: helpLink.addHyperlinkListener(new HyperlinkListener() {
110: public void hyperlinkUpdate(HyperlinkEvent e) {
111: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
112: browse(e.getDescription());
113: }
114: }
115: });
116: infoAndLogoPanel.add(helpLink, NORTH);
117:
118: ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource(
119: "resources/brandlogo.png"));
120: JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);
121:
122: JButton closeButton = new JButton(closeAction);
123:
124: JPanel bottomPanel = new TPanel(0, 0);
125: JPanel buttonPanel = new JPanel(new FlowLayout(
126: FlowLayout.TRAILING));
127: buttonPanel.setOpaque(false);
128:
129: mainPanel.add(infoAndLogoPanel, CENTER);
130: cp.add(bottomPanel, SOUTH);
131:
132: infoAndLogoPanel.add(brandLogo, SOUTH);
133:
134: buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
135: buttonPanel.add(closeButton);
136: bottomPanel.add(buttonPanel, NORTH);
137:
138: statusBar = new JLabel(" ");
139: bottomPanel.add(statusBar, SOUTH);
140:
141: cp.add(mainPanel, NORTH);
142:
143: pack();
144: setLocationRelativeTo(jConsole);
145: Utilities.updateTransparency(this );
146: }
147:
148: public void showDialog() {
149: statusBar.setText(" ");
150: setVisible(true);
151: try {
152: // Bring to front of other dialogs
153: setSelected(true);
154: } catch (PropertyVetoException e) {
155: // ignore
156: }
157: }
158:
159: private static AboutDialog getAboutDialog(JConsole jConsole) {
160: if (aboutDialog == null) {
161: aboutDialog = new AboutDialog(jConsole);
162: }
163: return aboutDialog;
164: }
165:
166: static void showAboutDialog(JConsole jConsole) {
167: getAboutDialog(jConsole).showDialog();
168: }
169:
170: static void browseUserGuide(JConsole jConsole) {
171: getAboutDialog(jConsole).browse(
172: getText("Help.AboutDialog.userGuideLink.url"));
173: }
174:
175: static boolean isBrowseSupported() {
176: return (Desktop.isDesktopSupported() && Desktop.getDesktop()
177: .isSupported(Desktop.Action.BROWSE));
178: }
179:
180: void browse(String urlStr) {
181: try {
182: Desktop.getDesktop().browse(new URI(urlStr));
183: } catch (Exception ex) {
184: showDialog();
185: statusBar.setText(ex.getLocalizedMessage());
186: if (JConsole.isDebug()) {
187: ex.printStackTrace();
188: }
189: }
190: }
191:
192: private void createActions() {
193: closeAction = new AbstractAction(getText("Close")) {
194: public void actionPerformed(ActionEvent ev) {
195: setVisible(false);
196: statusBar.setText("");
197: }
198: };
199: }
200:
201: private static class TPanel extends JPanel {
202: TPanel(int hgap, int vgap) {
203: super (new BorderLayout(hgap, vgap));
204: setOpaque(false);
205: }
206: }
207: }
|