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

Michiel van der Wulp <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-12-26 07:51:46-0800
New Revision: 16441

Added:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigKeyword.java   (contents, props changed)
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/FigPackage.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigSingleLineText.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotype.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotypesGroup.java

Log:
Next step in refactoring for issue 5421: The FigStereotype extended the CompartmentFigText, which is incorrect, since the
latter uses a notation provider and is editable. So, I changed FigStereotype to extend FigSingleLineText directly.
Also introduced the FigKeyword, for the first "stereotype" that isn't really a stereotype.


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&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- 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-12-26 07:51:46-0800
@@ -30,7 +30,6 @@
 import java.util.List;
 
 import org.argouml.model.Model;
-import org.argouml.uml.diagram.AttributesCompartmentContainer;
 import org.argouml.uml.diagram.DiagramSettings;
 import org.tigris.gef.base.Selection;
 import org.tigris.gef.graph.GraphModel;
@@ -44,8 +43,7 @@
  * A Class may show compartments for stereotypes,
  * attributes and operations.
  */
-public class FigClass extends FigClassifierBoxWithAttributes
-        implements AttributesCompartmentContainer {
+public class FigClass extends FigClassifierBoxWithAttributes {
 
 
     /**
@@ -114,8 +112,8 @@
     @Deprecated
     public FigClass(GraphModel gm, Object node) {
         super();
-        constructFigs();
         setOwner(node);
+        constructFigs();
     }
 
     private void constructFigs() {
@@ -157,7 +155,6 @@
             DiagramSettings settings) {
         super(element, bounds, settings);
         constructFigs();
-        renderingChanged();
     }
 
     /*

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigPackage.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigPackage.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigPackage.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigPackage.java	2008-12-26 07:51:46-0800
@@ -124,12 +124,13 @@
     private FigText body;
 
     /**
-     * Flag that indicates if the stereotype should be shown even if
-     * it is specified or not.
+     * Flag that indicates if the user wants any stereotype to be shown. 
+     * It corresponds to the check-mark on the Presentation tab.
+     * There is no relation with the actual presence of any stereotypes.
+     * This setting has Fig-scope, hence it is saved with the Fig layout data.
      */
     private boolean stereotypeVisible = true;
 
-
     /**
      * The main constructor.
      *
@@ -145,9 +146,10 @@
         // Create a Body that reacts to double-clicks and jumps to a diagram.
         body = new FigPackageFigText(0, textH, width, height - textH);
 
+        setOwner(node);
+
         initialize();
 
-        setOwner(node);
         setLocation(x, y);
     }
 
@@ -183,9 +185,6 @@
         setLineColor(Color.black);
         setLineWidth(1);
 
-        // TODO: Why do we need to do this? - Bob
-        setBounds(getBounds());
-
         updateEdges();
     }
 
@@ -331,20 +330,19 @@
             if (getStereotypeFig().isVisible()) {
                 getNameFig().setTopMargin(0);
                 getStereotypeFig().setVisible(false);
-            }
+            } // else nothing changed
         } else {
             /* we got at least one stereotype */
             /* This populates the stereotypes area: */
-            getStereotypeFig().setOwner(getOwner());
+            super.updateStereotypeText();
             if (!isStereotypeVisible()) {
+                // the user wants to hide them
                 getNameFig().setTopMargin(0);
                 getStereotypeFig().setVisible(false);
             } else if (!getStereotypeFig().isVisible()) {
-                if (isStereotypeVisible()) {
-                    getNameFig().setTopMargin(50); //TODO: Calc the right nr
+                    getNameFig().setTopMargin(getStereotypeFig().getMinimumSize().height);
                     getStereotypeFig().setVisible(true);
-                }
-            }
+            } // else nothing changed
         }
 
         forceRepaintShadow();

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java	2008-12-26 07:51:46-0800
@@ -42,6 +42,9 @@
 
 /**
  * Class to display graphics for a node with compartments in a diagram.<p>
+ * 
+ * It adds a border around the box, 
+ * and deals with highlighting editable compartments. <p>
  *
  * Note that the upper line of the name box will be blanked out
  * if there is eventually a stereotype above.
@@ -86,9 +89,9 @@
         // +1 to have 1 pixel overlap with getNameFig()
         getStereotypeFig().setHeight(STEREOHEIGHT + 1);
 
+        // The outside border of the box around all compartments.
         borderFig = new FigEmptyRect(X0, Y0, 0, 0);
         borderFig.setLineWidth(1);
-        borderFig.setLineColor(Color.black);
 
         getBigPort().setLineWidth(0);
         getBigPort().setFillColor(Color.white);

Added: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigKeyword.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigKeyword.java?view=markup&pathrev=16441
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigKeyword.java	2008-12-26 07:51:46-0800
@@ -0,0 +1,98 @@
+// $Id$
+// 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.ui;
+
+import java.awt.Color;
+import java.awt.Rectangle;
+
+import org.argouml.notation.providers.uml.NotationUtilityUml;
+import org.argouml.uml.diagram.DiagramSettings;
+import org.tigris.gef.presentation.FigText;
+
+/**
+ * Fig to show a keyword within a FigStereotypesGroup,
+ * which resembles a stereotype, but isn't one. 
+ * E.g. <<interface>>. 
+ * <p>
+ * The keyword is not editable on the fig, hence we
+ * do not use a Notation Provider. <p>
+ * This Fig does not need to listen to model changes 
+ * and is frozen.<p>
+ * 
+ * This Fig only supports updates of the text 
+ * for changes in guillemet style.
+ *
+ * @author Michiel
+ */
+public class FigKeyword extends FigSingleLineText {
+
+    private final String keywordText;
+
+    /**
+     * @param keyword the text to show
+     * @param bounds position and size
+     * @param settings rendering settings
+     */
+    public FigKeyword(String keyword, Rectangle bounds, 
+            DiagramSettings settings) {
+        super(bounds, settings, true);
+        initialize();
+        keywordText = keyword;
+        setText(keyword);
+    }
+    
+    private void initialize() {
+        setEditable(false);
+        setTextColor(Color.black);
+        setTextFilled(false);
+        setJustification(FigText.JUSTIFY_CENTER);
+        setRightMargin(3);
+        setLeftMargin(3);
+    }
+    
+    /* Force the line-width to 0, since the FigGroup that contains the 
+     * stereotype may want to show a border, but we don't. */
+    @Override
+    public void setLineWidth(int w) {
+        super.setLineWidth(0);
+    }
+
+    /**
+     * This is needed for updating the guillemet style.
+     */
+    protected void setText() {
+        setText(keywordText);
+    }
+
+    /**
+     * Add guillemets to any text set to this Fig.
+     * {@inheritDoc}
+     */
+    public void setText(String text) {
+        assert keywordText.equals(text);
+        super.setText(NotationUtilityUml.formatStereotype(text,
+                getSettings().getNotationSettings().isUseGuillemets()));
+    }
+}

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	2008-12-26 07:51:46-0800
@@ -371,6 +371,7 @@
     protected FigNodeModelElement(Object element, Rectangle bounds, 
             DiagramSettings renderSettings) {
         super();
+        super.setOwner(element);
         // TODO: We currently don't support per-fig settings for most stuff, so
         // we can just use the defaults that we were given.
 //        settings = new DiagramSettings(renderSettings);
@@ -400,7 +401,7 @@
                     "The owner must be a model element - got a "
                     + element.getClass().getName());
         }
-        super.setOwner(element);
+
         nameFig.setText(placeString());
         
         notationProviderName =
@@ -1523,7 +1524,7 @@
     }
 
     /**
-     * Updates the text of the sterotype FigText. Override in subclasses to get
+     * Updates the text of the stereotype FigText. Override in subclasses to get
      * wanted behaviour.
      */
     protected void updateStereotypeText() {
@@ -1606,7 +1607,7 @@
             if (elementNs != null) {
                 boolean visible = (elementNs != diagramNs);
                 getNotationSettings().setShowPaths(visible);
-                renderingChanged();
+                updateNameText();
                 damage();
             }
             // it is done
@@ -1908,7 +1909,9 @@
     
     /**
      * If you override this method, make sure to remove all listeners:
-     * If you don't, objects in a deleted project will still receive events.
+     * If you don't, objects in a deleted project will still receive events.<p>
+     * 
+     * Also important for remove from diagram!
      */
     protected void removeFromDiagramImpl() {
         if (notationProviderName != null) { //This test needed for a FigPool
@@ -1917,6 +1920,8 @@
         removeAllElementListeners();
         setShadowSize(0);
         super.removeFromDiagram();
+        // Get model listeners removed:
+        stereotypeFig.removeFromDiagram();
     }
 
     /**

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigSingleLineText.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigSingleLineText.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigSingleLineText.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigSingleLineText.java	2008-12-26 07:51:46-0800
@@ -49,7 +49,9 @@
  * <li>There is no line border
  * <li>There is space below the line for a "Clarifier",
  * i.e. a red squiggly line.
- * </ul>
+ * </ul><p>
+ * 
+ * Some of these have an UML object as owner, others do not.
  *
  * @author Bob Tarling
  */
@@ -159,6 +161,21 @@
 
         this(owner, bounds, settings, expandOnly, new String[] {property});
     }
+
+    /**
+     * Constructor for text fig without owner. 
+     * Using this constructor shall mean 
+     * that this fig will never have an owner.
+     * 
+     * @param bounds position and size
+     * @param settings rendering settings
+     * @param expandOnly true if the Fig should only expand and never contract
+     */
+    public FigSingleLineText(Rectangle bounds,
+            DiagramSettings settings, boolean expandOnly) {
+
+        this(null, bounds, settings, expandOnly);
+    }
     
     /**
      * Construct text fig
@@ -303,16 +320,13 @@
      * This function without parameter shall
      * determine the text of the Fig taking values from the owner,
      * and then call {@link #setText(String)}.
-     * TO be implemented as required by sub classes.
+     * To be implemented as required by sub classes.
      */
     protected void setText() {
     }
 
     public void renderingChanged() {
         super.renderingChanged();
-        if (getOwner() == null) {
-            return;
-        }
         /* This is needed for e.g. 
          * guillemet notation change on a class name, 
          * see issue 5419. */

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotype.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotype.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotype.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotype.java	2008-12-26 07:51:46-0800
@@ -26,10 +26,9 @@
 
 import java.awt.Color;
 import java.awt.Rectangle;
-import java.beans.PropertyChangeEvent;
 
-import org.argouml.model.AttributeChangeEvent;
 import org.argouml.model.Model;
+import org.argouml.model.UmlChangeEvent;
 import org.argouml.notation.providers.uml.NotationUtilityUml;
 import org.argouml.uml.diagram.DiagramSettings;
 import org.tigris.gef.presentation.Fig;
@@ -44,44 +43,7 @@
  *
  * @author Bob Tarling
  */
-public class FigStereotype extends CompartmentFigText {
-
-    /**
-     * The UID.
-     */
-    private static final long serialVersionUID = -6174252286709779782L;
-
-    /**
-    * Constructor for FigFeature.
-    * @param x x
-    * @param y x
-    * @param w w
-    * @param h h
-    * @param figCompartment the fig
-    * @param owner the UML element
-    * @deprecated for 0.27.3 by tfmorris.  Use 
-    * {@link #FigStereotype(Object, Rectangle, DiagramSettings)}.
-    */
-    @SuppressWarnings("deprecation")
-    @Deprecated
-    public FigStereotype(int x, int y, int w, int h, Fig figCompartment, 
-            Object owner) {
-        super(x, y, w, h, figCompartment, "name");
-
-        initialize();
-        setOwner(owner);
-    }
-
-    private void initialize() {
-        setFilled(false);
-        setLineWidth(0);
-        setTextColor(Color.black);
-        setTextFilled(false);
-        setJustification(FigText.JUSTIFY_LEFT);
-        setReturnAction(FigText.END_EDITING);
-        setRightMargin(3);
-        setLeftMargin(3);
-    }
+public class FigStereotype extends FigSingleLineText {
 
     /**
      * Construct a fig for a Stereotype or a keyword (which visually resembles a
@@ -94,12 +56,20 @@
      */
     public FigStereotype(Object owner, Rectangle bounds,
             DiagramSettings settings) {
-        super(owner, bounds, settings, 
-                owner != null ? new String[] {"name"} : (String[]) null);
+        super(owner, bounds, settings, true,
+                new String[] {"name"});
+        assert owner != null;
         initialize();
-        if (owner != null) {
-            setText();
-        }
+        setText();
+    }
+
+    private void initialize() {
+        setEditable(false);
+        setTextColor(Color.black);
+        setTextFilled(false);
+        setJustification(FigText.JUSTIFY_CENTER);
+        setRightMargin(3);
+        setLeftMargin(3);
     }
 
     /* Force the line-width to 0, since the FigGroup that contains the 
@@ -109,33 +79,56 @@
         super.setLineWidth(0);
     }
 
-    @Override
-    public void propertyChange(PropertyChangeEvent event) {
-        super.propertyChange(event);
-        if (event instanceof AttributeChangeEvent) {
-            if (event.getPropertyName().equals("name")) {
-                damage();
+    // Called by propertyChange
+    protected void updateLayout(UmlChangeEvent event) {
+        assert event != null;
+
+        Rectangle oldBounds = getBounds();
+
+        setText(); // this does a calcBounds()
+
+        if (oldBounds != getBounds()) {
+            setBounds(getBounds());
+        }
+
+        if (getGroup() != null ) {
+            /* TODO: Why do I need to do this? */
+            getGroup().calcBounds();
+            getGroup().setBounds(getGroup().getBounds());
+            if (oldBounds != getBounds()) {
+                Fig sg = getGroup().getGroup();
+                /* TODO: Why do I need to do this? */
+                if (sg != null) {
+                    sg.calcBounds();
+                    sg.setBounds(sg.getBounds());
+                }
             }
         }
+        /* Test-case for the above code: 
+         * Draw a class. 
+         * Create a stereotype for it by clicking on the prop-panel tool, and name it.
+         * Remove the class from the diagram.
+         * Drag the class from the explorer on the diagram.
+         * Select the stereotype in the explorer, and change
+         * its name in the prop-panel to something longer.
+         * The longer name does not make the class Fig wider 
+         * unless the above code is added.*/
+        damage();
     }
-    
+
     @Override
     protected void setText() {
-        if (getOwner() != null) {
-            setText(Model.getFacade().getName(getOwner()));
-        } else {
-            setText("");
-        }
+        setText(Model.getFacade().getName(getOwner()));
     }
-    
+
     /**
      * Add guillemets to any text set to this Fig.
      * {@inheritDoc}
      */
-    @Override
     public void setText(String text) {
         super.setText(NotationUtilityUml.formatStereotype(text,
-                getNotationSettings().isUseGuillemets()));
+                getSettings().getNotationSettings().isUseGuillemets()));
+        damage();
     }
-    
+
 }

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotypesGroup.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotypesGroup.java?view=diff&pathrev=16441&r1=16440&r2=16441
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotypesGroup.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigStereotypesGroup.java	2008-12-26 07:51:46-0800
@@ -31,7 +31,6 @@
 import java.beans.PropertyChangeEvent;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -51,13 +50,17 @@
  * each enclosed by guillemets.<p>
  * 
  * The minimum width of this fig is the largest minimum width of its child
+ * figs. The minimum height of this fig is the total minimum height of its child
  * figs.<p>
  * 
- * The minimum height of this fig is the total minimum height of its child
- * figs.<p>
+ * The owner of this Fig is the UML element that is extended 
+ * with the stereotypes. We are listening to changes to the model: 
+ * addition and removal of stereotypes. <p>
+ * 
+ * This fig supports showing one keyword 
+ * as the first "stereotype" in the list. <p>
  * 
- * The owner of this Fig is the UML element that is extended with the stereotypes.
- * We are listening to changes to the model: addition and removal of stereotypes. 
+ * There is no way to remove a keyword fig, once added. <p>
  * 
  * TODO: Allow for UML2 style display where all stereotypes are displayed in
  * the same guillemet pair and are delimited by commas. The style should be
@@ -146,6 +149,12 @@
      */
     @Override
     public void removeFromDiagram() {
+        /* Remove all items in the group, 
+         * otherwise the model event listeners remain: 
+         * TODO: Why does a FigGroup not do this? */
+        for (Object f : getFigs()) {
+            ((Fig) f).removeFromDiagram();
+        }
         super.removeFromDiagram();
         Model.getPump()
                 .removeModelEventListener(this, getOwner(), "stereotype");
@@ -169,21 +178,11 @@
             if (event.getPropertyName().equals("stereotype")) {
                 Object stereotype = aae.getChangedValue();
                 if (findFig(stereotype) == null) {
-                    Fig theBigPort = this.getBigPort();
                     FigText stereotypeTextFig =
-                        new FigStereotype(stereotype, new Rectangle(
-                                theBigPort.getX() + 1,
-                                theBigPort.getY() + 1
-                                + (++stereotypeCount)
-                                * ArgoFig.ROWHEIGHT,
-                                0,
-                                ArgoFig.ROWHEIGHT - 2),
+                        new FigStereotype(stereotype, 
+                                getBoundsForNextStereotype(),
                                 getSettings());
-                    stereotypeTextFig.setJustification(FigText.JUSTIFY_CENTER);
-                    stereotypeTextFig.setEditable(false);
-                    stereotypeTextFig.setText(
-                            Model.getFacade().getName(stereotype));
-                    stereotypeTextFig.setOwner(stereotype);
+                    stereotypeCount++;
                     addFig(stereotypeTextFig);
                     reorderStereotypeFigs();
                     damage();
@@ -199,6 +198,7 @@
                 Fig f = findFig(stereotype);
                 if (f != null) {
                     removeFig(f);
+                    f.removeFromDiagram(); // or vice versa?
                     --stereotypeCount;
                 }
             } else {
@@ -238,11 +238,22 @@
 	setFigs(n);
     }
 
-    private Fig findFig(Object stereotype) {
-        for (Iterator it = getFigs().iterator(); it.hasNext(); ) {
-            Fig f = (Fig) it.next();
-            if (f.getOwner() == stereotype) {
-                return f;
+    private FigStereotype findFig(Object stereotype) {
+        for (Object f : getFigs()) {
+            if (f instanceof FigStereotype) {
+                FigStereotype fs = (FigStereotype) f;
+                if (fs.getOwner() == stereotype) {
+                    return fs;
+                }
+            }
+        }
+        return null;
+    }
+    
+    private FigKeyword findFigKeyword() {
+        for (Object f : getFigs()) {
+            if (f instanceof FigKeyword) {
+                return (FigKeyword) f;
             }
         }
         return null;
@@ -268,65 +279,49 @@
             LOG.debug("Populating stereotypes compartment for "
                     + Model.getFacade().getName(modelElement));
         }
-        
-        int acounter = 1;
-        Fig theBigPort = this.getBigPort();
-        int xpos = theBigPort.getX();
-        int ypos = theBigPort.getY();
 
-        List figs = getFigs();
-        CompartmentFigText stereotypeTextFig;
+        /* This will contain the Figs that we do not need anymore: */
+        Collection<Fig> removeCollection = new ArrayList<Fig>(getFigs());
 
+        //There is one fig more in the group than (stereotypes + keyword):
         if (keyword != null) {
-            if (figs.size() <= acounter) {
-                ++stereotypeCount;
-                stereotypeTextFig =
-                    new FigStereotype(null, new Rectangle(
-                            xpos + 1,
-                            ypos + 1
-                            + (acounter - 1)
-                                * ArgoFig.ROWHEIGHT,
-                            0,
-                            ArgoFig.ROWHEIGHT - 2),
+            FigKeyword keywordFig = findFigKeyword();
+            if (keywordFig == null) {
+                // The keyword fig does not exist yet.
+                // Let's create one:
+                keywordFig =
+                    new FigKeyword(keyword, 
+                            getBoundsForNextStereotype(),
                             getSettings());
                 // bounds not relevant here
-                stereotypeTextFig.setJustification(FigText.JUSTIFY_CENTER);
-                stereotypeTextFig.setEditable(false);
-                addFig(stereotypeTextFig);
+                addFig(keywordFig);
             } else {
-                stereotypeTextFig =
-                    (CompartmentFigText) figs.get(acounter);
+                // The keyword fig already exists.
+                removeCollection.remove(keywordFig);
             }
-            stereotypeTextFig.setText(keyword);
-            acounter++;
+            ++stereotypeCount;
         }
 
         for (Object stereo : Model.getFacade().getStereotypes(modelElement)) {
-            if (figs.size() <= acounter) {
-                ++stereotypeCount;
+            FigStereotype stereotypeTextFig = findFig(stereo);
+            if (stereotypeTextFig == null) {
                 stereotypeTextFig =
-                    new FigStereotype(stereo, new Rectangle(
-                            xpos + 1,
-                            ypos + 1
-                            + (acounter - 1)
-                            * ArgoFig.ROWHEIGHT,
-                            0,
-                            ArgoFig.ROWHEIGHT - 2),
+                    new FigStereotype(stereo, 
+                            getBoundsForNextStereotype(),
                             getSettings());
                 // bounds not relevant here
-                stereotypeTextFig.setJustification(FigText.JUSTIFY_CENTER);
-                stereotypeTextFig.setEditable(false);
                 addFig(stereotypeTextFig);
             } else {
-                stereotypeTextFig = (CompartmentFigText) figs.get(acounter);
+             // The stereotype fig already exists.
+                removeCollection.remove(stereotypeTextFig);
             }
-
-            acounter++;
+            ++stereotypeCount;
         }
-        if (figs.size() > acounter) {
-            //cleanup of unused FigText's
-            for (int i = figs.size() - 1; i >= acounter; i--) {
-                removeFig((Fig) figs.get(i));
+        
+        //cleanup of unused FigText's
+        for (Fig f : removeCollection) {
+            if (f instanceof FigStereotype || f instanceof FigKeyword) {
+                removeFig(f);
             }
         }
 
@@ -336,6 +331,16 @@
         updateHiddenStereotypes();
 
     }
+    
+    private Rectangle getBoundsForNextStereotype() {
+        return new Rectangle(
+                bigPort.getX() + 1,
+                bigPort.getY() + 1
+                + (stereotypeCount
+                * ArgoFig.ROWHEIGHT),
+                0,
+                ArgoFig.ROWHEIGHT - 2);
+    }
 
     private void updateHiddenStereotypes() {
         List<Fig> figs = getFigs();
@@ -371,19 +376,19 @@
      */
     @Override
     protected void setBoundsImpl(int x, int y, int w, int h) {
-        Fig fig;
+        Rectangle oldBounds = getBounds();
+
         int yy = y;
-        Iterator figs = iterator();
-        while (figs.hasNext()) {
-            fig = (Fig) figs.next();
-            if (fig != getBigPort()) {
+        for  (Fig fig : (Collection<Fig>) getFigs()) {
+            if (fig != bigPort) {
                 fig.setBounds(x + 1, yy + 1, w - 2,
                               fig.getMinimumSize().height);
                 yy += fig.getMinimumSize().height;
             }
         }
-        getBigPort().setBounds(x, y, w, h);
+        bigPort.setBounds(x, y, w, h);
         calcBounds();
+        firePropChange("bounds", oldBounds, getBounds());
     }
 
     /**
@@ -430,11 +435,8 @@
                 int minWidth = 0;
                 int minHeight = 0;
                 //set new bounds for all included figs
-                Iterator figs = iterator();
-                Fig fig;
-                while (figs.hasNext()) {
-                    fig = (Fig) figs.next();
-                    if (fig.isVisible() && fig != getBigPort()) {
+                for (Fig fig : (Collection<Fig>) getFigs()) {
+                    if (fig.isVisible() && fig != bigPort) {
                         int fw = fig.getMinimumSize().width;
                         if (fw > minWidth) {
                             minWidth = fw;

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=992986

To unsubscribe from this discussion, e-mail: [[email protected]].
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.