Author: kono
Date: 2010-01-29 15:28:21 -0800 (Fri, 29 Jan 2010)
New Revision: 19076

Modified:
   cytoscape/trunk/src/cytoscape/data/readers/GMLParser.java
   cytoscape/trunk/src/cytoscape/data/readers/GMLReader.java
Log:
Fixed GML reader bug (ID 2139).  Also, attributes in GML file will be imported. 
 Tested with GML files generated by igraph.

Modified: cytoscape/trunk/src/cytoscape/data/readers/GMLParser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/GMLParser.java   2010-01-29 
22:33:00 UTC (rev 19075)
+++ cytoscape/trunk/src/cytoscape/data/readers/GMLParser.java   2010-01-29 
23:28:21 UTC (rev 19076)
@@ -92,7 +92,7 @@
        /**
         * Constructor has to initialize the relevenat regular expression 
patterns
         */
-       public GMLParser(StreamTokenizer tokenizer) {
+       public GMLParser(final StreamTokenizer tokenizer) {
                this.tokenizer = tokenizer;
        }
 
@@ -175,16 +175,17 @@
        public List<KeyValue> parseList() throws IOException, ParseException {
                final List<KeyValue> result = new ArrayList<KeyValue>();
 
+               String key;
+               Object value;
                while (isKey()) {
-                       String key = parseKey();
+                       key = parseKey();
 
-                       if (key == null) {
+                       if (key == null)
                                throw new ParseException("Bad key", 
tokenizer.lineno());
-                       }
 
                        tokenizer.nextToken();
 
-                       Object value = parseValue();
+                       value = parseValue();
 
                        if (value == null) {
                                throw new ParseException(
@@ -204,7 +205,7 @@
         */
        private boolean isKey() {
                /*
-                * A key must be some kind of wrod
+                * A key must be some kind of word
                 */
                if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
                        return false;
@@ -237,7 +238,7 @@
         * not supposed ot have a couple things in it, but I don't really have a
         * check for that.
         */
-       private boolean isString() {
+       private boolean isQuatedString() {
                return tokenizer.ttype == QUOTE_CHAR;
        }
 
@@ -267,38 +268,33 @@
         * has already been found to not be the end of file
         */
        private Object parseValue() throws IOException, ParseException {
-               Object result = null;
 
-               if (tokenizer.ttype == StreamTokenizer.TT_EOL) {
-                       return result;
-               }
+               if (tokenizer.ttype == StreamTokenizer.TT_EOL)
+                       return null;
 
-               if (isString()) {
+               if (isQuatedString())
                        return tokenizer.sval;
-               }
 
-               if (isInteger()) {
-                       return new Integer(tokenizer.sval);
-               }
+               if (isInteger())
+                       return Integer.parseInt(tokenizer.sval);
 
-               if (isReal()) {
-                       return new Double(tokenizer.sval);
-               }
+               if (isReal())
+                       return Double.parseDouble(tokenizer.sval);
 
                if (isList()) {
                        tokenizer.nextToken();
 
-                       List list = parseList();
+                       final List<KeyValue> list = parseList();
 
                        if (!tokenizer.sval.equals(LIST_CLOSE)) {
                                throw new ParseException("Unterminated list", 
tokenizer
                                                .lineno());
                        }
-
                        return list;
                }
-
-               return result;
+               
+               // Treat as a regular string value.
+               return tokenizer.sval;
        }
 
        /**

Modified: cytoscape/trunk/src/cytoscape/data/readers/GMLReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/GMLReader.java   2010-01-29 
22:33:00 UTC (rev 19075)
+++ cytoscape/trunk/src/cytoscape/data/readers/GMLReader.java   2010-01-29 
23:28:21 UTC (rev 19076)
@@ -37,6 +37,7 @@
 package cytoscape.data.readers;
 
 import giny.model.Edge;
+import giny.model.GraphObject;
 import giny.model.Node;
 import giny.view.EdgeView;
 import giny.view.GraphView;
@@ -46,10 +47,12 @@
 import java.awt.geom.Point2D;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
@@ -73,7 +76,6 @@
 import cytoscape.visual.NodeShape;
 import cytoscape.visual.VisualPropertyType;
 
-
 /**
  * This class is responsible for converting a gml object tree into cytoscape
  * objects New features to the current version: 1. Small bug fixes. 2. 
Translate
@@ -85,19 +87,26 @@
        /**
         * The following are all taken to be reserved keywords for gml (note 
that
         * not all of them are actually keywords according to the spec)
-        *
+        * 
         * Currently, only keywords below are supported by the Visual Style
         * generation methods.
-        *
+        * 
         * (Maybe we need some documents on "cytoscape-style" GML format...)
         */
 
+       // Global tags
+       protected static final String ID = "id";
+       protected static final String NAME = "name";
+       protected static final String LABEL = "label";
+       protected static final String COMMENT = "comment";
+       protected static final String VERSION = "Version";
+       protected static final String CREATOR = "Creator";
+
        // Graph Tags
        protected static final String GRAPH = "graph";
        protected static final String NODE = "node";
        protected static final String EDGE = "edge";
        protected static final String GRAPHICS = "graphics";
-       protected static final String LABEL = "label";
        protected static final String SOURCE = "source";
        protected static final String TARGET = "target";
 
@@ -107,7 +116,7 @@
        protected static final String H = "h";
        protected static final String W = "w";
        protected static final String TYPE = "type";
-       protected static final String ID = "id";
+
        protected static final String ROOT_INDEX = "root_index";
 
        // Shapes used in Cytoscape (not GML standard)
@@ -115,7 +124,7 @@
        protected static final String RECTANGLE = "rectangle";
        protected static final String ELLIPSE = "ellipse";
        protected static final String LINE = "Line"; // This is the Polyline 
object.
-                                              // no support for now...
+       // no support for now...
        protected static final String POINT = "point";
        protected static final String DIAMOND = "diamond";
        protected static final String HEXAGON = "hexagon";
@@ -150,12 +159,13 @@
        protected static final String OUTLINE = "outline";
        protected static final String OUTLINE_WIDTH = "outline_width";
        protected static final String DEFAULT_EDGE_INTERACTION = "pp";
-       protected static final String VERSION = "Version";
-       protected static final String CREATOR = "Creator";
        
+       private static final String VIZMAP_PREFIX = "vizmap:";
+
        private static final Color DEF_COLOR = new Color(153, 153, 255);
-       
-       private String vsbSwitch = 
CytoscapeInit.getProperties().getProperty("visualStyleBuilder");
+
+       private String vsbSwitch = CytoscapeInit.getProperties().getProperty(
+                       "visualStyleBuilder");
        private VisualStyleBuilder graphStyle = null;
 
        private static CyLogger logger = CyLogger.getLogger(GMLReader.class);
@@ -168,13 +178,20 @@
        IntArrayList nodes;
        IntArrayList sources;
        IntArrayList targets;
-       
-       Vector node_labels;
-       Vector edge_labels;
+
+       private List<String> nodeLabels;
+       private List<String> edgeLabels;
+
+       // Storage for CyAttributes
+       private List<Map<String, Object>> nodeAttributes;
+       private List<Map<String, Object>> edgeAttributes;
+
        Vector edge_root_index_pairs;
        Vector node_root_index_pairs;
-       Vector edge_names;
-       Vector node_names;
+
+       private List<String> edgeNames;
+       private List<String> nodeNames;
+
        IntArrayList giny_nodes;
        IntArrayList giny_edges;
        private TaskMonitor taskMonitor;
@@ -208,8 +225,9 @@
 
        /**
         * Constructor.
-        *
-        * @param filename File name.
+        * 
+        * @param filename
+        *            File name.
         */
        public GMLReader(final String filename) {
                this(filename, null);
@@ -218,10 +236,10 @@
        /**
         * Constructor.<br>
         * This is usually used for remote file loading.
-        *
+        * 
         * @param is
         *            Input stream of GML file,
-        *
+        * 
         */
        public GMLReader(final InputStream is, final String name) {
                super(name);
@@ -236,9 +254,11 @@
 
        /**
         * Constructor.
-        *
-        * @param filename File name.
-        * @param taskMonitor TaskMonitor Object.
+        * 
+        * @param filename
+        *            File name.
+        * @param taskMonitor
+        *            TaskMonitor Object.
         */
        public GMLReader(final String filename, final TaskMonitor taskMonitor) {
                super(filename);
@@ -256,10 +276,11 @@
        }
 
        /**
-         * Sets the task monitor we want to use
-         *
-         * @param monitor the TaskMonitor to use
-         */
+        * Sets the task monitor we want to use
+        * 
+        * @param monitor
+        *            the TaskMonitor to use
+        */
        public void setTaskMonitor(TaskMonitor monitor) {
                this.taskMonitor = monitor;
                percentUtil = new PercentUtil(3);
@@ -270,32 +291,32 @@
        }
 
        private void initializeHash() {
-               edge_names = new Vector();
-               node_names = new Vector();
+               edgeNames = new ArrayList<String>();
+               nodeNames = new ArrayList<String>();
+               nodeAttributes = new ArrayList<Map<String, Object>>();
+               edgeAttributes = new ArrayList<Map<String, Object>>();
        }
 
-       
        // Initialize variables for the new style created from GML
        private void initStyle() {
                graphStyle = new VisualStyleBuilder(styleName, false);
                graphStyle.setNodeSizeLocked(false);
        }
 
-
        /**
-        *  Read GML file contents
+        * Read GML file contents
         */
        public void read() {
                try {
-            try {
-                keyVals = (new GMLParser(inputStream)).parseList();
-            } finally {
-                if (inputStream != null) {
-                    inputStream.close();
-                }
-            }
+                       try {
+                               keyVals = (new 
GMLParser(inputStream)).parseList();
+                       } finally {
+                               if (inputStream != null) {
+                                       inputStream.close();
+                               }
+                       }
                } catch (Exception io) {
-                       logger.warn("Error reading GML file: "+io.getMessage(), 
io);
+                       logger.warn("Error reading GML file: " + 
io.getMessage(), io);
 
                        if (taskMonitor != null)
                                taskMonitor.setException(io, io.getMessage());
@@ -330,8 +351,8 @@
                nodes = new IntArrayList();
                sources = new IntArrayList();
                targets = new IntArrayList();
-               node_labels = new Vector();
-               edge_labels = new Vector();
+               nodeLabels = new ArrayList<String>();
+               edgeLabels = new ArrayList<String>();
                edge_root_index_pairs = new Vector();
                node_root_index_pairs = new Vector();
        }
@@ -340,12 +361,38 @@
                nodes = null;
                sources = null;
                targets = null;
-               node_labels = null;
-               edge_labels = null;
+               nodeLabels = null;
+               edgeLabels = null;
                edge_root_index_pairs = null;
                node_root_index_pairs = null;
        }
 
+       private void mapAttributes(final GraphObject obj,
+                       final CyAttributes attrs, final Map<String, Object> 
attrMap) {
+
+               for (String attrName : attrMap.keySet()) {
+                       final Object attrVal = attrMap.get(attrName);
+                       if (attrVal == null)
+                               continue;
+
+                       try {
+                               if (attrVal instanceof Double) {
+                                       attrs.setAttribute(obj.getIdentifier(), 
attrName,
+                                                       (Double) attrVal);
+                               } else if (attrVal instanceof Integer) {
+                                       attrs.setAttribute(obj.getIdentifier(), 
attrName,
+                                                       (Integer) attrVal);
+                               } else {
+                                       attrs.setAttribute(obj.getIdentifier(), 
attrName,
+                                                       attrVal.toString());
+                               }
+                       } catch (IllegalArgumentException e) {
+                               continue;
+                       }
+
+               }
+       }
+
        /**
         * This will create the graph model objects. This function expects node
         * labels to be unique and edge labels to be unique between a particular
@@ -360,29 +407,41 @@
                giny_nodes = new IntArrayList(nodes.size());
 
                OpenIntIntHashMap gml_id2order = new 
OpenIntIntHashMap(nodes.size());
-               Set nodeNameSet = new HashSet(nodes.size());
+               Set<String> nodeNameSet = new HashSet<String>(nodes.size());
 
+               final CyAttributes nodeAttr = Cytoscape.getNodeAttributes();
+
                // Add All Nodes to Network
                for (int idx = 0; idx < nodes.size(); idx++) {
                        // Report Status Value
-                       if (taskMonitor != null) {
-                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(2, idx, 
nodes.size()));
-                       }
+                       if (taskMonitor != null)
+                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(2,
+                                               idx, nodes.size()));
 
-                       String label = (String) node_labels.get(idx);
+                       final String label = nodeLabels.get(idx);
 
+                       Node node;
+
                        if (nodeNameSet.add(label)) {
-                               Node node = (Node) Cytoscape.getCyNode(label, 
true);
+                               node = Cytoscape.getCyNode(label, true);
+                               if (nodeLabels.get(idx) != null)
+                                       
nodeAttr.setAttribute(node.getIdentifier(), LABEL,
+                                                       nodeLabels.get(idx));
+                               if (nodeNames.get(idx) != null)
+                                       
nodeAttr.setAttribute(node.getIdentifier(), NAME, nodeNames
+                                                       .get(idx));
+
+                               // Map attributes
+                               mapAttributes(node, nodeAttr, 
nodeAttributes.get(idx));
+
                                giny_nodes.add(node.getRootGraphIndex());
                                nodeIDMap.put(nodes.get(idx), 
node.getRootGraphIndex());
                                gml_id2order.put(nodes.get(idx), idx);
-                               ((KeyValue) 
node_root_index_pairs.get(idx)).value = (new Integer(node
-                                                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
     .getRootGraphIndex()));
+                               ((KeyValue) 
node_root_index_pairs.get(idx)).value = (new Integer(
+                                               node.getRootGraphIndex()));
                        } else {
-                               throw new GMLException("GML id " + 
nodes.get(idx) + " has a duplicated label: "
-                                                      + label);
-
-                               // 
((KeyValue)node_root_index_pairs.get(idx)).value = null;
+                               throw new GMLException("GML id " + 
nodes.get(idx)
+                                               + " has a duplicated ID: " + 
label);
                        }
                }
 
@@ -392,33 +451,38 @@
 
                Set edgeNameSet = new HashSet(sources.size());
 
-               CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
+               final CyAttributes edgeAttr = Cytoscape.getEdgeAttributes();
 
                // Add All Edges to Network
                for (int idx = 0; idx < sources.size(); idx++) {
                        // Report Status Value
                        if (taskMonitor != null) {
-                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(3, idx, 
sources.size()));
+                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(3,
+                                               idx, sources.size()));
                        }
 
                        if (gml_id2order.containsKey(sources.get(idx))
-                           && gml_id2order.containsKey(targets.get(idx))) {
-                               String label = (String) edge_labels.get(idx);
-                               String sourceName = (String) 
node_labels.get(gml_id2order.get(sources.get(idx)));
-                               String targetName = (String) 
node_labels.get(gml_id2order.get(targets.get(idx)));
-                               String edgeName = 
CyEdge.createIdentifier(sourceName, label, targetName);
+                                       && 
gml_id2order.containsKey(targets.get(idx))) {
+                               String label = (String) edgeLabels.get(idx);
+                               String sourceName = (String) 
nodeLabels.get(gml_id2order
+                                               .get(sources.get(idx)));
+                               String targetName = (String) 
nodeLabels.get(gml_id2order
+                                               .get(targets.get(idx)));
+                               String edgeName = 
CyEdge.createIdentifier(sourceName, label,
+                                               targetName);
 
                                int duplicate_count = 1;
 
                                while (!edgeNameSet.add(edgeName)) {
-                                       edgeName = 
CyEdge.createIdentifier(sourceName, label, targetName) + "_"
-                                                  + duplicate_count;
+                                       edgeName = 
CyEdge.createIdentifier(sourceName, label,
+                                                       targetName)
+                                                       + "_" + duplicate_count;
 
                                        duplicate_count += 1;
                                }
 
                                // String tempstr = "E name is :" + idx + "==" 
+ edgeName;
-                               edge_names.add(idx, edgeName);
+                               edgeNames.add(idx, edgeName);
 
                                Edge edge = 
Cytoscape.getRootGraph().getEdge(edgeName);
 
@@ -427,20 +491,22 @@
                                        Node node_2 = 
Cytoscape.getCyNode(targetName);
                                        // edge = (Edge) rootGraph.getEdge
                                        // (rootGraph.createEdge(node_1, 
node_2));
-                                       edge = Cytoscape.getCyEdge(node_1, 
node_2, Semantics.INTERACTION, label, true,
-                                                                  true);
+                                       edge = Cytoscape.getCyEdge(node_1, 
node_2,
+                                                       Semantics.INTERACTION, 
label, true, true);
                                }
 
                                // Set correct ID, canonical name and 
interaction name
                                edge.setIdentifier(edgeName);
-                               edgeAttributes.setAttribute(edgeName, 
Semantics.INTERACTION, label);
+                               edgeAttr.setAttribute(edgeName, 
Semantics.INTERACTION, label);
+                               mapAttributes(edge, edgeAttr, 
edgeAttributes.get(idx));
 
                                giny_edges.add(edge.getRootGraphIndex());
-                               ((KeyValue) 
edge_root_index_pairs.get(idx)).value = (new Integer(edge
-                                                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                 
.getRootGraphIndex()));
+                               ((KeyValue) 
edge_root_index_pairs.get(idx)).value = (new Integer(
+                                               edge.getRootGraphIndex()));
                        } else {
-                               throw new GMLException("Non-existant 
source/target node for edge with gml (source,target): "
-                                                      + sources.get(idx) + "," 
+ targets.get(idx));
+                               throw new GMLException(
+                                               "Non-existant source/target 
node for edge with gml (source,target): "
+                                                               + 
sources.get(idx) + "," + targets.get(idx));
                        }
                }
 
@@ -455,11 +521,12 @@
                // Report Progress Message
                int counter = 0;
                final int size = list.size();
-               
-               for (KeyValue keyVal: list) {
+
+               for (KeyValue keyVal : list) {
                        // Report Progress Value
                        if (taskMonitor != null) {
-                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(1, counter, size));
+                               
taskMonitor.setPercentCompleted(percentUtil.getGlobalPercent(1,
+                                               counter, size));
                                counter++;
                        }
 
@@ -474,7 +541,7 @@
         */
        @SuppressWarnings("unchecked")
        protected void readGraph(final List<KeyValue> list) {
-               for (KeyValue keyVal: list) {
+               for (KeyValue keyVal : list) {
                        if (keyVal.key.equals(NODE))
                                readNode((List<KeyValue>) keyVal.value);
 
@@ -487,22 +554,28 @@
         * This will extract the model information from the list which is 
matched a
         * "node" key
         */
-       protected void readNode(List list) {
+       private void readNode(final List<KeyValue> list) {
                String label = "";
+               String name = null;
+               final Map<String, Object> attr = new HashMap<String, Object>();
+
                boolean contains_id = false;
                int id = 0;
                KeyValue root_index_pair = null;
 
-               for (Iterator it = list.iterator(); it.hasNext();) {
-                       KeyValue keyVal = (KeyValue) it.next();
-
+               for (final KeyValue keyVal : list) {
                        if (keyVal.key.equals(ID)) {
                                contains_id = true;
-                               id = ((Integer) keyVal.value).intValue();
+                               id = (Integer) keyVal.value;
                        } else if (keyVal.key.equals(LABEL)) {
-                               label = (String) keyVal.value;
+                               label = keyVal.value.toString();
+                       } else if (keyVal.key.equals(NAME)) {
+                               name = keyVal.value.toString();
                        } else if (keyVal.key.equals(ROOT_INDEX)) {
                                root_index_pair = keyVal;
+                       } else if (!keyVal.key.equals(GRAPHICS) && 
!keyVal.key.startsWith(VIZMAP_PREFIX)) {
+                               // This is a regular attribute value
+                               attr.put(keyVal.key, keyVal.value);
                        }
                }
 
@@ -516,7 +589,7 @@
                }
 
                if (!contains_id) {
-                       StringWriter stringWriter = new StringWriter();
+                       final StringWriter stringWriter = new StringWriter();
 
                        try {
                                GMLParser.printList(list, stringWriter);
@@ -525,12 +598,14 @@
                        }
 
                        throw new GMLException("The node-associated list\n" + 
stringWriter
-                                              + "is missing an id field");
+                                       + "is missing an id field");
                } else {
                        node_root_index_pairs.add(root_index_pair);
                        nodes.add(id);
-                       node_labels.add(label);
-                       node_names.add(label);
+                       nodeLabels.add(label);
+                       nodeNames.add(name);
+
+                       nodeAttributes.add(attr);
                }
        }
 
@@ -538,17 +613,16 @@
         * This will extract the model information from the list which is 
matched to
         * an "edge" key.
         */
-       protected void readEdge(List list) {
+       protected void readEdge(final List<KeyValue> list) {
                String label = DEFAULT_EDGE_INTERACTION;
                boolean contains_source = false;
                boolean contains_target = false;
                int source = 0;
                int target = 0;
                KeyValue root_index_pair = null;
+               final Map<String, Object> attr = new HashMap<String, Object>();
 
-               for (Iterator it = list.iterator(); it.hasNext();) {
-                       KeyValue keyVal = (KeyValue) it.next();
-
+               for (final KeyValue keyVal: list) {
                        if (keyVal.key.equals(SOURCE)) {
                                contains_source = true;
                                source = ((Integer) keyVal.value).intValue();
@@ -559,6 +633,8 @@
                                label = (String) keyVal.value;
                        } else if (keyVal.key.equals(ROOT_INDEX)) {
                                root_index_pair = keyVal;
+                       } else if (!keyVal.key.equals(GRAPHICS) && 
!keyVal.key.startsWith(VIZMAP_PREFIX)) {
+                               attr.put(keyVal.key, keyVal.value);
                        }
                }
 
@@ -577,36 +653,39 @@
                        }
 
                        throw new GMLException("The edge-associated list\n" + 
stringWriter
-                                              + " is missing a source or 
target key");
+                                       + " is missing a source or target key");
                } else {
                        sources.add(source);
                        targets.add(target);
 
-                       edge_labels.add(label);
+                       edgeLabels.add(label);
                        edge_root_index_pairs.add(root_index_pair);
+                       
+                       edgeAttributes.add(attr);
                }
        }
 
        /**
-        * getLayoutAlgorithm is called to get the Layout Algorithm that will 
be used
-        * to layout the resulting graph.  In our case, we just return a stub 
that will
-        * call our internal layout routine, which will just use the default 
layout, but
-        * with our task monitor
-        *
+        * getLayoutAlgorithm is called to get the Layout Algorithm that will be
+        * used to layout the resulting graph. In our case, we just return a 
stub
+        * that will call our internal layout routine, which will just use the
+        * default layout, but with our task monitor
+        * 
         * @return the CyLayoutAlgorithm to use
         */
        public CyLayoutAlgorithm getLayoutAlgorithm() {
                return new LayoutAdapter() {
-                               public void doLayout(CyNetworkView networkView, 
TaskMonitor monitor) {
-                                       layout(networkView);
-                               }
-                       };
+                       public void doLayout(CyNetworkView networkView, 
TaskMonitor monitor) {
+                               layout(networkView);
+                       }
+               };
        }
 
        /**
         * layout the graph based on the GML values we read
-        *
-        * @param myView the view of the network we want to layout
+        * 
+        * @param myView
+        *            the view of the network we want to layout
         */
        public void layout(CyNetworkView myView) {
                if ((myView == null) || (myView.nodeCount() == 0)) {
@@ -614,7 +693,8 @@
                }
 
                if (keyVals == null) {
-                       throw new RuntimeException("Failed to read gml file on 
initialization");
+                       throw new RuntimeException(
+                                       "Failed to read gml file on 
initialization");
                }
 
                for (Iterator it = keyVals.iterator(); it.hasNext();) {
@@ -628,11 +708,12 @@
 
        //
        /**
-        *  DOCUMENT ME!
+        * DOCUMENT ME!
         */
        public void extract() {
                if (keyVals == null) {
-                       throw new RuntimeException("Failed to read gml file on 
initialization");
+                       throw new RuntimeException(
+                                       "Failed to read gml file on 
initialization");
                }
 
                for (Iterator it = keyVals.iterator(); it.hasNext();) {
@@ -656,7 +737,7 @@
                        if (keyVal.key.equals(NODE)) {
                                extractNode((List) keyVal.value);
                        } else if (keyVal.key.equals(EDGE)) {
-                               edgeName = (String) edge_names.get(ePtr);
+                               edgeName = (String) edgeNames.get(ePtr);
                                ePtr++;
                                extractEdge((List) keyVal.value, edgeName);
                        }
@@ -688,7 +769,8 @@
                if (graphics_list != null) {
                        if (label == null) {
                                label = "node" + tempid;
-                               logger.info("Warning: node label is missing for 
node ID: " + tempid);
+                               logger.info("Warning: node label is missing for 
node ID: "
+                                               + tempid);
                        }
 
                        extractNodeAttributes(graphics_list, label);
@@ -726,12 +808,6 @@
 
                        if (keyVal.key.equals(NODE))
                                layoutNode(myView, (List) keyVal.value);
-
-                       //                      } else if 
(keyVal.key.equals(EDGE)) {
-                       //                              edgeName = (String) 
edge_names.get(ePtr);
-                       //                              ePtr++;
-                       //                              layoutEdge(myView, 
(List) keyVal.value, edgeName);
-                       //                      }
                }
        }
 
@@ -787,7 +863,8 @@
         * This will assign node graphic properties based on the values in the 
list
         * matches to the "graphics" key word
         */
-       protected void layoutNodeGraphics(GraphView myView, List list, NodeView 
nodeView) {
+       protected void layoutNodeGraphics(GraphView myView, List list,
+                       NodeView nodeView) {
                for (Iterator it = list.iterator(); it.hasNext();) {
                        KeyValue keyVal = (KeyValue) it.next();
 
@@ -839,21 +916,26 @@
                        if (keyVal.key.equals(X) || keyVal.key.equals(Y)) {
                                // Do nothing.
                        } else if (keyVal.key.equals(H)) {
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_HEIGHT, "" + keyVal.value);
+                               graphStyle.addProperty(nodeName,
+                                               VisualPropertyType.NODE_HEIGHT, 
"" + keyVal.value);
                        } else if (keyVal.key.equals(W)) {
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_WIDTH, "" + keyVal.value);
+                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_WIDTH,
+                                               "" + keyVal.value);
                        } else if (keyVal.key.equals(FILL)) {
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_FILL_COLOR,
-                                                      "" + keyVal.value);
+                               graphStyle.addProperty(nodeName,
+                                               
VisualPropertyType.NODE_FILL_COLOR, "" + keyVal.value);
                        } else if (keyVal.key.equals(OUTLINE)) {
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_BORDER_COLOR,
-                                                      "" + keyVal.value);
+                               graphStyle
+                                               .addProperty(nodeName,
+                                                               
VisualPropertyType.NODE_BORDER_COLOR, ""
+                                                                               
+ keyVal.value);
                        } else if (keyVal.key.equals(WIDTH)) {
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_LINE_WIDTH,
-                                                      "" + keyVal.value);
+                               graphStyle.addProperty(nodeName,
+                                               
VisualPropertyType.NODE_LINE_WIDTH, "" + keyVal.value);
                        } else if (keyVal.key.equals(TYPE)) {
                                String type = (String) keyVal.value;
-                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_SHAPE, type);
+                               graphStyle.addProperty(nodeName, 
VisualPropertyType.NODE_SHAPE,
+                                               type);
                        }
                }
        }
@@ -875,11 +957,12 @@
                                // Current version of CS does not support this, 
so ignore this
                                // at this point of time...
                        } else if (keyVal.key.equals(WIDTH)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_LINE_WIDTH,
-                                                      new 
String(keyVal.value.toString()));
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_LINE_WIDTH, new String(
+                                                               
keyVal.value.toString()));
                        } else if (keyVal.key.equals(FILL)) {
                                graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_COLOR,
-                                                      new 
String(keyVal.value.toString()));
+                                               new 
String(keyVal.value.toString()));
                                edgeFill = keyVal.value.toString();
                        } else if (keyVal.key.equals(ARROW)) {
                                isArrow = true;
@@ -889,57 +972,71 @@
 
                                if 
(keyVal.value.toString().equalsIgnoreCase(ARROW_FIRST)) {
                                        arrowShape = ARROW_FIRST;
-                                       graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_SHAPE,
-                                                              arrowName);
+                                       graphStyle.addProperty(edgeName,
+                                                       
VisualPropertyType.EDGE_SRCARROW_SHAPE, arrowName);
                                } else if 
(keyVal.value.toString().equalsIgnoreCase(ARROW_LAST)) {
                                        arrowShape = ARROW_LAST;
-                                       graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_SHAPE,
-                                                              arrowName);
+                                       graphStyle.addProperty(edgeName,
+                                                       
VisualPropertyType.EDGE_TGTARROW_SHAPE, arrowName);
                                } else if 
(keyVal.value.toString().equalsIgnoreCase(ARROW_BOTH)) {
                                        arrowShape = ARROW_BOTH;
-                                       graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_SHAPE,
-                                                              arrowName);
-                                       graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_SHAPE,
-                                                              arrowName);
+                                       graphStyle.addProperty(edgeName,
+                                                       
VisualPropertyType.EDGE_SRCARROW_SHAPE, arrowName);
+                                       graphStyle.addProperty(edgeName,
+                                                       
VisualPropertyType.EDGE_TGTARROW_SHAPE, arrowName);
                                }
                        } else if (keyVal.key.equals(TYPE)) {
                                value = (String) keyVal.value;
 
                                if (value.equals(STRAIGHT_LINES)) {
-                                       //edgeShape.put(edgeName, (String) 
keyVal.value);
+                                       // edgeShape.put(edgeName, (String) 
keyVal.value);
                                } else if (value.equals(CURVED_LINES)) {
                                        // 
edgeView.setLineType(EdgeView.CURVED_LINES);
                                }
                        } else if (keyVal.key.equals(SOURCE_ARROW)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_SHAPE,
-                                                      
ArrowShape.getArrowShape(((Number) keyVal.value).intValue())
-                                                                .getName());
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_SHAPE, ArrowShape
+                                                               .getArrowShape(
+                                                                               
((Number) keyVal.value).intValue())
+                                                               .getName());
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
                        } else if (keyVal.key.equals(TARGET_ARROW)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_SHAPE,
-                                                      
ArrowShape.getArrowShape(((Number) keyVal.value).intValue())
-                                                                .getName());
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_SHAPE, ArrowShape
+                                                               .getArrowShape(
+                                                                               
((Number) keyVal.value).intValue())
+                                                               .getName());
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
                        } else if (keyVal.key.equals(YED_SOURCE_ARROW)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_SHAPE,
-                                                      
convertYEDArrowShape(keyVal.value.toString()));
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_SHAPE,
+                                               
convertYEDArrowShape(keyVal.value.toString()));
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
                        } else if (keyVal.key.equals(YED_TARGET_ARROW)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_SHAPE,
-                                                      
convertYEDArrowShape(keyVal.value.toString()));
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_SHAPE,
+                                               
convertYEDArrowShape(keyVal.value.toString()));
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
                        }
                }
 
                // make the arrow color the same as edge
                if (isArrow) {
                        if (arrowShape.equals(ARROW_FIRST)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
                        } else if (arrowShape.equals(ARROW_LAST)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
                        } else if (arrowShape.equals(ARROW_BOTH)) {
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
-                               graphStyle.addProperty(edgeName, 
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_SRCARROW_COLOR, edgeFill);
+                               graphStyle.addProperty(edgeName,
+                                               
VisualPropertyType.EDGE_TGTARROW_COLOR, edgeFill);
                        }
                }
        }
@@ -949,7 +1046,8 @@
 
                if (yedArrow.equals(YED_DELTA) || 
yedArrow.equals(YED_WHITE_DELTA))
                        shape = ArrowShape.DELTA.getName();
-               else if (yedArrow.equals(YED_DIAMOND) || 
yedArrow.equals(YED_WHITE_DIAMOND))
+               else if (yedArrow.equals(YED_DIAMOND)
+                               || yedArrow.equals(YED_WHITE_DIAMOND))
                        shape = ArrowShape.DIAMOND.getName();
                else if (yedArrow.equals(YED_STANDARD) || 
yedArrow.equals(YED_SHORT))
                        shape = ArrowShape.ARROW.getName();
@@ -958,15 +1056,15 @@
        }
 
        /**
-        *  DOCUMENT ME!
+        * DOCUMENT ME!
         */
        public void showMaps() {
                String e = null;
                String n = null;
                String temp = null;
 
-               for (int i = 0; i < edge_names.size(); i++) {
-                       e = (String) edge_names.get(i);
+               for (int i = 0; i < edgeNames.size(); i++) {
+                       e = (String) edgeNames.get(i);
                        temp = e + ": ";
                        temp = temp + edgeCol.get(e) + ", ";
                        temp = temp + edgeWidth.get(e) + ", ";
@@ -997,7 +1095,8 @@
                                        return;
                                }
 
-                               edgeView = myView.getEdgeView(((Integer) 
keyVal.value).intValue());
+                               edgeView = myView.getEdgeView(((Integer) 
keyVal.value)
+                                               .intValue());
                        } else if (keyVal.key.equals(GRAPHICS)) {
                                graphics_list = (List) keyVal.value;
                        }
@@ -1010,11 +1109,12 @@
        /**
         * Assign edge graphics properties
         */
-       protected void layoutEdgeGraphics(GraphView myView, List<KeyValue> 
list, EdgeView edgeView) {
+       protected void layoutEdgeGraphics(GraphView myView, List<KeyValue> list,
+                       EdgeView edgeView) {
                // Local vars.
                String value = null;
 
-               //              KeyValue keyVal = null;
+               // KeyValue keyVal = null;
                for (KeyValue keyVal : list) {
                        // This is a polyline obj. However, it will be 
translated into
                        // straight line.
@@ -1062,7 +1162,8 @@
         * "Line" key We make sure that there is both an x,y present in the
         * underlying point list before trying to generate a bend point
         */
-       protected void layoutEdgeGraphicsLine(GraphView myView, List list, 
EdgeView edgeView) {
+       protected void layoutEdgeGraphicsLine(GraphView myView, List list,
+                       EdgeView edgeView) {
                for (Iterator it = list.iterator(); it.hasNext();) {
                        KeyValue keyVal = (KeyValue) it.next();
 
@@ -1070,7 +1171,8 @@
                                Number x = null;
                                Number y = null;
 
-                               for (Iterator pointIt = ((List) 
keyVal.value).iterator(); pointIt.hasNext();) {
+                               for (Iterator pointIt = ((List) 
keyVal.value).iterator(); pointIt
+                                               .hasNext();) {
                                        KeyValue pointVal = (KeyValue) 
pointIt.next();
 
                                        if (pointVal.key.equals(X)) {
@@ -1081,7 +1183,8 @@
                                }
 
                                if (!((x == null) || (y == null))) {
-                                       Point2D.Double pt = new 
Point2D.Double(x.doubleValue(), y.doubleValue());
+                                       Point2D.Double pt = new 
Point2D.Double(x.doubleValue(), y
+                                                       .doubleValue());
                                        edgeView.getBend().addHandle(pt);
                                }
                        }
@@ -1114,9 +1217,10 @@
        }
 
        /**
-        *  DOCUMENT ME!
-        *
-        * @param net DOCUMENT ME!
+        * DOCUMENT ME!
+        * 
+        * @param net
+        *            DOCUMENT ME!
         */
        public void doPostProcessing(final CyNetwork net) {
 
@@ -1126,7 +1230,7 @@
                        return;
 
                if ((init.getMode() == CyInitParams.GUI)
-                   || (init.getMode() == CyInitParams.EMBEDDED_WINDOW)) {
+                               || (init.getMode() == 
CyInitParams.EMBEDDED_WINDOW)) {
                        if (!((vsbSwitch != null) && vsbSwitch.equals("off"))) {
                                graphStyle.buildStyle();
                        }

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