Author: tfmorris
Date: 2008-10-06 13:05:27-0700
New Revision: 15896

Modified:
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java

Log:
Issue 5438: Minimal listener update for more figs, including 
FigEdgeModelElement and some of its subclasses
http://argouml.tigris.org/issues/show_bug.cgi?id=5438

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java?view=diff&rev=15896&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java&r1=15895&r2=15896
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
 (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
 2008-10-06 13:05:27-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-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
@@ -29,7 +29,9 @@
 import java.awt.Rectangle;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.Action;
@@ -105,6 +107,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
+    @Override
     public Selection makeSelection() {
         return new SelectionStereotype(this);
     }
@@ -114,6 +117,7 @@
      * popup menu on a Stereotype.
      * [EMAIL PROTECTED]
      */
+    @Override
     public Vector getPopUpActions(MouseEvent me) {
         Vector popUpActions = super.getPopUpActions(me);
 
@@ -155,6 +159,7 @@
      *
      * @return  the size of the minimum bounding box.
      */
+    @Override
     public Dimension getMinimumSize() {
         Dimension aSize = getNameFig().getMinimumSize();
         if (getStereotypeFig().isVisible()) {
@@ -193,6 +198,7 @@
      *
      * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
      */
+    @Override
     protected void setStandardBounds(final int x, final int y,
             final int w, final int h) {
         Rectangle oldBounds = getBounds();
@@ -240,6 +246,7 @@
     /*
      * @see 
org.argouml.uml.diagram.static_structure.ui.FigCompartmentBox#unhighlight()
      */
+    @Override
     protected CompartmentFigText unhighlight() {
         CompartmentFigText fc = super.unhighlight();
         if (fc == null) {
@@ -253,9 +260,10 @@
      * Handles changes to the model. Takes into account the event that
      * occurred. If you need to update the whole fig, consider using
      * renderingChanged.
-     *
+     * [EMAIL PROTECTED]
      * @see 
org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
      */
+    @Override
     protected void modelChanged(PropertyChangeEvent mee) {
         super.modelChanged(mee);
         if (mee instanceof AssociationChangeEvent 
@@ -269,21 +277,19 @@
     /*
      * @see 
org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object)
      */
+    @Override
     protected void updateListeners(Object oldOwner, Object newOwner) {
-        if (oldOwner != null) {
-            removeAllElementListeners();
-        }
+        
+        Set<Object[]> listeners = new HashSet<Object[]>();
         if (newOwner != null) {
-            addElementListener(newOwner);
+            listeners.add(new Object[] {newOwner, null});
             // register for tagdefinitions:
-            Iterator it =
-                Model.getFacade().getTagDefinitions(newOwner).iterator();
-            while (it.hasNext()) {
-                Object td = it.next();
-                addElementListener(td, 
-                        new String[] {"name", "tagType", "multiplicity"});
+            for (Object td : Model.getFacade().getTagDefinitions(newOwner)) {
+                listeners.add(new Object[] {td,
+                    new String[] {"name", "tagType", "multiplicity"}});
             }
             /* TODO: constraints, ... */
         }
+        updateElementListeners(listeners);
     }
-} /* end class FigClass */
+}

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java?view=diff&rev=15896&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java&r1=15895&r2=15896
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java    
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociation.java    
2008-10-06 13:05:27-0700
@@ -32,7 +32,9 @@
 import java.beans.PropertyChangeListener;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -194,10 +196,14 @@
      */
     @Override
     public void updateListeners(Object oldOwner, Object newOwner) {
-        removeAllElementListeners();
+        Set<Object[]> listeners = new HashSet<Object[]>();
         if (newOwner != null) {
-            addElementListener(newOwner, new String[] {"isAbstract", 
"remove"});
+            listeners.add(
+                    new Object[] {newOwner,
+                                  new String[] {"isAbstract", "remove"}
+                    });
         }
+        updateElementListeners(listeners);
         /* No further listeners required in this case - the rest is handled 
          * by the notationProvider and sub-Figs. */
     }

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java?view=diff&rev=15896&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java&r1=15895&r2=15896
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java 
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigAssociationEnd.java 
2008-10-06 13:05:27-0700
@@ -27,6 +27,8 @@
 import java.awt.Color;
 import java.awt.Graphics;
 import java.beans.PropertyChangeEvent;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.argouml.kernel.Project;
@@ -159,20 +161,11 @@
      */
     @Override
     public void updateListeners(Object oldOwner, Object newOwner) {
-        if (oldOwner == newOwner) {
-            LOG.warn("Listeners being added and removed from the same owner");
-        }
-        if (oldOwner != null) {
-            removeAllElementListeners();
-        }
-        /* Now, let's register for events from all modelelements
-         * that change the association-end representation: 
-         */
+        Set<Object[]> l = new HashSet<Object[]>();
         if (newOwner != null) {
-            /* Many different event types are needed, 
-             * so let's register for them all: */
-            addElementListener(newOwner);
+            l.add(new Object[] {newOwner, null});
         }
+        updateElementListeners(l);
     }
 
     /** Returns the name of the OrderingKind.

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java?view=diff&rev=15896&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java&r1=15895&r2=15896
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java   
    (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java   
    2008-10-06 13:05:27-0700
@@ -36,11 +36,11 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.beans.VetoableChangeListener;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.Action;
@@ -65,6 +65,7 @@
 import org.argouml.kernel.DelayedChangeNotify;
 import org.argouml.kernel.DelayedVChangeListener;
 import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectSettings;
 import org.argouml.model.AddAssociationEvent;
 import org.argouml.model.AssociationChangeEvent;
 import org.argouml.model.AttributeChangeEvent;
@@ -156,7 +157,7 @@
     /*
      * List of model element listeners we've registered.
      */
-    private Collection listeners = new ArrayList();
+    private Set<Object[]> listeners = new HashSet<Object[]>();
 
     ////////////////////////////////////////////////////////////////
     // constructors
@@ -261,8 +262,9 @@
     }
 
     /**
-     * @return a Vector containing a combination of these 4 types:
-     * Action, JMenu, JMenuItem, JSeparator.
+     * @param me the MouseEvent that triggered the popup menu request
+     * @return a Vector containing a combination of these 4 types: Action,
+     *         JMenu, JMenuItem, JSeparator.
      */
     @Override
     public Vector getPopUpActions(MouseEvent me) {
@@ -421,8 +423,9 @@
             if (y >= p.y + yOff
                 && y <= p.y + height + yOff
                 && x >= p.x + xOff
-                && x <= p.x + width + xOff)
+                && x <= p.x + width + xOff) {
                 return item;
+            }
             iconPos += width;
         }
         for (ToDoItem item : items) {
@@ -430,8 +433,9 @@
             if (icon instanceof Clarifier) {
                 ((Clarifier) icon).setFig(this);
                 ((Clarifier) icon).setToDoItem(item);
-                if (((Clarifier) icon).hit(x, y))
+                if (((Clarifier) icon).hit(x, y)) {
                     return item;
+                }
             }
         }
         items = tdList.elementListForOffender(this);
@@ -443,8 +447,9 @@
             if (y >= p.y + yOff
                 && y <= p.y + height + yOff
                 && x >= p.x + xOff
-                && x <= p.x + width + xOff)
+                && x <= p.x + width + xOff) {
                 return item;
+            }
             iconPos += width;
         }
         for (ToDoItem item : items) {
@@ -452,8 +457,9 @@
             if (icon instanceof Clarifier) {
                 ((Clarifier) icon).setFig(this);
                 ((Clarifier) icon).setToDoItem(item);
-                if (((Clarifier) icon).hit(x, y))
+                if (((Clarifier) icon).hit(x, y)) {
                     return item;
+                }
             }
         }
         return null;
@@ -656,8 +662,9 @@
      */
     protected void textEdited(FigText ft) {
         if (ft == nameFig) {
-            if (getOwner() == null)
+            if (getOwner() == null) {
                 return;
+            }
             notationProviderName.parse(getOwner(), ft.getText());
             ft.setText(notationProviderName.toString(getOwner(), npArguments));
         }
@@ -959,15 +966,11 @@
      *          or null if there was none, and all listeners have to be set
      */
     protected void updateListeners(Object oldOwner, Object newOwner) {
-        if (oldOwner == newOwner) {
-            LOG.debug("Listeners being added and removed from the same owner");
-        }
-        if (oldOwner != null) {
-            removeElementListener(oldOwner);
-        }
+        Set<Object[]> l = new HashSet<Object[]>();
         if (newOwner != null) {
-            addElementListener(newOwner, "remove");
+            l.add(new Object[] {newOwner, "remove"});
         }
+        updateElementListeners(l);
     }
 
     /*
@@ -1001,7 +1004,9 @@
      * @see 
org.argouml.application.events.ArgoNotationEventListener#notationChanged(org.argouml.application.events.ArgoNotationEvent)
      */
     public void notationChanged(ArgoNotationEvent event) {
-        if (getOwner() == null) return;
+        if (getOwner() == null) {
+            return;
+        }
         initNotationProviders(getOwner());
         renderingChanged();
     }
@@ -1045,8 +1050,9 @@
        Iterator it = getPathItemFigs().iterator();
        while (it.hasNext()) {
            Fig f = (Fig) it.next();
-           if (f.hit(r))
+           if (f.hit(r)) {
                return true;
+           }
        }
        return super.hit(r);
     }
@@ -1054,6 +1060,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#removeFromDiagram()
      */
+    @Override
     public final void removeFromDiagram() {
         Fig delegate = getRemoveDelegate();
         if (delegate instanceof FigNodeModelElement) {
@@ -1364,28 +1371,66 @@
         Model.getPump().removeModelEventListener(this, element);
     }
    
+    
     /**
      * Unregister all listeners registered through addElementListener
      * @see #addElementListener(Object, String)
      */
     protected void removeAllElementListeners() {
-        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
-            Object[] l = (Object[]) iter.next();
-            Object property = l[1];
+        removeElementListeners(listeners);
+    }
+
+    private void removeElementListeners(Set<Object[]> listenerSet) {
+        for (Object[] listener : listenerSet) {
+            Object property = listener[1];
             if (property == null) {
-                Model.getPump().removeModelEventListener(this, l[0]);
+                Model.getPump().removeModelEventListener(this, listener[0]);
             } else if (property instanceof String[]) {
-                Model.getPump().removeModelEventListener(this, l[0],
+                Model.getPump().removeModelEventListener(this, listener[0],
                         (String[]) property);
             } else if (property instanceof String) {
-                Model.getPump().removeModelEventListener(this, l[0],
+                Model.getPump().removeModelEventListener(this, listener[0],
                         (String) property);
             } else {
                 throw new RuntimeException(
                         "Internal error in removeAllElementListeners");
             }
         }
-        listeners.clear();
+        listeners.removeAll(listenerSet);
+    }
+
+    private void addElementListeners(Set<Object[]> listenerSet) {
+        for (Object[] listener : listenerSet) {
+            Object property = listener[1];
+            if (property == null) {
+                addElementListener(listener[0]);
+            } else if (property instanceof String[]) {
+                addElementListener(listener[0], (String[]) property);
+            } else if (property instanceof String) {
+                addElementListener(listener[0], (String) property);
+            } else {
+                throw new RuntimeException(
+                        "Internal error in addElementListeners");
+            }
+        }
+    }
+
+    /**
+     * Update the set of registered listeners to match the given set using 
+     * a minimal update strategy to remove unneeded listeners and add new 
+     * listeners.
+     * 
+     * @param listenerSet a set of arrays containing a tuple of a UML element
+     * to be listened to and a set of property to be listened for.  
+     */
+    protected void updateElementListeners(Set<Object[]> listenerSet) {
+        Set<Object[]> removes = new HashSet<Object[]>(listeners);
+        removes.removeAll(listenerSet);
+        removeElementListeners(removes);
+        
+        Set<Object[]> adds = new HashSet<Object[]>(listenerSet);
+        adds.removeAll(listeners);
+        addElementListeners(adds);
     }
 
     protected HashMap<String, Object> getNotationArguments() {

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java?view=diff&rev=15896&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java&r1=15895&r2=15896
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java    
    (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/use_case/ui/FigExtend.java    
    2008-10-06 13:05:27-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-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
@@ -27,6 +27,8 @@
 import java.awt.Color;
 import java.awt.Graphics;
 import java.beans.PropertyChangeEvent;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectManager;
@@ -72,11 +74,6 @@
 
     private ArrowHeadGreater endArrow = new ArrowHeadGreater();
 
-    ///////////////////////////////////////////////////////////////////////////
-    //
-    // Constructors
-    //
-    ///////////////////////////////////////////////////////////////////////////
 
     /**
      * The default constructor, but should never be called directly
@@ -154,12 +151,6 @@
     }
 
 
-    ///////////////////////////////////////////////////////////////////////////
-    //
-    // Accessors
-    //
-    ///////////////////////////////////////////////////////////////////////////
-
     /**
      * Set a new fig to represent this edge.<p>
      *
@@ -169,6 +160,7 @@
      *
      * @param f  The fig to use.
      */
+    @Override
     public void setFig(Fig f) {
         super.setFig(f);
 
@@ -185,6 +177,7 @@
      *
      * @return   <code>false</code> under all circumstances.
      */
+    @Override
     protected boolean canEdit(Fig f) {
         return false;
     }
@@ -192,6 +185,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#paint(java.awt.Graphics)
      */
+    @Override
     public void paint(Graphics g) {
         endArrow.setLineColor(getLineColor());
         super.paint(g);
@@ -200,11 +194,16 @@
     /*
      * @see 
org.argouml.uml.diagram.ui.FigEdgeModelElement#updateListeners(java.lang.Object,
 java.lang.Object)
      */
+    @Override
     protected void updateListeners(Object oldOwner, Object newOwner) {
-        removeAllElementListeners();
+        Set<Object[]> listeners = new HashSet<Object[]>();
         if (newOwner != null) {
-            addElementListener(newOwner, new String[] {"condition", "remove"});
+            listeners.add(
+                    new Object[] {newOwner,
+                                  new String[] {"condition", "remove"}
+                    });
         }
+        updateElementListeners(listeners);
     }
 
 
@@ -213,6 +212,7 @@
      * 
      * @see 
org.argouml.uml.diagram.ui.FigEdgeModelElement#modelChanged(java.beans.PropertyChangeEvent)
      */
+    @Override
     protected void modelChanged(PropertyChangeEvent e) {
         Object extend = getOwner();
         if (extend == null) {
@@ -228,6 +228,7 @@
     /*
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#renderingChanged()
      */
+    @Override
     protected void renderingChanged() {
         if (getOwner() != null) {
             updateConditionText();
@@ -242,7 +243,9 @@
      * so we show the "body" of it, and ignore the "language".
      */
     protected void updateConditionText() {
-        if (getOwner() == null) return;
+        if (getOwner() == null) {
+            return;
+        }
 
         Object c = Model.getFacade().getCondition(getOwner());
         if (c == null) {
@@ -270,4 +273,4 @@
                 + ps.getRightGuillemot());
     }
 
-} /* end class FigExtend */
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to