Coverage Report - org.argouml.ui.ProjectSettingsTabProperties
 
Classes in this File Line Coverage Branch Coverage Complexity
ProjectSettingsTabProperties
100%
78/78
25%
3/12
1
 
 1  
 /* $Id: ProjectSettingsTabProperties.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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2006-2009 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.GridBagConstraints;
 43  
 import java.awt.GridBagLayout;
 44  
 import java.awt.Insets;
 45  
 
 46  
 import javax.swing.JLabel;
 47  
 import javax.swing.JPanel;
 48  
 import javax.swing.JScrollPane;
 49  
 import javax.swing.JTextArea;
 50  
 import javax.swing.JTextField;
 51  
 import javax.swing.SwingConstants;
 52  
 
 53  
 import org.argouml.application.api.Argo;
 54  
 import org.argouml.configuration.Configuration;
 55  
 import org.argouml.i18n.Translator;
 56  
 import org.argouml.kernel.Project;
 57  
 
 58  
 /**
 59  
  * Tab Panel for setting the project attributes: 
 60  
  * author name and email, project description. 
 61  
  * These are stored in the project file.
 62  
  *
 63  
  * @author Michiel
 64  
  */
 65  900
 public class ProjectSettingsTabProperties extends JPanel implements
 66  
         GUIProjectSettingsTabInterface {
 67  
 
 68  
     private Project p;
 69  
     
 70  
     /**
 71  
      * This is where the user enters full name in settings tab.
 72  
      * This information is stored in the zargo file.
 73  
      */
 74  
     private JTextField userFullname;
 75  
 
 76  
     /**
 77  
      * This is where the user enters email in settings tab.
 78  
      * This information is stored in the zargo file.
 79  
      */
 80  
     private JTextField userEmail;
 81  
 
 82  
     /**
 83  
      * This is where the user enters a description of the project
 84  
      * in the settings tab.
 85  
      * This information is stored in the zargo file.
 86  
      */
 87  
     private JTextArea description;
 88  
 
 89  
     /**
 90  
      * This is where the ArgoUML version that last saved this project
 91  
      * is shown in the settings tab.
 92  
      * This information is stored in the zargo file.
 93  
      */
 94  
     private JTextField version;
 95  
 
 96  
     /**
 97  
      * The constructor.
 98  
      */
 99  900
     ProjectSettingsTabProperties() {
 100  900
         setLayout(new BorderLayout());
 101  900
         JPanel top = new JPanel();
 102  900
         top.setLayout(new GridBagLayout());
 103  
 
 104  900
         GridBagConstraints labelConstraints = new GridBagConstraints();
 105  
         /* Labels at the left ... */
 106  900
         labelConstraints.anchor = GridBagConstraints.LINE_START;
 107  900
         labelConstraints.gridy = 0;
 108  900
         labelConstraints.gridx = 0;
 109  900
         labelConstraints.gridwidth = 1;
 110  900
         labelConstraints.gridheight = 1;
 111  900
         labelConstraints.insets = new Insets(2, 20, 2, 4);
 112  900
         labelConstraints.anchor = 
 113  
             GridBagConstraints.FIRST_LINE_START;
 114  
         
 115  900
         GridBagConstraints fieldConstraints = new GridBagConstraints();
 116  
         /* ... and fields at the right. */
 117  900
         fieldConstraints.anchor = GridBagConstraints.LINE_END;
 118  900
         fieldConstraints.fill = GridBagConstraints.BOTH;
 119  900
         fieldConstraints.gridy = 0;
 120  900
         fieldConstraints.gridx = 1;
 121  900
         fieldConstraints.gridwidth = 3;
 122  900
         fieldConstraints.gridheight = 1;
 123  900
         fieldConstraints.weightx = 1.0;
 124  900
         fieldConstraints.insets = new Insets(2, 4, 2, 20);
 125  
 
 126  
         /* The user's full name: */
 127  900
         labelConstraints.gridy = 0;
 128  900
         fieldConstraints.gridy = 0;
 129  900
         top.add(new JLabel(Translator.localize("label.user")),
 130  
                 labelConstraints);
 131  900
         userFullname = new JTextField();
 132  900
         top.add(userFullname, fieldConstraints);
 133  
 
 134  
         /* The user's email: */
 135  900
         labelConstraints.gridy = 1;
 136  900
         fieldConstraints.gridy = 1;
 137  900
         top.add(new JLabel(Translator.localize("label.email")),
 138  
                 labelConstraints);
 139  900
         userEmail = new JTextField();
 140  900
         top.add(userEmail, fieldConstraints);
 141  
 
 142  
         /* The project description: */
 143  900
         labelConstraints.gridy = 2;
 144  900
         fieldConstraints.gridy = 2;
 145  900
         fieldConstraints.weighty = 1.0;
 146  900
         labelConstraints.weighty = 1.0;
 147  900
         JLabel lblDescription = new JLabel(
 148  
                 Translator.localize("label.project.description"));
 149  900
         lblDescription.setVerticalAlignment(SwingConstants.TOP);
 150  900
         top.add(lblDescription,
 151  
                 labelConstraints);
 152  900
         description = new JTextArea();
 153  900
         JScrollPane area = new JScrollPane(description);
 154  900
         area.setVerticalScrollBarPolicy(
 155  
                         JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
 156  900
         description.setMargin(new Insets(3, 3, 3, 3));
 157  900
         description.setLineWrap(true);
 158  900
         description.setWrapStyleWord(true);
 159  900
         top.add(area, fieldConstraints);
 160  
 
 161  
         /* This non-editable field shows 
 162  
          * the version of the ArgoUML 
 163  
          * that last saved this project: */
 164  900
         labelConstraints.gridy = 3;
 165  900
         fieldConstraints.gridy = 3;
 166  900
         fieldConstraints.weighty = 0.0;
 167  900
         labelConstraints.weighty = 0.0;
 168  900
         top.add(new JLabel(Translator.localize("label.argouml.version")),
 169  
                 labelConstraints);
 170  900
         version = new JTextField();
 171  900
         version.setEditable(false);
 172  900
         top.add(version, fieldConstraints);
 173  
 
 174  
         /* We need to fill the whole pane, 
 175  
          * so that the description field can 
 176  
          * take all available space: */
 177  900
         add(top, BorderLayout.CENTER);
 178  900
     }
 179  
 
 180  
     /*
 181  
      * @see org.argouml.ui.GUISettingsTabInterface#handleSettingsTabRefresh()
 182  
      */
 183  
     public void handleSettingsTabRefresh() {
 184  106
         assert p != null;
 185  106
         userFullname.setText(p.getAuthorname());
 186  106
         userEmail.setText(p.getAuthoremail());
 187  106
         description.setText(p.getDescription());
 188  106
         description.setCaretPosition(0);
 189  106
         version.setText(p.getVersion());
 190  106
     }
 191  
 
 192  
     /*
 193  
      * @see org.argouml.ui.GUISettingsTabInterface#handleSettingsTabSave()
 194  
      */
 195  
     public void handleSettingsTabSave() {
 196  12
         assert p != null;
 197  12
         p.setAuthorname(userFullname.getText());
 198  12
         p.setAuthoremail(userEmail.getText());
 199  12
         p.setDescription(description.getText());
 200  12
     }
 201  
 
 202  
     /*
 203  
      * @see org.argouml.ui.GUISettingsTabInterface#handleSettingsTabCancel()
 204  
      */
 205  
     public void handleSettingsTabCancel() {
 206  6
         handleSettingsTabRefresh();
 207  6
     }
 208  
 
 209  
     /*
 210  
      * @see org.argouml.ui.GUISettingsTabInterface#handleResetToDefault()
 211  
      */
 212  
     public void handleResetToDefault() {
 213  6
         userFullname.setText(Configuration.getString(Argo.KEY_USER_FULLNAME));
 214  6
         userEmail.setText(Configuration.getString(Argo.KEY_USER_EMAIL));
 215  
         // There is no default description.
 216  6
     }
 217  
 
 218  
     /*
 219  
      * @see org.argouml.ui.GUISettingsTabInterface#getTabKey()
 220  
      */
 221  100
     public String getTabKey() { return "tab.user"; }
 222  
 
 223  
     /*
 224  
      * @see org.argouml.ui.GUISettingsTabInterface#getTabPanel()
 225  
      */
 226  100
     public JPanel getTabPanel() { return this; }
 227  
 
 228  
     public void setProject(Project project) {
 229  100
         assert project != null;
 230  100
         p = project;
 231  100
     }
 232  
 }