KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > about > SystemPropertiesFrame


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * --------------------------
28  * SystemPropertiesFrame.java
29  * --------------------------
30  * (C) Copyright 2000-2004, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: SystemPropertiesFrame.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
36  *
37  * Changes (from 26-Oct-2001)
38  * --------------------------
39  * 26-Oct-2001 : Changed package to com.jrefinery.ui (DG);
40  * 26-Nov-2001 : Made a separate class SystemPropertiesPanel.java (DG);
41  * 28-Feb-2002 : Moved to package com.jrefinery.ui.about (DG);
42  * 15-Mar-2002 : Modified to use a ResourceBundle for elements that require localisation (DG);
43  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
44  *
45  */

46
47 package org.jfree.ui.about;
48
49 import java.awt.BorderLayout JavaDoc;
50 import java.awt.event.ActionEvent JavaDoc;
51 import java.awt.event.ActionListener JavaDoc;
52 import java.util.ResourceBundle JavaDoc;
53
54 import javax.swing.BorderFactory JavaDoc;
55 import javax.swing.JButton JavaDoc;
56 import javax.swing.JFrame JavaDoc;
57 import javax.swing.JMenu JavaDoc;
58 import javax.swing.JMenuBar JavaDoc;
59 import javax.swing.JMenuItem JavaDoc;
60 import javax.swing.JPanel JavaDoc;
61 import javax.swing.WindowConstants JavaDoc;
62
63 /**
64  * A frame containing a table that displays the system properties for the current Java Virtual
65  * Machine (JVM). It is useful to incorporate this frame into an application for diagnostic
66  * purposes, since it provides a convenient means for the user to return configuration and
67  * version information when reporting problems.
68  *
69  * @author David Gilbert
70  */

71 public class SystemPropertiesFrame extends JFrame JavaDoc implements ActionListener JavaDoc {
72
73     /** Copy action command. */
74     private static final String JavaDoc COPY_COMMAND = "COPY";
75
76     /** Close action command. */
77     private static final String JavaDoc CLOSE_COMMAND = "CLOSE";
78
79     /** A system properties panel. */
80     private SystemPropertiesPanel panel;
81
82     /**
83      * Constructs a standard frame that displays system properties.
84      * <P>
85      * If a menu is requested, it provides a menu item that allows the user to copy the contents of
86      * the table to the clipboard in tab-delimited format.
87      *
88      * @param menu flag indicating whether or not the frame should display a menu to allow
89      * the user to copy properties to the clipboard.
90      */

91     public SystemPropertiesFrame(final boolean menu) {
92
93         final String JavaDoc baseName = "org.jfree.ui.about.resources.AboutResources";
94         final ResourceBundle JavaDoc resources = ResourceBundle.getBundle(baseName);
95
96         final String JavaDoc title = resources.getString("system-frame.title");
97         setTitle(title);
98
99         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
100
101         if (menu) {
102             setJMenuBar(createMenuBar(resources));
103         }
104
105         final JPanel JavaDoc content = new JPanel JavaDoc(new BorderLayout JavaDoc());
106         this.panel = new SystemPropertiesPanel();
107         this.panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
108
109         content.add(this.panel, BorderLayout.CENTER);
110
111         final JPanel JavaDoc buttonPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
112         buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
113
114         final String JavaDoc label = resources.getString("system-frame.button.close");
115         final Character JavaDoc mnemonic = (Character JavaDoc) resources.getObject("system-frame.button.close.mnemonic");
116         final JButton JavaDoc closeButton = new JButton JavaDoc(label);
117         closeButton.setMnemonic(mnemonic.charValue());
118
119         closeButton.setActionCommand(CLOSE_COMMAND);
120         closeButton.addActionListener(this);
121
122         buttonPanel.add(closeButton, BorderLayout.EAST);
123         content.add(buttonPanel, BorderLayout.SOUTH);
124
125         setContentPane(content);
126
127     }
128
129     /**
130      * Handles action events generated by the user.
131      *
132      * @param e the event.
133      */

134     public void actionPerformed(final ActionEvent JavaDoc e) {
135
136         final String JavaDoc command = e.getActionCommand();
137         if (command.equals(CLOSE_COMMAND)) {
138             dispose();
139         }
140         else if (command.equals(COPY_COMMAND)) {
141             this.panel.copySystemPropertiesToClipboard();
142         }
143
144     }
145
146
147     /**
148      * Creates and returns a menu-bar for the frame.
149      *
150      * @param resources localised resources.
151      *
152      * @return a menu bar.
153      */

154     private JMenuBar JavaDoc createMenuBar(final ResourceBundle JavaDoc resources) {
155
156         final JMenuBar JavaDoc menuBar = new JMenuBar JavaDoc();
157
158         String JavaDoc label = resources.getString("system-frame.menu.file");
159         Character JavaDoc mnemonic = (Character JavaDoc) resources.getObject("system-frame.menu.file.mnemonic");
160         final JMenu JavaDoc fileMenu = new JMenu JavaDoc(label, true);
161         fileMenu.setMnemonic(mnemonic.charValue());
162
163         label = resources.getString("system-frame.menu.file.close");
164         mnemonic = (Character JavaDoc) resources.getObject("system-frame.menu.file.close.mnemonic");
165         final JMenuItem JavaDoc closeItem = new JMenuItem JavaDoc(label, mnemonic.charValue());
166         closeItem.setActionCommand(CLOSE_COMMAND);
167
168         closeItem.addActionListener(this);
169         fileMenu.add(closeItem);
170
171         label = resources.getString("system-frame.menu.edit");
172         mnemonic = (Character JavaDoc) resources.getObject("system-frame.menu.edit.mnemonic");
173         final JMenu JavaDoc editMenu = new JMenu JavaDoc(label);
174         editMenu.setMnemonic(mnemonic.charValue());
175
176         label = resources.getString("system-frame.menu.edit.copy");
177         mnemonic = (Character JavaDoc) resources.getObject("system-frame.menu.edit.copy.mnemonic");
178         final JMenuItem JavaDoc copyItem = new JMenuItem JavaDoc(label, mnemonic.charValue());
179         copyItem.setActionCommand(COPY_COMMAND);
180         copyItem.addActionListener(this);
181         editMenu.add(copyItem);
182
183         menuBar.add(fileMenu);
184         menuBar.add(editMenu);
185         return menuBar;
186
187     }
188
189 }
190
Popular Tags