2
|
1 |
/*
|
|
2 |
* Copyright 2006-2007 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any 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.accessibility.*;
|
|
34 |
import javax.swing.*;
|
|
35 |
import javax.swing.border.*;
|
|
36 |
import javax.swing.event.*;
|
|
37 |
|
|
38 |
import static java.awt.BorderLayout.*;
|
|
39 |
import static sun.tools.jconsole.Resources.*;
|
|
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(getText("Help.AboutDialog.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, Resources.getText("Help.AboutDialog.title"), false);
|
|
59 |
|
|
60 |
setAccessibleDescription(this,
|
|
61 |
getText("Help.AboutDialog.accessibleDescription"));
|
|
62 |
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
|
63 |
setResizable(false);
|
|
64 |
JComponent cp = (JComponent)getContentPane();
|
|
65 |
|
|
66 |
createActions();
|
|
67 |
|
|
68 |
JLabel mastheadLabel = new JLabel(mastheadIcon);
|
|
69 |
setAccessibleName(mastheadLabel,
|
|
70 |
getText("Help.AboutDialog.masthead.accessibleName"));
|
|
71 |
|
|
72 |
JPanel mainPanel = new TPanel(0, 0);
|
|
73 |
mainPanel.add(mastheadLabel, NORTH);
|
|
74 |
|
|
75 |
String jConsoleVersion = Version.getVersion();
|
|
76 |
String vmName = System.getProperty("java.vm.name");
|
|
77 |
String vmVersion = System.getProperty("java.vm.version");
|
|
78 |
String urlStr = getText("Help.AboutDialog.userGuideLink.url");
|
|
79 |
if (isBrowseSupported()) {
|
|
80 |
urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
|
|
81 |
}
|
|
82 |
|
|
83 |
JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
|
|
84 |
infoAndLogoPanel.setBackground(bgColor);
|
|
85 |
|
|
86 |
String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
|
|
87 |
JEditorPane helpLink = new JEditorPane("text/html",
|
|
88 |
"<html><font color=#"+ colorStr + ">" +
|
|
89 |
getText("Help.AboutDialog.jConsoleVersion", jConsoleVersion) +
|
|
90 |
"<p>" + getText("Help.AboutDialog.javaVersion", (vmName +", "+ vmVersion)) +
|
|
91 |
"<p>" + getText("Help.AboutDialog.userGuideLink", urlStr) +
|
|
92 |
"</html>");
|
|
93 |
helpLink.setOpaque(false);
|
|
94 |
helpLink.setEditable(false);
|
|
95 |
helpLink.setForeground(textColor);
|
|
96 |
mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
|
|
97 |
infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
|
98 |
helpLink.addHyperlinkListener(new HyperlinkListener() {
|
|
99 |
public void hyperlinkUpdate(HyperlinkEvent e) {
|
|
100 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
|
101 |
browse(e.getDescription());
|
|
102 |
}
|
|
103 |
}
|
|
104 |
});
|
|
105 |
infoAndLogoPanel.add(helpLink, NORTH);
|
|
106 |
|
|
107 |
ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));
|
|
108 |
JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);
|
|
109 |
|
|
110 |
JButton closeButton = new JButton(closeAction);
|
|
111 |
|
|
112 |
JPanel bottomPanel = new TPanel(0, 0);
|
|
113 |
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
|
|
114 |
buttonPanel.setOpaque(false);
|
|
115 |
|
|
116 |
mainPanel.add(infoAndLogoPanel, CENTER);
|
|
117 |
cp.add(bottomPanel, SOUTH);
|
|
118 |
|
|
119 |
infoAndLogoPanel.add(brandLogo, SOUTH);
|
|
120 |
|
|
121 |
buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
|
|
122 |
buttonPanel.add(closeButton);
|
|
123 |
bottomPanel.add(buttonPanel, NORTH);
|
|
124 |
|
|
125 |
statusBar = new JLabel(" ");
|
|
126 |
bottomPanel.add(statusBar, SOUTH);
|
|
127 |
|
|
128 |
cp.add(mainPanel, NORTH);
|
|
129 |
|
|
130 |
pack();
|
|
131 |
setLocationRelativeTo(jConsole);
|
|
132 |
Utilities.updateTransparency(this);
|
|
133 |
}
|
|
134 |
|
|
135 |
public void showDialog() {
|
|
136 |
statusBar.setText(" ");
|
|
137 |
setVisible(true);
|
|
138 |
try {
|
|
139 |
// Bring to front of other dialogs
|
|
140 |
setSelected(true);
|
|
141 |
} catch (PropertyVetoException e) {
|
|
142 |
// ignore
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
private static AboutDialog getAboutDialog(JConsole jConsole) {
|
|
147 |
if (aboutDialog == null) {
|
|
148 |
aboutDialog = new AboutDialog(jConsole);
|
|
149 |
}
|
|
150 |
return aboutDialog;
|
|
151 |
}
|
|
152 |
|
|
153 |
static void showAboutDialog(JConsole jConsole) {
|
|
154 |
getAboutDialog(jConsole).showDialog();
|
|
155 |
}
|
|
156 |
|
|
157 |
static void browseUserGuide(JConsole jConsole) {
|
|
158 |
getAboutDialog(jConsole).browse(getText("Help.AboutDialog.userGuideLink.url"));
|
|
159 |
}
|
|
160 |
|
|
161 |
static boolean isBrowseSupported() {
|
|
162 |
return (Desktop.isDesktopSupported() &&
|
|
163 |
Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
|
|
164 |
}
|
|
165 |
|
|
166 |
void browse(String urlStr) {
|
|
167 |
try {
|
|
168 |
Desktop.getDesktop().browse(new URI(urlStr));
|
|
169 |
} catch (Exception ex) {
|
|
170 |
showDialog();
|
|
171 |
statusBar.setText(ex.getLocalizedMessage());
|
|
172 |
if (JConsole.isDebug()) {
|
|
173 |
ex.printStackTrace();
|
|
174 |
}
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
private void createActions() {
|
|
179 |
closeAction = new AbstractAction(getText("Close")) {
|
|
180 |
public void actionPerformed(ActionEvent ev) {
|
|
181 |
setVisible(false);
|
|
182 |
statusBar.setText("");
|
|
183 |
}
|
|
184 |
};
|
|
185 |
}
|
|
186 |
|
|
187 |
private static class TPanel extends JPanel {
|
|
188 |
TPanel(int hgap, int vgap) {
|
|
189 |
super(new BorderLayout(hgap, vgap));
|
|
190 |
setOpaque(false);
|
|
191 |
}
|
|
192 |
}
|
|
193 |
}
|