Coverage Report - org.argouml.uml.diagram.ui.PropPanelString
 
Classes in this File Line Coverage Branch Coverage Complexity
PropPanelString
0%
0/53
0%
0/14
1.538
 
 1  
 /* $Id: PropPanelString.java 17865 2010-01-12 20:45:26Z 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) 1996-2006 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.uml.diagram.ui;
 40  
 
 41  
 import java.awt.GridBagConstraints;
 42  
 import java.awt.GridBagLayout;
 43  
 import java.beans.PropertyChangeEvent;
 44  
 import java.beans.PropertyChangeListener;
 45  
 
 46  
 import javax.swing.JLabel;
 47  
 import javax.swing.JTextField;
 48  
 import javax.swing.event.DocumentEvent;
 49  
 import javax.swing.event.DocumentListener;
 50  
 
 51  
 import org.argouml.application.api.AbstractArgoJPanel;
 52  
 import org.argouml.i18n.Translator;
 53  
 import org.argouml.ui.TabModelTarget;
 54  
 import org.argouml.ui.targetmanager.TargetEvent;
 55  
 import org.tigris.gef.presentation.FigText;
 56  
 
 57  
 /**
 58  
  * The properties panel for a simple text / string.
 59  
  *
 60  
  */
 61  
 public class PropPanelString
 62  
     extends AbstractArgoJPanel
 63  
     implements TabModelTarget, PropertyChangeListener, DocumentListener {
 64  
 
 65  
     private FigText target;
 66  0
     private JLabel nameLabel = new JLabel(Translator.localize("label.text"));
 67  0
     private JTextField nameField = new JTextField();
 68  
 
 69  
     /**
 70  
      * The constructor.
 71  
      *
 72  
      */
 73  
     public PropPanelString() {
 74  0
         super(Translator.localize("tab.string"));
 75  0
         GridBagLayout gb = new GridBagLayout();
 76  0
         setLayout(gb);
 77  0
         GridBagConstraints c = new GridBagConstraints();
 78  0
         c.fill = GridBagConstraints.BOTH;
 79  0
         c.weightx = 0.0;
 80  0
         c.ipadx = 3; c.ipady = 3;
 81  
 
 82  0
         c.gridx = 0;
 83  0
         c.gridwidth = 1;
 84  0
         c.gridy = 0;
 85  0
         gb.setConstraints(nameLabel, c);
 86  0
         add(nameLabel);
 87  
 
 88  0
         c.weightx = 1.0;
 89  0
         c.gridx = 1;
 90  0
         c.gridwidth = GridBagConstraints.REMAINDER;
 91  0
         c.gridheight = GridBagConstraints.REMAINDER;
 92  0
         c.gridy = 0;
 93  0
         gb.setConstraints(nameField, c);
 94  0
         add(nameField);
 95  
 
 96  0
         nameField.getDocument().addDocumentListener(this);
 97  0
         nameField.setEditable(true);
 98  
         // TODO: set font?
 99  
 
 100  0
     }
 101  
 
 102  
 
 103  
     /*
 104  
      * @see org.argouml.ui.TabTarget#setTarget(java.lang.Object)
 105  
      */
 106  
     public void setTarget(Object t) {
 107  0
         if (target != null) {
 108  0
             target.removePropertyChangeListener(this);
 109  
         }
 110  0
         if (t instanceof FigText) {
 111  0
             target = (FigText) t;
 112  
             // to circumvent too many registered listeners
 113  0
             target.removePropertyChangeListener(this);
 114  0
             if (isVisible()) {
 115  0
                 target.addPropertyChangeListener(this);
 116  
             }
 117  
         }
 118  
 
 119  0
     }
 120  
 
 121  
     /*
 122  
      * @see org.argouml.ui.TabTarget#getTarget()
 123  
      */
 124  
     public Object getTarget() {
 125  0
         return target;
 126  
     }
 127  
 
 128  
     /*
 129  
      * @see org.argouml.ui.TabTarget#refresh()
 130  
      */
 131  
     public void refresh() {
 132  0
         setTarget(target);
 133  0
     }
 134  
 
 135  
     /*
 136  
      * @see org.argouml.ui.TabTarget#shouldBeEnabled(java.lang.Object)
 137  
      */
 138  0
     public boolean shouldBeEnabled(Object theTarget) { return false; }
 139  
 
 140  
 
 141  
     /**
 142  
      * Set the target name.
 143  
      */
 144  
     protected void setTargetName() {
 145  0
     }
 146  
 
 147  
     ////////////////////////////////////////////////////////////////
 148  
     // event handling
 149  
 
 150  
     /*
 151  
      * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
 152  
      */
 153  
     public void insertUpdate(DocumentEvent e) {
 154  0
         if (e.getDocument() == nameField.getDocument() && target != null) {
 155  0
             target.setText(nameField.getText());
 156  0
             target.damage();
 157  
         }
 158  0
     }
 159  
 
 160  
     /*
 161  
      * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
 162  
      */
 163  
     public void removeUpdate(DocumentEvent e) {
 164  0
         insertUpdate(e);
 165  0
     }
 166  
 
 167  
     /*
 168  
      * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
 169  
      */
 170  
     public void changedUpdate(DocumentEvent e) {
 171  0
     }
 172  
 
 173  
     /*
 174  
      * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent)
 175  
      */
 176  
     public void propertyChange(PropertyChangeEvent evt) {
 177  0
         if (evt.getPropertyName().equals("editing")
 178  
             && evt.getNewValue().equals(Boolean.FALSE)) {
 179  
             // ending editing
 180  0
             nameField.setText(target.getText());
 181  
         }
 182  
 
 183  0
     }
 184  
 
 185  
     /*
 186  
      * @see org.argouml.ui.targetmanager.TargetListener#targetAdded(org.argouml.ui.targetmanager.TargetEvent)
 187  
      */
 188  
     public void targetAdded(TargetEvent e) {
 189  0
         setTarget(e.getNewTarget());
 190  0
     }
 191  
 
 192  
     /*
 193  
      * @see org.argouml.ui.targetmanager.TargetListener#targetRemoved(org.argouml.ui.targetmanager.TargetEvent)
 194  
      */
 195  
     public void targetRemoved(TargetEvent e) {
 196  0
         setTarget(e.getNewTarget());
 197  0
     }
 198  
 
 199  
     /*
 200  
      * @see org.argouml.ui.targetmanager.TargetListener#targetSet(org.argouml.ui.targetmanager.TargetEvent)
 201  
      */
 202  
     public void targetSet(TargetEvent e) {
 203  0
         setTarget(e.getNewTarget());
 204  0
     }
 205  
 
 206  
 }