Coverage Report - org.argouml.uml.ui.UMLCheckBox2
 
Classes in this File Line Coverage Branch Coverage Complexity
UMLCheckBox2
26%
6/23
0%
0/6
1.375
 
 1  
 /* $Id: UMLCheckBox2.java 17881 2010-01-12 21:09:28Z 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) 2002-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.uml.ui;
 40  
 
 41  
 import java.beans.PropertyChangeEvent;
 42  
 import java.beans.PropertyChangeListener;
 43  
 
 44  
 import javax.swing.Action;
 45  
 import javax.swing.JCheckBox;
 46  
 
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.ui.LookAndFeelMgr;
 49  
 import org.argouml.ui.targetmanager.TargetEvent;
 50  
 import org.argouml.ui.targetmanager.TargetListener;
 51  
 import org.tigris.gef.presentation.Fig;
 52  
 
 53  
 /**
 54  
  * The checkbox to be used to show boolean UML attributes in the GUI's. Mostly
 55  
  * used on proppanels. Other GUI elements (like UMLLinkedList) divide the
 56  
  * responsibility of showing an attribute and maintaining the state of the
 57  
  * attribute between a GUI element and a model. This is not the case for the
 58  
  * UMLCheckBox2. Reason for this is that the model is just too simple to need
 59  
  * extra classes for the model.
 60  
  * 
 61  
  * @since Oct 12, 2002
 62  
  * @author jaap.branderhorst@xs4all.nl
 63  
  */
 64  
 public abstract class UMLCheckBox2 extends JCheckBox
 65  
     implements TargetListener, PropertyChangeListener {
 66  
 
 67  
     private Object checkBoxTarget;
 68  
     private String propertySetName;
 69  
 
 70  
     /**
 71  
      * Constructor for UMLCheckBox2.
 72  
      * @param text the text of the check box
 73  
      * @param a the action we're going to listen to
 74  
      * @param name the property set name
 75  
      */
 76  
     public UMLCheckBox2(String text, Action a, String name) {
 77  900
         super(text);
 78  900
         setFont(LookAndFeelMgr.getInstance().getStandardFont());
 79  900
         propertySetName = name;
 80  900
         addActionListener(a);
 81  
 
 82  900
         setActionCommand((String) a.getValue(Action.ACTION_COMMAND_KEY));
 83  900
     }
 84  
 
 85  
     /*
 86  
      * The property value has changed so rebuild our view.
 87  
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
 88  
      */
 89  
     public void propertyChange(PropertyChangeEvent evt) {
 90  0
         buildModel();
 91  0
     }
 92  
 
 93  
     /**
 94  
      * Return the target. 
 95  
      *
 96  
      * @return the target
 97  
      */
 98  
     public Object getTarget() {
 99  0
         return checkBoxTarget;
 100  
     }
 101  
 
 102  
     /**
 103  
      * Sets the target. This method will not be used until the target does
 104  
      * not come via the container.
 105  
      * @param target The target to set
 106  
      */
 107  
     public void setTarget(Object target) {
 108  0
         target = target instanceof Fig ? ((Fig) target).getOwner() : target;
 109  0
         if (Model.getFacade().isAUMLElement(checkBoxTarget)) {
 110  0
             Model.getPump().removeModelEventListener(
 111  
                     this, checkBoxTarget, propertySetName);
 112  
         }
 113  
 
 114  0
         if (Model.getFacade().isAUMLElement(target)) {
 115  0
             checkBoxTarget = target;
 116  0
             Model.getPump().addModelEventListener(
 117  
                     this, checkBoxTarget, propertySetName);
 118  0
             buildModel();
 119  
         }
 120  0
     }
 121  
 
 122  
     /**
 123  
      * Builds the model. That is: it sets the checkbox to true or
 124  
      * false. The name of this method is chosen to be compliant with
 125  
      * for example UMLModelElementListModel2.
 126  
      */
 127  
     public abstract void buildModel();
 128  
 
 129  
 
 130  
     /*
 131  
      * @see TargetListener#targetAdded(TargetEvent)
 132  
      */
 133  
     public void targetAdded(TargetEvent e) {
 134  0
         setTarget(e.getNewTarget());
 135  0
     }
 136  
 
 137  
     /*
 138  
      * @see TargetListener#targetRemoved(TargetEvent)
 139  
      */
 140  
     public void targetRemoved(TargetEvent e) {
 141  0
         setTarget(e.getNewTarget());
 142  0
     }
 143  
 
 144  
     /*
 145  
      * @see TargetListener#targetSet(TargetEvent)
 146  
      */
 147  
     public void targetSet(TargetEvent e) {
 148  0
         setTarget(e.getNewTarget());
 149  0
     }
 150  
 }