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.6 2007/11/02 17:50:36 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 import javax.swing.BorderFactory;
054 import javax.swing.JButton;
055 import javax.swing.JFrame;
056 import javax.swing.JMenu;
057 import javax.swing.JMenuBar;
058 import javax.swing.JMenuItem;
059 import javax.swing.JPanel;
060 import javax.swing.WindowConstants;
061
062 /**
063 * A frame containing a table that displays the system properties for the current Java Virtual
064 * Machine (JVM). It is useful to incorporate this frame into an application for diagnostic
065 * purposes, since it provides a convenient means for the user to return configuration and
066 * version information when reporting problems.
067 *
068 * @author David Gilbert
069 */
070 public class SystemPropertiesFrame extends JFrame implements ActionListener {
071
072 /** Copy action command. */
073 private static final String COPY_COMMAND = "COPY";
074
075 /** Close action command. */
076 private static final String CLOSE_COMMAND = "CLOSE";
077
078 /** A system properties panel. */
079 private SystemPropertiesPanel panel;
080
081 /**
082 * Constructs a standard frame that displays system properties.
083 * <P>
084 * If a menu is requested, it provides a menu item that allows the user to copy the contents of
085 * the table to the clipboard in tab-delimited format.
086 *
087 * @param menu flag indicating whether or not the frame should display a menu to allow
088 * the user to copy properties to the clipboard.
089 */
090 public SystemPropertiesFrame(final boolean menu) {
091
092 final String baseName = "org.jfree.ui.about.resources.AboutResources";
093 final ResourceBundle resources = ResourceBundle.getBundle(baseName);
094
095 final String title = resources.getString("system-frame.title");
096 setTitle(title);
097
098 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
099
100 if (menu) {
101 setJMenuBar(createMenuBar(resources));
102 }
103
104 final JPanel content = new JPanel(new BorderLayout());
105 this.panel = new SystemPropertiesPanel();
106 this.panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
107
108 content.add(this.panel, BorderLayout.CENTER);
109
110 final JPanel buttonPanel = new JPanel(new BorderLayout());
111 buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
112
113 final String label = resources.getString("system-frame.button.close");
114 final Character mnemonic = (Character) resources.getObject("system-frame.button.close.mnemonic");
115 final JButton closeButton = new JButton(label);
116 closeButton.setMnemonic(mnemonic.charValue());
117
118 closeButton.setActionCommand(CLOSE_COMMAND);
119 closeButton.addActionListener(this);
120
121 buttonPanel.add(closeButton, BorderLayout.EAST);
122 content.add(buttonPanel, BorderLayout.SOUTH);
123
124 setContentPane(content);
125
126 }
127
128 /**
129 * Handles action events generated by the user.
130 *
131 * @param e the event.
132 */
133 public void actionPerformed(final ActionEvent e) {
134
135 final String command = e.getActionCommand();
136 if (command.equals(CLOSE_COMMAND)) {
137 dispose();
138 }
139 else if (command.equals(COPY_COMMAND)) {
140 this.panel.copySystemPropertiesToClipboard();
141 }
142
143 }
144
145
146 /**
147 * Creates and returns a menu-bar for the frame.
148 *
149 * @param resources localised resources.
150 *
151 * @return a menu bar.
152 */
153 private JMenuBar createMenuBar(final ResourceBundle resources) {
154
155 final JMenuBar menuBar = new JMenuBar();
156
157 String label = resources.getString("system-frame.menu.file");
158 Character mnemonic = (Character) resources.getObject("system-frame.menu.file.mnemonic");
159 final JMenu fileMenu = new JMenu(label, true);
160 fileMenu.setMnemonic(mnemonic.charValue());
161
162 label = resources.getString("system-frame.menu.file.close");
163 mnemonic = (Character) resources.getObject("system-frame.menu.file.close.mnemonic");
164 final JMenuItem closeItem = new JMenuItem(label, mnemonic.charValue());
165 closeItem.setActionCommand(CLOSE_COMMAND);
166
167 closeItem.addActionListener(this);
168 fileMenu.add(closeItem);
169
170 label = resources.getString("system-frame.menu.edit");
171 mnemonic = (Character) resources.getObject("system-frame.menu.edit.mnemonic");
172 final JMenu editMenu = new JMenu(label);
173 editMenu.setMnemonic(mnemonic.charValue());
174
175 label = resources.getString("system-frame.menu.edit.copy");
176 mnemonic = (Character) resources.getObject("system-frame.menu.edit.copy.mnemonic");
177 final JMenuItem copyItem = new JMenuItem(label, mnemonic.charValue());
178 copyItem.setActionCommand(COPY_COMMAND);
179 copyItem.addActionListener(this);
180 editMenu.add(copyItem);
181
182 menuBar.add(fileMenu);
183 menuBar.add(editMenu);
184 return menuBar;
185
186 }
187
188 }