svn commit: r16779 - trunk/src/argouml-app/src/org/argouml/uml/diagram: state/ui ui

Michiel van der Wulp <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2009-02-11 11:14:24-0800
New Revision: 16779

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigCompositeState.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigConcurrentRegion.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddConcurrentRegion.java

Log:
Fix for issue 5070.
This includes the refactoring I did to be able to understand the code.

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigCompositeState.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigCompositeState.java?view=diff&pathrev=16779&r1=16778&r2=16779
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigCompositeState.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigCompositeState.java	2009-02-11 11:14:24-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -47,7 +47,7 @@
 import org.tigris.gef.presentation.FigText;
 
 /**
- * Class to display graphics for a UML MCompositeState in a diagram.
+ * Class to display graphics for a UML CompositeState in a diagram.
  *
  * @author [email protected]
  */
@@ -68,6 +68,7 @@
             DiagramSettings settings) {
         super(owner, bounds, settings);
         initFigs();
+        updateNameText();
     }
     
     /**
@@ -181,12 +182,13 @@
         /* If it is concurrent and contains concurrent regions,
         the bottom region has a minimum height*/
         if (getOwner() != null) {
-            if (Model.getFacade().isConcurrent(getOwner())
+            if (isConcurrent()
                     && !regionsList.isEmpty()
                     && regionsList.get(regionsList.size() - 1)
                         instanceof FigConcurrentRegion) {
                 FigConcurrentRegion f = 
-                    ((FigConcurrentRegion) regionsList.get(regionsList.size() - 1));
+                    ((FigConcurrentRegion) regionsList.get(
+                            regionsList.size() - 1));
                 Rectangle regionBounds = f.getBounds();
                 if ((h - oldBounds.height + regionBounds.height)
                         <= (f.getMinimumSize().height)) {
@@ -221,7 +223,7 @@
         /*If it is concurrent and contains concurrent regions,
         the regions are resized*/
         if (getOwner() != null) {
-            if (Model.getFacade().isConcurrent(getOwner())
+            if (isConcurrent()
                     && !regionsList.isEmpty()
                     && regionsList.get(regionsList.size() - 1)
                         instanceof FigConcurrentRegion) {
@@ -230,15 +232,20 @@
                 for (int i = 0; i < regionsList.size() - 1; i++) {
                     ((FigConcurrentRegion) regionsList.get(i))
                         .setBounds(x - oldBounds.x, y - oldBounds.y,
-                                w - 6, true);
+                                w - 2 * FigConcurrentRegion.INSET_HORZ, true);
                 }
                 f.setBounds(x - oldBounds.x,
-                        y - oldBounds.y, w - 6, h - oldBounds.height, true);
+                        y - oldBounds.y, 
+                        w - 2 * FigConcurrentRegion.INSET_HORZ, 
+                        h - oldBounds.height, true);
             }
         }
 
     }
     
+    /*
+     * The returned list of Figs is sorted according layout: from top to bottom.
+     */
     @Override
     public Vector<Fig> getEnclosedFigs() {
         Vector<Fig> enclosedFigs = super.getEnclosedFigs();
@@ -270,13 +277,26 @@
     /**
      * To resize only when a new concurrent region is added,
      * changing the height.
-     * TODO: Badly named method, it actually sets height. Probably shouldn't
+     * TODO: Badly named method, it actually sets height. 
+     * @deprecated by mvw in V0.28alpha, 
+     * replaced by better named method.
+     * @param h the new height
+     */
+    @Deprecated
+    public void setBounds(int h) {
+        setCompositeStateHeight(h);
+    }
+
+    /**
+     * To resize only when a new concurrent region is added,
+     * changing the height.
+     * TODO: Probably shouldn't
      * exist as this class should be listening for added concurrent regions
      * and call this internally itself.
      *
      * @param h the new height
      */
-    public void setBounds(int h) {
+    public void setCompositeStateHeight(int h) {
         if (getNameFig() == null) {
             return;
         }
@@ -287,8 +307,10 @@
         int w = oldBounds.width;
 
         getInternal().setBounds(
-                x + 2, y + nameDim.height + 4,
-                w - 4, h - nameDim.height - 6);
+                x + MARGIN, 
+                y + nameDim.height + 4,
+                w - 2 * MARGIN, 
+                h - nameDim.height - 6);
         getBigPort().setBounds(x, y, w, h);
         cover.setBounds(x, y, w, h);
 
@@ -376,8 +398,9 @@
 
     @Override 
     protected void updateLayout(UmlChangeEvent event) {
-                
-        if (!(event instanceof RemoveAssociationEvent)) {
+        /* We only handle the case where a region has been removed: */
+        if (!(event instanceof RemoveAssociationEvent) || 
+                !"subvertex".equals(event.getPropertyName())) {
             return;
         }
         
@@ -444,8 +467,4 @@
         return 0;
     }
 
-    /**
-     * The UID.
-     */
-    private static final long serialVersionUID = -8173637358029852407L;
 } /* end class FigCompositeState */

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigConcurrentRegion.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigConcurrentRegion.java?view=diff&pathrev=16779&r1=16778&r2=16779
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigConcurrentRegion.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/state/ui/FigConcurrentRegion.java	2009-02-11 11:14:24-0800
@@ -30,6 +30,7 @@
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
+import java.beans.PropertyChangeEvent;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -60,12 +61,24 @@
         MouseListener,
         MouseMotionListener {
 
+    /**
+     * The horizontal margin between the region and its composite parent state.
+     */
+    public static final int INSET_HORZ = 3;
+    /**
+     * The vertical margin between the region and its composite parent state.
+     */
+    public static final int INSET_VERT = 5;
 
     private FigRect cover;
+    /**
+     * The divider line is the horizontal dashed line
+     * shown at the top side for
+     * every region except the first one.
+     */
     private FigLine dividerline;
     private static Handle curHandle = new Handle(-1);
 
-
     /**
      * The constructor.
      * @deprecated for 0.27.4 by tfmorris.  Use 
@@ -101,7 +114,6 @@
         addFig(getInternal());
 
         setShadowSize(0);
-        setBounds(getBounds());
     }
 
     /**
@@ -151,7 +163,10 @@
         super(node, bounds, settings);
         initialize();
         if (bounds != null) {
-            setLocation(bounds.getLocation());
+            /* We have to use the specific methods written for this Fig: 
+             * This fixes issue 5070. */
+            setBounds(bounds.x - _x, bounds.y - _y, bounds.width, 
+                    bounds.height - _h, true);
         }
         updateNameText();
     }
@@ -406,6 +421,10 @@
     // fig accessors
 
     /*
+     * This function only sets the color of the divider line 
+     * (since that is the only visible part), and can be used to make 
+     * the divider line invisible for the top region in a composite state.
+     * 
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
      */
     @Override
@@ -472,6 +491,17 @@
     ////////////////////////////////////////////////////////////////
     // event processing
 
+    protected void modelChanged(PropertyChangeEvent mee) {
+        if ("container".equals(mee.getPropertyName())
+                || "isConcurrent".equals(mee.getPropertyName())
+                || "subvertex".equals(mee.getPropertyName())) {
+            //do nothing
+            // this only happens at creation time - I hope
+        } else {
+            super.modelChanged(mee);
+        }
+    }
+    
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
@@ -523,7 +553,10 @@
 
     @Override
     protected void updateLayout(UmlChangeEvent event) {
-        super.updateLayout(event);
+        if (!"container".equals(event.getPropertyName()) &&
+                !"isConcurrent".equals(event.getPropertyName())) {
+            super.updateLayout(event);
+        }
         final String eName = event.getPropertyName();
         /*
          * A Concurrent region cannot have incoming or outgoing transitions so

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddConcurrentRegion.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddConcurrentRegion.java?view=diff&pathrev=16779&r1=16778&r2=16779
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddConcurrentRegion.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddConcurrentRegion.java	2009-02-11 11:14:24-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -55,14 +55,16 @@
 /**
  * Add a concurrent region to a concurrent composite state
  * <p>
+ * This action can be executed with either 
+ * the composite concurrent state selected,
+ * or one of its concurrent regions.
+ * <p>
  * TODO: Move all the magic numbers to constants
  * 
  * @author [email protected]
  */
 public class ActionAddConcurrentRegion extends UndoableAction {
 
-    ////////////////////////////////////////////////////////////////
-    // static variables
 
     /** logger */
     private static final Logger LOG =
@@ -108,10 +110,10 @@
             }
 
             final FigCompositeState figCompositeState = (FigCompositeState) f;
-            
+
             final List<FigConcurrentRegion> regionFigs = 
                 ((List<FigConcurrentRegion>) f.getEnclosedFigs().clone());
-            final Object compositeState = figCompositeState.getOwner();
+            final Object umlCompositeState = figCompositeState.getOwner();
             Editor editor = Globals.curEditor();
             GraphModel gm = editor.getGraphModel();
             LayerDiagram lay =
@@ -129,68 +131,80 @@
             final StateMachinesFactory factory =
                 Model.getStateMachinesFactory();
             
-            if (!Model.getFacade().isConcurrent(compositeState)) {
+            if (!Model.getFacade().isConcurrent(umlCompositeState)) {
 
-                final Object region1 =
-                    factory.buildCompositeState(compositeState);
-                // TODO: What do all these magic numbers represent??
+                final Object umlRegion1 =
+                    factory.buildCompositeState(umlCompositeState);
                 Rectangle bounds = new Rectangle(
-                        f.getX() + 3, 
-                        f.getY() + rName.height + 5, 
-                        rFig.width - 6, 
-                        rFig.height - rName.height - 10);
-                // TODO: Get these settings from some place reasonable
-                DiagramSettings settings = new DiagramSettings();
-                final FigConcurrentRegion region =
+                        f.getX() + FigConcurrentRegion.INSET_HORZ, 
+                        f.getY() + rName.height 
+                            + FigConcurrentRegion.INSET_VERT, 
+                        rFig.width - 2 * FigConcurrentRegion.INSET_HORZ, 
+                        rFig.height - rName.height 
+                            - 2 * FigConcurrentRegion.INSET_VERT);
+                DiagramSettings settings = figCompositeState.getSettings();
+                final FigConcurrentRegion firstRegionFig =
                     new FigConcurrentRegion(
-                        region1, bounds, settings);
-                // Invisible border (was Color.white)
-                // TODO: Should this be LINE_COLOR's complement or something?
-                region.setLineColor(ArgoFig.INVISIBLE_LINE_COLOR);
-
-                region.setEnclosingFig(figCompositeState);
-                region.setLayer(lay);
-                lay.add(region);
-
-                if (mgm.canAddNode(region1)) {
-                    mgm.getNodes().add(region1);
-                    mgm.fireNodeAdded(region1);
-
+                        umlRegion1, bounds, settings);
+                /* The 1st region has an invisible divider line 
+                 * (the box is always invisible): */
+                firstRegionFig.setLineColor(ArgoFig.INVISIBLE_LINE_COLOR);
+
+                firstRegionFig.setEnclosingFig(figCompositeState);
+                firstRegionFig.setLayer(lay);
+                lay.add(firstRegionFig);
+
+                if (mgm.canAddNode(umlRegion1)) {
+                    mgm.getNodes().add(umlRegion1);
+                    mgm.fireNodeAdded(umlRegion1);
                 }
 
+                /* Throw out any previous elements that were 
+                 * enclosed but are not a concurrent region;
+                 * let's move them onto the first region: */
                 if (!regionFigs.isEmpty()) {
                     for (int i = 0; i < regionFigs.size(); i++) {
                         FigStateVertex curFig = regionFigs.get(i);
-                        curFig.setEnclosingFig(region);
-                        region.addEnclosedFig(curFig);
+                        curFig.setEnclosingFig(firstRegionFig);
+                        firstRegionFig.addEnclosedFig(curFig);
                         curFig.redrawEnclosedFigs();
                     }
                 }
             }
 
-            final Object region2 = factory.buildCompositeState(compositeState);
-            // TODO: What are all these magic numbers?
-            Rectangle bounds = new Rectangle(f.getX() + 3, f.getY()
-                    + rFig.height - 1, rFig.width - 6, 126);
-            // TODO: Get the settings from someplace reasonable
-            DiagramSettings settings = new DiagramSettings();
-            final FigConcurrentRegion regionNew =
-                new FigConcurrentRegion(region2, bounds, settings);
-            // Uses default line color (was Color.black)
-//            regionNew.setLineColor(ArgoFig.LINE_COLOR);
-
-            figCompositeState.setBounds(rFig.height + 130);
-            regionNew.setEnclosingFig(figCompositeState);
-            figCompositeState.addEnclosedFig(regionNew);
-            regionNew.setLayer(lay);
-            lay.add(regionNew);
+            final Object umlRegion2 = 
+                factory.buildCompositeState(umlCompositeState);
+            // TODO: What are these magic numbers?
+            Rectangle bounds = new Rectangle(
+                    f.getX() + FigConcurrentRegion.INSET_HORZ, 
+                    f.getY() + rFig.height - 1, //linewidth?
+                    rFig.width - 2 * FigConcurrentRegion.INSET_HORZ, 
+                    126);
+            DiagramSettings settings = figCompositeState.getSettings();
+            final FigConcurrentRegion newRegionFig =
+                new FigConcurrentRegion(umlRegion2, bounds, settings);
+            /* The divider line should be visible, so no need to change its color. */
+
+            /* Make the composite state 1 region higher: */
+            figCompositeState.setCompositeStateHeight(
+                    rFig.height + newRegionFig.getInitialHeight());
+            newRegionFig.setEnclosingFig(figCompositeState);
+            figCompositeState.addEnclosedFig(newRegionFig);
+            newRegionFig.setLayer(lay);
+            lay.add(newRegionFig);
             editor.getSelectionManager().select(f);
-            if (mgm.canAddNode(region2)) {
-                mgm.getNodes().add(region2);
-                mgm.fireNodeAdded(region2);
+            if (mgm.canAddNode(umlRegion2)) {
+                mgm.getNodes().add(umlRegion2);
+                mgm.fireNodeAdded(umlRegion2);
             }
 
-            Model.getStateMachinesHelper().setConcurrent(compositeState, true);
+            /* TODO: Verify this. 
+             * IIUC, then this triggers the CompountStateFig 
+             * to draw itself correctly.
+             * Hence, there was a reason to wait this long 
+             * to make the state concurrent. */
+            Model.getStateMachinesHelper().setConcurrent(
+                    umlCompositeState, true);
 
         } catch (Exception ex) {
             LOG.error("Exception caught", ex);

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

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.