001 /* ========================================================================
002 * JCommon : a free general purpose class library for the Java(tm) platform
003 * ========================================================================
004 *
005 * (C) Copyright 2000-2008, 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-2008, by Object Refinery Limited.
031 *
032 * Original Author: David Gilbert (for Object Refinery Limited);
033 * Contributor(s): -;
034 *
035 * $Id: SystemPropertiesFrame.java,v 1.7 2008/12/18 09:57:32 mungady 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
043 * localisation (DG);
044 * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
045 * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
046 * Jess Thrysoee (DG);
047 *
048 */
049
050 package org.jfree.ui.about;
051
052 import java.awt.BorderLayout;
053 import java.awt.event.ActionEvent;
054 import java.awt.event.ActionListener;
055 import java.util.ResourceBundle;
056
057 import javax.swing.BorderFactory;
058 import javax.swing.JButton;
059 import javax.swing.JFrame;
060 import javax.swing.JMenu;
061 import javax.swing.JMenuBar;
062 import javax.swing.JMenuItem;
063 import javax.swing.JPanel;
064 import javax.swing.WindowConstants;
065
066 import org.jfree.util.ResourceBundleWrapper;
067
068 /**
069 * A frame containing a table that displays the system properties for the
070 * current Java Virtual Machine (JVM). It is useful to incorporate this frame
071 * into an application for diagnostic purposes, since it provides a convenient
072 * means for the user to return configuration and version information when
073 * reporting problems.
074 *
075 * @author David Gilbert
076 */
077 public class SystemPropertiesFrame extends JFrame implements ActionListener {
078
079 /** Copy action command. */
080 private static final String COPY_COMMAND = "COPY";
081
082 /** Close action command. */
083 private static final String CLOSE_COMMAND = "CLOSE";
084
085 /** A system properties panel. */
086 private SystemPropertiesPanel panel;
087
088 /**
089 * Constructs a standard frame that displays system properties.
090 * <P>
091 * If a menu is requested, it provides a menu item that allows the user to
092 * copy the contents of the table to the clipboard in tab-delimited format.
093 *
094 * @param menu flag indicating whether or not the frame should display a
095 * menu to allow the user to copy properties to the clipboard.
096 */
097 public SystemPropertiesFrame(final boolean menu) {
098
099 final String baseName = "org.jfree.ui.about.resources.AboutResources";
100 final ResourceBundle resources = ResourceBundleWrapper.getBundle(
101 baseName);
102
103 final String title = resources.getString("system-frame.title");
104 setTitle(title);
105
106 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
107
108 if (menu) {
109 setJMenuBar(createMenuBar(resources));
110 }
111
112 final JPanel content = new JPanel(new BorderLayout());
113 this.panel = new SystemPropertiesPanel();
114 this.panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
115
116 content.add(this.panel, BorderLayout.CENTER);
117
118 final JPanel buttonPanel = new JPanel(new BorderLayout());
119 buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
120
121 final String label = resources.getString("system-frame.button.close");
122 final Character mnemonic = (Character) resources.getObject(
123 "system-frame.button.close.mnemonic");
124 final JButton closeButton = new JButton(label);
125 closeButton.setMnemonic(mnemonic.charValue());
126
127 closeButton.setActionCommand(CLOSE_COMMAND);
128 closeButton.addActionListener(this);
129
130 buttonPanel.add(closeButton, BorderLayout.EAST);
131 content.add(buttonPanel, BorderLayout.SOUTH);
132
133 setContentPane(content);
134
135 }
136
137 /**
138 * Handles action events generated by the user.
139 *
140 * @param e the event.
141 */
142 public void actionPerformed(final ActionEvent e) {
143
144 final String command = e.getActionCommand();
145 if (command.equals(CLOSE_COMMAND)) {
146 dispose();
147 }
148 else if (command.equals(COPY_COMMAND)) {
149 this.panel.copySystemPropertiesToClipboard();
150 }
151
152 }
153
154
155 /**
156 * Creates and returns a menu-bar for the frame.
157 *
158 * @param resources localised resources.
159 *
160 * @return a menu bar.
161 */
162 private JMenuBar createMenuBar(final ResourceBundle resources) {
163
164 final JMenuBar menuBar = new JMenuBar();
165
166 String label = resources.getString("system-frame.menu.file");
167 Character mnemonic = (Character) resources.getObject(
168 "system-frame.menu.file.mnemonic");
169 final JMenu fileMenu = new JMenu(label, true);
170 fileMenu.setMnemonic(mnemonic.charValue());
171
172 label = resources.getString("system-frame.menu.file.close");
173 mnemonic = (Character) resources.getObject(
174 "system-frame.menu.file.close.mnemonic");
175 final JMenuItem closeItem = new JMenuItem(label, mnemonic.charValue());
176 closeItem.setActionCommand(CLOSE_COMMAND);
177
178 closeItem.addActionListener(this);
179 fileMenu.add(closeItem);
180
181 label = resources.getString("system-frame.menu.edit");
182 mnemonic = (Character) resources.getObject(
183 "system-frame.menu.edit.mnemonic");
184 final JMenu editMenu = new JMenu(label);
185 editMenu.setMnemonic(mnemonic.charValue());
186
187 label = resources.getString("system-frame.menu.edit.copy");
188 mnemonic = (Character) resources.getObject(
189 "system-frame.menu.edit.copy.mnemonic");
190 final JMenuItem copyItem = new JMenuItem(label, mnemonic.charValue());
191 copyItem.setActionCommand(COPY_COMMAND);
192 copyItem.addActionListener(this);
193 editMenu.add(copyItem);
194
195 menuBar.add(fileMenu);
196 menuBar.add(editMenu);
197 return menuBar;
198
199 }
200
201 }