001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------------
028: * SystemPropertiesFrame.java
029: * --------------------------
030: * (C) Copyright 2000-2004, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: SystemPropertiesFrame.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
036: *
037: * Changes (from 26-Oct-2001)
038: * --------------------------
039: * 26-Oct-2001 : Changed package to com.jrefinery.ui (DG);
040: * 26-Nov-2001 : Made a separate class SystemPropertiesPanel.java (DG);
041: * 28-Feb-2002 : Moved to package com.jrefinery.ui.about (DG);
042: * 15-Mar-2002 : Modified to use a ResourceBundle for elements that require localisation (DG);
043: * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
044: *
045: */
046:
047: package org.jfree.ui.about;
048:
049: import java.awt.BorderLayout;
050: import java.awt.event.ActionEvent;
051: import java.awt.event.ActionListener;
052: import java.util.ResourceBundle;
053:
054: import javax.swing.BorderFactory;
055: import javax.swing.JButton;
056: import javax.swing.JFrame;
057: import javax.swing.JMenu;
058: import javax.swing.JMenuBar;
059: import javax.swing.JMenuItem;
060: import javax.swing.JPanel;
061: import javax.swing.WindowConstants;
062:
063: /**
064: * A frame containing a table that displays the system properties for the current Java Virtual
065: * Machine (JVM). It is useful to incorporate this frame into an application for diagnostic
066: * purposes, since it provides a convenient means for the user to return configuration and
067: * version information when reporting problems.
068: *
069: * @author David Gilbert
070: */
071: public class SystemPropertiesFrame extends JFrame implements
072: ActionListener {
073:
074: /** Copy action command. */
075: private static final String COPY_COMMAND = "COPY";
076:
077: /** Close action command. */
078: private static final String CLOSE_COMMAND = "CLOSE";
079:
080: /** A system properties panel. */
081: private SystemPropertiesPanel panel;
082:
083: /**
084: * Constructs a standard frame that displays system properties.
085: * <P>
086: * If a menu is requested, it provides a menu item that allows the user to copy the contents of
087: * the table to the clipboard in tab-delimited format.
088: *
089: * @param menu flag indicating whether or not the frame should display a menu to allow
090: * the user to copy properties to the clipboard.
091: */
092: public SystemPropertiesFrame(final boolean menu) {
093:
094: final String baseName = "org.jfree.ui.about.resources.AboutResources";
095: final ResourceBundle resources = ResourceBundle
096: .getBundle(baseName);
097:
098: final String title = resources.getString("system-frame.title");
099: setTitle(title);
100:
101: setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
102:
103: if (menu) {
104: setJMenuBar(createMenuBar(resources));
105: }
106:
107: final JPanel content = new JPanel(new BorderLayout());
108: this .panel = new SystemPropertiesPanel();
109: this .panel.setBorder(BorderFactory
110: .createEmptyBorder(5, 5, 5, 5));
111:
112: content.add(this .panel, BorderLayout.CENTER);
113:
114: final JPanel buttonPanel = new JPanel(new BorderLayout());
115: buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0,
116: 0));
117:
118: final String label = resources
119: .getString("system-frame.button.close");
120: final Character mnemonic = (Character) resources
121: .getObject("system-frame.button.close.mnemonic");
122: final JButton closeButton = new JButton(label);
123: closeButton.setMnemonic(mnemonic.charValue());
124:
125: closeButton.setActionCommand(CLOSE_COMMAND);
126: closeButton.addActionListener(this );
127:
128: buttonPanel.add(closeButton, BorderLayout.EAST);
129: content.add(buttonPanel, BorderLayout.SOUTH);
130:
131: setContentPane(content);
132:
133: }
134:
135: /**
136: * Handles action events generated by the user.
137: *
138: * @param e the event.
139: */
140: public void actionPerformed(final ActionEvent e) {
141:
142: final String command = e.getActionCommand();
143: if (command.equals(CLOSE_COMMAND)) {
144: dispose();
145: } else if (command.equals(COPY_COMMAND)) {
146: this .panel.copySystemPropertiesToClipboard();
147: }
148:
149: }
150:
151: /**
152: * Creates and returns a menu-bar for the frame.
153: *
154: * @param resources localised resources.
155: *
156: * @return a menu bar.
157: */
158: private JMenuBar createMenuBar(final ResourceBundle resources) {
159:
160: final JMenuBar menuBar = new JMenuBar();
161:
162: String label = resources.getString("system-frame.menu.file");
163: Character mnemonic = (Character) resources
164: .getObject("system-frame.menu.file.mnemonic");
165: final JMenu fileMenu = new JMenu(label, true);
166: fileMenu.setMnemonic(mnemonic.charValue());
167:
168: label = resources.getString("system-frame.menu.file.close");
169: mnemonic = (Character) resources
170: .getObject("system-frame.menu.file.close.mnemonic");
171: final JMenuItem closeItem = new JMenuItem(label, mnemonic
172: .charValue());
173: closeItem.setActionCommand(CLOSE_COMMAND);
174:
175: closeItem.addActionListener(this );
176: fileMenu.add(closeItem);
177:
178: label = resources.getString("system-frame.menu.edit");
179: mnemonic = (Character) resources
180: .getObject("system-frame.menu.edit.mnemonic");
181: final JMenu editMenu = new JMenu(label);
182: editMenu.setMnemonic(mnemonic.charValue());
183:
184: label = resources.getString("system-frame.menu.edit.copy");
185: mnemonic = (Character) resources
186: .getObject("system-frame.menu.edit.copy.mnemonic");
187: final JMenuItem copyItem = new JMenuItem(label, mnemonic
188: .charValue());
189: copyItem.setActionCommand(COPY_COMMAND);
190: copyItem.addActionListener(this);
191: editMenu.add(copyItem);
192:
193: menuBar.add(fileMenu);
194: menuBar.add(editMenu);
195: return menuBar;
196:
197: }
198:
199: }
|