svn commit: r12666 - trunk/src_new/org/argouml/uml/diagram/state/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-05-26 11:22:42-0700
New Revision: 12666

Modified:
   trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java
   trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java
   trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java

Log:
Minor refactoring and cleanup of FigInitialState & FigFinalState

Modified: trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java?view=diff&rev=12666&p1=trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java&p2=trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java&r1=12665&r2=12666
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java	(original)
+++ trunk/src_new/org/argouml/uml/diagram/state/ui/FigFinalState.java	2007-05-26 11:22:42-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2007 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
@@ -25,11 +25,9 @@
 package org.argouml.uml.diagram.state.ui;
 
 import java.awt.Color;
-import java.awt.Point;
 import java.awt.event.MouseEvent;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Vector;
 
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.activity.ui.SelectionActionState;
@@ -45,22 +43,13 @@
  */
 public class FigFinalState extends FigStateVertex {
 
-    ////////////////////////////////////////////////////////////////
-    // constants
-
     private static final int X = 10;
     private static final int Y = 10;
     private static final int WIDTH = 24;
     private static final int HEIGHT = 24;
 
-    ////////////////////////////////////////////////////////////////
-    // instance variables
-
     private FigCircle inCircle;
 
-    ////////////////////////////////////////////////////////////////
-    // constructors
-
     /**
      * The main constructor.
      */
@@ -99,9 +88,7 @@
     	setOwner(node);
     }
 
-    /*
-     * @see java.lang.Object#clone()
-     */
+    @Override
     public Object clone() {
         FigFinalState figClone = (FigFinalState) super.clone();
         Iterator it = figClone.getFigs().iterator();
@@ -111,17 +98,14 @@
         return figClone;
     }
 
-    ////////////////////////////////////////////////////////////////
-    // Fig accessors
-
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
+    @Override
     public Selection makeSelection() {
-        Object pstate = null;
+        Object pstate = getOwner();
         Selection sel = null;
-        if (getOwner() != null) {
-            pstate = getOwner();
+        if ( pstate != null) {
             if (Model.getFacade().isAActivityGraph(
                             Model.getFacade().getStateMachine(
                             Model.getFacade().getContainer(pstate)))) {
@@ -140,6 +124,7 @@
      * @return false
      * @see org.tigris.gef.presentation.Fig#isResizable()
      */
+    @Override
     public boolean isResizable() {
         return false;
     }
@@ -147,6 +132,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
      */
+    @Override
     public void setLineColor(Color col) {
         getBigPort().setLineColor(col);
     }
@@ -154,6 +140,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getLineColor()
      */
+    @Override
     public Color getLineColor() {
         return getBigPort().getLineColor();
     }
@@ -161,6 +148,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
      */
+    @Override
     public void setFillColor(Color col) {
         inCircle.setFillColor(col);
     }
@@ -168,6 +156,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getFillColor()
      */
+    @Override
     public Color getFillColor() {
         return inCircle.getFillColor();
     }
@@ -175,6 +164,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
      */
+    @Override
     public void setFilled(boolean f) {
         // ignored - rendering is fixed
     }
@@ -182,6 +172,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getFilled()
      */
+    @Override
     public boolean getFilled() {
         return true;
     }
@@ -189,6 +180,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
      */
+    @Override
     public void setLineWidth(int w) {
         getBigPort().setLineWidth(w);
     }
@@ -196,16 +188,15 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
      */
+    @Override
     public int getLineWidth() {
 	return getBigPort().getLineWidth();
     }
 
-    ////////////////////////////////////////////////////////////////
-    // Event handlers
-
     /*
      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
      */
+    @Override
     public void mouseClicked(MouseEvent me) {
         // ignore mouse clicks
     }
@@ -215,43 +206,15 @@
      */
     static final long serialVersionUID = -3506578343969467480L;
 
-
     /**
-     * TODO: MVW: I do not see any reason for this. Can we remove it?
+     * Return a list of gravity points around the outer circle. Used in place of
+     * the default bounding box.
      *
-     * @see org.tigris.gef.presentation.Fig#setBounds(int, int, int, int)
-     */
-    /*public void setBoundsImpl(int boundX, int boundY,
-        int boundW, int boundH) {
-        _x = boundX;
-        _y = boundY;
-        getBigPort().setX(boundX);
-        getBigPort().setY(boundY);
-        inCircle.setX(boundX + 5);
-        inCircle.setY(boundY + 5);
-    }*/
-
-    /*
-     * Makes sure that edges stick to the outer circle and not to the box.
-     *
-     * @see org.tigris.gef.presentation.Fig#getGravityPoints()
+     * {@inheritDoc}
      */
+    @Override
     public List getGravityPoints() {
-        Vector ret = new Vector();
-        int cx = getBigPort().getCenter().x;
-        int cy = getBigPort().getCenter().y;
-        double radius = getBigPort().getWidth() / 2 + 1;
-        final int maxPoints = 32;
-        Point point = null;
-        final double pi2 = Math.PI * 2;
-        for (int i = 0; i < maxPoints; i++) {
-            int px = (int) (cx + Math.cos(pi2 * i / maxPoints) * radius);
-            int py = (int) (cy + Math.sin(pi2 * i / maxPoints) * radius);
-            point = new Point(px, py);
-            ret.add(point);
-        }
-        return ret;
-
+        return getCircleGravityPoints();
     }
 
-} /* end class FigFinalState */
+}

Modified: trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java?view=diff&rev=12666&p1=trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java&p2=trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java&r1=12665&r2=12666
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java	(original)
+++ trunk/src_new/org/argouml/uml/diagram/state/ui/FigInitialState.java	2007-05-26 11:22:42-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2007 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
@@ -25,12 +25,10 @@
 package org.argouml.uml.diagram.state.ui;
 
 import java.awt.Color;
-import java.awt.Point;
 import java.awt.event.MouseEvent;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Vector;
 
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.activity.ui.SelectionActionState;
@@ -45,24 +43,15 @@
  */
 public class FigInitialState extends FigStateVertex {
 
-    ////////////////////////////////////////////////////////////////
-    // constants
-
     private static final int X = 10;
     private static final int Y = 10;
     private static final int WIDTH = 16;
     private static final int HEIGHT = 16;
 
-    ////////////////////////////////////////////////////////////////
-    // instance variables
-
     private FigCircle head;
 
-    ////////////////////////////////////////////////////////////////
-    // constructors
-
     /**
-     * Main constructor.
+     * Default constructor.
      */
     public FigInitialState() {
         setEditable(false);
@@ -90,9 +79,8 @@
         setOwner(node);
     }
 
-    /*
-     * @see java.lang.Object#clone()
-     */
+
+    @Override
     public Object clone() {
         FigInitialState figClone = (FigInitialState) super.clone();
         Iterator it = figClone.getFigs().iterator();
@@ -101,20 +89,14 @@
         return figClone;
     }
 
-    ////////////////////////////////////////////////////////////////
-    // Fig accessors
-
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
+    @Override
     public Selection makeSelection() {
-        Object pstate = null;
+        Object pstate = getOwner();
         Selection sel = null;
-        if (getOwner() != null) {
-            pstate = getOwner();
-            if (pstate == null) {
-                return sel;
-            }
+        if ( pstate != null) {
             if (Model.getFacade().isAActivityGraph(
                     Model.getFacade().getStateMachine(
                             Model.getFacade().getContainer(pstate)))) {
@@ -122,14 +104,13 @@
                 ((SelectionActionState) sel).setIncomingButtonEnabled(false);
                 Collection outs = Model.getFacade().getOutgoings(getOwner());
                 ((SelectionActionState) sel)
-                        .setOutgoingButtonEnabled(outs == null
-                                || outs.size() == 0);
+                        .setOutgoingButtonEnabled(outs.isEmpty());
             } else {
                 sel = new SelectionState(this);
                 ((SelectionState) sel).setIncomingButtonEnabled(false);
                 Collection outs = Model.getFacade().getOutgoings(getOwner());
-                ((SelectionState) sel).setOutgoingButtonEnabled(outs == null
-                        || outs.size() == 0);
+                ((SelectionState) sel)
+                        .setOutgoingButtonEnabled(outs.isEmpty());
             }
         }
         return sel;
@@ -140,6 +121,7 @@
      *
      * @return false
      */
+    @Override
     public boolean isResizable() {
         return false;
     }
@@ -147,6 +129,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
      */
+    @Override
     public void setLineColor(Color col) {
         head.setLineColor(col);
     }
@@ -154,6 +137,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getLineColor()
      */
+    @Override
     public Color getLineColor() {
         return head.getLineColor();
     }
@@ -161,6 +145,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
      */
+    @Override
     public void setFillColor(Color col) {
         head.setFillColor(col);
     }
@@ -168,6 +153,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getFillColor()
      */
+    @Override
     public Color getFillColor() {
         return head.getFillColor();
     }
@@ -176,13 +162,15 @@
      * Ignored - figure has fixed rendering
      * @param f ignored
      */
+    @Override
     public void setFilled(boolean f) {
-        // ignored
+        // ignored - rendering is fixed
     }
 
     /*
      * @see org.tigris.gef.presentation.Fig#getFilled()
      */
+    @Override
     public boolean getFilled() {
         return true;
     }
@@ -190,6 +178,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
      */
+    @Override
     public void setLineWidth(int w) {
         head.setLineWidth(w);
     }
@@ -197,18 +186,17 @@
     /*
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
      */
+    @Override
     public int getLineWidth() {
         return head.getLineWidth();
     }
 
-    ////////////////////////////////////////////////////////////////
-    // Event handlers
-
     /*
      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
      */
+    @Override
     public void mouseClicked(MouseEvent me) {
-        // ignored
+        // ignore mouse clicks
     }
 
     /**
@@ -216,26 +204,15 @@
      */
     static final long serialVersionUID = 6572261327347541373L;
 
-    /*
-     * Makes sure that edges stick to the outer circle and not to the box.
-     *
-     * @see org.tigris.gef.presentation.Fig#getGravityPoints()
+    /**
+     * Return a list of gravity points around the outer circle. Used in place of
+     * the default bounding box.
+     * 
+     * {@inheritDoc}
      */
+    @Override
     public List getGravityPoints() {
-        Vector ret = new Vector();
-        int cx = getBigPort().getCenter().x;
-        int cy = getBigPort().getCenter().y;
-        double radius = getBigPort().getWidth() / 2 + 1;
-        final int maxPoints = 32;
-        Point point = null;
-        final double pi2 = Math.PI * 2;
-        for (int i = 0; i < maxPoints; i++) {
-            int px = (int) (cx + Math.cos(pi2 * i / maxPoints) * radius);
-            int py = (int) (cy + Math.sin(pi2 * i / maxPoints) * radius);
-            point = new Point(px, py);
-            ret.add(point);
-        }
-        return ret;
-
+        return getCircleGravityPoints();
     }
-} /* end class FigInitialState */
+    
+}

Modified: trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java?view=diff&rev=12666&p1=trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java&p2=trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java&r1=12665&r2=12666
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java	(original)
+++ trunk/src_new/org/argouml/uml/diagram/state/ui/FigStateVertex.java	2007-05-26 11:22:42-0700
@@ -24,7 +24,10 @@
 
 package org.argouml.uml.diagram.state.ui;
 
+import java.awt.Point;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.activity.ui.SelectionActionState;
@@ -45,9 +48,6 @@
  */
 public abstract class FigStateVertex extends FigNodeModelElement {
 
-    ////////////////////////////////////////////////////////////////
-    // constructors
-
     /**
      * The main constructor
      */
@@ -55,31 +55,38 @@
         this.allowRemoveFromDiagram(false);
     }
 
-    /** The constructor which hooks the Fig into the UML element
-     * @param gm ignored
-     * @param node the UML elm
+    /**
+     * The constructor which hooks the Fig into the UML element
+     * 
+     * @param gm
+     *            ignored
+     * @param node
+     *            the UML elm
      */
     public FigStateVertex(GraphModel gm, Object node) {
         this();
         setOwner(node);
     }
 
-    ////////////////////////////////////////////////////////////////
-    // nestable nodes
-
     /*
      * Overriden to make it possible to include a statevertex in a composite
      * state.
      * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig)
      */
+    @Override
     public void setEnclosingFig(Fig encloser) {
         LayerPerspective layer = (LayerPerspective) getLayer();
+        
         // If the layer is null, then most likely we are being deleted.
-        if (layer == null) return;
+        if (layer == null) {
+            return;
+        }
 
         super.setEnclosingFig(encloser);
         
-        if (!(Model.getFacade().isAStateVertex(getOwner()))) return;
+        if (!(Model.getFacade().isAStateVertex(getOwner()))) {
+            return;
+        }
         Object stateVertex = getOwner();
         Object compositeState = null;
         if (encloser != null
@@ -130,6 +137,7 @@
      *
      * {@inheritDoc}
      */
+    @Override
     public Selection makeSelection() {
         Object pstate = getOwner();
 
@@ -144,5 +152,30 @@
         }
         return null;
     }
+    
+    /**
+     * Number of points to compute for gravity point circle.
+     */
+    private final static int CIRCLE_POINTS = 32;
+    
+    /**
+     * Return a list of gravity points around circle which is enclosed
+     * in the bounding box.  Convenience method for use by FigInitialState
+     * and FigFinalState.
+     * @return a List of Points
+     */
+    List<Point> getCircleGravityPoints() {
+        List<Point> ret = new ArrayList<Point>();
+        int cx = getBigPort().getCenter().x;
+        int cy = getBigPort().getCenter().y;
+        double radius = getBigPort().getWidth() / 2 + 1;
+        final double pi2 = Math.PI * 2;
+        for (int i = 0; i < CIRCLE_POINTS; i++) {
+            int x = (int) (cx + Math.cos(pi2 * i / CIRCLE_POINTS) * radius);
+            int y = (int) (cy + Math.sin(pi2 * i / CIRCLE_POINTS) * radius);
+            ret.add(new Point(x, y));
+        }
+        return ret;
+    }
 
-} /* end class FigStateVertex */
+}
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.