Author: jm
Date: 2011-01-25 08:53:35 -0800 (Tue, 25 Jan 2011)
New Revision: 23600

Modified:
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReader.java
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderFactory.java
   
core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderTest.java
Log:
Updated GMLNetworkViewReader to use default VisualLexicon instead of that of 
current RenderingEngine

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReader.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReader.java
      2011-01-25 16:05:48 UTC (rev 23599)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReader.java
      2011-01-25 16:53:35 UTC (rev 23600)
@@ -31,7 +31,6 @@
 
 
 import java.awt.Color;
-import java.awt.Paint;
 import java.io.InputStream;
 import java.io.StringWriter;
 import java.util.ArrayList;
@@ -59,6 +58,7 @@
 import org.cytoscape.view.model.VisualLexicon;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.presentation.RenderingEngine;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
 import org.cytoscape.view.vizmap.VisualStyle;
 import org.cytoscape.work.AbstractTask;
@@ -187,7 +187,7 @@
        private final InputStream inputStream;
        private final CyNetworkFactory networkFactory;
        private final CyNetworkViewFactory viewFactory;
-       private final CyApplicationManager applicationManager;
+       private final RenderingEngineManager renderingEngineManager;
        
        private CyNetwork network;
        private CyNetworkView view;
@@ -202,12 +202,12 @@
         *
         */
        public GMLNetworkViewReader(InputStream inputStream, CyNetworkFactory 
networkFactory,
-                                               CyNetworkViewFactory 
viewFactory, CyApplicationManager applicationManager)
+                                               CyNetworkViewFactory 
viewFactory, RenderingEngineManager renderingEngineManager)
        {
                this.inputStream = inputStream;
                this.networkFactory = networkFactory;
                this.viewFactory = viewFactory;
-               this.applicationManager = applicationManager;
+               this.renderingEngineManager = renderingEngineManager;
                
                // Set new style name
                edge_names = new Vector<CyEdge>();
@@ -698,70 +698,52 @@
         * matches to the "graphics" key word
         */
        private void layoutNodeGraphics(CyNetworkView myView, List<KeyValue> 
list, View<CyNode> nodeView) {
-               RenderingEngine<CyNetwork> engine = 
applicationManager.getCurrentRenderingEngine();
-               if (engine == null) {
-                       // TODO: Remove this once CyNetworkManager can provide 
an engine
-                       //       instance with zero networks loaded.
-                       return;
-               }
-               VisualLexicon lexicon = engine.getVisualLexicon();
-               
+               VisualLexicon lexicon = 
renderingEngineManager.getDefaultVisualLexicon();
                Collection<VisualProperty<?>> properties = 
lexicon.getAllDescendants(TwoDVisualLexicon.NODE);
                for (VisualProperty<?> property : properties) {
                        String id = property.getIdString();
                        
                        for (KeyValue keyVal : list) {
                                if (keyVal.key.equals(X) && 
id.equals("NODE_X_LOCATION")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(Y) && 
id.equals("NODE_Y_LOCATION")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(W) && 
id.equals("NODE_X_SIZE")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(H) && 
id.equals("NODE_Y_SIZE")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(FILL) && 
id.equals("NODE_COLOR")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asPaint(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(OUTLINE) && 
id.equals("NODE_BORDER_PAINT")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asPaint(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(OUTLINE_WIDTH) && 
id.equals("NODE_BORDER_WIDTH")) {
-                                       nodeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       nodeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
+                               } else if (keyVal.key.equals(TYPE) && 
id.equals("NODE_SHAPE")) {
+                                       String type = (String) keyVal.value;
+                                       String value = null;
+                                       if (type.equals(ELLIPSE)) {
+                                               value = "ELLIPSE";
+                                       } else if (type.equals(RECTANGLE)) {
+                                               value = "RECT";
+                                       } else if (type.equals(DIAMOND)) {
+                                               value = "DIAMOND";
+                                       } else if (type.equals(HEXAGON)) {
+                                               value = "HEXAGON";
+                                       } else if (type.equals(OCTAGON)) {
+                                               value = "OCTAGON";
+                                       } else if (type.equals(PARALELLOGRAM)) {
+                                               value = "PARALLELOGRAM";
+                                       } else if (type.equals(TRIANGLE)) {
+                                               value = "TRIANGLE";
+                                       }
+                                       if (value != null) {
+                                               
nodeView.setVisualProperty(property, (Object) 
property.parseSerializableString(value));
+                                       }
                                }
                        }
                }
-//                     } else if (keyVal.key.equals(TYPE)) {
-//                             String type = (String) keyVal.value;
-//
-//                             if (type.equals(ELLIPSE)) {
-//                                     nodeView.setShape(NodeView.ELLIPSE);
-//                             } else if (type.equals(RECTANGLE)) {
-//                                     nodeView.setShape(NodeView.RECTANGLE);
-//                             } else if (type.equals(DIAMOND)) {
-//                                     nodeView.setShape(NodeView.DIAMOND);
-//                             } else if (type.equals(HEXAGON)) {
-//                                     nodeView.setShape(NodeView.HEXAGON);
-//                             } else if (type.equals(OCTAGON)) {
-//                                     nodeView.setShape(NodeView.OCTAGON);
-//                             } else if (type.equals(PARALELLOGRAM)) {
-//                                     
nodeView.setShape(NodeView.PARALELLOGRAM);
-//                             } else if (type.equals(TRIANGLE)) {
-//                                     nodeView.setShape(NodeView.TRIANGLE);
-//                             }
        }
 
-       private Paint asPaint(Object object) {
-               if (object instanceof String) {
-                       return getColor((String) object);
-               }
-               return null;
-       }
-
-       private Double asDouble(Object object) {
-               if (object instanceof Number) {
-                       return ((Number) object).doubleValue();
-               }
-               return null;
-       }
-       
        //
        // Extract node attributes from GML file
        private void extractNodeAttributes(List<KeyValue> list, CyNode node) {
@@ -913,13 +895,7 @@
        //
        @SuppressWarnings("unchecked")
        private void layoutEdgeGraphics(CyNetworkView myView, List<KeyValue> 
list, View<CyEdge> edgeView) {
-               RenderingEngine<CyNetwork> engine = 
applicationManager.getCurrentRenderingEngine();
-               if (engine == null) {
-                       // TODO: Remove this once CyNetworkManager can provide 
an engine
-                       //       instance with zero networks loaded.
-                       return;
-               }
-               VisualLexicon lexicon = engine.getVisualLexicon();
+               VisualLexicon lexicon = 
renderingEngineManager.getDefaultVisualLexicon();
                Collection<VisualProperty<?>> properties = 
lexicon.getAllDescendants(TwoDVisualLexicon.NODE);
                for (VisualProperty<?> property : properties) {
                        String id = property.getIdString();
@@ -930,9 +906,23 @@
                                if (keyVal.key.equals(LINE)) {
                                        layoutEdgeGraphicsLine(myView, 
(List<KeyValue>) keyVal.value, edgeView);
                                } else if (keyVal.key.equals(WIDTH) && 
id.equals("EDGE_WIDTH")) {
-                                       edgeView.setVisualProperty(property, 
(Object) asDouble(keyVal.value));
+                                       edgeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
                                } else if (keyVal.key.equals(FILL) && 
id.equals("EDGE_COLOR")) {
-                                       edgeView.setVisualProperty(property, 
(Object) asPaint(keyVal.value));
+                                       edgeView.setVisualProperty(property, 
(Object) property.parseSerializableString(keyVal.value.toString()));
+                               } else if (keyVal.key.equals(ARROW) && 
id.equals("EDGE_SOURCE_ARROW_SHAPE")) {
+                                       String value = (String) keyVal.value;
+                                       if (value.equals(ARROW_BOTH) || 
value.equals(ARROW_FIRST)) {
+                                               
edgeView.setVisualProperty(property, (Object) 
property.parseSerializableString("ARROW"));
+                                       }
+                               } else if (keyVal.key.equals(ARROW) && 
id.equals("EDGE_TARGET_ARROW_SHAPE")) {
+                                       String value = (String) keyVal.value;
+                                       if (value.equals(ARROW_BOTH) || 
value.equals(ARROW_LAST)) {
+                                               
edgeView.setVisualProperty(property, (Object) 
property.parseSerializableString("ARROW"));
+                                       }
+                               } else if (keyVal.key.equals(SOURCE_ARROW) && 
id.equals("EDGE_SOURCE_ARROW_SHAPE")) {
+                                       edgeView.setVisualProperty(property, 
(Object) property.parseSerializableString("ARROW"));
+                               } else if (keyVal.key.equals(TARGET_ARROW) && 
id.equals("EDGE_TARGET_ARROW_SHAPE")) {
+                                       edgeView.setVisualProperty(property, 
(Object) property.parseSerializableString("ARROW"));
                                }
                        }
                }
@@ -945,24 +935,6 @@
 //                             } else if (value.equals(CURVED_LINES)) {
 //                                     
edgeView.setLineType(EdgeView.CURVED_LINES);
 //                             }
-//                     } else if (keyVal.key.equals(ARROW)) {
-//                             // The position of the arrow.
-//                             // There are 4 states: no arrows, both ends 
have arrows, source,
-//                             // or target.
-//                             //
-//                             // The arrow type below is hard-coded since GML 
does not
-//                             // support shape of the arrow.
-//                             if (keyVal.value.equals(ARROW_FIRST)) {
-//                                     edgeView.setSourceEdgeEnd(2);
-//                             } else if (keyVal.value.equals(ARROW_LAST)) {
-//                                     edgeView.setTargetEdgeEnd(2);
-//                             } else if (keyVal.value.equals(ARROW_BOTH)) {
-//                                     edgeView.setSourceEdgeEnd(2);
-//                                     edgeView.setTargetEdgeEnd(2);
-//                             } else if (keyVal.value.equals(ARROW_NONE)) {
-//                                     // Do nothing. No arrows.
-//                             }
-//
 //                             if (keyVal.key.equals(SOURCE_ARROW)) {
 //                                     edgeView.setSourceEdgeEnd(((Number) 
keyVal.value).intValue());
 //                             } else if (keyVal.value.equals(TARGET_ARROW)) {
@@ -1002,11 +974,4 @@
                }
                */
        }
-
-       /**
-        * Create a color object from the string like it is stored in a gml file
-        */
-       private Color getColor(String colorString) {
-               return new Color(Integer.parseInt(colorString.substring(1), 
16));
-       }
 }

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderFactory.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderFactory.java
       2011-01-25 16:05:48 UTC (rev 23599)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderFactory.java
       2011-01-25 16:53:35 UTC (rev 23600)
@@ -4,25 +4,25 @@
 import org.cytoscape.io.CyFileFilter;
 import org.cytoscape.io.internal.read.AbstractNetworkViewReaderFactory;
 import org.cytoscape.model.CyNetworkFactory;
-import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.work.TaskIterator;
 
 
 public class GMLNetworkViewReaderFactory extends 
AbstractNetworkViewReaderFactory {
-       private final CyApplicationManager applicationManager;
+       private final RenderingEngineManager renderingEngineManager;
 
        public GMLNetworkViewReaderFactory(CyFileFilter filter,
                        CyNetworkViewFactory networkViewFactory,
                        CyNetworkFactory networkFactory,
-                       CyApplicationManager applicationManager) {
+                       RenderingEngineManager renderingEngineManager) {
                super(filter, networkViewFactory, networkFactory);
-               this.applicationManager = applicationManager;
+               this.renderingEngineManager = renderingEngineManager;
        }
 
        @Override
        public TaskIterator getTaskIterator() {
-               return new TaskIterator(new GMLNetworkViewReader(inputStream, 
cyNetworkFactory, cyNetworkViewFactory, applicationManager));
+               return new TaskIterator(new GMLNetworkViewReader(inputStream, 
cyNetworkFactory, cyNetworkViewFactory, renderingEngineManager));
        }
 
 }

Modified: 
core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml  
    2011-01-25 16:05:48 UTC (rev 23599)
+++ 
core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml  
    2011-01-25 16:53:35 UTC (rev 23600)
@@ -39,6 +39,9 @@
                
interface="org.cytoscape.view.vizmap.VisualMappingFunctionFactory"
                filter="(mapping.type=discrete)" />
 
+       <osgi:reference id="renderingEngineManagerServiceRef"
+               
interface="org.cytoscape.view.presentation.RenderingEngineManager" />
+
        <!-- Export services -->
        <osgi:service id="cyNetworkViewReaderManagerService" 
ref="cyNetworkViewReaderManager"
                interface="org.cytoscape.io.read.CyNetworkViewReaderManager">

Modified: 
core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
2011-01-25 16:05:48 UTC (rev 23599)
+++ core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
2011-01-25 16:53:35 UTC (rev 23600)
@@ -266,7 +266,7 @@
                <constructor-arg ref="gmlFilter" />
                <constructor-arg ref="cyNetworkViewFactoryServiceRef" />
                <constructor-arg ref="cyNetworkFactoryServiceRef" />
-               <constructor-arg ref="cyApplicationManagerServiceRef" />
+               <constructor-arg ref="renderingEngineManagerServiceRef" />
        </bean>
 
        <!-- Writer Factories -->

Modified: 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderTest.java
===================================================================
--- 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderTest.java
  2011-01-25 16:05:48 UTC (rev 23599)
+++ 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/gml/GMLNetworkViewReaderTest.java
  2011-01-25 16:53:35 UTC (rev 23600)
@@ -2,28 +2,23 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.when;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.util.LinkedList;
 
 import org.cytoscape.io.internal.read.AbstractNetworkViewReaderTester;
 import org.cytoscape.model.CyNetwork;
-import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.VisualLexicon;
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.presentation.RenderingEngine;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
 public class GMLNetworkViewReaderTest extends AbstractNetworkViewReaderTester {
-       @Mock private CyApplicationManager applicationManager;
-       @Mock private RenderingEngine<CyNetwork> engine;
+       @Mock private RenderingEngineManager renderingEngineManager;
        @Mock private VisualLexicon lexicon;
 
        @Before
@@ -32,8 +27,7 @@
                
                MockitoAnnotations.initMocks(this);
                
-               
when(applicationManager.getCurrentRenderingEngine()).thenReturn(engine);
-               when(engine.getVisualLexicon()).thenReturn(lexicon);
+               
when(renderingEngineManager.getDefaultVisualLexicon()).thenReturn(lexicon);
                
                // FIXME
                
//when(lexicon.getVisualProperties(any(String.class))).thenReturn(new 
LinkedList<VisualProperty<?>>());
@@ -43,7 +37,7 @@
        public void testLoadGml() throws Exception {
                File file = new 
File("src/test/resources/testData/gml/example1.gml");
                GMLNetworkViewReader reader =
-                       new GMLNetworkViewReader(new FileInputStream(file), 
netFactory, viewFactory, applicationManager);
+                       new GMLNetworkViewReader(new FileInputStream(file), 
netFactory, viewFactory, renderingEngineManager);
                reader.run(taskMonitor);
                CyNetworkView[] networkViews = reader.getNetworkViews();
                

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