Author: Christian Lopes
Date: 2011-02-14 15:00:39 -0800 (Mon, 14 Feb 2011)
New Revision: 24120

Modified:
   
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleSerializerImpl.java
   
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleSerializerTest.java
   core3/vizmap-impl/trunk/pom.xml
Log:
Added dependency to default-mappings, in order to fix an integration test error.
Change the visual style serializer implementation to modify the current default 
style when loading a style with the same name, which prevents 2 styles called 
"default" in the session (Note: a default style cannot be removed, so modifying 
its properties sounds reasonable).

Modified: 
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleSerializerImpl.java
===================================================================
--- 
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleSerializerImpl.java
        2011-02-14 22:49:44 UTC (rev 24119)
+++ 
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleSerializerImpl.java
        2011-02-14 23:00:39 UTC (rev 24120)
@@ -52,6 +52,7 @@
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
+import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyle;
 import org.cytoscape.view.vizmap.VisualStyleFactory;
 import org.cytoscape.view.vizmap.VisualStyleSerializer;
@@ -61,7 +62,7 @@
 public class VisualStyleSerializerImpl implements VisualStyleSerializer {
 
     private final VisualStyleFactory visualStyleFactory;
-    private final VisualStyle defaultStyle;
+    private final VisualMappingManager visualMappingManager;
     private final VisualMappingFunctionFactory discreteMappingFactory;
     private final VisualMappingFunctionFactory continuousMappingFactory;
     private final VisualMappingFunctionFactory passthroughMappingFactory;
@@ -79,16 +80,17 @@
     }
 
     public VisualStyleSerializerImpl(VisualStyleFactory visualStyleFactory,
+                                     VisualMappingManager visualMappingManager,
                                      VisualMappingFunctionFactory 
discreteMappingFactory,
                                      VisualMappingFunctionFactory 
continuousMappingFactory,
                                      VisualMappingFunctionFactory 
passthroughMappingFactory,
                                      RenderingEngineManager 
renderingEngineManager) {
         this.visualStyleFactory = visualStyleFactory;
+        this.visualMappingManager = visualMappingManager;
         this.discreteMappingFactory = discreteMappingFactory;
         this.continuousMappingFactory = continuousMappingFactory;
         this.passthroughMappingFactory = passthroughMappingFactory;
         this.renderingEngineManager = renderingEngineManager;
-        this.defaultStyle = 
visualStyleFactory.getInstance(VisualMappingManagerImpl.DEFAULT_STYLE_NAME);
     }
 
     public Properties createProperties(Collection<VisualStyle> styles) {
@@ -99,6 +101,7 @@
     public Collection<VisualStyle> createVisualStyles(Properties props) {
         Set<VisualStyle> styles = new HashSet<VisualStyle>();
         VisualLexicon lexicon = 
renderingEngineManager.getDefaultVisualLexicon();
+        VisualStyle defaultStyle = 
visualMappingManager.getDefaultVisualStyle();
 
         if (lexicon == null) {
             // TODO: warning
@@ -106,7 +109,7 @@
         }
 
         if (props != null) {
-            // 1. Group properties keys/values by visual style name:
+            // Group properties keys/values by visual style name:
             Map<String, Map<String, String>> styleNamesMap = new 
Hashtable<String, Map<String, String>>();
 
             for (String key : props.stringPropertyNames()) {
@@ -140,15 +143,22 @@
                 }
             }
 
-            // 2. Modify the default style:
-            // TODO
-
-            // 3. Create a Visual Style for each style name:
+            // Create a Visual Style for each style name:
             for (Entry<String, Map<String, String>> entry : 
styleNamesMap.entrySet()) {
-                // Each new style should be created from the default one
-                VisualStyle vs = visualStyleFactory.getInstance(defaultStyle);
-                vs.setTitle(entry.getKey());
+                String styleName = entry.getKey();
+                // Each new style should be created from the default one:
+                VisualStyle vs = null;
 
+                if 
(styleName.equalsIgnoreCase(VisualMappingManagerImpl.DEFAULT_STYLE_NAME)) {
+                    // If loading the default style, do not create another one,
+                    // but just modify the current default object!
+                    vs = defaultStyle;
+                    // TODO: delete mappings?
+                } else {
+                    vs = visualStyleFactory.getInstance(defaultStyle);
+                    vs.setTitle(styleName);
+                }
+
                 // Create and set the visual properties and mappings:
                 Map<String, String> vsProps = entry.getValue();
 
@@ -165,7 +175,8 @@
                     }
                 }
 
-                styles.add(vs);
+                // Do not add the modified default style to the list!
+                if (!vs.equals(defaultStyle)) styles.add(vs);
             }
         }
 

Modified: 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
     2011-02-14 22:49:44 UTC (rev 24119)
+++ 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
     2011-02-14 23:00:39 UTC (rev 24120)
@@ -16,7 +16,6 @@
                interface="org.cytoscape.view.vizmap.VisualStyleFactory">
        </osgi:service>
 
-
        <!-- Export Visual Style Serializer as an OSGi Service -->
        <osgi:service id="visualStyleSerializerService" 
ref="visualStyleSerializer"
                interface="org.cytoscape.view.vizmap.VisualStyleSerializer">

Modified: 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
  2011-02-14 22:49:44 UTC (rev 24119)
+++ 
core3/vizmap-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
  2011-02-14 23:00:39 UTC (rev 24120)
@@ -35,6 +35,7 @@
        <bean id="visualStyleSerializer"
                
class="org.cytoscape.view.vizmap.internal.VisualStyleSerializerImpl">
                <constructor-arg ref="visualStyleFactory" />
+               <constructor-arg ref="visualMappingManager" />
                <constructor-arg ref="discreteMappingFactoryServiceRef" />
                <constructor-arg ref="continuousMappingFactoryServiceRef" />
                <constructor-arg ref="passthroughMappingFactoryServiceRef" />

Modified: 
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleSerializerTest.java
===================================================================
--- 
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleSerializerTest.java
 2011-02-14 22:49:44 UTC (rev 24119)
+++ 
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleSerializerTest.java
 2011-02-14 23:00:39 UTC (rev 24120)
@@ -9,7 +9,6 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.awt.Color;
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Map;
@@ -19,7 +18,6 @@
 import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.presentation.property.NullVisualProperty;
 import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
-import org.cytoscape.view.vizmap.internal.VisualMappingManagerImpl;
 import org.cytoscape.view.vizmap.internal.VisualStyleSerializerImpl;
 import org.junit.Before;
 import org.junit.Test;
@@ -36,6 +34,7 @@
         styleNames = new Hashtable<VisualStyle, String>();
         styleProperties = new Hashtable<VisualStyle, Map<VisualProperty<?>, ? 
extends Object>>();
 
+        final VisualMappingManager visualMappingManager = 
mock(VisualMappingManager.class);
         final VisualMappingFunctionFactory discreteMappingFactory = 
mock(VisualMappingFunctionFactory.class);
         final VisualMappingFunctionFactory continuousMappingFactory = 
mock(VisualMappingFunctionFactory.class);
         final VisualMappingFunctionFactory passthroughMappingFactory = 
mock(VisualMappingFunctionFactory.class);
@@ -43,7 +42,7 @@
 
         final VisualStyleFactory visualStyleFactory = 
mock(VisualStyleFactory.class);
 
-        
when(visualStyleFactory.getInstance(VisualMappingManagerImpl.DEFAULT_STYLE_NAME)).thenReturn(dummyDefaultStyle);
+        
when(visualMappingManager.getDefaultVisualStyle()).thenReturn(dummyDefaultStyle);
         when(visualStyleFactory.getInstance(dummyDefaultStyle)).thenAnswer(new 
Answer<VisualStyle>() {
 
             public VisualStyle answer(InvocationOnMock invocation) throws 
Throwable {
@@ -55,7 +54,7 @@
         NullVisualProperty twoDRoot = new NullVisualProperty("TWO_D_ROOT", "2D 
Root Visual Property");
         when(renderingEngineManager.getDefaultVisualLexicon()).thenReturn(new 
TwoDVisualLexicon(twoDRoot));
 
-        serializer = new VisualStyleSerializerImpl(visualStyleFactory, 
discreteMappingFactory,
+        serializer = new VisualStyleSerializerImpl(visualStyleFactory, 
visualMappingManager, discreteMappingFactory,
                                                    continuousMappingFactory, 
passthroughMappingFactory,
                                                    renderingEngineManager);
     }
@@ -81,10 +80,10 @@
             assertTrue(title.equals(styleNames.get(vs)));
 
             if (title.equals("Style A")) {
-//                assertEquals(new Color(255, 255, 255), 
vs.getDefaultValue(TwoDVisualLexicon.NETWORK_BACKGROUND_PAINT));
-//                assertEquals(new Double(2), 
vs.getDefaultValue(TwoDVisualLexicon.EDGE_WIDTH));
+                //                assertEquals(new Color(255, 255, 255), 
vs.getDefaultValue(TwoDVisualLexicon.NETWORK_BACKGROUND_PAINT));
+                //                assertEquals(new Double(2), 
vs.getDefaultValue(TwoDVisualLexicon.EDGE_WIDTH));
             } else if (title.equals("Style B")) {
-//                assertEquals(new Color(0, 255, 0), 
vs.getDefaultValue(TwoDVisualLexicon.NETWORK_BACKGROUND_PAINT));
+                //                assertEquals(new Color(0, 255, 0), 
vs.getDefaultValue(TwoDVisualLexicon.NETWORK_BACKGROUND_PAINT));
             }
         }
     }

Modified: core3/vizmap-impl/trunk/pom.xml
===================================================================
--- core3/vizmap-impl/trunk/pom.xml     2011-02-14 22:49:44 UTC (rev 24119)
+++ core3/vizmap-impl/trunk/pom.xml     2011-02-14 23:00:39 UTC (rev 24120)
@@ -114,5 +114,11 @@
                        <version>3.0.0-alpha2</version>
                        <scope>provided</scope>
                </dependency>
+               <dependency>
+            <groupId>org.cytoscape</groupId>
+            <artifactId>default-mappings</artifactId>
+            <version>3.0.0-alpha1</version>
+            <scope>provided</scope>
+        </dependency>
        </dependencies>
 </project>

-- 
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