/
PlatformInfoWindow.java
102 lines (86 loc) · 3.75 KB
/
PlatformInfoWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package net.ME1312.Galaxi.Engine.Runtime;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PlatformInfoWindow extends JDialog {
private JPanel window;
private JLabel icon;
private JLabel name;
private JLabel tagLine;
private JLabel infoLabel;
private JTextArea info;
private JButton close;
private JButton copy;
private JLabel copied;
public PlatformInfoWindow(final JFrame parent, PluginInfo app, final double scale) {
super(parent, "Platform Information");
PluginInfo engine = Engine.getInstance().getEngineInfo();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize((int) (600 * scale), (int) (300 * scale));
setResizable(false);
setContentPane(window);
setModal(true);
final Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screen = toolkit.getScreenSize();
if (parent != null) setLocation(
Math.abs(parent.getX() + ((parent.getWidth() - getWidth()) / 2)),
Math.abs(parent.getY() + ((parent.getHeight() - getHeight()) / 2))
); else setLocation(
(int) Math.abs((screen.getWidth() - getWidth()) / 2),
(int) Math.abs((screen.getHeight() - getHeight()) / 2)
);
icon.setIcon(new ImageIcon(engine.getIcon()
.getScaledInstance((int) (100 * scale), (int) (100 * scale), Image.SCALE_SMOOTH)));
name.setText(engine.getDisplayName());
name.setFont(tagLine.getFont().deriveFont((float) (36 * scale)));
tagLine.setText(engine.getDescription());
tagLine.setFont(tagLine.getFont().deriveFont((float) (12 * scale)));
StringBuilder infoText = new StringBuilder();
for (String item : app.getPlatformStack()) {
infoText.append(item);
if (item.endsWith(",")) infoText.append('\n');
}
info.setOpaque(false);
info.setMargin(new Insets(0, 0, 0, 0));
info.setText(infoText.toString());
info.setFont(tagLine.getFont().deriveFont((float) (12 * scale)));
infoLabel.setFont(tagLine.getFont().deriveFont((float) (18 * scale)));
close.setDefaultCapable(false);
close.setFont(close.getFont().deriveFont((float) (12 * scale)));
close.setText("\u00A0Close\u00A0");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
final StringSelection clipboard = new StringSelection(infoText.toString());
final Container<Timer> timer = new Container<>();
copy.setDefaultCapable(false);
copy.setFont(copy.getFont().deriveFont((float) (12 * scale)));
copy.setText("\u00A0Copy\u00A0");
copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (timer.value != null) timer.value.stop();
toolkit.getSystemClipboard().setContents(clipboard, clipboard);
copied.setVisible(true);
(timer.value = new Timer(2500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copied.setVisible(false);
timer.value.stop();
}
})).start();
}
});
copied.setVisible(false);
copied.setFont(copied.getFont().deriveFont((float) (12 * scale)));
}
public void open() {
setVisible(true);
toFront();
}
}