Source for 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-2008, 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-2008, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: SystemPropertiesFrame.java,v 1.7 2008/12/18 09:57:32 mungady 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
  43:  *               localisation (DG);
  44:  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  45:  * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
  46:  *               Jess Thrysoee (DG);
  47:  *
  48:  */
  49: 
  50: package org.jfree.ui.about;
  51: 
  52: import java.awt.BorderLayout;
  53: import java.awt.event.ActionEvent;
  54: import java.awt.event.ActionListener;
  55: import java.util.ResourceBundle;
  56: 
  57: import javax.swing.BorderFactory;
  58: import javax.swing.JButton;
  59: import javax.swing.JFrame;
  60: import javax.swing.JMenu;
  61: import javax.swing.JMenuBar;
  62: import javax.swing.JMenuItem;
  63: import javax.swing.JPanel;
  64: import javax.swing.WindowConstants;
  65: 
  66: import org.jfree.util.ResourceBundleWrapper;
  67: 
  68: /**
  69:  * A frame containing a table that displays the system properties for the
  70:  * current Java Virtual Machine (JVM).  It is useful to incorporate this frame
  71:  * into an application for diagnostic purposes, since it provides a convenient
  72:  * means for the user to return configuration and version information when
  73:  * reporting problems.
  74:  *
  75:  * @author David Gilbert
  76:  */
  77: public class SystemPropertiesFrame extends JFrame implements ActionListener {
  78: 
  79:     /** Copy action command. */
  80:     private static final String COPY_COMMAND = "COPY";
  81: 
  82:     /** Close action command. */
  83:     private static final String CLOSE_COMMAND = "CLOSE";
  84: 
  85:     /** A system properties panel. */
  86:     private SystemPropertiesPanel panel;
  87: 
  88:     /**
  89:      * Constructs a standard frame that displays system properties.
  90:      * <P>
  91:      * If a menu is requested, it provides a menu item that allows the user to
  92:      * copy the contents of the table to the clipboard in tab-delimited format.
  93:      *
  94:      * @param menu  flag indicating whether or not the frame should display a
  95:      *              menu to allow the user to copy properties to the clipboard.
  96:      */
  97:     public SystemPropertiesFrame(final boolean menu) {
  98: 
  99:         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: }