Author: kono
Date: 2010-07-08 15:06:32 -0700 (Thu, 08 Jul 2010)
New Revision: 20860

Modified:
   cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
   cytoscape/trunk/src/cytoscape/data/writers/CytoscapeSessionWriter.java
   cytoscape/trunk/src/cytoscape/visual/VisualMappingManager.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
   cytoscape/trunk/src/cytoscape/visual/customgraphic/PersistImageTask.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsBrowser.java
   
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsManagerDialog.java
   cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java
   cytoscape/trunk/src/cytoscape/visual/properties/NodeCustomGraphicsProp.java
Log:
Comments are added to some classes related to Custom Graphics.

Modified: cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-07-08 22:06:32 UTC (rev 20860)
@@ -323,11 +323,13 @@
                                        bookmarksFileURL = new URL("jar:" + 
sourceURL.toString()
                                                        + "!/" + entryName);
                                } else if (entryName.endsWith(".png")) {
+                                       
                                        // All bitmap images are saved as PNG 
files.
                                        final URL imageURL = new URL("jar:" + 
sourceURL.toString()
                                                        + "!/" + entryName);
-                                       restoreCustomGraphics(entryName, 
imageURL);
+                                       loadBitmapImageFiles(entryName, 
imageURL);
                                } else if 
(entryName.endsWith(CustomGraphicsManager.METADATA_FILE)) {
+                                       // This is the image property file.
                                        imagePropsURL = new URL("jar:" + 
sourceURL.toString()
                                                        + "!/" + entryName);
                                } else
@@ -362,42 +364,55 @@
                }
        }
 
-       private void restoreCustomGraphics(final String entryName,
-                       final URL imageURL) throws IOException {
+       
+       private void loadBitmapImageFiles(final String entryName,
+                       final URL imageFileURL) throws IOException {
                final String[] ent = entryName.split(System
                                .getProperty("file.separator"));
                final String displayName = ent[ent.length - 1];
                String name = displayName.split("\\.")[0];
 
-               imageMap.put(name, imageURL);
+               imageMap.put(name, imageFileURL);
        }
        
 
-       private void createCustomGraphics() throws IOException {
+       private void restoreCustomGraphics() throws IOException {
                
                // Restore metadata
                final Properties imageProps = new Properties();
                imageProps.load(URLUtil.getBasicInputStream(imagePropsURL));
 
-               // Remove all custom graphics
-               final CustomGraphicsManager pool = 
Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsPool();
-               pool.removeAll();
+               // Remove all custom graphics from current session
+               final CustomGraphicsManager manager = 
Cytoscape.getVisualMappingManager()
+                               .getCustomGraphicsManager();
+               manager.removeAll();
 
+               // First, restore image-based custom graphics
                for (String id : imageMap.keySet()) {
+                       
+                       // Create Custom Graphics with specified ID.
                        final CyCustomGraphics graphics = new 
URLImageCustomGraphics(Long.parseLong(id),
                                        imageMap.get(id).toString());
+                       
+                       // This property contains display name and tags.
                        final String propEntry = imageProps.getProperty(id);
+                       if(propEntry == null)
+                               continue;
                        
-                       // Remove image prop.
+                       // Remove this prop.
                        imageProps.remove(id);
                        
-                       String[] parts = propEntry.split(",");
+                       // Split string into blocks.
+                       // This line should have: class Name, ID, name, tags.
+                       final String[] parts = propEntry.split(",");
                        String name = parts[parts.length - 2];
                        if (name.contains("___"))
                                name = name.replace("___", ",");
+                       
+                       // Set display name
                        graphics.setDisplayName(name);
 
+                       // Restore tags
                        String tagStr = null;
                        if (parts.length > 3 && graphics instanceof Taggable) {
                                tagStr = parts[3];
@@ -406,19 +421,24 @@
                                                + 
AbstractDCustomGraphics.LIST_DELIMITER);
                                for (String tag : tagParts)
                                        tags.add(tag.trim());
+                               
+                               // Add all restored tags.
                                ((Taggable) graphics).getTags().addAll(tags);
                        }
 
+                       
+                       // If name is a valid URL, store as data source.
                        try {
                                final URL nameAsURL = new URL(name);
                                // The name is URL. Use as its source.
-                               final CyCustomGraphics currentValue = 
pool.getBySourceURL(nameAsURL);
+                               final CyCustomGraphics currentValue = 
manager.getBySourceURL(nameAsURL);
                                
                                // Add only if the graphics does not exist in 
memory.
                                if(currentValue == null)
-                                       pool.addGraphics(graphics, nameAsURL);
+                                       manager.addGraphics(graphics, 
nameAsURL);
                        } catch (MalformedURLException e) {
-                               pool.addGraphics(graphics, null);
+                               // Name is not an URL.  These should be added 
always.
+                               manager.addGraphics(graphics, null);
                        }
                }
                
@@ -426,17 +446,24 @@
                System.out.println("Need to restore non-image graphics: " + 
imageProps.size());
                
                //TODO: Fix vector images
-//             for(Object key:imageProps.keySet()) {
-//                     System.out.println("Key = " + key +", val = " + 
imageProps.getProperty(key.toString()));
-//                     CyCustomGraphics<?> nonImage = 
parser.parseStringValue(imageProps.getProperty(key.toString()));
-//                     pool.addGraphics(nonImage, null);
-//             }
-               
+
                // Reset the counter
-               final Long currentMax = pool.getIDSet().last();
+               final Long currentMax = manager.getIDSet().last();
                IDGenerator.getIDGenerator().initCounter(currentMax+1);
        }
        
+       private void restoreNonImageGraphics(final Properties imageProps, final 
CustomGraphicsManager manager) {
+               
+               
+               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);
+               }
+       }
+       
 
        /**
         * Read a session file.
@@ -597,8 +624,9 @@
                        throw e;
                }
 
+               // Need to restore custom graphics BEFORE Visual Styles.
                if (imagePropsURL != null)
-                       createCustomGraphics();
+                       restoreCustomGraphics();
 
                if (loadVizmap) {
                        // restore vizmap.props

Modified: cytoscape/trunk/src/cytoscape/data/writers/CytoscapeSessionWriter.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/writers/CytoscapeSessionWriter.java      
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/data/writers/CytoscapeSessionWriter.java      
2010-07-08 22:06:32 UTC (rev 20860)
@@ -364,7 +364,7 @@
        
        
        private void zipCustomGraphics() throws IOException, 
InterruptedException {
-               final CustomGraphicsManager pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsPool();
+               final CustomGraphicsManager pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsManager();
                // Collect all custom graphics
                final Collection<CyCustomGraphics> customGraphics = 
pool.getAll();
                

Modified: cytoscape/trunk/src/cytoscape/visual/VisualMappingManager.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/VisualMappingManager.java      
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/visual/VisualMappingManager.java      
2010-07-08 22:06:32 UTC (rev 20860)
@@ -442,7 +442,7 @@
                myEdgeApp.applyAppearance(edgeView, activeVS.getDependency());
        }
 
-       public CustomGraphicsManager getCustomGraphicsPool() {
+       public CustomGraphicsManager getCustomGraphicsManager() {
                return pool;
        }
        

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
       2010-07-08 21:13:33 UTC (rev 20859)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/DefaultCyCustomGraphicsParser.java
       2010-07-08 22:06:32 UTC (rev 20860)
@@ -17,7 +17,7 @@
                final Long id = Long.parseLong(parts[1]);
 
                CyCustomGraphics cg = Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsPool().getByID(id);
+                               .getCustomGraphicsManager().getByID(id);
                
                if(cg == null) {
                        // Create new one by reflection
@@ -26,7 +26,7 @@
                                cg = (CyCustomGraphics) cls.newInstance();
                                cg.setDisplayName(parts[2]);
                                Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsPool().addGraphics(cg, null);
+                               .getCustomGraphicsManager().addGraphics(cg, 
null);
                        } catch (ClassNotFoundException e) {
                                e.printStackTrace();
                                return null;

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/PersistImageTask.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/customgraphic/PersistImageTask.java    
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/visual/customgraphic/PersistImageTask.java    
2010-07-08 22:06:32 UTC (rev 20860)
@@ -47,7 +47,7 @@
 
                final long startTime = System.currentTimeMillis();
                final CustomGraphicsManager pool = 
Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsPool();
+                               .getCustomGraphicsManager();
 
                final ExecutorService exService = Executors
                                .newFixedThreadPool(NUM_THREADS);

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
        2010-07-08 21:13:33 UTC (rev 20859)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/URLImageCustomGraphicsParser.java
        2010-07-08 22:06:32 UTC (rev 20860)
@@ -36,7 +36,7 @@
 
                final String imageName = entry[1];
                CyCustomGraphics cg = Cytoscape.getVisualMappingManager()
-                               
.getCustomGraphicsPool().getByID(Long.parseLong(imageName));
+                               
.getCustomGraphicsManager().getByID(Long.parseLong(imageName));
                cg.setDisplayName(entry[2]);
                return cg;
        }

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
     2010-07-08 21:13:33 UTC (rev 20859)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/impl/vector/GradientLayerCustomGraphics.java
     2010-07-08 22:06:32 UTC (rev 20860)
@@ -28,7 +28,7 @@
        // Bound of this graphics
        protected Shape bound;
        
-       private static final float FIT = 1.0f;
+       private static final float FIT = 0.9f;
        
        protected static final String COLOR1 = "Color 1";
        protected static final String COLOR2 = "Color 2";
@@ -39,8 +39,8 @@
        // Pre-Rendered image for icon.
        protected BufferedImage rendered;
        
-       private static final Color transparentWhite = new Color(255, 255, 255, 
150);
-       private static final Color transparentBlack = new Color(150, 150, 150, 
100);
+       private static final Color transparentWhite = new Color(255, 255, 255, 
100);
+       private static final Color transparentBlack = new Color(100, 100, 100, 
100);
        
        private static final int DEF_W = 100;
        private static final int DEF_H = 100;

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsBrowser.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsBrowser.java
    2010-07-08 21:13:33 UTC (rev 20859)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsBrowser.java
    2010-07-08 22:06:32 UTC (rev 20860)
@@ -56,7 +56,7 @@
         * @throws IOException
         */
        public CustomGraphicsBrowser() throws IOException {
-               pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsPool();
+               pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsManager();
 
                initComponents();
                addAllImages();

Modified: 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsManagerDialog.java
===================================================================
--- 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsManagerDialog.java
      2010-07-08 21:13:33 UTC (rev 20859)
+++ 
cytoscape/trunk/src/cytoscape/visual/customgraphic/ui/CustomGraphicsManagerDialog.java
      2010-07-08 22:06:32 UTC (rev 20860)
@@ -38,7 +38,7 @@
        /** Creates new form CustomGraphicsManagerDialog */
        public CustomGraphicsManagerDialog(java.awt.Frame parent, boolean 
modal) {
                super(parent, modal);
-               pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsPool();
+               pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsManager();
                initComponents();
                try {
                        browser = new CustomGraphicsBrowser();

Modified: cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java    
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/visual/parsers/GraphicsParser.java    
2010-07-08 22:06:32 UTC (rev 20860)
@@ -48,10 +48,10 @@
                // Special case:  URL String.
                try {
                        final URL url = new URL(value);
-                       CyCustomGraphics graphics = 
Cytoscape.getVisualMappingManager().getCustomGraphicsPool().getBySourceURL(url);
+                       CyCustomGraphics graphics = 
Cytoscape.getVisualMappingManager().getCustomGraphicsManager().getBySourceURL(url);
                        if(graphics == null) {
                                graphics = new 
URLImageCustomGraphics(url.toString());
-                               
Cytoscape.getVisualMappingManager().getCustomGraphicsPool().addGraphics(graphics,
 url);
+                               
Cytoscape.getVisualMappingManager().getCustomGraphicsManager().addGraphics(graphics,
 url);
                        }
                        return graphics;
                } catch (IOException e) {

Modified: 
cytoscape/trunk/src/cytoscape/visual/properties/NodeCustomGraphicsProp.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/properties/NodeCustomGraphicsProp.java 
2010-07-08 21:13:33 UTC (rev 20859)
+++ cytoscape/trunk/src/cytoscape/visual/properties/NodeCustomGraphicsProp.java 
2010-07-08 22:06:32 UTC (rev 20860)
@@ -272,7 +272,7 @@
        public Map<Object, Icon> getIconSet() {
                final Map<Object, Icon> customGraphicsIcons = new 
HashMap<Object, Icon>();
                final CustomGraphicsManager pool = 
Cytoscape.getVisualMappingManager()
-                               .getCustomGraphicsPool();
+                               .getCustomGraphicsManager();
                for (CyCustomGraphics graphics : pool.getAll()) {
                        VisualPropertyIcon icon = (VisualPropertyIcon) 
getIcon(graphics);
                        icon.setName(graphics.getDisplayName());

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