svn commit: r15108 - branches/gsoc2008/seq2_5130_bszanto: . src/org/argouml/uml/diagram/sequence2/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bszanto
Date: 2008-06-29 13:00:27-0700
New Revision: 15108

Added:
   branches/gsoc2008/seq2_5130_bszanto/
      - copied from r15087, /trunk/src/argouml-core-diagrams-sequence2/
Modified:
   branches/gsoc2008/seq2_5130_bszanto/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java

Log:


Modified: branches/gsoc2008/seq2_5130_bszanto/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/seq2_5130_bszanto/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java?view=diff&rev=15108&p1=/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java&p2=branches/gsoc2008/seq2_5130_bszanto/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java&r1=15087&r2=15108
==============================================================================
--- /trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java	(original)
+++ branches/gsoc2008/seq2_5130_bszanto/src/org/argouml/uml/diagram/sequence2/ui/FigClassifierRole.java	2008-06-29 13:00:27-0700
@@ -74,8 +74,8 @@
     // TODO: Do we need this? Is this the same as emptyFig.getHeight()?
     private int offset = 0;
     
-    // the Y position of the lower most FigMessage
-    private int yMax = 0;
+    // minimum height of the CR
+    private int minimumHeight = 0;
     
     /**
      * Constructor 
@@ -97,6 +97,8 @@
         
         emptyFig.setLineWidth(0);
         
+        minimumHeight = headFig.getMinimumHeight() + 10;
+        
         addFig(emptyFig);        
         addFig(lifeLineFig);
         addFig(headFig);
@@ -141,7 +143,6 @@
         final Rectangle oldBounds = getBounds();
         final int ww = Math.max(w, headFig.getMinimumSize().width);
         
-        updateHeadOffset();
         emptyFig.setBounds(x, y, ww, offset);
         headFig.setBounds(x, y + offset, ww, headFig.getMinimumHeight());
         lifeLineFig.setBounds(x, y + offset + headFig.getHeight(),
@@ -171,7 +172,7 @@
         if (createMessage != null) {
             int y = createMessage.getFirstPoint().y;
             if (y > 0) {
-                offset = y - (headFig.getY() + headFig.getHeight() / 2);
+                offset = y - (getY() + headFig.getHeight() / 2);
             }
         } else {
             offset = 0;
@@ -206,12 +207,31 @@
      * 10 pixels of the lifeline.
      */
     public Dimension getMinimumSize() {
-        if (getEdges().size() > 0) {
-            return new Dimension(headFig.getMinimumWidth(), yMax - getY() + 10);
+        updateMinimumHeight();
+        return new Dimension(headFig.getMinimumWidth(), minimumHeight);
+    }
+    
+    /**
+     * Updates minimumHeight when an edge has been added or removed
+     */
+    private void updateMinimumHeight() {
+        int yMax = getY();
+        List<Fig> figs = getEdges();
+        FigMessage createMessage = getFirstCreateFigMessage();
+        
+        if (figs.size() == 1 && createMessage != null) {
+            minimumHeight = headFig.getMinimumSize().height + offset + 10;
         } else {
-            return new Dimension(headFig.getMinimumWidth(), emptyFig
-                    .getHeight()
-                    + headFig.getMinimumHeight() + 10);
+            for (Fig fig : figs) {
+                if ( fig instanceof FigMessage
+                        // we need the edge to be complete
+                        && ((FigMessage) fig).getDestFigNode() != null
+                        && ((FigMessage) fig).getSourceFigNode() != null
+                        && ((FigMessage) fig).getY() > yMax) {
+                    yMax = ((FigMessage) fig).getY();
+                }
+            }
+            minimumHeight = yMax - getY() + 10;
         }
     }
     
@@ -219,17 +239,10 @@
     public void removeFigEdge(FigEdge edge){
         super.removeFigEdge(edge);
 
-        // if the removed edge is the last Y positioned message, yMax should be
-        // updated
-        if (edge.getY() == yMax) {
-            List<Fig> figs = this.getEdges();
-            for (Fig fig : figs) {
-                if (fig instanceof FigMessage) {
-                    if (fig.getLastPoint().y > yMax) {
-                        yMax = getLastPoint().y;
-                    }
-                }
-            }
+        // if the removed edge is a FigMessage it might affect minimumHeight 
+        // so it should be updated
+        if (edge instanceof FigMessage) {
+            updateMinimumHeight();
         }
     }
     
@@ -238,11 +251,6 @@
         super.addFigEdge(edge);
         
         if (edge instanceof FigMessage) {
-
-            // if a new message has been added, yMax should be updated
-            if (edge.getLastPoint().y > yMax) {
-                yMax = edge.getY();
-            }
             
             FigMessage mess = (FigMessage) edge;
             if (mess.isSelfMessage()) {
@@ -255,6 +263,12 @@
                 LOG.info("Added a create message");
                 relocate();
             }
+            
+            // adding a FigMessage might affect minimumHeight so it
+            // should be updated
+            if (edge instanceof FigMessage) {
+                updateMinimumHeight();
+            }
         }        
     }
     /**
@@ -281,6 +295,7 @@
      * Called when a create message is added or moved.
      */
     void relocate() {
+        updateHeadOffset();
         setBounds(getX(), getY(), getWidth(), getHeight());
     }
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.