1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.devaki.nextobjects.ui.others;
21 import java.util.Enumeration;
22 import java.util.Vector;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import javax.swing.DefaultListSelectionModel;
30 import javax.swing.JDialog;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JTabbedPane;
35 import javax.swing.SwingConstants;
36 import javax.swing.WindowConstants;
37 import javax.swing.table.AbstractTableModel;
38 import org.devaki.nextobjects.NextObjects;
39 import org.devaki.nextobjects.ui.components.CustomButton;
40 import org.devaki.nextobjects.ui.components.CustomTable;
41 import javax.swing.ImageIcon;
42 import org.devaki.nextobjects.ui.workspace.models.PropertyEdit;
43 import org.devaki.nextobjects.util.NOPreferences;
44 import org.devaki.nextobjects.workspace.models.Property;
45 /***
46 * The about screen of devaki-nextobjects
47 */
48 public class AboutNO extends JDialog
49 {
50 /***
51 * The label who handle splash image
52 */
53 private JLabel jLabelImage;
54 /***
55 * The OK button
56 */
57 private CustomButton jButtonOK = new CustomButton("OK", "", true, false);
58 /***
59 * The JVM Garbage Collect button
60 */
61 private CustomButton jButtonGC =
62 new CustomButton("Free up resources", "", true, false);
63 /***
64 * The jtable handling JVM Properties
65 */
66 private CustomTable jTableProperties =
67 new CustomTable(
68 true,
69 DefaultListSelectionModel.SINGLE_SELECTION,
70 false,
71 true);
72 /***
73 * The table model for the JTable JVM propertie
74 */
75 private AboutFieldTableModel model = new AboutFieldTableModel();
76 /***
77 * The splash tab
78 */
79 private JTabbedPane jTabbedPaneAboutNO = new JTabbedPane(SwingConstants.TOP);
80 /***
81 * A kind of 'main' panel
82 */
83 private JPanel jPanelAbout = new JPanel(new GridBagLayout());
84 /***
85 * The application properties editor
86 */
87 private PropertyEdit propertyEdit = new PropertyEdit();
88 /***
89 * The JVM info panel
90 */
91 private JPanel jPanelInfos = new JPanel(new GridBagLayout());
92 /***
93 * The scrollpane handling properties
94 */
95 private JScrollPane jScrollPaneProperties = new JScrollPane(jTableProperties);
96 /***
97 * Construct the about window
98 */
99 public AboutNO()
100 {
101
102 super(NextObjects.getReference(), "About - devaki-nextobjects");
103
104 this.setSize(new Dimension(570, 443));
105
106 this.setLocationRelativeTo(null);
107
108
109
110 this.setResizable(false);
111
112 this.getRootPane().setDefaultButton(jButtonOK);
113
114 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
115
116
117 this.getContentPane().setLayout(new GridBagLayout());
118
119 Vector vctProps = new Vector();
120 Enumeration enum = NOPreferences.getAppProperties().keys();
121 while (enum.hasMoreElements())
122 {
123 String key = enum.nextElement().toString();
124 Property prop =
125 new Property(
126 key,
127 NOPreferences.getAppProperties().getProperty(key));
128 vctProps.addElement(prop);
129 }
130 propertyEdit.getModel().setProperties(vctProps);
131
132 jTableProperties.setModel(model);
133 Enumeration enum2 = System.getProperties().propertyNames();
134 while (enum2.hasMoreElements())
135 {
136 String prop = (String) enum2.nextElement();
137 model.addField(new SysInfo(prop, System.getProperty(prop)));
138 }
139 jTableProperties.getColumnModel().getColumn(0).setPreferredWidth(170);
140 jTableProperties.getColumnModel().getColumn(1).setPreferredWidth(380);
141
142
143 jButtonOK.addActionListener(new ActionListener()
144 {
145 public void actionPerformed(ActionEvent e)
146 {
147 dispose();
148 }
149 });
150 jButtonGC.addActionListener(new ActionListener()
151 {
152 public void actionPerformed(ActionEvent e)
153 {
154 System.gc();
155 }
156 });
157
158 ClassLoader cl = this.getClass().getClassLoader();
159 jLabelImage =
160 new JLabel(
161 new ImageIcon(
162 cl.getResource("org/devaki/nextobjects/icons/splash.png")));
163 JPanel jvmStats = new JVMInfo();
164
165
166 jPanelAbout.add(
167 jLabelImage,
168 new GridBagConstraints(
169 0,
170 0,
171 1,
172 1,
173 0.0,
174 0.0,
175 GridBagConstraints.CENTER,
176 GridBagConstraints.NONE,
177 new Insets(0, 0, 0, 0),
178 0,
179 0));
180
181 jPanelInfos.add(
182 jvmStats,
183 new GridBagConstraints(
184 0,
185 0,
186 2,
187 1,
188 1.0,
189 1.0,
190 GridBagConstraints.CENTER,
191 GridBagConstraints.BOTH,
192 new Insets(5, 5, 0, 5),
193 0,
194 0));
195 jPanelInfos.add(
196 jScrollPaneProperties,
197 new GridBagConstraints(
198 0,
199 1,
200 2,
201 1,
202 1.0,
203 1.0,
204 GridBagConstraints.CENTER,
205 GridBagConstraints.BOTH,
206 new Insets(5, 5, 0, 5),
207 0,
208 0));
209 jPanelInfos.add(
210 jButtonGC,
211 new GridBagConstraints(
212 0,
213 2,
214 1,
215 1,
216 0.0,
217 0.0,
218 GridBagConstraints.WEST,
219 GridBagConstraints.NONE,
220 new Insets(5, 0, 5, 5),
221 0,
222 0));
223
224 jTabbedPaneAboutNO.add(jPanelAbout, "About");
225 jTabbedPaneAboutNO.add(propertyEdit, "Preferences");
226 jTabbedPaneAboutNO.add(jPanelInfos, "Infos");
227
228 this.getContentPane().add(
229 jTabbedPaneAboutNO,
230 new GridBagConstraints(
231 0,
232 0,
233 1,
234 1,
235 1.0,
236 1.0,
237 GridBagConstraints.CENTER,
238 GridBagConstraints.BOTH,
239 new Insets(5, 5, 0, 5),
240 0,
241 0));
242 this.getContentPane().add(
243 jButtonOK,
244 new GridBagConstraints(
245 0,
246 1,
247 1,
248 1,
249 0.0,
250 0.0,
251 GridBagConstraints.EAST,
252 GridBagConstraints.NONE,
253 new Insets(5, 5, 5, 5),
254 0,
255 0));
256 }
257 public void showPref()
258 {
259 this.jTabbedPaneAboutNO.setSelectedIndex(1);
260 }
261 }
262 /***
263 * SysInfo represent JVM properties key pairs
264 */
265 class SysInfo
266 {
267 private String name;
268 private String value;
269 public SysInfo(String name, String value)
270 {
271 this.name = name;
272 this.value = value;
273 }
274 public String getName()
275 {
276 return name;
277 }
278 public String getValue()
279 {
280 return value;
281 }
282 }
283 /***
284 * AboutFieldTableModel is a table model for JVM properties (key pairs)
285 */
286 class AboutFieldTableModel extends AbstractTableModel
287 {
288 final String[] columnNames = { "Name", "Value" };
289 final Class[] columnClasses = { String.class, String.class };
290 Vector data = new Vector();
291 public void addField(SysInfo w)
292 {
293 data.addElement(w);
294 fireTableRowsInserted(data.size() - 1, data.size() - 1);
295 }
296 public int getColumnCount()
297 {
298 return columnNames.length;
299 }
300 public int getRowCount()
301 {
302 return data.size();
303 }
304 public String getColumnName(int col)
305 {
306 return columnNames[col];
307 }
308 public Class getColumnClass(int c)
309 {
310 return columnClasses[c];
311 }
312 public Object getValueAt(int row, int col)
313 {
314 SysInfo info = (SysInfo) data.elementAt(row);
315 if (col == 0)
316 {
317 return info.getName();
318 }
319 else
320 if (col == 1)
321 {
322 return info.getValue();
323 }
324 else
325 {
326 return null;
327 }
328 }
329 public boolean isCellEditable(int row, int col)
330 {
331 return false;
332 }
333 }