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 | |
package org.argouml.ui; |
44 | |
|
45 | |
import java.awt.Frame; |
46 | |
import java.awt.Insets; |
47 | |
import java.awt.datatransfer.Clipboard; |
48 | |
import java.awt.datatransfer.ClipboardOwner; |
49 | |
import java.awt.datatransfer.StringSelection; |
50 | |
import java.awt.datatransfer.Transferable; |
51 | |
import java.awt.event.ActionEvent; |
52 | |
import java.awt.event.ActionListener; |
53 | |
import java.awt.event.WindowAdapter; |
54 | |
import java.awt.event.WindowEvent; |
55 | |
|
56 | |
import javax.swing.JButton; |
57 | |
import javax.swing.JScrollPane; |
58 | |
import javax.swing.JTextArea; |
59 | |
|
60 | |
import org.argouml.application.helpers.ApplicationVersion; |
61 | |
import org.argouml.i18n.Translator; |
62 | |
import org.argouml.util.ArgoDialog; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | public class SystemInfoDialog extends ArgoDialog { |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
private static final long serialVersionUID = 1595302214402366939L; |
76 | |
|
77 | |
|
78 | |
private static final int INSET_PX = 3; |
79 | |
|
80 | 0 | private JTextArea info = new JTextArea(); |
81 | 0 | private JButton runGCButton = new JButton(); |
82 | 0 | private JButton copyButton = new JButton(); |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public SystemInfoDialog(boolean modal) { |
90 | 0 | super(Translator.localize("dialog.title.system-information"), |
91 | |
ArgoDialog.CLOSE_OPTION, modal); |
92 | |
|
93 | 0 | info.setEditable(false); |
94 | 0 | info.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX)); |
95 | |
|
96 | 0 | runGCButton.addActionListener(new ActionListener() { |
97 | |
public void actionPerformed(ActionEvent e) { |
98 | 0 | runGCActionPerformed(e); |
99 | 0 | } |
100 | |
}); |
101 | 0 | copyButton.addActionListener(new ActionListener() { |
102 | |
public void actionPerformed(ActionEvent e) { |
103 | 0 | copyActionPerformed(e); |
104 | 0 | } |
105 | |
}); |
106 | |
|
107 | 0 | nameButton(copyButton, "button.copy-to-clipboard"); |
108 | 0 | nameButton(runGCButton, "button.run-gc"); |
109 | 0 | addButton(copyButton, 0); |
110 | 0 | addButton(runGCButton, 0); |
111 | 0 | setContent(new JScrollPane(info)); |
112 | 0 | updateInfo(); |
113 | 0 | addWindowListener(new WindowAdapter() { |
114 | |
public void windowActivated(WindowEvent e) { |
115 | 0 | updateInfo(); |
116 | 0 | } |
117 | |
}); |
118 | 0 | pack(); |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private void runGCActionPerformed(ActionEvent e) { |
127 | 0 | assert e.getSource() == runGCButton; |
128 | 0 | Runtime.getRuntime().gc(); |
129 | 0 | updateInfo(); |
130 | 0 | } |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
private void copyActionPerformed(ActionEvent e) { |
138 | 0 | assert e.getSource() == copyButton; |
139 | 0 | String infoText = info.getText(); |
140 | 0 | StringSelection contents = new StringSelection(infoText); |
141 | 0 | Clipboard clipboard = getToolkit().getSystemClipboard(); |
142 | 0 | clipboard.setContents(contents, defaultClipboardOwner); |
143 | 0 | } |
144 | |
|
145 | |
void updateInfo() { |
146 | 0 | info.setText(getInfo()); |
147 | 0 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
public static String getInfo() { |
154 | 0 | StringBuffer s = new StringBuffer(); |
155 | 0 | s.append(Translator.localize("dialog.systeminfo.argoumlversion")); |
156 | 0 | s.append(ApplicationVersion.getVersion() + "\n"); |
157 | 0 | s.append(Translator.localize("dialog.systeminfo.javaversion")); |
158 | 0 | s.append(System.getProperty("java.version", "") + "\n"); |
159 | 0 | s.append(Translator.localize("dialog.systeminfo.javavendor")); |
160 | 0 | s.append(System.getProperty("java.vendor", "") + "\n"); |
161 | 0 | s.append(Translator.localize("dialog.systeminfo.url-javavendor")); |
162 | 0 | s.append(System.getProperty("java.vendor.url", "") + "\n"); |
163 | 0 | s.append(Translator.localize("dialog.systeminfo.java-home-directory")); |
164 | 0 | s.append(System.getProperty("java.home", "") + "\n"); |
165 | 0 | s.append(Translator.localize("dialog.systeminfo.java-classpath")); |
166 | 0 | s.append(System.getProperty("java.class.path", "") + "\n"); |
167 | 0 | s.append(Translator.localize("dialog.systeminfo.operating-system")); |
168 | 0 | s.append(System.getProperty("os.name", "")); |
169 | 0 | s.append(Translator.localize( |
170 | |
"dialog.systeminfo.operating-systemversion")); |
171 | 0 | s.append(System.getProperty("os.version", "") + "\n"); |
172 | 0 | s.append(Translator.localize("dialog.systeminfo.architecture")); |
173 | 0 | s.append(System.getProperty("os.arch", "") + "\n"); |
174 | 0 | s.append(Translator.localize("dialog.systeminfo.user-name")); |
175 | 0 | s.append(System.getProperty("user.name", "") + "\n"); |
176 | 0 | s.append(Translator.localize("dialog.systeminfo.user-home-directory")); |
177 | 0 | s.append(System.getProperty("user.home", "") + "\n"); |
178 | 0 | s.append(Translator.localize("dialog.systeminfo.current-directory")); |
179 | 0 | s.append(System.getProperty("user.dir", "") + "\n"); |
180 | 0 | s.append(Translator.localize("dialog.systeminfo.jvm-total-memory")); |
181 | 0 | s.append(String.valueOf(Runtime.getRuntime().totalMemory()) + "\n"); |
182 | 0 | s.append(Translator.localize("dialog.systeminfo.jvm-free-memory")); |
183 | 0 | s.append(String.valueOf(Runtime.getRuntime().freeMemory()) + "\n"); |
184 | 0 | return s.toString(); |
185 | |
} |
186 | |
|
187 | 0 | private static ClipboardOwner defaultClipboardOwner = |
188 | |
new ClipboardObserver(); |
189 | |
|
190 | 0 | static class ClipboardObserver implements ClipboardOwner { |
191 | |
public void lostOwnership(Clipboard clipboard, Transferable contents) { |
192 | 0 | } |
193 | |
} |
194 | |
|
195 | |
} |