Coverage Report - org.argouml.ui.SystemInfoDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemInfoDialog
0%
0/61
0%
0/8
1
SystemInfoDialog$1
0%
0/3
N/A
1
SystemInfoDialog$2
0%
0/3
N/A
1
SystemInfoDialog$3
0%
0/3
N/A
1
SystemInfoDialog$ClipboardObserver
0%
0/2
N/A
1
 
 1  
 /* $Id: SystemInfoDialog.java 17841 2010-01-12 19:17:52Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2003-2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 /*
 40  
  * SystemInfoDialog.java
 41  
  */
 42  
 
 43  
 package org.argouml.ui;
 44  
 
 45  
 import java.awt.Frame;
 46  
 import java.awt.Insets;
 47  
 import java.awt.datatransfer.Clipboard;
 48  
 import java.awt.datatransfer.ClipboardOwner;
 49  
 import java.awt.datatransfer.StringSelection;
 50  
 import java.awt.datatransfer.Transferable;
 51  
 import java.awt.event.ActionEvent;
 52  
 import java.awt.event.ActionListener;
 53  
 import java.awt.event.WindowAdapter;
 54  
 import java.awt.event.WindowEvent;
 55  
 
 56  
 import javax.swing.JButton;
 57  
 import javax.swing.JScrollPane;
 58  
 import javax.swing.JTextArea;
 59  
 
 60  
 import org.argouml.application.helpers.ApplicationVersion;
 61  
 import org.argouml.i18n.Translator;
 62  
 import org.argouml.util.ArgoDialog;
 63  
 
 64  
 /**
 65  
  * Display System Information (JDK Version, JDK Vendor, etc).
 66  
  * A Copy to System Clipboard button is provided to help generate bug reports.
 67  
  *
 68  
  * @author Eugenio Alvarez
 69  
  */
 70  0
 public class SystemInfoDialog extends ArgoDialog {
 71  
 
 72  
     /**
 73  
      * Version generated by Eclipse for rev. 1.12
 74  
      */
 75  
     private static final long serialVersionUID = 1595302214402366939L;
 76  
 
 77  
     /** Insets in pixels  */
 78  
     private static final int INSET_PX = 3;
 79  
 
 80  0
     private JTextArea   info = new JTextArea();
 81  0
     private JButton     runGCButton = new JButton();
 82  0
     private JButton     copyButton = new JButton();
 83  
 
 84  
     /**
 85  
      * The constructor.
 86  
      * 
 87  
      * @param modal true if the dialog is modal
 88  
      */
 89  
     public SystemInfoDialog(boolean modal) {
 90  0
         super(Translator.localize("dialog.title.system-information"),
 91  
                 ArgoDialog.CLOSE_OPTION, modal);
 92  
 
 93  0
         info.setEditable(false);
 94  0
         info.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX));
 95  
 
 96  0
         runGCButton.addActionListener(new ActionListener() {
 97  
             public void actionPerformed(ActionEvent e) {
 98  0
                 runGCActionPerformed(e);
 99  0
             }
 100  
         });
 101  0
         copyButton.addActionListener(new ActionListener() {
 102  
             public void actionPerformed(ActionEvent e) {
 103  0
                 copyActionPerformed(e);
 104  0
             }
 105  
         });
 106  
 
 107  0
         nameButton(copyButton, "button.copy-to-clipboard");
 108  0
         nameButton(runGCButton, "button.run-gc");
 109  0
         addButton(copyButton, 0);
 110  0
         addButton(runGCButton, 0);
 111  0
         setContent(new JScrollPane(info));
 112  0
         updateInfo();
 113  0
         addWindowListener(new WindowAdapter() {
 114  
             public void windowActivated(WindowEvent e) {
 115  0
                 updateInfo();
 116  0
             }
 117  
         });
 118  0
         pack();
 119  0
     }
 120  
 
 121  
     /**
 122  
      * Run garbage collector.
 123  
      * 
 124  
      * @param e the action
 125  
      */
 126  
     private void runGCActionPerformed(ActionEvent e) {
 127  0
         assert e.getSource() == runGCButton;
 128  0
         Runtime.getRuntime().gc();
 129  0
         updateInfo();
 130  0
     } // end runGC_actionPerformed()
 131  
 
 132  
     /**
 133  
      * Copy system info to clipboard.
 134  
      * 
 135  
      * @param e the action
 136  
      */
 137  
     private void copyActionPerformed(ActionEvent e) {
 138  0
         assert e.getSource() == copyButton;
 139  0
         String infoText = info.getText();
 140  0
         StringSelection contents = new StringSelection(infoText);
 141  0
         Clipboard clipboard = getToolkit().getSystemClipboard();
 142  0
         clipboard.setContents(contents, defaultClipboardOwner);
 143  0
     } // end copy_actionPerformed()
 144  
 
 145  
     void updateInfo() {
 146  0
         info.setText(getInfo());
 147  0
     } //end updateInfo()
 148  
     
 149  
     /**
 150  
      * Collect system information.
 151  
      * @return string containing a variety of system info
 152  
      */
 153  
     public static String getInfo() {
 154  0
         StringBuffer s = new StringBuffer();
 155  0
         s.append(Translator.localize("dialog.systeminfo.argoumlversion"));
 156  0
         s.append(ApplicationVersion.getVersion() + "\n");
 157  0
         s.append(Translator.localize("dialog.systeminfo.javaversion"));
 158  0
         s.append(System.getProperty("java.version", "") + "\n");
 159  0
         s.append(Translator.localize("dialog.systeminfo.javavendor"));
 160  0
         s.append(System.getProperty("java.vendor", "") + "\n");
 161  0
         s.append(Translator.localize("dialog.systeminfo.url-javavendor"));
 162  0
         s.append(System.getProperty("java.vendor.url", "") + "\n");
 163  0
         s.append(Translator.localize("dialog.systeminfo.java-home-directory"));
 164  0
         s.append(System.getProperty("java.home", "") + "\n");
 165  0
         s.append(Translator.localize("dialog.systeminfo.java-classpath"));
 166  0
         s.append(System.getProperty("java.class.path", "") + "\n");
 167  0
         s.append(Translator.localize("dialog.systeminfo.operating-system"));
 168  0
         s.append(System.getProperty("os.name", ""));
 169  0
         s.append(Translator.localize(
 170  
                 "dialog.systeminfo.operating-systemversion"));
 171  0
         s.append(System.getProperty("os.version", "") + "\n");
 172  0
         s.append(Translator.localize("dialog.systeminfo.architecture"));
 173  0
         s.append(System.getProperty("os.arch", "") + "\n");
 174  0
         s.append(Translator.localize("dialog.systeminfo.user-name"));
 175  0
         s.append(System.getProperty("user.name", "") + "\n");
 176  0
         s.append(Translator.localize("dialog.systeminfo.user-home-directory"));
 177  0
         s.append(System.getProperty("user.home", "") + "\n");
 178  0
         s.append(Translator.localize("dialog.systeminfo.current-directory"));
 179  0
         s.append(System.getProperty("user.dir", "") + "\n");
 180  0
         s.append(Translator.localize("dialog.systeminfo.jvm-total-memory"));
 181  0
         s.append(String.valueOf(Runtime.getRuntime().totalMemory()) + "\n");
 182  0
         s.append(Translator.localize("dialog.systeminfo.jvm-free-memory"));
 183  0
         s.append(String.valueOf(Runtime.getRuntime().freeMemory()) + "\n");
 184  0
         return s.toString();
 185  
     }
 186  
 
 187  0
     private static ClipboardOwner defaultClipboardOwner =
 188  
         new ClipboardObserver();
 189  
 
 190  0
     static class ClipboardObserver implements ClipboardOwner {
 191  
         public void lostOwnership(Clipboard clipboard, Transferable contents) {
 192  0
         }
 193  
     }
 194  
 
 195  
 } /* end class SystemInfoDialog */