svn commit: r14906 - trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-06-12 11:07:59-0700
New Revision: 14906

Added:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java

Log:
Created a FigClassifierBoxWithAttributes, and applied it to FigSignal and FigClass. There may be some other Figs derived from FigClassifierBox that can benefit from this change.
This fixes the malfunctioning FigSignal for most of its problems.

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java?view=diff&rev=14906&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java&r1=14905&r2=14906
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java	2008-06-12 11:07:59-0700
@@ -24,30 +24,12 @@
 
 package org.argouml.uml.diagram.static_structure.ui;
 
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Rectangle;
-import java.beans.PropertyVetoException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.swing.Action;
-
-import org.argouml.model.AddAssociationEvent;
-import org.argouml.model.AssociationChangeEvent;
-import org.argouml.model.AttributeChangeEvent;
 import org.argouml.model.Model;
-import org.argouml.model.RemoveAssociationEvent;
-import org.argouml.model.UmlChangeEvent;
-import org.argouml.ui.ArgoJMenu;
 import org.argouml.uml.diagram.AttributesCompartmentContainer;
-import org.argouml.uml.diagram.ui.CompartmentFigText;
-import org.argouml.uml.diagram.ui.FigAttributesCompartment;
-import org.argouml.uml.ui.foundation.core.ActionAddAttribute;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Selection;
 import org.tigris.gef.graph.GraphModel;
 import org.tigris.gef.presentation.Fig;
@@ -56,8 +38,11 @@
 
 /**
  * Class to display graphics for a UML Class in a diagram.<p>
+ * 
+ * A Class may show compartments for stereotypes,
+ * attributes and operations.
  */
-public class FigClass extends FigClassifierBox
+public class FigClass extends FigClassifierBoxWithAttributes
         implements AttributesCompartmentContainer {
 
     /**
@@ -65,8 +50,6 @@
      */
     //private static final Logger LOG = Logger.getLogger(FigClass.class);
 
-    private FigAttributesCompartment attributesFigCompartment;
-
     /**
      * Constructor for a {@link FigClass} during file load.<p>
      *
@@ -128,13 +111,11 @@
      */
     public FigClass(GraphModel gm, Object node) {
         super();
-        attributesFigCompartment =
-            new FigAttributesCompartment(10, 30, 60, ROWHEIGHT + 2);
         addFig(getBigPort());
         addFig(getStereotypeFig());
         addFig(getNameFig());
         addFig(getOperationsFig());
-        addFig(attributesFigCompartment);
+        addFig(getAttributesFig());
         addFig(borderFig);
         setOwner(node);
     }
@@ -156,10 +137,6 @@
         return figClone;
     }
 
-
-    ////////////////////////////////////////////////////////////////
-    // accessors
-
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
@@ -167,82 +144,10 @@
         return new SelectionClass(this);
     }
 
-    /*
-     * Insert an Add Attribute entry before the default menu.
-     * 
-     * @see org.argouml.uml.diagram.static_structure.ui.FigClassifierBox#buildAddMenu()
-     */
-    protected ArgoJMenu buildAddMenu() {
-        ArgoJMenu addMenu = super.buildAddMenu();
-        Action addAttribute = new ActionAddAttribute();
-        addAttribute.setEnabled(isSingleTarget());
-        addMenu.insert(addAttribute, 0);
-        return addMenu;
-    }
-
     protected Object buildModifierPopUp() {
         return buildModifierPopUp(ABSTRACT | LEAF | ROOT | ACTIVE);
     }
 
-    /**
-     * @return The bounds of the attributes compartment.
-     */
-    public Rectangle getAttributesBounds() {
-        return attributesFigCompartment.getBounds();
-    }
-
-    /**
-     * @return The vector of graphics for operations (if any).
-     * First one is the rectangle for the entire operations box.
-     */
-    private FigAttributesCompartment getAttributesFig() {
-        return attributesFigCompartment;
-    }
-
-    /**
-     * Returns the status of the attribute field.
-     * @return true if the attributes are visible, false otherwise
-     *
-     * @see org.argouml.uml.diagram.AttributesCompartmentContainer#isAttributesVisible()
-     */
-    public boolean isAttributesVisible() {
-        return getAttributesFig().isVisible();
-    }
-
-    /**
-     * @param isVisible true if the attribute compartment is visible
-     *
-     * @see org.argouml.uml.diagram.AttributesCompartmentContainer#setAttributesVisible(boolean)
-     */
-    public void setAttributesVisible(boolean isVisible) {
-        Rectangle rect = getBounds();
-        if (getAttributesFig().isVisible()) {
-            if (!isVisible) {  // hide compartment
-                damage();
-                Iterator it = getAttributesFig().getFigs().iterator();
-                while (it.hasNext()) {
-                    ((Fig) (it.next())).setVisible(false);
-                }
-                getAttributesFig().setVisible(false);
-                Dimension aSize = this.getMinimumSize();
-                setBounds(rect.x, rect.y,
-			  (int) aSize.getWidth(), (int) aSize.getHeight());
-            }
-        } else {
-            if (isVisible) { // show compartement
-                Iterator it = getAttributesFig().getFigs().iterator();
-                while (it.hasNext()) {
-                    ((Fig) (it.next())).setVisible(true);
-                }
-                getAttributesFig().setVisible(true);
-                Dimension aSize = this.getMinimumSize();
-                setBounds(rect.x, rect.y,
-			  (int) aSize.getWidth(), (int) aSize.getHeight());
-                damage();
-            }
-        }
-    }
-
     /*
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
      */
@@ -258,76 +163,6 @@
     }
 
     /**
-     * USED BY PGML.tee.
-     * @return the class name and bounds together with compartment
-     * visibility.
-     */
-    public String classNameAndBounds() {
-        return super.classNameAndBounds()
-            + "operationsVisible=" + isOperationsVisible() + ";"
-            + "attributesVisible=" + isAttributesVisible();
-    }
-
-    /**
-     * Gets the minimum size permitted for a class on the diagram.<p>
-     *
-     * Parts of this are hardcoded, notably the fact that the name
-     * compartment has a minimum height of 21 pixels.<p>
-     *
-     * @return  the size of the minimum bounding box.
-     */
-    public Dimension getMinimumSize() {
-        // Use "aSize" to build up the minimum size. Start with the size of the
-        // name compartment and build up.
-
-        Dimension aSize = getNameFig().getMinimumSize();
-
-        // If we have a stereotype displayed, then allow some space for that
-        // (width and height)
-
-        if (getStereotypeFig().isVisible()) {
-            Dimension stereoMin = getStereotypeFig().getMinimumSize();
-            aSize.width = Math.max(aSize.width, stereoMin.width);
-            aSize.height += stereoMin.height;
-        }
-
-        // Allow space for each of the attributes we have
-
-        if (getAttributesFig().isVisible()) {
-            Dimension attrMin = getAttributesFig().getMinimumSize();
-            aSize.width = Math.max(aSize.width, attrMin.width);
-            aSize.height += attrMin.height;
-        }
-
-        // Allow space for each of the operations we have
-
-        if (isOperationsVisible()) {
-            Dimension operMin = getOperationsFig().getMinimumSize();
-            aSize.width = Math.max(aSize.width, operMin.width);
-            aSize.height += operMin.height;
-        }
-
-        // we want to maintain a minimum width for the class
-        aSize.width = Math.max(60, aSize.width);
-
-        // And now aSize has the answer
-
-        return aSize;
-    }
-
-    /*
-     * @see org.tigris.gef.presentation.Fig#translate(int, int)
-     */
-    public void translate(int dx, int dy) {
-        super.translate(dx, dy);
-        Editor ce = Globals.curEditor();
-        Selection sel = ce.getSelectionManager().findSelectionFor(this);
-        if (sel instanceof SelectionClass) {
-            ((SelectionClass) sel).hideButtons();
-        }
-    }
-
-    /**
      * @param fgVec the FigGroup
      * @param ft    the Figtext
      * @param i     get the fig before fig i
@@ -396,89 +231,6 @@
         return ft2;
     }
 
-    /*
-     * @see org.argouml.uml.diagram.ui.FigNodeModelElement#renderingChanged()
-     * TODO: Does this have to be public?
-     */
-    public void renderingChanged() {
-        if (getOwner() != null) {
-            updateAttributes();
-        }
-        super.renderingChanged();
-    }
-    
-    /*
-     * TODO: Based on my comments below, with that work done,
-     * this method can be removed - Bob.
-     */
-    protected void updateLayout(UmlChangeEvent event) {
-        super.updateLayout(event);
-
-        if (event instanceof AttributeChangeEvent) {
-            Object source = event.getSource();
-            if (Model.getFacade().isAAttribute(source)) {
-                // TODO: We just need to get someone to rerender a single line
-                // of text which represents the element here, but I'm not sure
-                // how to do that. - tfm
-        	// TODO: Bob replies - we shouldn't be interested in this event
-        	// here. The FigFeature (or its notation) should be listen for
-        	// change and the FigFeature should be update from that.
-                updateAttributes();
-            }
-        } else if (event instanceof AssociationChangeEvent 
-                && getOwner().equals(event.getSource())) {
-            Object o = null;
-            if (event instanceof AddAssociationEvent) {
-                o = event.getNewValue();
-            } else if (event instanceof RemoveAssociationEvent) {
-                o = event.getOldValue();
-            }
-            if (Model.getFacade().isAAttribute(o)) {
-        	// TODO: Bob says - we should not be listening here for
-        	// addition and removal of attributes. This should be done in
-        	// FigAttributesCompartment.
-                updateAttributes();
-            }
-        }
-    }
-
-    /*
-     * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateStereotypeText()
-     * TODO: Refactor into FigClassifierBox
-     */
-    protected void updateStereotypeText() {
-
-        Rectangle rect = getBounds();
-
-        int stereotypeHeight = 0;
-        if (getStereotypeFig().isVisible()) {
-            stereotypeHeight = getStereotypeFig().getHeight();
-        }
-        int heightWithoutStereo = getHeight() - stereotypeHeight;
-
-        getStereotypeFig().setOwner(getOwner());
-
-        stereotypeHeight = 0;
-        if (getStereotypeFig().isVisible()) {
-            stereotypeHeight = getStereotypeFig().getHeight();
-        }
-
-        int minWidth = this.getMinimumSize().width;
-        if (minWidth > rect.width) {
-            rect.width = minWidth;
-        }
-
-        setBounds(
-                rect.x,
-                rect.y,
-                rect.width,
-                heightWithoutStereo + stereotypeHeight);
-        calcBounds();
-    }
-
-    /*
-     * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig)
-     */
     public void setEnclosingFig(Fig encloser) {
         if (encloser == getEncloser()) {
             return;
@@ -499,114 +251,6 @@
 
     }
 
-    /**
-     * Sets the bounds, but the size will be at least the one returned by
-     * {@link #getMinimumSize()}, unless checking of size is disabled.<p>
-     *
-     * If the required height is bigger, then the additional height is
-     * equally distributed among all figs (i.e. compartments), such that the
-     * cumulated height of all visible figs equals the demanded height<p>.
-     *
-     * Some of this has "magic numbers" hardcoded in. In particular there is
-     * a knowledge that the minimum height of a name compartment is 21
-     * pixels.<p>
-     *
-     * @param x  Desired X coordinate of upper left corner
-     *
-     * @param y  Desired Y coordinate of upper left corner
-     *
-     * @param w  Desired width of the FigClass
-     *
-     * @param h  Desired height of the FigClass
-     * 
-     * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
-     */
-    protected void setStandardBounds(final int x, final int y,
-            final int w, final int h) {
-        Rectangle oldBounds = getBounds();
-
-        // set bounds of big box
-        getBigPort().setBounds(x, y, w, h);
-        borderFig.setBounds(x, y, w, h);
-
-        // Save our old boundaries (needed later), and get minimum size
-        // info. "whitespace" will be used to maintain a running calculation
-        // of our size at various points.
-
-        final int whitespace = h - getMinimumSize().height;
-
-        getNameFig().setLineWidth(0);
-        getNameFig().setLineColor(Color.red);
-        int currentHeight = 0;
-
-        if (getStereotypeFig().isVisible()) {
-            int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
-            getStereotypeFig().setBounds(
-                    x,
-                    y,
-                    w,
-                    stereotypeHeight);
-            currentHeight = stereotypeHeight;
-        }
-
-        int nameHeight = getNameFig().getMinimumSize().height;
-        getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
-        currentHeight += nameHeight;
-
-        if (isAttributesVisible()) {
-            int attributesHeight = getAttributesFig().getMinimumSize().height;
-            if (isOperationsVisible()) {
-                attributesHeight += whitespace / 2;
-            }
-            getAttributesFig().setBounds(
-                    x,
-                    y + currentHeight,
-                    w,
-                    attributesHeight);
-            currentHeight += attributesHeight;
-        }
-
-        if (isOperationsVisible()) {
-            int operationsY = y + currentHeight;
-            int operationsHeight = (h + y) - operationsY - 1;
-            if (operationsHeight < getOperationsFig().getMinimumSize().height) {
-                operationsHeight = getOperationsFig().getMinimumSize().height;
-            }
-            getOperationsFig().setBounds(
-                    x,
-                    operationsY,
-                    w,
-                    operationsHeight);
-        }
-
-        // Now force calculation of the bounds of the figure, update the edges
-        // and trigger anyone who's listening to see if the "bounds" property
-        // has changed.
-
-        calcBounds();
-        updateEdges();
-        firePropChange("bounds", oldBounds, getBounds());
-    }
-
-    /**
-     * Updates the attributes in the fig. Called from modelchanged if there is
-     * a modelevent effecting the attributes and from renderingChanged in all
-     * cases.
-     * TODO: Looks like this should be private - Bob.
-     */
-    protected void updateAttributes() {
-        if (!isAttributesVisible()) {
-            return;
-        }
-        attributesFigCompartment.populate();
-
-        Rectangle rect = getBounds();
-        // ouch ugly but that's for a next refactoring
-        // TODO: make setBounds, calcBounds and updateBounds consistent
-        setBounds(rect.x, rect.y, rect.width, rect.height);
-    }
-
-
     /*
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateNameText()
      */
@@ -616,43 +260,4 @@
         setBounds(getBounds());
     }
     
-    /*
-     * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object, java.lang.Object)
-     */
-    protected void updateListeners(Object oldOwner, Object newOwner) {
-        // Note: although this never removes listeners for features which have
-        // been deleted, they should get cleaned up as part of 
-        // the delete process.
-//        if (oldOwner != null) {
-//            removeAllElementListeners();
-//        }
-        if (newOwner != null) {
-            // add the listeners to the newOwner
-            addElementListener(newOwner);
-            // and its stereotypes
-            // TODO: Aren't stereotypes handled elsewhere?
-            Collection c = new ArrayList(
-                    Model.getFacade().getStereotypes(newOwner));
-            // and its features
-            for (Object feat : Model.getFacade().getFeatures(newOwner)) {
-                c.add(feat);
-                // and the stereotypes of its features
-                c.addAll(new ArrayList(Model.getFacade().getStereotypes(feat)));
-                // and the parameter of its operations
-                if (Model.getFacade().isAOperation(feat)) {
-                    c.addAll(Model.getFacade().getParameters(feat));
-                }
-            }
-            // And now add listeners to them all:
-            for (Object obj : c) {
-                addElementListener(obj);
-            }
-        }
-    }
-
-    /**
-     * The UID.
-     */
-    private static final long serialVersionUID = 3415118710864626882L;
-
 } /* end class FigClass */

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java?view=diff&rev=14906&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java&r1=14905&r2=14906
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java	2008-06-12 11:07:59-0700
@@ -36,7 +36,6 @@
 
 import org.argouml.model.AddAssociationEvent;
 import org.argouml.model.AssociationChangeEvent;
-import org.argouml.model.DeleteInstanceEvent;
 import org.argouml.model.Model;
 import org.argouml.model.RemoveAssociationEvent;
 import org.argouml.model.UmlChangeEvent;
@@ -308,6 +307,17 @@
         return addMenu;
     }
 
+    /**
+     * USED BY PGML.tee.
+     * @return the class name and bounds together with compartment
+     * visibility.
+     */
+    public String classNameAndBounds() {
+        return super.classNameAndBounds()
+            + "operationsVisible=" + isOperationsVisible() + ";";
+    }
+
+    
     protected Object buildModifierPopUp() {
         return buildModifierPopUp(ABSTRACT | LEAF | ROOT);
     }

Added: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java?view=auto&rev=14906
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java	2008-06-12 11:07:59-0700
@@ -0,0 +1,386 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

+// Copyright (c) 2008 The Regents of the University of California. All

+// Rights Reserved. Permission to use, copy, modify, and distribute this

+// software and its documentation without fee, and without a written

+// agreement is hereby granted, provided that the above copyright notice

+// and this paragraph appear in all copies. This software program and

+// documentation are copyrighted by The Regents of the University of

+// California. The software program and documentation are supplied "AS

+// IS", without any accompanying services from The Regents. The Regents

+// does not warrant that the operation of the program will be

+// uninterrupted or error-free. The end-user understands that the program

+// was developed for research purposes and is advised not to rely

+// exclusively on the program for any reason. IN NO EVENT SHALL THE

+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,

+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,

+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF

+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF

+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY

+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE

+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF

+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,

+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

+

+package org.argouml.uml.diagram.static_structure.ui;

+

+import java.awt.Color;

+import java.awt.Dimension;

+import java.awt.Rectangle;

+import java.util.ArrayList;

+import java.util.Collection;

+import java.util.Iterator;

+

+import javax.swing.Action;

+

+import org.argouml.model.AddAssociationEvent;

+import org.argouml.model.AssociationChangeEvent;

+import org.argouml.model.AttributeChangeEvent;

+import org.argouml.model.Model;

+import org.argouml.model.RemoveAssociationEvent;

+import org.argouml.model.UmlChangeEvent;

+import org.argouml.ui.ArgoJMenu;

+import org.argouml.uml.diagram.AttributesCompartmentContainer;

+import org.argouml.uml.diagram.ui.FigAttributesCompartment;

+import org.argouml.uml.ui.foundation.core.ActionAddAttribute;

+import org.tigris.gef.presentation.Fig;

+

+/**

+ * A Fig for a ClassifierBox that adds an attributes compartment.

+ *

+ * @author Michiel

+ */

+public class FigClassifierBoxWithAttributes extends FigClassifierBox 

+    implements AttributesCompartmentContainer {

+

+    private FigAttributesCompartment attributesFigCompartment;

+

+    /**

+     * The constructor.

+     */

+    public FigClassifierBoxWithAttributes() {

+        super();

+        attributesFigCompartment =

+            new FigAttributesCompartment(10, 30, 60, ROWHEIGHT + 2);

+        

+    }

+

+    /**

+     * @return The vector of graphics for operations (if any).

+     * First one is the rectangle for the entire operations box.

+     */

+    protected FigAttributesCompartment getAttributesFig() {

+        return attributesFigCompartment;

+    }

+    

+    public Rectangle getAttributesBounds() {

+        return attributesFigCompartment.getBounds();

+    }

+

+    public boolean isAttributesVisible() {

+        return attributesFigCompartment.isVisible();

+    }

+    

+    /*

+     * Insert an Add Attribute entry before the default menu.

+     * 

+     * @see org.argouml.uml.diagram.static_structure.ui.FigClassifierBox#buildAddMenu()

+     */

+    protected ArgoJMenu buildAddMenu() {

+        ArgoJMenu addMenu = super.buildAddMenu();

+        Action addAttribute = new ActionAddAttribute();

+        addAttribute.setEnabled(isSingleTarget());

+        addMenu.insert(addAttribute, 0);

+        return addMenu;

+    }

+    

+    /**

+     * USED BY PGML.tee.

+     * @return the class name and bounds together with compartment

+     * visibility.

+     */

+    public String classNameAndBounds() {

+        return super.classNameAndBounds()

+            + "attributesVisible=" + isAttributesVisible() + ";";

+    }

+

+    protected void updateListeners(Object oldOwner, Object newOwner) {

+        if (oldOwner != null) {

+            removeAllElementListeners();

+        }

+        if (newOwner != null) {

+            // add the listeners to the newOwner

+            addElementListener(newOwner);

+            // and its stereotypes

+            // TODO: Aren't stereotypes handled elsewhere?

+            Collection c = new ArrayList(

+                    Model.getFacade().getStereotypes(newOwner));

+            // and its features

+            for (Object feat : Model.getFacade().getFeatures(newOwner)) {

+                c.add(feat);

+                // and the stereotypes of its features

+                c.addAll(new ArrayList(Model.getFacade().getStereotypes(feat)));

+                // and the parameter of its operations

+                if (Model.getFacade().isAOperation(feat)) {

+                    c.addAll(Model.getFacade().getParameters(feat));

+                }

+            }

+            // And now add listeners to them all:

+            for (Object obj : c) {

+                addElementListener(obj);

+            }

+        }

+    }

+    

+    public void renderingChanged() {

+        if (getOwner() != null) {

+            updateAttributes();

+        }

+        super.renderingChanged();

+    }

+    

+    /*

+     * TODO: Based on my comments below, with that work done,

+     * this method can be removed - Bob.

+     */

+    protected void updateLayout(UmlChangeEvent event) {

+        super.updateLayout(event);

+

+        if (event instanceof AttributeChangeEvent) {

+            Object source = event.getSource();

+            if (Model.getFacade().isAAttribute(source)) {

+                // TODO: We just need to get someone to rerender a single line

+                // of text which represents the element here, but I'm not sure

+                // how to do that. - tfm

+                // TODO: Bob replies - we shouldn't be interested in this event

+                // here. The FigFeature (or its notation) should be listen for

+                // change and the FigFeature should be update from that.

+                updateAttributes();

+            }

+        } else if (event instanceof AssociationChangeEvent 

+                && getOwner().equals(event.getSource())) {

+            Object o = null;

+            if (event instanceof AddAssociationEvent) {

+                o = event.getNewValue();

+            } else if (event instanceof RemoveAssociationEvent) {

+                o = event.getOldValue();

+            }

+            if (Model.getFacade().isAAttribute(o)) {

+                // TODO: Bob says - we should not be listening here for

+                // addition and removal of attributes. This should be done in

+                // FigAttributesCompartment.

+                updateAttributes();

+            }

+        }

+    }

+

+    protected void updateStereotypeText() {

+

+        Rectangle rect = getBounds();

+

+        int stereotypeHeight = 0;

+        if (getStereotypeFig().isVisible()) {

+            stereotypeHeight = getStereotypeFig().getHeight();

+        }

+        int heightWithoutStereo = getHeight() - stereotypeHeight;

+

+        getStereotypeFig().setOwner(getOwner());

+

+        stereotypeHeight = 0;

+        if (getStereotypeFig().isVisible()) {

+            stereotypeHeight = getStereotypeFig().getHeight();

+        }

+

+        int minWidth = this.getMinimumSize().width;

+        if (minWidth > rect.width) {

+            rect.width = minWidth;

+        }

+

+        setBounds(

+                rect.x,

+                rect.y,

+                rect.width,

+                heightWithoutStereo + stereotypeHeight);

+        calcBounds();

+    }

+

+    

+    /**

+     * Updates the attributes in the fig. Called from modelchanged if there is

+     * a modelevent effecting the attributes and from renderingChanged in all

+     * cases.

+     * TODO: Looks like this should be private - Bob.

+     */

+    protected void updateAttributes() {

+        if (!isAttributesVisible()) {

+            return;

+        }

+        attributesFigCompartment.populate();

+

+        Rectangle rect = getBounds();

+        // ouch ugly but that's for a next refactoring

+        // TODO: make setBounds, calcBounds and updateBounds consistent

+        setBounds(rect.x, rect.y, rect.width, rect.height);

+    }

+    

+    /**

+     * @param isVisible true if the attribute compartment is visible

+     *

+     * @see org.argouml.uml.diagram.AttributesCompartmentContainer#setAttributesVisible(boolean)

+     */

+    public void setAttributesVisible(boolean isVisible) {

+        Rectangle rect = getBounds();

+        if (getAttributesFig().isVisible()) {

+            if (!isVisible) {  // hide compartment

+                damage();

+                Iterator it = getAttributesFig().getFigs().iterator();

+                while (it.hasNext()) {

+                    ((Fig) (it.next())).setVisible(false);

+                }

+                getAttributesFig().setVisible(false);

+                Dimension aSize = this.getMinimumSize();

+                setBounds(rect.x, rect.y,

+                          (int) aSize.getWidth(), (int) aSize.getHeight());

+            }

+        } else {

+            if (isVisible) { // show compartment

+                Iterator it = getAttributesFig().getFigs().iterator();

+                while (it.hasNext()) {

+                    ((Fig) (it.next())).setVisible(true);

+                }

+                getAttributesFig().setVisible(true);

+                Dimension aSize = this.getMinimumSize();

+                setBounds(rect.x, rect.y,

+                          (int) aSize.getWidth(), (int) aSize.getHeight());

+                damage();

+            }

+        }

+    }

+

+    public Dimension getMinimumSize() {

+        // Use "aSize" to build up the minimum size. Start with the size of the

+        // name compartment and build up.

+

+        Dimension aSize = getNameFig().getMinimumSize();

+        aSize.height += 4; // +2 padding above and below name

+        aSize.height = Math.max(21, aSize.height);

+

+        aSize = addChildDimensions(aSize, getStereotypeFig());

+        aSize = addChildDimensions(aSize, getAttributesFig());

+        aSize = addChildDimensions(aSize, getOperationsFig());

+

+        aSize.width = Math.max(60, aSize.width);

+

+        return aSize;

+    }

+

+    /**

+     * Add size of a child component to overall size.  Width is maximized

+     * with child's width and child's height is added to the overall height.

+     * If the child figure is not visible, it's size is not added.

+     * 

+     * @param size current dimensions

+     * @param child child figure

+     * @return new Dimension with child size added

+     */

+    protected Dimension addChildDimensions(Dimension size, Fig child) {

+        if (child.isVisible()) {

+            Dimension childSize = child.getMinimumSize();

+            size.width = Math.max(size.width, childSize.width);

+            size.height += childSize.height;

+        }

+        return size;

+    }

+

+    /**

+     * Sets the bounds, but the size will be at least the one returned by

+     * {@link #getMinimumSize()}, unless checking of size is disabled.<p>

+     *

+     * If the required height is bigger, then the additional height is

+     * equally distributed among all figs (i.e. compartments), such that the

+     * cumulated height of all visible figs equals the demanded height<p>.

+     *

+     * Some of this has "magic numbers" hardcoded in. In particular there is

+     * a knowledge that the minimum height of a name compartment is 21

+     * pixels.<p>

+     *

+     * @param x  Desired X coordinate of upper left corner

+     *

+     * @param y  Desired Y coordinate of upper left corner

+     *

+     * @param w  Desired width of the FigClass

+     *

+     * @param h  Desired height of the FigClass

+     * 

+     * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)

+     */

+    protected void setStandardBounds(final int x, final int y, final int w,

+            final int h) {

+

+        // Save our old boundaries so it can be used in property message later

+        Rectangle oldBounds = getBounds();

+

+        // set bounds of big box

+        getBigPort().setBounds(x, y, w, h);

+        borderFig.setBounds(x, y, w, h);

+        

+        // Save our old boundaries (needed later), and get minimum size

+        // info. "whitespace" will be used to maintain a running calculation

+        // of our size at various points.

+        final int whitespace = h - getMinimumSize().height;

+

+        getNameFig().setLineWidth(0);

+        getNameFig().setLineColor(Color.red);

+        int currentHeight = 0;

+

+        if (getStereotypeFig().isVisible()) {

+            int stereotypeHeight = getStereotypeFig().getMinimumSize().height;

+            getStereotypeFig().setBounds(

+                    x,

+                    y,

+                    w,

+                    stereotypeHeight);

+            currentHeight += stereotypeHeight;

+        }

+

+        int nameHeight = getNameFig().getMinimumSize().height;

+        getNameFig().setBounds(x, y + currentHeight, w, nameHeight);

+        currentHeight += nameHeight;

+

+        if (attributesFigCompartment.isVisible()){

+            int attributesHeight = attributesFigCompartment.getMinimumSize().height;

+            if (isOperationsVisible()) {

+                attributesHeight += whitespace / 2;

+            }

+            attributesFigCompartment.setBounds(

+                    x,

+                    y + currentHeight,

+                    w,

+                    attributesHeight);

+            currentHeight += attributesHeight;

+        }

+

+        if (getOperationsFig().isVisible()) {

+            int operationsY = y + currentHeight;

+            int operationsHeight = (h + y) - operationsY - 1;

+            if (operationsHeight < getOperationsFig().getMinimumSize().height) {

+                operationsHeight = getOperationsFig().getMinimumSize().height;

+            }

+            getOperationsFig().setBounds(

+                    x,

+                    operationsY,

+                    w,

+                    operationsHeight);

+        }

+

+        // Now force calculation of the bounds of the figure, update the edges

+        // and trigger anyone who's listening to see if the "bounds" property

+        // has changed.

+

+        calcBounds();

+        updateEdges();

+        firePropChange("bounds", oldBounds, getBounds());

+    }

+

+

+}


Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java?view=diff&rev=14906&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java&r1=14905&r2=14906
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigException.java	2008-06-12 11:07:59-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2007 The Regents of the University of California. All
+// Copyright (c) 2007-2008 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -34,27 +34,16 @@
  */
 public class FigException extends FigSignal {
     
-    public FigException(GraphModel gm, Object node) {
-        super(gm, node);
-    }
-    
     /**
-     * Construct a FigSignal owned by the given Signal and with
-     * bounds specified.
-     *
-     * @param node The UML object being placed.
-     * @param x X coordinate
-     * @param y Y coordinate
-     * @param w width
-     * @param h height
+     * The Constructor.
+     * 
+     * @param gm the GraphModel
+     * @param node the UML object
      */
-    public FigException(Object node, int x, int y, int w, int h) {
-        super(node, x, y, w, h);
+    public FigException(GraphModel gm, Object node) {
+        super(gm, node);
     }
 
-    /*
-     * @see org.argouml.uml.diagram.static_structure.ui.FigDataType#makeSelection()
-     */
     public Selection makeSelection() {
         return new SelectionException(this);
     }

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java?view=diff&rev=14906&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java&r1=14905&r2=14906
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java	2008-06-12 11:07:59-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2007 The Regents of the University of California. All
+// Copyright (c) 2007-2008 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -24,31 +24,28 @@
 
 package org.argouml.uml.diagram.static_structure.ui;
 
-import java.awt.Dimension;
-import java.awt.Rectangle;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Vector;
 
 import org.argouml.model.AssociationChangeEvent;
 import org.argouml.model.AttributeChangeEvent;
-import org.argouml.model.Model;
-import org.argouml.uml.diagram.ui.FigAttributesCompartment;
 import org.argouml.uml.diagram.ui.FigStereotypesCompartment;
 import org.tigris.gef.base.Selection;
 import org.tigris.gef.graph.GraphModel;
-import org.tigris.gef.presentation.Fig;
 
 /**
  * Class to display graphics for a UML Signal in a diagram.
+ * <p>
+ * A Signal may have attributes - the UML standard document 
+ * contains an example diagram showing this.
+ * <p>
+ * A Signal may have operations.
  * 
  * @author Tom Morris
  */
-public class FigSignal extends FigClassifierBox {
+public class FigSignal extends FigClassifierBoxWithAttributes {
     
-    private FigAttributesCompartment attributesFigCompartment;
 
     /**
      * Default constructor for a {@link FigSignal}.
@@ -59,20 +56,16 @@
             (FigStereotypesCompartment) getStereotypeFig();
         fsc.setKeyword("signal");
 
-        enableSizeChecking(false);
-        setSuppressCalcBounds(true);
         addFig(getBigPort());
         addFig(getStereotypeFig());
         addFig(getNameFig());
+        addFig(getOperationsFig());
+        addFig(getAttributesFig());
         addFig(borderFig);
-        attributesFigCompartment =
-            new FigAttributesCompartment(10, 30, 60, ROWHEIGHT + 2);
-        addFig(attributesFigCompartment);
-        
+
+        // by default, do not show operations nor attributes:
         setOperationsVisible(false);
-        enableSizeChecking(true);
-        setSuppressCalcBounds(false);
-//        setBounds(getBounds());     
+        setAttributesVisible(false);
     }
 
     /**
@@ -85,26 +78,9 @@
      */
     public FigSignal(GraphModel gm, Object node) {
         this();
-        enableSizeChecking(true);
         setOwner(node);
-        setBounds(getBounds());
     }
 
-    /**
-     * Construct a FigSignal owned by the given Signal and with
-     * bounds specified.
-     *
-     * @param node The UML object being placed.
-     * @param x X coordinate
-     * @param y Y coordinate
-     * @param w width
-     * @param h height
-     */
-    public FigSignal(Object node, int x, int y, int w, int h) {
-        this(null, node);
-        setBounds(x, y, w, h);
-    }
-    
     /*
      * @see org.argouml.uml.diagram.static_structure.ui.FigDataType#makeSelection()
      */
@@ -112,41 +88,6 @@
         return new SelectionSignal(this);
     }
 
-
-    /*
-     * @see org.tigris.gef.presentation.Fig#getMinimumSize()
-     */
-    public Dimension getMinimumSize() {
-        Dimension aSize = getNameFig().getMinimumSize();
-        aSize.height += 4; // +2 padding above and below name
-        aSize.height = Math.max(21, aSize.height);
-
-        aSize = addChildDimensions(aSize, getStereotypeFig());
-        aSize = addChildDimensions(aSize, getOperationsFig());
-
-        aSize.width = Math.max(40, aSize.width);
-
-        return aSize;
-    }
-
-    /**
-     * Add size of a child component to overall size.  Width is maximized
-     * with child's width and child's height is added to the overall height.
-     * If the child figure is not visible, it's size is not added.
-     * 
-     * @param size current dimensions
-     * @param child child figure
-     * @return new Dimension with child size added
-     */
-    private Dimension addChildDimensions(Dimension size, Fig child) {
-        if (child.isVisible()) {
-            Dimension childSize = child.getMinimumSize();
-            size.width = Math.max(size.width, childSize.width);
-            size.height += childSize.height;
-        }
-        return size;
-    }
-
     /*
      * @see org.argouml.uml.diagram.static_structure.ui.FigClassifierBox#getPopUpActions(java.awt.event.MouseEvent)
      */
@@ -169,67 +110,5 @@
             updateListeners(getOwner(), getOwner());
         }
     }
-    
-    /*
-     * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object)
-     */
-    protected void updateListeners(Object oldOwner, Object newOwner) {
-        if (oldOwner != null) {
-            removeAllElementListeners();
-        }
-        if (newOwner != null) {
-            // add the listeners to the newOwner
-            addElementListener(newOwner);
-            // and its stereotypes
-            Collection c = new ArrayList(
-                    Model.getFacade().getStereotypes(newOwner));
-            // And now add listeners to them all:
-            for (Object obj : c) {
-                addElementListener(obj);
-            }
-        }
-    }
-
-
-    /*
-     * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
-     */
-    protected void setStandardBounds(final int x, final int y, final int w,
-            final int h) {
-
-        // Save our old boundaries so it can be used in property message later
-        Rectangle oldBounds = getBounds();
-
-        // set bounds of big box
-        getBigPort().setBounds(x, y, w, h);
-        borderFig.setBounds(x, y, w, h);
-
-        getNameFig().setLineWidth(0);
-
-        int currentHeight = 0;
-
-        if (getStereotypeFig().isVisible()) {
-            int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
-            getStereotypeFig().setBounds(
-                    x,
-                    y,
-                    w,
-                    stereotypeHeight);
-            currentHeight += stereotypeHeight;
-        }
-
-        int nameHeight = getNameFig().getMinimumSize().height;
-        getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
-        currentHeight += nameHeight;
-
-
-        // Now force calculation of the bounds of the figure, update the edges
-        // and trigger anyone who's listening to see if the "bounds" property
-        // has changed.
-
-        calcBounds();
-        updateEdges();
-        firePropChange("bounds", oldBounds, getBounds());
-    }
 
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.