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
047package org.jfree.ui.about;
048
049import java.awt.BorderLayout;
050import java.awt.event.ActionEvent;
051import java.awt.event.ActionListener;
052import java.util.ResourceBundle;
053
054import javax.swing.BorderFactory;
055import javax.swing.JButton;
056import javax.swing.JFrame;
057import javax.swing.JMenu;
058import javax.swing.JMenuBar;
059import javax.swing.JMenuItem;
060import javax.swing.JPanel;
061import 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 */
071public class SystemPropertiesFrame extends JFrame implements ActionListener {
072
073    /** Copy action command. */
074    private static final String COPY_COMMAND = "COPY";
075
076    /** Close action command. */
077    private static final String CLOSE_COMMAND = "CLOSE";
078
079    /** A system properties panel. */
080    private SystemPropertiesPanel panel;
081
082    /**
083     * Constructs a standard frame that displays system properties.
084     * <P>
085     * If a menu is requested, it provides a menu item that allows the user to copy the contents of
086     * the table to the clipboard in tab-delimited format.
087     *
088     * @param menu  flag indicating whether or not the frame should display a menu to allow
089     *              the user to copy properties to the clipboard.
090     */
091    public SystemPropertiesFrame(final boolean menu) {
092
093        final String baseName = "org.jfree.ui.about.resources.AboutResources";
094        final ResourceBundle resources = ResourceBundle.getBundle(baseName);
095
096        final String title = resources.getString("system-frame.title");
097        setTitle(title);
098
099        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
100
101        if (menu) {
102            setJMenuBar(createMenuBar(resources));
103        }
104
105        final JPanel content = new JPanel(new BorderLayout());
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 buttonPanel = new JPanel(new BorderLayout());
112        buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
113
114        final String label = resources.getString("system-frame.button.close");
115        final Character mnemonic = (Character) resources.getObject("system-frame.button.close.mnemonic");
116        final JButton closeButton = new JButton(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 e) {
135
136        final String 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 createMenuBar(final ResourceBundle resources) {
155
156        final JMenuBar menuBar = new JMenuBar();
157
158        String label = resources.getString("system-frame.menu.file");
159        Character mnemonic = (Character) resources.getObject("system-frame.menu.file.mnemonic");
160        final JMenu fileMenu = new JMenu(label, true);
161        fileMenu.setMnemonic(mnemonic.charValue());
162
163        label = resources.getString("system-frame.menu.file.close");
164        mnemonic = (Character) resources.getObject("system-frame.menu.file.close.mnemonic");
165        final JMenuItem closeItem = new JMenuItem(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) resources.getObject("system-frame.menu.edit.mnemonic");
173        final JMenu editMenu = new JMenu(label);
174        editMenu.setMnemonic(mnemonic.charValue());
175
176        label = resources.getString("system-frame.menu.edit.copy");
177        mnemonic = (Character) resources.getObject("system-frame.menu.edit.copy.mnemonic");
178        final JMenuItem copyItem = new JMenuItem(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}