Author: kono
Date: 2010-07-08 17:08:23 -0700 (Thu, 08 Jul 2010)
New Revision: 20863

Modified:
   cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientOvalLayer.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientRoundRectangleLayer.java
   cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java
Log:
Fixed vector graphics restore code.  However, still update timing is broken.  
Need to check redraw timing.

Modified: cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-07-08 22:57:16 UTC (rev 20862)
+++ cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-07-09 00:08:23 UTC (rev 20863)
@@ -91,6 +91,7 @@
 import cytoscape.visual.customgraphic.Taggable;
 import cytoscape.visual.customgraphic.impl.AbstractDCustomGraphics;
 import cytoscape.visual.customgraphic.impl.bitmap.URLImageCustomGraphics;
+import cytoscape.visual.parsers.GraphicsParser;
 
 /**
  * Reader to load CYtoscape Session file (.cys).<br>
@@ -405,6 +406,9 @@
                        // Split string into blocks.
                        // This line should have: class Name, ID, name, tags.
                        final String[] parts = propEntry.split(",");
+                       if(parts.length < 3)
+                               continue;
+                       
                        String name = parts[parts.length - 2];
                        if (name.contains("___"))
                                name = name.replace("___", ",");
@@ -446,7 +450,8 @@
                System.out.println("Need to restore non-image graphics: " + 
imageProps.size());
                
                //TODO: Fix vector images
-
+               restoreNonImageGraphics(imageProps, manager);
+               
                // Reset the counter
                final Long currentMax = manager.getIDSet().last();
                IDGenerator.getIDGenerator().initCounter(currentMax+1);
@@ -456,14 +461,18 @@
                
                
                for(Object key:imageProps.keySet()) {
-//                     System.out.println("Key = " + key +", val = " + 
imageProps.getProperty(key.toString()));
-//                     final CyCustomGraphics cg = 
parser.parseStringValue(imageProps.getProperty(key.toString()));
-//                     
-//                     if(cg != null)
-//                             manager.addGraphics(cg, null);
+                       final String value = 
imageProps.getProperty(key.toString());
+                       
+                       System.out.println("Key = " + key +", val = " + value);
+                       final CyCustomGraphics cg = 
parser.parseStringValue(imageProps.getProperty(key.toString()));
+                       System.out.println("CG result = " + cg);
+                       if(cg != null)
+                               manager.addGraphics(cg, null);
                }
        }
        
+       private final GraphicsParser parser = new GraphicsParser();
+       
 
        /**
         * Read a session file.

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
       2010-07-08 22:57:16 UTC (rev 20862)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
       2010-07-09 00:08:23 UTC (rev 20863)
@@ -1,5 +1,8 @@
 package cytoscape.visual.customgraphic;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
 import cytoscape.Cytoscape;
 
 public class DefaultCyCustomGraphicsParser implements CyCustomGraphicsParser {
@@ -15,15 +18,19 @@
                
                final String className = parts[0];
                final Long id = Long.parseLong(parts[1]);
+               final String name = parts[2];
 
-               CyCustomGraphics cg = Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsManager().getByID(id);
+//             CyCustomGraphics cg = Cytoscape.getVisualMappingManager()
+//                             .getCustomGraphicsManager().getByID(id);
                
+               
+               CyCustomGraphics cg = null;
                if(cg == null) {
                        // Create new one by reflection
                        try {
                                final Class<?> cls = Class.forName(className);
-                               cg = (CyCustomGraphics) cls.newInstance();
+                               final Constructor<?> ct = 
cls.getConstructor(Long.class, String.class);
+                               cg = (CyCustomGraphics) ct.newInstance(id, 
name);
                                cg.setDisplayName(parts[2]);
                                Cytoscape.getVisualMappingManager()
                                .getCustomGraphicsManager().addGraphics(cg, 
null);
@@ -38,6 +45,18 @@
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                return null;
+                       } catch (SecurityException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       } catch (NoSuchMethodException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       } catch (IllegalArgumentException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       } catch (InvocationTargetException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
                        }
                }
                

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
     2010-07-08 22:57:16 UTC (rev 20862)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
     2010-07-09 00:08:23 UTC (rev 20863)
@@ -48,8 +48,8 @@
        protected final Map<String, CustomGraphicsProperty<?>> props;
 
        
-       public GradientLayerCustomGraphics(final String name) {
-               super(name);
+       public GradientLayerCustomGraphics(final Long id, final String name) {
+               super(id, name);
                width = DEF_W;
                height = DEF_H;
                props = new HashMap<String, CustomGraphicsProperty<?>>();

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientOvalLayer.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientOvalLayer.java
       2010-07-08 22:57:16 UTC (rev 20862)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientOvalLayer.java
       2010-07-09 00:08:23 UTC (rev 20863)
@@ -5,7 +5,7 @@
 import java.awt.geom.Ellipse2D;
 
 import cytoscape.render.stateful.CustomGraphic;
-import cytoscape.visual.customgraphic.Layer;
+import cytoscape.visual.customgraphic.IDGenerator;
 import cytoscape.visual.customgraphic.impl.DLayer;
 import cytoscape.visual.customgraphic.paint.GradientPaintFactory;
 
@@ -14,10 +14,16 @@
        // Name of this custom graphics.
        private static final String NAME = "Glossy Oval Layer";
 
+       
        public GradientOvalLayer() {
-               super(NAME);
+               this(IDGenerator.getIDGenerator().getNextId(), NAME);
        }
        
+       
+       public GradientOvalLayer(Long id, String name) {
+               super(id, name);
+       }
+       
        protected void renderImage(Graphics graphics) {
                super.renderImage(graphics);
                

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientRoundRectangleLayer.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientRoundRectangleLayer.java
     2010-07-08 22:57:16 UTC (rev 20862)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientRoundRectangleLayer.java
     2010-07-09 00:08:23 UTC (rev 20863)
@@ -5,6 +5,7 @@
 import java.awt.geom.RoundRectangle2D;
 
 import cytoscape.render.stateful.CustomGraphic;
+import cytoscape.visual.customgraphic.IDGenerator;
 import cytoscape.visual.customgraphic.Layer;
 import cytoscape.visual.customgraphic.impl.DLayer;
 import cytoscape.visual.customgraphic.paint.GradientPaintFactory;
@@ -15,10 +16,16 @@
        private static final String NAME = "Glossy Round Rectangle Layer";
        private int r =20;
        
+       
        public GradientRoundRectangleLayer() {
-               super(NAME);
+               this(IDGenerator.getIDGenerator().getNextId(), NAME);
        }
        
+       
+       public GradientRoundRectangleLayer(Long id, String name) {
+               super(id, name);
+       }
+       
        protected void renderImage(Graphics graphics) {
                super.renderImage(graphics);
                

Modified: cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java    
2010-07-08 22:57:16 UTC (rev 20862)
+++ cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java    
2010-07-09 00:08:23 UTC (rev 20863)
@@ -22,7 +22,6 @@
        // Maybe injected from outside if we use DI framework.
        private final CyCustomGraphicsParserFactory parserFactory;
        
-       
        private final CyCustomGraphicsParser defaultParser;
        
        public GraphicsParser() {
@@ -41,32 +40,55 @@
                return parse(value);
        }
        
+       
+       /**
+        * Parse given string.
+        * 
+        * Syntax 1: (URL)
+        * Syntax 2: (Class Name, ID, Name, Tags)
+        * 
+        * @param value
+        * @return
+        */
        private CyCustomGraphics parse(String value) {
                if(value == null || value.equals(NULL_CG))
                        return null;
                
-               // Special case:  URL String.
+               // Syntax 1:  URL String.
                try {
                        final URL url = new URL(value);
                        CyCustomGraphics graphics = 
Cytoscape.getVisualMappingManager().getCustomGraphicsManager().getBySourceURL(url);
                        if(graphics == null) {
+                               // Currently not in the Manager.  Need to 
create new instance.
                                graphics = new 
URLImageCustomGraphics(url.toString());
+                               // Use URL as display name
+                               graphics.setDisplayName(value);
+                               
+                               // Register to manager.
                                
Cytoscape.getVisualMappingManager().getCustomGraphicsManager().addGraphics(graphics,
 url);
                        }
                        return graphics;
                } catch (IOException e) {
-                       logger.warn("Invalid URL found. This will be ignored: " 
+ value);
+                       
+                       // Syntax 2:
+                       final String[] parts = value.split(",");
+                       if(parts.length<4)
+                               return null;
+                       
+                       // Extract class name
+                       final String className = parts[0];
+                       
+                       // Get class-specific parser
+                       final CyCustomGraphicsParser parser = 
parserFactory.getParser(className);
+                       
+                       if(parser == null) 
+                               return defaultParser.getInstance(value);
+                       else
+                               return parser.getInstance(value);
+                       
                }
-                               
-               final String[] parts = value.split(",");
-               // Extract class
-               final String className = parts[0];
-               final CyCustomGraphicsParser parser = 
parserFactory.getParser(className);
-               
-               if(parser == null) 
-                       return defaultParser.getInstance(value);
-               else
-                       return parser.getInstance(value);
        }
+       
+       
 
 }

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