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

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2007-06-07 12:10:36-0700
New Revision: 12774

Added:
   trunk/src_new/org/argouml/uml/diagram/ui/StylePanelFigAssociationClass.java   (contents, props changed)
Modified:
   trunk/src_new/org/argouml/ui/StylePanelFig.java
   trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java
   trunk/src_new/org/argouml/uml/ui/TabStyle.java

Log:
Fix for issue 4629: "Unable to set color of AssociationClass". Patch provided by Aleksandar.

Fixed many small problems in the process: 2 nullpointerexceptions, dragging an association did not update its bounds field, idem for associationclass.

Modified: trunk/src_new/org/argouml/ui/StylePanelFig.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/StylePanelFig.java?view=diff&rev=12774&p1=trunk/src_new/org/argouml/ui/StylePanelFig.java&p2=trunk/src_new/org/argouml/ui/StylePanelFig.java&r1=12773&r2=12774
==============================================================================
--- trunk/src_new/org/argouml/ui/StylePanelFig.java	(original)
+++ trunk/src_new/org/argouml/ui/StylePanelFig.java	2007-06-07 12:10:36-0700
@@ -193,6 +193,7 @@
      */
     public void refresh() {
     	Fig target = getPanelTarget();
+    	 //TODO: How about FigAssociationClass?
         if (target instanceof FigEdgeModelElement) {
             hasEditableBoundingBox(false);
         } else {

Modified: trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java?view=diff&rev=12774&p1=trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java&p2=trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java&r1=12773&r2=12774
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java	(original)
+++ trunk/src_new/org/argouml/uml/diagram/ui/FigAssociationClass.java	2007-06-07 12:10:36-0700
@@ -24,6 +24,8 @@
 
 package org.argouml.uml.diagram.ui;
 
+import java.awt.Color;
+import java.awt.Rectangle;
 import java.util.Iterator;
 import java.util.List;
 
@@ -33,28 +35,31 @@
 import org.tigris.gef.presentation.FigPoly;
 import org.tigris.gef.presentation.FigText;
 
-
 /**
- * An Association Class is represented by 3 separate Figs: <nl>
- * <li>FigAssociationClass is the association edge drawn between two classifiers
- * this displays that association properties of the association class.</li>
+ * An Association Class is represented by 3 separate Figs:
+ * <nl>
+ * <li>FigAssociationClass is the association edge drawn between two
+ * classifiers this displays that association properties of the association
+ * class.</li>
  * <li>FigClassAssociationClass is the classifier box that displays the class
  * properties of the association class.</li>
- * </li>FigEdgeAssociationClass is the dashed line that joins these two.</li>
+ * </li>
+ * FigEdgeAssociationClass is the dashed line that joins these two.</li>
  * </nl>
- * 
+ *
  * Whenever the user attempts to remove or delete one of these parts then all
- * parts must go.
- * Delete would be handled because the model element is deleted and all parts
- * are listening for such an event and will remove themselves.
+ * parts must go. Delete would be handled because the model element is deleted
+ * and all parts are listening for such an event and will remove themselves.
  * However if the user attempts to just remove from diagram one of these parts
- * then there is no such event. Hence the removeFromDiagram method is
- * overridden to delegate removal from a single removeFromDiagram method on
+ * then there is no such event. Hence the removeFromDiagram method is overridden
+ * to delegate removal from a single removeFromDiagram method on
  * FigAssociationClass.
  *
  * @author [email protected]
  */
-public class FigAssociationClass extends FigAssociation {
+public class FigAssociationClass extends FigAssociation implements
+        AttributesCompartmentContainer, PathContainer,
+        OperationsCompartmentContainer {
 
     /**
      * The UID.
@@ -74,15 +79,17 @@
     /**
      * Construct a new FigAssociationClass from user interaction.
      *
-     * @param ed the edge
-     * @param lay the layer
+     * @param ed
+     *            the edge
+     * @param lay
+     *            the layer
      */
     public FigAssociationClass(Object ed, Layer lay) {
         this();
         setLayer(lay);
         setOwner(ed);
     }
-    
+
     /**
      * Discover the attached FigEdgeAssociationClass and the
      * FigClassAssociationClass attached to that. Remove them from the diagram
@@ -91,22 +98,22 @@
     protected void removeFromDiagramImpl() {
         FigEdgeAssociationClass figEdgeLink = null;
         List edges = null;
-        
+
         FigEdgePort figEdgePort = getEdgePort();
         if (figEdgePort != null) {
             edges = figEdgePort.getFigEdges();
         }
-        
+
         if (edges != null) {
-            for (Iterator it = edges.iterator();
-                    it.hasNext() && figEdgeLink == null; ) {
+            for (Iterator it = edges.iterator(); it.hasNext()
+                    && figEdgeLink == null;) {
                 Object o = it.next();
                 if (o instanceof FigEdgeAssociationClass) {
                     figEdgeLink = (FigEdgeAssociationClass) o;
                 }
             }
         }
-        
+
         if (figEdgeLink != null) {
             FigNode figClassBox = figEdgeLink.getDestFigNode();
             if (!(figClassBox instanceof FigClassAssociationClass)) {
@@ -115,14 +122,14 @@
             figEdgeLink.removeFromDiagramImpl();
             ((FigClassAssociationClass) figClassBox).removeFromDiagramImpl();
         }
-        
+
         super.removeFromDiagramImpl();
     }
 
     /*
      * @see org.tigris.gef.presentation.FigEdge#setFig(
-     *         org.tigris.gef.presentation.Fig)
-     * TODO: Is this required? Why would the fig already be dashed?
+     *      org.tigris.gef.presentation.Fig) TODO: Is this required? Why would
+     *      the fig already be dashed?
      */
     public void setFig(Fig f) {
         super.setFig(f);
@@ -135,6 +142,177 @@
     protected FigText getNameFig() {
         return null;
     }
-    
-} /* end class FigAssociationClass */
 
+    /**
+     * Overrided in order to implement AttributesCompartmentContainer.
+     */
+    public Rectangle getAttributesBounds() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().getAttributesBounds();
+        else
+            return new Rectangle(0, 0, 0, 0);
+    }
+
+    /**
+     * Overrided in order to implement AttributesCompartmentContainer.
+     */
+    public boolean isAttributesVisible() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().isAttributesVisible();
+        else
+            return true;
+    }
+
+    /**
+     * Overrided in order to implement AttributesCompartmentContainer.
+     */
+    public void setAttributesVisible(boolean visible) {
+        getAssociationClass().setAttributesVisible(visible);
+
+    }
+
+    /**
+     * Overrided in order to implement PathCompartmentContainer.
+     */
+    public boolean isPathVisible() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().isPathVisible();
+        else
+            return false;
+    }
+
+    /**
+     * Overrided in order to implement PathCompartmentContainer.
+     */
+    public void setPathVisible(boolean visible) {
+        getAssociationClass().setPathVisible(visible);
+    }
+
+    /**
+     * Overrided in order to implement OperationsCompartmentContainer.
+     */
+    public Rectangle getOperationsBounds() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().getOperationsBounds();
+        else
+            return new Rectangle(0, 0, 0, 0);
+    }
+
+    /**
+     * Overrided in order to implement OperationsCompartmentContainer.
+     */
+    public boolean isOperationsVisible() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().isOperationsVisible();
+        else
+            return true;
+    }
+
+    /**
+     * Overrided in order to implement OperationsCompartmentContainer.
+     */
+    public void setOperationsVisible(boolean visible) {
+        getAssociationClass().setOperationsVisible(visible);
+    }
+
+    /**
+     * Overrided in order to set fill color of contained
+     * FigClassAssociationClass.
+     */
+    @Override
+    public void setFillColor(Color color) {
+        getAssociationClass().setFillColor(color);
+    }
+
+    /**
+     * Overrided in order to get fill color of contained
+     * FigClassAssociationClass.
+     */
+    @Override
+    public Color getFillColor() {
+        if (getAssociationClass() != null)
+            return getAssociationClass().getFillColor();
+        else
+            return Color.white;
+    }
+
+    /**
+     * Overrided in order to set line color of contained
+     * FigClassAssociationClass.
+     */
+    @Override
+    public void setLineColor(Color arg0) {
+        super.setLineColor(arg0);
+        if (getAssociationClass() != null) {
+            getAssociationClass().setLineColor(arg0);
+        }
+        if (getFigEdgeAssociationClass() != null) {
+            getFigEdgeAssociationClass().setLineColor(arg0);
+        }
+    }
+
+    /**
+     * Gets FigClassAssociationClass that is contained in this
+     * FigAssociationClass.
+     *
+     * @return FigClassAssociationClass that is contained in this
+     *         FigAssociationClass.
+     */
+    public FigClassAssociationClass getAssociationClass() {
+        FigEdgeAssociationClass figEdgeLink = null;
+        List edges = null;
+
+        FigEdgePort figEdgePort = this.getEdgePort();
+        if (figEdgePort != null) {
+            edges = figEdgePort.getFigEdges();
+        }
+
+        if (edges != null) {
+            for (Iterator it = edges.iterator(); it.hasNext()
+                    && figEdgeLink == null;) {
+                Object o = it.next();
+                if (o instanceof FigEdgeAssociationClass) {
+                    figEdgeLink = (FigEdgeAssociationClass) o;
+                }
+            }
+        }
+
+        FigNode figClassBox = null;
+        if (figEdgeLink != null) {
+            figClassBox = figEdgeLink.getDestFigNode();
+            if (!(figClassBox instanceof FigClassAssociationClass)) {
+                figClassBox = figEdgeLink.getSourceFigNode();
+            }
+        }
+        return (FigClassAssociationClass) figClassBox;
+    }
+
+    /**
+     * Gets FigEdgeAssociationClass that is contained in this
+     * FigAssociationClass.
+     *
+     * @return FigEdgeAssociationClass that is contained in this
+     *         FigAssociationClass
+     */
+    public FigEdgeAssociationClass getFigEdgeAssociationClass() {
+        FigEdgeAssociationClass figEdgeLink = null;
+        List edges = null;
+
+        FigEdgePort figEdgePort = this.getEdgePort();
+        if (figEdgePort != null) {
+            edges = figEdgePort.getFigEdges();
+        }
+
+        if (edges != null) {
+            for (Iterator it = edges.iterator(); it.hasNext()
+                    && figEdgeLink == null;) {
+                Object o = it.next();
+                if (o instanceof FigEdgeAssociationClass) {
+                    figEdgeLink = (FigEdgeAssociationClass) o;
+                }
+            }
+        }
+
+        return figEdgeLink;
+    }
+} /* end class FigAssociationClass */

Added: trunk/src_new/org/argouml/uml/diagram/ui/StylePanelFigAssociationClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/ui/StylePanelFigAssociationClass.java?view=auto&rev=12774
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/uml/diagram/ui/StylePanelFigAssociationClass.java	2007-06-07 12:10:36-0700
@@ -0,0 +1,124 @@
+// $Id$
+// Copyright (c) 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
+// 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.Rectangle;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyListener;
+
+import org.argouml.uml.diagram.static_structure.ui.StylePanelFigClass;
+import org.tigris.gef.presentation.Fig;
+
+/**
+ * The style Panel for FigEdgeModelElement.
+ *
+ */
+public class StylePanelFigAssociationClass extends StylePanelFigClass implements
+        ItemListener, FocusListener, KeyListener {
+
+    public StylePanelFigAssociationClass() {
+    }
+
+    /**
+     * Bounding box is editable (although this is style panel for an
+     * FigEdgeModelElement).
+     */
+    @Override
+    protected void hasEditableBoundingBox(boolean value) {
+        super.hasEditableBoundingBox(true);
+    }
+
+    /*
+     * @see org.argouml.ui.StylePanelFig#setTargetBBox()
+     */
+    @Override
+    protected void setTargetBBox() {
+        Fig target = getPanelTarget();
+        // Can't do anything if we don't have a fig.
+        if (target == null) {
+            return;
+        }
+        // Parse the boundary box text. Null is
+        // returned if it is empty or
+        // invalid, which causes no change. Otherwise we tell
+        // GEF we are making
+        // a change, make the change and tell GEF we've
+        // finished.
+        Rectangle bounds = parseBBox();
+        if (bounds == null) {
+            return;
+        }
+
+        // Get class box, because we will set it's bounding box
+        Rectangle oldAssociationBounds = target.getBounds();
+        if (((FigAssociationClass) target).getAssociationClass() != null) {
+            target = ((FigAssociationClass) target).getAssociationClass();
+        }
+
+        if (!target.getBounds().equals(bounds)
+                && !oldAssociationBounds.equals(bounds)) {
+            target.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
+            target.endTrans();
+        }
+    }
+
+    /*
+     * @see org.argouml.ui.StylePanelFig#refresh()
+     */
+    @Override
+    public void refresh() {
+        super.refresh();
+
+        // The boundary box as held in the target fig, and as listed in
+        // the
+        // boundary box style field (null if we don't have anything
+        // valid)
+        Fig target = getPanelTarget();
+
+        // Get class box, because we will set it's bounding box in text field
+        if (((FigAssociationClass) target).getAssociationClass() != null) {
+            target = ((FigAssociationClass) target).getAssociationClass();
+        }
+
+        Rectangle figBounds = target.getBounds();
+        Rectangle styleBounds = parseBBox();
+
+        // Only reset the text if the two are not the same (i.e the fig
+        // has
+        // moved, rather than we've just edited the text, when
+        // setTargetBBox()
+        // will have made them the same). Note that styleBounds could
+        // be null,
+        // so we do the test this way round.
+
+        if (!(figBounds.equals(styleBounds))) {
+            getBBoxField().setText(
+                    figBounds.x + "," + figBounds.y + "," + figBounds.width
+                            + "," + figBounds.height);
+        }
+    }
+
+} /* end class StylePanelFigAssociationClass */

Modified: trunk/src_new/org/argouml/uml/ui/TabStyle.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/ui/TabStyle.java?view=diff&rev=12774&p1=trunk/src_new/org/argouml/uml/ui/TabStyle.java&p2=trunk/src_new/org/argouml/uml/ui/TabStyle.java&r1=12773&r2=12774
==============================================================================
--- trunk/src_new/org/argouml/uml/ui/TabStyle.java	(original)
+++ trunk/src_new/org/argouml/uml/ui/TabStyle.java	2007-06-07 12:10:36-0700
@@ -46,10 +46,12 @@
 import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetListener;
 import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.uml.diagram.ui.FigAssociationClass;
 import org.argouml.uml.util.namespace.Namespace;
 import org.argouml.uml.util.namespace.StringNamespace;
 import org.argouml.uml.util.namespace.StringNamespaceElement;
 import org.tigris.gef.presentation.Fig;
+import org.tigris.gef.presentation.FigEdge;
 
 /**
  * Provides support for changing the appearance of a diagram element. For each
@@ -155,15 +157,24 @@
 
     /**
      * Sets the target of the style tab.
-     *
-     * @deprecated As of ArgoUml version 0.13.5, the visibility of this method
-     *             will change in the future, replaced by
-     *             {@link org.argouml.ui.targetmanager.TargetManager}.
+     * 
      * @param t
      *            is the new target
      */
     public void setTarget(Object t) {
-        if (target != null) target.removePropertyChangeListener(this);
+        if (target != null) {
+            target.removePropertyChangeListener(this);
+            if (target instanceof FigEdge) {
+                // In this case, the bounds are determined by the FigEdge
+                ((FigEdge) target).getFig().removePropertyChangeListener(this);
+            }
+            if (target instanceof FigAssociationClass) {
+                // In this case, the bounds (of the box) are determined 
+                // by the FigClassAssociationClass
+                ((FigAssociationClass) target).getAssociationClass()
+                    .removePropertyChangeListener(this);
+            }
+        }
         
         // TODO: Defer most of this work if the panel isn't visible - tfm
 
@@ -188,7 +199,19 @@
         }
 
         target = (Fig) t;
-        if (target != null) target.addPropertyChangeListener(this);
+        if (target != null) {
+            target.addPropertyChangeListener(this);
+            if (target instanceof FigEdge) {
+                // In this case, the bounds are determined by the FigEdge
+                ((FigEdge) target).getFig().addPropertyChangeListener(this);
+            }
+            if (target instanceof FigAssociationClass) {
+                // In this case, the bounds (of the box) are determined 
+                // by the FigClassAssociationClass
+                ((FigAssociationClass) target).getAssociationClass()
+                    .addPropertyChangeListener(this);
+            }
+        }
         if (lastPanel != null) {
             remove(lastPanel);
             if (lastPanel instanceof TargetListener) {
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.