Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jconsole/share/classes/sun/tools/jconsole/AboutDialog.java
40948 views
1
/*
2
* Copyright (c) 2006, 2021, 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.BasicStroke;
29
import java.awt.BorderLayout;
30
import java.awt.Color;
31
import java.awt.Desktop;
32
import java.awt.FlowLayout;
33
import java.awt.Graphics2D;
34
import java.awt.Graphics;
35
import java.awt.Rectangle;
36
import java.awt.Shape;
37
import java.awt.Stroke;
38
import java.awt.event.ActionEvent;
39
import java.awt.event.FocusEvent;
40
import java.awt.event.FocusListener;
41
import java.awt.event.KeyAdapter;
42
import java.awt.event.KeyEvent;
43
import java.awt.geom.Rectangle2D;
44
import java.beans.PropertyVetoException;
45
import java.net.URI;
46
import javax.swing.AbstractAction;
47
import javax.swing.Action;
48
import javax.swing.BorderFactory;
49
import javax.swing.Icon;
50
import javax.swing.ImageIcon;
51
import javax.swing.JButton;
52
import javax.swing.JComponent;
53
import javax.swing.JEditorPane;
54
import javax.swing.JLabel;
55
import javax.swing.JPanel;
56
import javax.swing.border.EmptyBorder;
57
import javax.swing.event.HyperlinkEvent;
58
import javax.swing.event.HyperlinkListener;
59
import javax.swing.text.BadLocationException;
60
import javax.swing.text.DefaultHighlighter;
61
import javax.swing.text.Document;
62
import javax.swing.text.Highlighter;
63
import javax.swing.text.JTextComponent;
64
import javax.swing.text.View;
65
66
import static java.awt.BorderLayout.CENTER;
67
import static java.awt.BorderLayout.NORTH;
68
import static java.awt.BorderLayout.SOUTH;
69
70
import static sun.tools.jconsole.Utilities.setAccessibleDescription;
71
import static sun.tools.jconsole.Utilities.setAccessibleName;
72
73
@SuppressWarnings("serial")
74
public class AboutDialog extends InternalDialog {
75
76
private static final Color textColor = new Color(87, 88, 89);
77
private static final Color bgColor = new Color(232, 237, 241);
78
private static final Color borderColor = Color.black;
79
80
private Icon mastheadIcon =
81
new MastheadIcon(Messages.HELP_ABOUT_DIALOG_MASTHEAD_TITLE);
82
83
private static AboutDialog aboutDialog;
84
85
private JLabel statusBar;
86
private Action closeAction;
87
private JEditorPane helpLink;
88
private final String urlStr = getOnlineDocUrl();
89
90
public AboutDialog(JConsole jConsole) {
91
super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false);
92
93
setAccessibleDescription(this, Messages.HELP_ABOUT_DIALOG_ACCESSIBLE_DESCRIPTION);
94
setDefaultCloseOperation(HIDE_ON_CLOSE);
95
setResizable(false);
96
JComponent cp = (JComponent)getContentPane();
97
98
createActions();
99
100
JLabel mastheadLabel = new JLabel(mastheadIcon);
101
setAccessibleName(mastheadLabel,
102
Messages.HELP_ABOUT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);
103
104
JPanel mainPanel = new TPanel(0, 0);
105
mainPanel.add(mastheadLabel, NORTH);
106
107
String jConsoleVersion = Version.getVersion();
108
String vmName = System.getProperty("java.vm.name");
109
String vmVersion = System.getProperty("java.vm.version");
110
String locUrlStr = urlStr;
111
if (isBrowseSupported()) {
112
locUrlStr = "<a style='color:#35556b' href=\"" + locUrlStr + "\">" + locUrlStr + "</a>";
113
}
114
115
JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
116
infoAndLogoPanel.setBackground(bgColor);
117
118
String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
119
helpLink = new JEditorPane("text/html",
120
"<html><font color=#"+ colorStr + ">" +
121
Resources.format(Messages.HELP_ABOUT_DIALOG_JCONSOLE_VERSION, jConsoleVersion) +
122
"<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) +
123
"<p>" + locUrlStr + "</html>");
124
125
helpLink.setOpaque(false);
126
helpLink.setEditable(false);
127
helpLink.setForeground(textColor);
128
129
mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
130
infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
131
132
helpLink.addKeyListener(new KeyAdapter() {
133
@Override
134
public void keyPressed(KeyEvent e) {
135
if ((e.getKeyCode() == KeyEvent.VK_ENTER) || (e.getKeyCode() == KeyEvent.VK_SPACE)) {
136
browse(urlStr);
137
e.consume();
138
}
139
}
140
});
141
142
helpLink.addFocusListener(new FocusListener() {
143
@Override
144
public void focusGained(FocusEvent e) {
145
highlight();
146
}
147
@Override
148
public void focusLost(FocusEvent e) {
149
removeHighlights();
150
}
151
});
152
153
helpLink.addHyperlinkListener(new HyperlinkListener() {
154
public void hyperlinkUpdate(HyperlinkEvent e) {
155
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
156
browse(e.getDescription());
157
}
158
}
159
});
160
infoAndLogoPanel.add(helpLink, NORTH);
161
162
ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));
163
JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);
164
165
JButton closeButton = new JButton(closeAction);
166
167
JPanel bottomPanel = new TPanel(0, 0);
168
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
169
buttonPanel.setOpaque(false);
170
171
mainPanel.add(infoAndLogoPanel, CENTER);
172
cp.add(bottomPanel, SOUTH);
173
174
infoAndLogoPanel.add(brandLogo, SOUTH);
175
176
buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
177
buttonPanel.add(closeButton);
178
bottomPanel.add(buttonPanel, NORTH);
179
180
statusBar = new JLabel(" ");
181
bottomPanel.add(statusBar, SOUTH);
182
183
cp.add(mainPanel, NORTH);
184
185
pack();
186
setLocationRelativeTo(jConsole);
187
Utilities.updateTransparency(this);
188
}
189
190
public void highlight() {
191
try {
192
removeHighlights();
193
194
Highlighter hilite = helpLink.getHighlighter();
195
Document doc = helpLink.getDocument();
196
String text = doc.getText(0, doc.getLength());
197
int pos = text.indexOf(urlStr, 0);
198
hilite.addHighlight(pos, pos + urlStr.length(), new HighlightPainter());
199
} catch (BadLocationException e) {
200
// ignore
201
}
202
}
203
204
public void removeHighlights() {
205
Highlighter hilite = helpLink.getHighlighter();
206
hilite.removeAllHighlights();
207
}
208
209
public void showDialog() {
210
statusBar.setText(" ");
211
setVisible(true);
212
try {
213
// Bring to front of other dialogs
214
setSelected(true);
215
} catch (PropertyVetoException e) {
216
// ignore
217
}
218
}
219
220
private static AboutDialog getAboutDialog(JConsole jConsole) {
221
if (aboutDialog == null) {
222
aboutDialog = new AboutDialog(jConsole);
223
}
224
return aboutDialog;
225
}
226
227
static void showAboutDialog(JConsole jConsole) {
228
getAboutDialog(jConsole).showDialog();
229
}
230
231
static void browseUserGuide(JConsole jConsole) {
232
getAboutDialog(jConsole).browse(getOnlineDocUrl());
233
}
234
235
static boolean isBrowseSupported() {
236
return (Desktop.isDesktopSupported() &&
237
Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
238
}
239
240
void browse(String urlStr) {
241
try {
242
Desktop.getDesktop().browse(new URI(urlStr));
243
} catch (Exception ex) {
244
showDialog();
245
statusBar.setText(ex.getLocalizedMessage());
246
if (JConsole.isDebug()) {
247
ex.printStackTrace();
248
}
249
}
250
}
251
252
private void createActions() {
253
closeAction = new AbstractAction(Messages.CLOSE) {
254
public void actionPerformed(ActionEvent ev) {
255
setVisible(false);
256
statusBar.setText("");
257
}
258
};
259
}
260
261
private static String getOnlineDocUrl() {
262
String version = Integer.toString(Runtime.version().feature());
263
return Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL,
264
version);
265
}
266
267
private static class TPanel extends JPanel {
268
TPanel(int hgap, int vgap) {
269
super(new BorderLayout(hgap, vgap));
270
setOpaque(false);
271
}
272
}
273
274
private static class HighlightPainter
275
extends DefaultHighlighter.DefaultHighlightPainter {
276
277
public HighlightPainter() {
278
super(null);
279
}
280
@Override
281
public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds,
282
JTextComponent c, View view) {
283
g.setColor(c.getSelectionColor());
284
Rectangle alloc;
285
286
if (bounds instanceof Rectangle) {
287
alloc = (Rectangle)bounds;
288
} else {
289
alloc = bounds.getBounds();
290
}
291
292
Graphics2D g2d = (Graphics2D)g;
293
294
float[] dash = { 2F, 2F };
295
Stroke dashedStroke = new BasicStroke(1F, BasicStroke.CAP_SQUARE,
296
BasicStroke.JOIN_MITER, 3F, dash, 0F);
297
g2d.fill(dashedStroke.createStrokedShape(
298
new Rectangle2D.Float(alloc.x, alloc.y,
299
alloc.width - 1, alloc.height - 1)));
300
return alloc;
301
}
302
}
303
}
304
305