Coverage Report - org.argouml.ui.SettingsTabUser
 
Classes in this File Line Coverage Branch Coverage Complexity
SettingsTabUser
90%
57/63
50%
1/2
1.125
 
 1  
 /* $Id: SettingsTabUser.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.awt.Component;
 43  
 import java.awt.GridBagConstraints;
 44  
 import java.awt.GridBagLayout;
 45  
 import java.awt.Insets;
 46  
 
 47  
 import javax.swing.BoxLayout;
 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.swingext.JLinkButton;
 57  
 
 58  
 /**
 59  
  * Tab Panel for setting the default user attributes: name and email.
 60  
  *
 61  
  * @author Thierry Lach
 62  
  * @since  0.9.4
 63  
  */
 64  
 class SettingsTabUser extends JPanel
 65  
     implements GUISettingsTabInterface {
 66  
 
 67  
     private JPanel topPanel;
 68  
     
 69  
     /**
 70  
      * This is where the user enters full name in settings tab.
 71  
      * This information is stored
 72  
      * in the argo.user.properties file.
 73  
      */
 74  
     private JTextField userFullname;
 75  
 
 76  
     /**
 77  
      * This is where the user enters email in settings tab.
 78  
      * This information is stored
 79  
      * in the argo.user.properties file.
 80  
      */
 81  
     private JTextField userEmail;
 82  
 
 83  
     /**
 84  
      * The constructor.
 85  
      */
 86  900
     SettingsTabUser() {
 87  
         // defer work until fetched/visible
 88  900
     }
 89  
 
 90  
     private void buildPanel() {
 91  19
         setLayout(new BorderLayout());
 92  
         
 93  19
         topPanel = new JPanel();
 94  19
         topPanel.setLayout(new BorderLayout());
 95  
         
 96  19
         JPanel warning = new JPanel();
 97  19
         warning.setLayout(new BoxLayout(warning, BoxLayout.PAGE_AXIS));
 98  19
         JLabel warningLabel = new JLabel(Translator.localize("label.warning"));
 99  19
         warningLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
 100  19
         warning.add(warningLabel);
 101  
 
 102  19
         JLinkButton projectSettings = new JLinkButton();
 103  19
         projectSettings.setAction(new ActionProjectSettings());
 104  19
         projectSettings.setText(Translator.localize("button.project-settings"));
 105  19
         projectSettings.setIcon(null);
 106  19
         projectSettings.setAlignmentX(Component.RIGHT_ALIGNMENT);
 107  19
         warning.add(projectSettings);
 108  
         
 109  19
         topPanel.add(warning, BorderLayout.NORTH);
 110  
         
 111  19
         JPanel settings = new JPanel();
 112  19
             settings.setLayout(new GridBagLayout());
 113  
 
 114  19
         GridBagConstraints labelConstraints = new GridBagConstraints();
 115  19
         labelConstraints.anchor = GridBagConstraints.WEST;
 116  19
         labelConstraints.gridy = 0;
 117  19
         labelConstraints.gridx = 0;
 118  19
         labelConstraints.gridwidth = 1;
 119  19
         labelConstraints.gridheight = 1;
 120  19
         labelConstraints.insets = new Insets(2, 20, 2, 4);
 121  
 
 122  19
         GridBagConstraints fieldConstraints = new GridBagConstraints();
 123  19
         fieldConstraints.anchor = GridBagConstraints.EAST;
 124  19
         fieldConstraints.fill = GridBagConstraints.HORIZONTAL;
 125  19
         fieldConstraints.gridy = 0;
 126  19
         fieldConstraints.gridx = 1;
 127  19
         fieldConstraints.gridwidth = 3;
 128  19
         fieldConstraints.gridheight = 1;
 129  19
         fieldConstraints.weightx = 1.0;
 130  19
         fieldConstraints.insets = new Insets(2, 4, 2, 20);
 131  
 
 132  19
         labelConstraints.gridy = 0;
 133  19
         fieldConstraints.gridy = 0;
 134  19
         settings.add(new JLabel(Translator.localize("label.user")),
 135  
                 labelConstraints);
 136  19
         JTextField j = new JTextField();
 137  19
         userFullname = j;
 138  19
         settings.add(userFullname, fieldConstraints);
 139  
 
 140  19
         labelConstraints.gridy = 1;
 141  19
         fieldConstraints.gridy = 1;
 142  19
          settings.add(new JLabel(Translator.localize("label.email")),
 143  
                 labelConstraints);
 144  19
          JTextField j1 = new JTextField();
 145  19
         userEmail = j1;
 146  19
         settings.add(userEmail, fieldConstraints);
 147  19
         topPanel.add(settings, BorderLayout.CENTER);
 148  
         
 149  19
         add(topPanel, BorderLayout.NORTH);
 150  19
     }
 151  
 
 152  
     /*
 153  
      * @see GUISettingsTabInterface#handleSettingsTabRefresh()
 154  
      */
 155  
     public void handleSettingsTabRefresh() {
 156  19
         userFullname.setText(Configuration.getString(Argo.KEY_USER_FULLNAME));
 157  19
         userEmail.setText(Configuration.getString(Argo.KEY_USER_EMAIL));
 158  19
     }
 159  
 
 160  
     /*
 161  
      * @see GUISettingsTabInterface#handleSettingsTabSave()
 162  
      */
 163  
     public void handleSettingsTabSave() {
 164  0
         Configuration.setString(Argo.KEY_USER_FULLNAME, userFullname.getText());
 165  0
         Configuration.setString(Argo.KEY_USER_EMAIL, userEmail.getText());
 166  0
     }
 167  
 
 168  
     /*
 169  
      * @see GUISettingsTabInterface#handleSettingsTabCancel()
 170  
      */
 171  
     public void handleSettingsTabCancel() {
 172  0
         handleSettingsTabRefresh();
 173  0
     }
 174  
 
 175  
     /*
 176  
      * @see org.argouml.ui.GUISettingsTabInterface#handleResetToDefault()
 177  
      */
 178  
     public void handleResetToDefault() {
 179  
         // Do nothing - these buttons are not shown.
 180  0
     }
 181  
 
 182  
     /*
 183  
      * @see GUISettingsTabInterface#getTabKey()
 184  
      */
 185  
     public String getTabKey() {
 186  19
         return "tab.user";
 187  
     }
 188  
 
 189  
     /*
 190  
      * @see GUISettingsTabInterface#getTabPanel()
 191  
      */
 192  
     public JPanel getTabPanel() {
 193  19
         if (topPanel == null) {
 194  19
             buildPanel();
 195  
         }
 196  19
         return this;
 197  
     }
 198  
 
 199  
     /**
 200  
      * The UID.
 201  
      */
 202  
     private static final long serialVersionUID = -742258688091914619L;
 203  
 }