svn commit: r15091 - trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-06-27 12:06:31-0700
New Revision: 15091

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java

Log:
 Issue 5182:ArgoUML incredibly slow with large models.

 This patch reduces the amount of refreshes of the diagram considerably.

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&rev=15091&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&r1=15090&r2=15091
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	2008-06-27 12:06:31-0700
@@ -282,7 +282,15 @@
 
     // TODO: A more strongly typed data structure could be used here.
     private Collection<Object[]> listeners = new ArrayList<Object[]>();
-    
+
+    /**
+     * If this semaphore is false, then a Runnable to update the layout 
+     * is already waiting to be executed. The semaphore is then used to 
+     * guarantee that not more than one such (functionally identical) Runnable
+     * is created and queued in the SwingUtilities.invokeLater() call.
+     */
+    private boolean semaphore = true;
+
     /**
      * The main constructor. <p>
      * 
@@ -998,23 +1006,33 @@
                     && "stereotype".equals(event.getPropertyName())) {
                 stereotypeChanged(event);            
             }
-            
-            Runnable doWorkRunnable = new Runnable() {
-                public void run() {
-                    try {
-                        updateLayout(event);
-                    } catch (InvalidElementException e) {
-                        LOG.debug("event = " + event.getClass().getName());
-                        LOG.debug("source = " + event.getSource());
-                        LOG.debug("old = " + event.getOldValue());
-                        LOG.debug("name = " + event.getPropertyName());
-                        LOG.debug(
-                                "updateLayout method accessed deleted element ",
-                                e);
-                    }
-                }  
-            };
-            SwingUtilities.invokeLater(doWorkRunnable);
+
+            /*
+             * If this semaphore is false, then a Runnable to update the layout 
+             * is already waiting to be executed. The semaphore is then used to 
+             * guarantee that not more than one such (functionally identical) 
+             * Runnable is created and queued in the 
+             * SwingUtilities.invokeLater() call.
+             */
+            if (semaphore) {
+                semaphore = false;
+                Runnable doWorkRunnable = new Runnable() {
+                    public void run() {
+                        try {
+                            semaphore = true;
+                            updateLayout(event);
+                        } catch (InvalidElementException e) {
+                            LOG.debug("event = " + event.getClass().getName());
+                            LOG.debug("source = " + event.getSource());
+                            LOG.debug("old = " + event.getOldValue());
+                            LOG.debug("name = " + event.getPropertyName());
+                            LOG.debug("updateLayout method accessed "
+                            		+ "deleted element ", e);
+                        }
+                    }  
+                };
+                SwingUtilities.invokeLater(doWorkRunnable);
+            }
         }
     }
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.