Author: kono
Date: 2012-05-07 14:06:52 -0700 (Mon, 07 May 2012)
New Revision: 29135

Modified:
   
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualStyle.java
   
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/bypass/BypassTask.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyHandler.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToEdgeHandler.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNetworkHandler.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNodeHandler.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/CyActivator.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleFactoryImpl.java
   
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
   
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleFactoryTest.java
   
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
Log:
fixes #959 New method had been added to avoid inefficient apply implementation.

Modified: 
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualStyle.java
===================================================================
--- 
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualStyle.java
 2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualStyle.java
 2012-05-07 21:06:52 UTC (rev 29135)
@@ -38,6 +38,8 @@
 import java.util.Set;
 
 import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
 
@@ -137,12 +139,21 @@
 
        
        /**
-        * Apply visual only to a individual View Object (node/edge), 
-        * not the entire network view.
+        * Apply Visual Style to the entire network view.
         * 
+        * @param networkView The view that the visual property should be 
applied to.
+        */
+       void apply(final CyNetworkView networkView);
+
+
+       /**
+        * Apply Visual Property values only to the given View Object (node or 
edge).
+        * If you need to update only few set of node/edge views, then this is 
more efficient.
+        * 
+        * @param row Data table row for the view's model.  This is necessary 
for applying mapped values.
         * @param view The view that the visual property should be applied to.
         */
-       void apply(final View<? extends CyIdentifiable> view);
+       void apply(final CyRow row, final View<? extends CyIdentifiable> view);
        
        /**
         * Get all dependencies for this style.

Modified: 
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
===================================================================
--- 
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
     2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/api/trunk/vizmap-api/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
     2012-05-07 21:06:52 UTC (rev 29135)
@@ -12,6 +12,7 @@
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTable;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.model.CyNetworkView;
@@ -105,8 +106,8 @@
                // Apply to individual values
                style.setDefaultValue(BasicVisualLexicon.NODE_FILL_COLOR, 
Color.YELLOW);
                
-               // FIXME!
-               style.apply(nodeView3);
+               final CyRow row = 
networkView.getModel().getRow(nodeView3.getModel());
+               style.apply(row, nodeView3);
                assertEquals(RED1, 
nodeView1.getVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR));
                assertEquals(RED1, 
nodeView2.getVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR));
                assertEquals(Color.YELLOW, 
nodeView3.getVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR));            

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/bypass/BypassTask.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/bypass/BypassTask.java
        2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/bypass/BypassTask.java
        2012-05-07 21:06:52 UTC (rev 29135)
@@ -5,6 +5,7 @@
 import javax.swing.SwingUtilities;
 
 import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
@@ -66,7 +67,8 @@
                        view.clearValueLock(vp);
                }
 
-               selectedManager.getCurrentVisualStyle().apply(view);
+               final CyRow row = 
networkView.getModel().getRow(view.getModel());
+               selectedManager.getCurrentVisualStyle().apply(row, view);
                networkView.updateView();
        }
 }

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
        2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
        2012-05-07 21:06:52 UTC (rev 29135)
@@ -3,6 +3,7 @@
 import java.util.Collection;
 
 import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.vizmap.VisualMappingFunction;
@@ -19,12 +20,12 @@
        }
 
        
-       protected void applyValues(final View<T> view, final 
Collection<VisualProperty<?>> vps) {
+       protected void applyValues(final CyRow row, final View<T> view, final 
Collection<VisualProperty<?>> vps) {
                for (final VisualProperty<?> vp : vps) {
                        // check mapping exists or not
                        final VisualMappingFunction<?, ?> mapping = 
style.getVisualMappingFunction(vp);
                        if (mapping != null) {
-                               applyMappedValue(view, vp, mapping);
+                               applyMappedValue(row, view, vp, mapping);
                                continue;
                        }
                        Object defaultValue = style.getDefaultValue(vp);
@@ -39,7 +40,18 @@
                }
        }
 
-       protected void applyMappedValue(final View<T> nodeView, final 
VisualProperty<?> vp,
-                       final VisualMappingFunction<?, ?> mapping) {}
+       private void applyMappedValue(final CyRow row, final View<T> view, 
final VisualProperty<?> vp,
+                       final VisualMappingFunction<?, ?> mapping) {
+               // Default of this style
+               final Object styleDefaultValue = style.getDefaultValue(vp);
+               // Default of this Visual Property
+               final Object vpDefault = vp.getDefault();
 
+               mapping.apply(row, view);
+
+               if (view.getVisualProperty(vp) == vpDefault)
+                       view.setVisualProperty(vp, styleDefaultValue);
+
+       }
+
 }

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyHandler.java
        2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyHandler.java
        2012-05-07 21:06:52 UTC (rev 29135)
@@ -1,9 +1,12 @@
 package org.cytoscape.view.vizmap.internal;
 
 import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.View;
 
 
 public interface ApplyHandler<T extends CyIdentifiable> {
-       void apply(final View<T> view);
+       
+       void apply(final CyRow row, final View<T> view);
+
 }

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToEdgeHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToEdgeHandler.java
  2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToEdgeHandler.java
  2012-05-07 21:06:52 UTC (rev 29135)
@@ -1,59 +1,23 @@
 package org.cytoscape.view.vizmap.internal;
 
 import java.util.Collection;
-import java.util.Set;
 
 import org.cytoscape.model.CyEdge;
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.VisualMappingFunction;
 import org.cytoscape.view.vizmap.VisualStyle;
 
 public class ApplyToEdgeHandler extends AbstractApplyHandler<CyEdge> {
 
-       private final CyNetworkManager networkManager;
-       
-       ApplyToEdgeHandler(final VisualStyle style, final VisualLexiconManager 
lexManager, final CyNetworkManager networkManager) {
+
+       ApplyToEdgeHandler(final VisualStyle style, final VisualLexiconManager 
lexManager) {
                super(style, lexManager);
-               this.networkManager = networkManager;
        }
 
        @Override
-       public void apply(final View<CyEdge> edgeView) {
+       public void apply(final CyRow row, final View<CyEdge> edgeView) {
                final Collection<VisualProperty<?>> edgeVP = 
lexManager.getEdgeVisualProperties();
-               applyValues(edgeView, edgeVP);
+               applyValues(row, edgeView, edgeVP);
        }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void applyMappedValue(final View<CyEdge> view, final 
VisualProperty<?> vp,
-                       final VisualMappingFunction<?, ?> mapping) {
-               final CyEdge model = view.getModel();
-               CyNetwork targetNetwork = null;
-               Set<CyNetwork> networks = networkManager.getNetworkSet();
-               for (CyNetwork net : networks) {
-                       if (net.containsEdge(model)) {
-                               targetNetwork = net;
-                               break;
-                       }
-               }
-               
-               if (targetNetwork==null) {
-                       throw new NullPointerException("Could'nt find network");
-               }
-               // Default of this style
-               final Object styleDefaultValue = style.getDefaultValue(vp);
-               // Default of this Visual Property
-               final Object vpDefault = vp.getDefault();
-
-               mapping.apply(targetNetwork.getRow(model), view);
-
-               if (view.getVisualProperty(vp) == vpDefault)
-                       view.setVisualProperty(vp, styleDefaultValue);
-       }
-
 }

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNetworkHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNetworkHandler.java
       2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNetworkHandler.java
       2012-05-07 21:06:52 UTC (rev 29135)
@@ -8,6 +8,7 @@
 import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualLexicon;
@@ -29,7 +30,7 @@
        }
 
        @Override
-       public void apply(final View<CyNetwork> view) {
+       public void apply(final CyRow row, final View<CyNetwork> view) {
                final long start = System.currentTimeMillis();
 
                CyNetworkView networkView = (CyNetworkView) view;

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNodeHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNodeHandler.java
  2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/ApplyToNodeHandler.java
  2012-05-07 21:06:52 UTC (rev 29135)
@@ -1,62 +1,22 @@
 package org.cytoscape.view.vizmap.internal;
 
 import java.util.Collection;
-import java.util.Set;
 
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.VisualMappingFunction;
 import org.cytoscape.view.vizmap.VisualStyle;
 
 public class ApplyToNodeHandler extends AbstractApplyHandler<CyNode> {
 
-       private final CyNetworkManager networkManager;
-
-       ApplyToNodeHandler(final VisualStyle style, final VisualLexiconManager 
lexManager,
-                       final CyNetworkManager networkManager) {
+       ApplyToNodeHandler(final VisualStyle style, final VisualLexiconManager 
lexManager) {
                super(style, lexManager);
-               this.networkManager = networkManager;
        }
 
        @Override
-       public void apply(final View<CyNode> nodeView) {
+       public void apply(final CyRow row, final View<CyNode> nodeView) {
                final Collection<VisualProperty<?>> nodeVP = 
lexManager.getNodeVisualProperties();
-               applyValues(nodeView, nodeVP);
+               applyValues(row, nodeView, nodeVP);
        }
-
-       /**
-        * Apply mapped values if mapping exists for the given VP.
-        * 
-        * @param view
-        * @param vp
-        */
-       @Override
-       protected void applyMappedValue(final View<CyNode> view, final 
VisualProperty<?> vp,
-                       final VisualMappingFunction<?, ?> mapping) {
-               final CyNode model = view.getModel();
-               CyNetwork targetNetwork = null;
-               Set<CyNetwork> networks = networkManager.getNetworkSet();
-               for (CyNetwork net : networks) {
-                       if (net.containsNode(model)) {
-                               targetNetwork = net;
-                               break;
-                       }
-               }
-               
-               if (targetNetwork==null) {
-                       throw new NullPointerException("Could'nt find network");
-               }
-
-               // Default of this style
-               final Object styleDefaultValue = style.getDefaultValue(vp);
-               // Default of this Visual Property
-               final Object vpDefault = vp.getDefault();
-               mapping.apply(targetNetwork.getRow(model), view);
-
-               if (view.getVisualProperty(vp) == vpDefault)
-                       view.setVisualProperty(vp, styleDefaultValue);
-       }
 }

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/CyActivator.java
 2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/CyActivator.java
 2012-05-07 21:06:52 UTC (rev 29135)
@@ -3,7 +3,6 @@
 import java.util.Properties;
 
 import org.cytoscape.event.CyEventHelper;
-import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.service.util.AbstractCyActivator;
 import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.view.presentation.RenderingEngineFactory;
@@ -24,11 +23,10 @@
 
                final CyServiceRegistrar serviceRegistrarServiceRef = 
getService(bc, CyServiceRegistrar.class);
                CyEventHelper cyEventHelperServiceRef = getService(bc, 
CyEventHelper.class);
-               CyNetworkManager cyNetworkManagerServiceRef = getService(bc, 
CyNetworkManager.class);
 
                VisualLexiconManager visualLexiconManager = new 
VisualLexiconManager();
                VisualStyleFactoryImpl visualStyleFactory = new 
VisualStyleFactoryImpl(visualLexiconManager,
-                               serviceRegistrarServiceRef, 
cyNetworkManagerServiceRef);
+                               serviceRegistrarServiceRef);
                VisualMappingManagerImpl visualMappingManager = new 
VisualMappingManagerImpl(cyEventHelperServiceRef,
                                visualStyleFactory, visualLexiconManager);
                DiscreteMappingFactory discreteMappingFactory = new 
DiscreteMappingFactory();

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleFactoryImpl.java
      2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleFactoryImpl.java
      2012-05-07 21:06:52 UTC (rev 29135)
@@ -23,18 +23,15 @@
 
        private final VisualLexiconManager lexManager;
        private final CyServiceRegistrar serviceRegistrar;
-       private final CyNetworkManager networkManager;
 
-       public VisualStyleFactoryImpl(final VisualLexiconManager lexManager, 
final CyServiceRegistrar serviceRegistrar,
-                       final CyNetworkManager networkManager) {
+       public VisualStyleFactoryImpl(final VisualLexiconManager lexManager, 
final CyServiceRegistrar serviceRegistrar) {
                this.lexManager = lexManager;
                this.serviceRegistrar = serviceRegistrar;
-               this.networkManager = networkManager;
        }
 
        @Override
        public VisualStyle createVisualStyle(final VisualStyle original) {
-               final VisualStyle copy = new 
VisualStyleImpl(original.getTitle(), lexManager, 
serviceRegistrar,networkManager);
+               final VisualStyle copy = new 
VisualStyleImpl(original.getTitle(), lexManager, serviceRegistrar);
 
                copyDefaultValues(original, copy);
                copyMappingFunctions(original, copy);
@@ -44,7 +41,7 @@
 
        @Override
        public VisualStyle createVisualStyle(final String title) {
-               return new VisualStyleImpl(title, lexManager, serviceRegistrar, 
networkManager);
+               return new VisualStyleImpl(title, lexManager, serviceRegistrar);
        }
 
        private <V, S extends V> void copyDefaultValues(final VisualStyle 
original, final VisualStyle copy) {

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
     2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
     2012-05-07 21:06:52 UTC (rev 29135)
@@ -44,9 +44,10 @@
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.vizmap.VisualMappingFunction;
@@ -80,7 +81,7 @@
         * @param lexManager
         */
        public VisualStyleImpl(final String title, final VisualLexiconManager 
lexManager,
-                       final CyServiceRegistrar serviceRegistrar, final 
CyNetworkManager networkManager) {
+                       final CyServiceRegistrar serviceRegistrar) {
 
                if (lexManager == null)
                        throw new NullPointerException("Lexicon Manager is 
missing.");
@@ -96,8 +97,8 @@
                // Init Apply handlers for node, egde and network.
                this.applyHandlersMap = new HashMap<Class<? extends 
CyIdentifiable>, ApplyHandler>();
                applyHandlersMap.put(CyNetwork.class, new 
ApplyToNetworkHandler(this, lexManager));
-               applyHandlersMap.put(CyNode.class, new ApplyToNodeHandler(this, 
lexManager, networkManager));
-               applyHandlersMap.put(CyEdge.class, new ApplyToEdgeHandler(this, 
lexManager, networkManager));
+               applyHandlersMap.put(CyNode.class, new ApplyToNodeHandler(this, 
lexManager));
+               applyHandlersMap.put(CyEdge.class, new ApplyToEdgeHandler(this, 
lexManager));
 
                dependencies = new HashSet<VisualPropertyDependency<?>>();
 
@@ -149,18 +150,24 @@
                styleDefaults.put(vp, value);
        }
 
+       
+       @Override
+       public void apply(final CyNetworkView networkView) {
+               @SuppressWarnings("unchecked") // This is always safe.
+               final ApplyHandler<CyNetwork> networkViewHandler = 
applyHandlersMap.get(CyNetwork.class);
+               networkViewHandler.apply(null, networkView);
+       }
        /**
         * {@inheritDoc}
         */
+       @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
-       public void apply(final View<? extends CyIdentifiable> view) {
+       public void apply(final CyRow row, final View<? extends CyIdentifiable> 
view) {
                if (view == null) {
                        logger.warn("Tried to apply Visual Style to null view");
                        return;
                }
 
-               final long start = System.currentTimeMillis();
-
                ApplyHandler handler = null;
                for (final Class<?> viewType : applyHandlersMap.keySet()) {
                        if 
(viewType.isAssignableFrom(view.getModel().getClass())) {
@@ -172,9 +179,7 @@
                if (handler == null)
                        throw new IllegalArgumentException("This view type is 
not supported: " + view.getClass());
 
-               handler.apply(view);
-
-               logger.info(title + ": Visual Style applied in " + 
(System.currentTimeMillis() - start) + " msec.");
+               handler.apply(row, view);
        }
 
        /**

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleFactoryTest.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleFactoryTest.java
       2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleFactoryTest.java
       2012-05-07 21:06:52 UTC (rev 29135)
@@ -16,8 +16,7 @@
        public void setUp() throws Exception {
                final VisualLexiconManager lexManager = 
mock(VisualLexiconManager.class);
                final CyServiceRegistrar serviceRegistrar = 
mock(CyServiceRegistrar.class);
-               final CyNetworkManager cyNetworkManagerServiceRef = 
mock(CyNetworkManager.class);
-               factory = new VisualStyleFactoryImpl(lexManager, 
serviceRegistrar, cyNetworkManagerServiceRef);
+               factory = new VisualStyleFactoryImpl(lexManager, 
serviceRegistrar);
        }
 
        @After

Modified: 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
===================================================================
--- 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
      2012-05-07 20:54:07 UTC (rev 29134)
+++ 
core3/impl/trunk/vizmap-impl/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
      2012-05-07 21:06:52 UTC (rev 29135)
@@ -1,18 +1,25 @@
 package org.cytoscape.view.vizmap;
 
+import static org.junit.Assert.*;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 
 import org.cytoscape.ding.NetworkViewTestSupport;
+import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyTable;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualLexicon;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.presentation.property.BasicVisualLexicon;
@@ -20,8 +27,11 @@
 import org.cytoscape.view.vizmap.internal.VisualLexiconManager;
 import org.cytoscape.view.vizmap.internal.VisualStyleFactoryImpl;
 import org.junit.Before;
+import org.junit.Test;
 
 public class VisualStyleTest extends AbstractVisualStyleTest {
+       
+       private static final int NETWORK_SIZE = 1000;
 
        @Before
        public void setUp() throws Exception {
@@ -60,10 +70,53 @@
                when(lexManager.getAllVisualLexicon()).thenReturn(lexSet);
 
                final CyServiceRegistrar serviceRegistrar = 
mock(CyServiceRegistrar.class);
-               final CyNetworkManager cyNetworkManagerServiceRef = 
mock(CyNetworkManager.class);
-               final VisualStyleFactoryImpl visualStyleFactory = new 
VisualStyleFactoryImpl(lexManager, serviceRegistrar, 
cyNetworkManagerServiceRef);
+               final VisualStyleFactoryImpl visualStyleFactory = new 
VisualStyleFactoryImpl(lexManager, serviceRegistrar);
                originalTitle = "Style 1";
                newTitle = "Style 2";
                style = visualStyleFactory.createVisualStyle(originalTitle);
        }
+       
+       @Test
+       public void testApplyPerformance() throws Exception {
+               
+               NetworkViewTestSupport nvts = new NetworkViewTestSupport();
+               final CyNetwork largeNetwork = 
nvts.getNetworkFactory().createNetwork();
+               for(int i=0; i<NETWORK_SIZE; i++) {
+                       CyNode node = largeNetwork.addNode();
+               }
+               
+               CyNetworkView largeNetworkView = 
nvts.getNetworkViewFactory().createNetworkView(largeNetwork);
+               
+               final long start = System.currentTimeMillis();
+               style.apply(largeNetworkView);
+               final long endNetwork = System.currentTimeMillis()-start;
+               
+               System.out.println("* Apply to network takes " + endNetwork + " 
msec.");
+               
+               
+               // Pick 10 random nodes in the network
+               final List<View<CyNode>> views = new 
ArrayList<View<CyNode>>(largeNetworkView.getNodeViews());
+               Set<View<CyNode>> targets = new HashSet<View<CyNode>>();
+               for(int i=0; i<10; i++) {
+                       double rand = Math.random();
+                       int index = (int) (NETWORK_SIZE*rand);
+                       if(index<0)
+                               index=0;
+                       else if(index>NETWORK_SIZE-1)
+                               index = NETWORK_SIZE-1;
+                       
+                       targets.add(views.get(index));
+               }
+               
+               // Apply to individual views
+               final long start2 = System.currentTimeMillis();
+               for(final View<CyNode> view:targets)
+                       style.apply(largeNetwork.getRow(view.getModel()), view);
+               final long endNode = System.currentTimeMillis()-start2;
+               
+               System.out.println("* Apply to nodes takes " + endNode + " 
msec.");
+               
+               assertTrue(endNetwork>endNode);
+       }
+       
 }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to