Coverage Report - org.argouml.ui.SettingsTabEnvironment
 
Classes in this File Line Coverage Branch Coverage Complexity
GResolution
100%
6/6
N/A
1.273
SettingsTabEnvironment
91%
81/89
50%
3/6
1.273
 
 1  
 /* $Id: SettingsTabEnvironment.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) 1996-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  
 package org.argouml.ui;
 40  
 
 41  
 import java.awt.BorderLayout;
 42  
 import java.util.ArrayList;
 43  
 import java.util.Collection;
 44  
 
 45  
 import javax.swing.BorderFactory;
 46  
 import javax.swing.DefaultComboBoxModel;
 47  
 import javax.swing.JComboBox;
 48  
 import javax.swing.JLabel;
 49  
 import javax.swing.JPanel;
 50  
 import javax.swing.JTextField;
 51  
 
 52  
 import org.argouml.application.api.Argo;
 53  
 import org.argouml.application.api.GUISettingsTabInterface;
 54  
 import org.argouml.configuration.Configuration;
 55  
 import org.argouml.i18n.Translator;
 56  
 import org.argouml.uml.ui.SaveGraphicsManager;
 57  
 import org.argouml.util.SuffixFilter;
 58  
 import org.tigris.swidgets.LabelledLayout;
 59  
 
 60  
 /**
 61  
  * Settings panel for handling ArgoUML environment related settings.
 62  
  *
 63  
  * @author Thierry Lach
 64  
  * @since  0.9.4
 65  
  */
 66  
 class SettingsTabEnvironment extends JPanel
 67  
     implements GUISettingsTabInterface {
 68  
 
 69  
     private JPanel topPanel;
 70  
     private JTextField fieldArgoExtDir;
 71  
     private JTextField fieldJavaHome;
 72  
     private JTextField fieldUserHome;
 73  
     private JTextField fieldUserDir;
 74  
     private JTextField fieldStartupDir;
 75  
     private JComboBox fieldGraphicsFormat;
 76  
     private JComboBox fieldGraphicsResolution;
 77  
     private Collection<GResolution> theResolutions;
 78  
 
 79  
     /**
 80  
      * The constructor.
 81  
      */
 82  
     SettingsTabEnvironment() {
 83  900
         super();
 84  900
     }
 85  
 
 86  
     private void buildPanel() {
 87  19
         setLayout(new BorderLayout());
 88  19
         int labelGap = 10;
 89  19
         int componentGap = 5;
 90  19
         topPanel = new JPanel(new LabelledLayout(labelGap, componentGap));
 91  
 
 92  19
         JLabel label =
 93  
             new JLabel(Translator.localize("label.default.graphics-format"));
 94  19
         fieldGraphicsFormat = new JComboBox();
 95  19
         label.setLabelFor(fieldGraphicsFormat);
 96  19
         topPanel.add(label);
 97  19
         topPanel.add(fieldGraphicsFormat);
 98  
 
 99  19
         label =
 100  
             new JLabel(
 101  
                     Translator.localize("label.default.graphics-resolution"));
 102  19
         theResolutions = new ArrayList<GResolution>();
 103  19
         theResolutions.add(new GResolution(1, "combobox.item.resolution-1"));
 104  19
         theResolutions.add(new GResolution(2, "combobox.item.resolution-2"));
 105  19
         theResolutions.add(new GResolution(4, "combobox.item.resolution-4"));
 106  19
         fieldGraphicsResolution = new JComboBox(); //filled in later
 107  19
         label.setLabelFor(fieldGraphicsResolution);
 108  19
         topPanel.add(label);
 109  19
         topPanel.add(fieldGraphicsResolution);
 110  
 
 111  
          // This string is NOT to be translated! See issue 2381.
 112  19
         label = new JLabel("${argo.ext.dir}");
 113  19
         JTextField j2 = new JTextField();
 114  19
         fieldArgoExtDir = j2;
 115  19
         fieldArgoExtDir.setEnabled(false);
 116  19
         label.setLabelFor(fieldArgoExtDir);
 117  19
         topPanel.add(label);
 118  19
         topPanel.add(fieldArgoExtDir);
 119  
 
 120  
           // This string is NOT to be translated! See issue 2381.
 121  19
         label = new JLabel("${java.home}");
 122  19
         JTextField j3 = new JTextField();
 123  19
         fieldJavaHome = j3;
 124  19
         fieldJavaHome.setEnabled(false);
 125  19
         label.setLabelFor(fieldJavaHome);
 126  19
         topPanel.add(label);
 127  19
         topPanel.add(fieldJavaHome);
 128  
 
 129  
           // This string is NOT to be translated! See issue 2381.
 130  19
         label = new JLabel("${user.home}");
 131  19
         JTextField j4 = new JTextField();
 132  19
         fieldUserHome = j4;
 133  19
         fieldUserHome.setEnabled(false);
 134  19
         label.setLabelFor(fieldUserHome);
 135  19
         topPanel.add(label);
 136  19
         topPanel.add(fieldUserHome);
 137  
 
 138  
         // This string is NOT to be translated! See issue 2381.
 139  19
         label = new JLabel("${user.dir}");
 140  19
         JTextField j5 = new JTextField();
 141  19
         fieldUserDir = j5;
 142  19
         fieldUserDir.setEnabled(false);
 143  19
         label.setLabelFor(fieldUserDir);
 144  19
         topPanel.add(label);
 145  19
         topPanel.add(fieldUserDir);
 146  
 
 147  19
           label = new JLabel(Translator.localize("label.startup-directory"));
 148  19
           JTextField j6 = new JTextField();
 149  19
         fieldStartupDir = j6;
 150  19
         fieldStartupDir.setEnabled(false);
 151  19
         label.setLabelFor(fieldStartupDir);
 152  19
         topPanel.add(label);
 153  19
         topPanel.add(fieldStartupDir);
 154  
 
 155  19
         topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
 156  19
         add(topPanel, BorderLayout.NORTH);
 157  
         
 158  19
         JPanel bottom = new JPanel();
 159  19
         bottom.add(new JLabel(
 160  
             Translator.localize("label.graphics-export-resolution.warning")));
 161  19
         add(bottom, BorderLayout.SOUTH);
 162  19
     }
 163  
 
 164  
     /*
 165  
      * @see GUISettingsTabInterface#handleSettingsTabRefresh()
 166  
      */
 167  
     public void handleSettingsTabRefresh() {
 168  19
         fieldArgoExtDir.setText(System.getProperty("argo.ext.dir"));
 169  19
         fieldJavaHome.setText(System.getProperty("java.home"));
 170  19
         fieldUserHome.setText(System.getProperty("user.home"));
 171  19
         fieldUserDir.setText(Configuration.getString(Argo.KEY_STARTUP_DIR,
 172  
                 System.getProperty("user.dir")));
 173  19
         fieldStartupDir.setText(Argo.getDirectory());
 174  
 
 175  19
         fieldGraphicsFormat.removeAllItems();
 176  19
         Collection c = SaveGraphicsManager.getInstance().getSettingsList();
 177  19
         fieldGraphicsFormat.setModel(new DefaultComboBoxModel(c.toArray()));
 178  
 
 179  19
         fieldGraphicsResolution.removeAllItems();
 180  19
         fieldGraphicsResolution.setModel(new DefaultComboBoxModel(
 181  
                 theResolutions.toArray()));
 182  19
         int defaultResolution =
 183  
             Configuration.getInteger(
 184  
                 SaveGraphicsManager.KEY_GRAPHICS_RESOLUTION, 1);
 185  19
         for (GResolution gr : theResolutions) {
 186  19
             if (defaultResolution == gr.getResolution()) {
 187  19
                 fieldGraphicsResolution.setSelectedItem(gr);
 188  19
                 break;
 189  
             }
 190  
         }
 191  19
     }
 192  
 
 193  
     /*
 194  
      * @see GUISettingsTabInterface#handleSettingsTabSave()
 195  
      */
 196  
     public void handleSettingsTabSave() {
 197  0
         Configuration.setString(Argo.KEY_STARTUP_DIR, fieldUserDir.getText());
 198  
 
 199  0
         GResolution r = (GResolution) fieldGraphicsResolution.getSelectedItem();
 200  0
         Configuration.setInteger(SaveGraphicsManager.KEY_GRAPHICS_RESOLUTION,
 201  
                 r.getResolution());
 202  
 
 203  0
         SaveGraphicsManager.getInstance().setDefaultFilter(
 204  
                 (SuffixFilter) fieldGraphicsFormat.getSelectedItem());
 205  0
     }
 206  
 
 207  
     /*
 208  
      * @see GUISettingsTabInterface#handleSettingsTabCancel()
 209  
      */
 210  
     public void handleSettingsTabCancel() {
 211  0
         handleSettingsTabRefresh();
 212  0
     }
 213  
 
 214  
     /*
 215  
      * @see org.argouml.ui.GUISettingsTabInterface#handleResetToDefault()
 216  
      */
 217  
     public void handleResetToDefault() {
 218  
         // Do nothing - these buttons are not shown.
 219  0
     }
 220  
 
 221  
     /*
 222  
      * @see GUISettingsTabInterface#getTabKey()
 223  
      */
 224  
     public String getTabKey() {
 225  19
         return "tab.environment";
 226  
     }
 227  
 
 228  
     /*
 229  
      * @see GUISettingsTabInterface#getTabPanel()
 230  
      */
 231  
     public JPanel getTabPanel() {
 232  19
         if (topPanel == null) {
 233  19
             buildPanel();
 234  
         }
 235  19
         return this;
 236  
     }
 237  
 
 238  
     /**
 239  
      * The UID.
 240  
      */
 241  
     private static final long serialVersionUID = 543442930918741133L;
 242  
 }
 243  
 
 244  
 
 245  
 class GResolution {
 246  
     private int resolution;
 247  
     private String label;
 248  
 
 249  
     /**
 250  
      * Constructor.
 251  
      *
 252  
      * @param r
 253  
      * @param name
 254  
      */
 255  57
     GResolution(int r, String name) {
 256  57
         resolution = r;
 257  57
         label = Translator.localize(name);
 258  57
     }
 259  
 
 260  
     int getResolution() {
 261  19
         return resolution;
 262  
     }
 263  
 
 264  
     /*
 265  
      * @see java.lang.Object#toString()
 266  
      */
 267  
     public String toString() {
 268  57
         return label;
 269  
     }
 270  
 }
 271