Author: Christian Lopes
Date: 2011-01-25 16:01:44 -0800 (Tue, 25 Jan 2011)
New Revision: 23620

Modified:
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/VisualStyleBuilder.java
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReader.java
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderFactory.java
   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/xgmml/XGMMLNetworkViewReaderTest.java
Log:
Fixed data type (String) of table column used by the Discrete Mappers when 
building a style from XGMML. Using Visual Lexicon's lookup to get some visual 
properties.

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/VisualStyleBuilder.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/VisualStyleBuilder.java
    2011-01-25 23:21:02 UTC (rev 23619)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/VisualStyleBuilder.java
    2011-01-26 00:01:44 UTC (rev 23620)
@@ -58,8 +58,8 @@
  */
 public class VisualStyleBuilder {
 
-    Map<VisualProperty<?>, Map<Object, Object>>  valueMaps;
-    Map<VisualProperty<?>, Map<Object, Integer>> counts;
+    Map<VisualProperty<?>, Map<String, Object>>  valueMaps;
+    Map<VisualProperty<?>, Map<String, Integer>> counts;
     String                                       name;
     private boolean                              nodeSizeLocked = true;
 
@@ -94,8 +94,8 @@
         this.nodesTable = nodesTable;
         this.edgesTable = edgesTable;
 
-        this.valueMaps = new Hashtable<VisualProperty<? extends Object>, 
Map<Object, Object>>();
-        this.counts = new Hashtable<VisualProperty<? extends Object>, 
Map<Object, Integer>>();
+        this.valueMaps = new Hashtable<VisualProperty<? extends Object>, 
Map<String, Object>>();
+        this.counts = new Hashtable<VisualProperty<? extends Object>, 
Map<String, Integer>>();
     }
 
     /**
@@ -106,7 +106,7 @@
      * @param defStyle
      *            the default syle
      */
-    public <V, K> VisualStyle buildStyle() {
+    public <V> VisualStyle buildStyle() {
         // Create the new style
         VisualStyle style = 
styleFactory.getInstance(visMappingManager.getDefaultVisualStyle());
         String styleName = name + " style";
@@ -120,7 +120,7 @@
         for (VisualProperty<?> _vp : valueMaps.keySet()) {
             final VisualProperty<V> vp = (VisualProperty<V>) _vp;
             final Class<?> type = vp.getTargetDataType();
-            Map<K, V> valMap = (Map<K, V>) valueMaps.get(vp);
+            Map<String, V> valMap = (Map<String, V>) valueMaps.get(vp);
 
             if (createMapping(vp)) {
                 // If there is more than one value specified for a given visual
@@ -128,7 +128,7 @@
                 // then create a mapping and calculator.
                 final String attrName = getAttrName(vp);
 
-                DiscreteMapping<K, V> dm = (DiscreteMapping<K, V>) 
discreteMappingFactory
+                DiscreteMapping<String, V> dm = (DiscreteMapping<String, V>) 
discreteMappingFactory
                         .createVisualMappingFunction(attrName, String.class, 
vp);
 
                 dm.putAll(valMap);
@@ -136,7 +136,7 @@
             } else {
                 // Otherwise, set the default appearance value for the visual
                 // style and then remove the attribute that was created.
-                for (Object key : valMap.keySet()) {
+                for (String key : valMap.keySet()) {
                     V val = (V) valMap.get(key);
                     style.setDefaultValue(vp, val);
                 }
@@ -193,12 +193,12 @@
         }
 
         // store the value
-        if (!valueMaps.containsKey(vp)) valueMaps.put(vp, new 
Hashtable<Object, Object>());
+        if (!valueMaps.containsKey(vp)) valueMaps.put(vp, new 
Hashtable<String, Object>());
 
         valueMaps.get(vp).put(vString, value);
 
         // store the count
-        if (!counts.containsKey(vp)) counts.put(vp, new Hashtable<Object, 
Integer>());
+        if (!counts.containsKey(vp)) counts.put(vp, new Hashtable<String, 
Integer>());
         if (!counts.get(vp).containsKey(vString)) counts.get(vp).put(vString, 
0);
 
         counts.get(vp).put(vString, counts.get(vp).get(vString) + 1);

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReader.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReader.java
  2011-01-25 23:21:02 UTC (rev 23619)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReader.java
  2011-01-26 00:01:44 UTC (rev 23620)
@@ -37,8 +37,11 @@
 package org.cytoscape.io.internal.read.xgmml;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Map.Entry;
@@ -56,10 +59,14 @@
 import org.cytoscape.model.CyNetworkFactory;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTableEntry;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.CyNetworkViewFactory;
 import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualLexicon;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
@@ -88,6 +95,7 @@
 
     protected static final String              CY_NAMESPACE = 
"http://www.cytoscape.org";;
 
+    private final RenderingEngineManager       renderingEngineManager;
     private final XGMMLParser                  parser;
     private final ReadDataManager              readDataManager;
     private final AttributeValueUtil           attributeValueUtil;
@@ -96,14 +104,20 @@
     private final VisualMappingFunctionFactory discreteMappingFactory;
     private final CyProperty<Properties>       properties;
 
+    private VisualLexicon                      lexicon;
+
     private CyNetworkView                      view;
 
+    private final List<GraphicsConverter<?>>   nodeGraphics;
+    private final List<GraphicsConverter<?>>   edgeGraphics;
+
     private static final Logger                logger       = 
LoggerFactory.getLogger(XGMMLNetworkViewReader.class);
 
     /**
      * Constructor.
      */
     public XGMMLNetworkViewReader(InputStream inputStream,
+                                  RenderingEngineManager 
renderingEngineManager,
                                   CyNetworkViewFactory cyNetworkViewFactory,
                                   CyNetworkFactory cyNetworkFactory,
                                   ReadDataManager readDataManager,
@@ -114,6 +128,7 @@
                                   XGMMLParser parser,
                                   CyProperty<Properties> properties) {
         super(inputStream, cyNetworkViewFactory, cyNetworkFactory);
+        this.renderingEngineManager = renderingEngineManager;
         this.readDataManager = readDataManager;
         this.attributeValueUtil = attributeValueUtil;
         this.styleFactory = styleFactory;
@@ -121,6 +136,30 @@
         this.discreteMappingFactory = discreteMappingFactory;
         this.parser = parser;
         this.properties = properties;
+        this.lexicon = renderingEngineManager.getDefaultVisualLexicon();
+
+        nodeGraphics = new ArrayList<GraphicsConverter<?>>();
+        edgeGraphics = new ArrayList<GraphicsConverter<?>>();
+
+        // TODO: should add x/y to style?
+        //        nodeProps.put("x", Double.class);
+        //        nodeProps.put("y", Double.class);
+        // TODO: NODE_SIZE: locking h/w
+        nodeGraphics.add(new GraphicsConverter<Double>("h", Double.class));
+        nodeGraphics.add(new GraphicsConverter<Double>("w", Double.class));
+        nodeGraphics.add(new GraphicsConverter<Color>("fill", Color.class));
+        nodeGraphics.add(new GraphicsConverter<Color>("outline", Color.class));
+        nodeGraphics.add(new GraphicsConverter<Double>("width", Double.class));
+        //        nodeProps.add(new ValueMapping<Object>("borderLineType", 
Object.class));
+        nodeGraphics.add(new GraphicsConverter<Font>("nodeLabelFont", 
Font.class, CY_NAMESPACE));
+        nodeGraphics.add(new GraphicsConverter<Integer>("nodeTransparency", 
Integer.class, CY_NAMESPACE));
+        //        nodeProps.add(new ValueMapping<Object>("type", 
Object.class));
+        
+        // TODO: add more
+        edgeGraphics.add(new GraphicsConverter<Double>("width", Double.class));
+        edgeGraphics.add(new GraphicsConverter<Color>("fill", Color.class));
+        edgeGraphics.add(new GraphicsConverter<Font>("edgeLabelFont", 
Font.class, CY_NAMESPACE));
+        edgeGraphics.add(new GraphicsConverter<Integer>("edgeTransparency", 
Integer.class, CY_NAMESPACE));
     }
 
     @Override
@@ -223,7 +262,7 @@
 
         String netName = readDataManager.getNetworkName();
         netRow.set(NODE_NAME_ATTR_LABEL, netName);
-
+        
         if (styleBuilder != null) {
             // Network name
             styleBuilder.addProperty(netRow, TwoDVisualLexicon.NETWORK_TITLE, 
netName);
@@ -310,107 +349,32 @@
         nodeView.setVisualProperty(TwoDVisualLexicon.NODE_X_LOCATION, x);
         nodeView.setVisualProperty(TwoDVisualLexicon.NODE_Y_LOCATION, y);
 
-        // The attributes of this node
-        CyRow row = nodeView.getModel().getCyRow();
+        layoutGraphics(graphics, nodeView, styleBuilder, nodeGraphics);
 
-        if (styleBuilder != null) {
-            // Size
-            double h = attributeValueUtil.getDoubleAttribute(graphics, "h");
-            double w = attributeValueUtil.getDoubleAttribute(graphics, "w");
-
-            // TODO: NODE_SIZE: locking h/w
-            if (h != 0.0) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.NODE_Y_SIZE, 
h);
-            }
-            if (w != 0.0) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.NODE_X_SIZE, 
w);
-            }
-
-            if (w != 0.0) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.NODE_SIZE, w);
-            }
-
-            // Color
-            Color fillColor = attributeValueUtil.getColorAttribute(graphics, 
"fill");
-
-            if (fillColor != null) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.NODE_PAINT, 
fillColor);
-            }
-
-            // Border color
-            Color borderColor = attributeValueUtil.getColorAttribute(graphics, 
"outline");
-            // TODO:
-            // if (borderColor != null) {
-            // styleBuilder.addProperty(row,
-            // TwoDVisualLexicon.NODE_BORDER_COLOR, borderColor);
-            // }
-
-            // Border width
-            double borderWidth = 
attributeValueUtil.getDoubleAttribute(graphics, "width");
-            // TODO:
-            // if (borderWidth >= 0) {
-            // styleBuilder.addProperty(row,
-            // TwoDVisualLexicon.NODE_BORDER_WIDTH, borderWidth);
-            // }
-
-            // if (attributeValueUtil.getAttributeNS(graphics,
-            // "nodeTransparency", CY_NAMESPACE) != null) {
-            // String opString = attributeValueUtil.getAttributeNS(graphics,
-            // "nodeTransparency", CY_NAMESPACE);
-            // float opacity = (float) Double.parseDouble(opString) * 255;
-            // // Opacity is saved as a float from 0-1, but internally we use
-            // 0-255
-            // // nodeView.setTransparency(opacity);
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_OPACITY,
-            // "" + opacity);
-            // }
-            //
-            // if (buildStyle
-            // && attributeValueUtil.getAttributeNS(graphics, "opacity",
-            // CY_NAMESPACE) != null) {
-            // String opString = attributeValueUtil.getAttributeNS(graphics,
-            // "opacity", CY_NAMESPACE);
-            // float opacity = (float) Double.parseDouble(opString);
-            // // nodeView.setTransparency(opacity);
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_OPACITY,
-            // opString);
-            // }
-            //
-            // // These are saved in the exported XGMML, but it's not clear how
-            // they
-            // // get set
-            // if (buildStyle
-            // && attributeValueUtil.getAttributeNS(graphics, "nodeLabelFont",
-            // CY_NAMESPACE) != null) {
-            // String nodeLabelFont =
-            // attributeValueUtil.getAttributeNS(graphics,
-            // "nodeLabelFont", CY_NAMESPACE);
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_FONT_FACE, nodeLabelFont);
-            // }
-            //
-            // if (buildStyle
-            // && attributeValueUtil.getAttributeNS(graphics,
-            // "borderLineType", CY_NAMESPACE) != null) {
-            // String borderLineType =
-            // attributeValueUtil.getAttributeNS(graphics,
-            // "borderLineType", CY_NAMESPACE);
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_LINE_STYLE, borderLineType);
-            // }
-            //
-            // String type = attributeValueUtil.getAttribute(graphics, "type");
-            // if (buildStyle && type != null) {
-            // if (type.equals("rhombus"))
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_SHAPE, "parallelogram");
-            // else
-            // graphStyle.addProperty(nodeAttrs,
-            // VisualPropertyType.NODE_SHAPE, type);
-            // }
-        }
+        // // These are saved in the exported XGMML, but it's not clear how 
they get set
+        // if (zattributeValueUtil.getAttributeNS(graphics, "nodeLabelFont", 
CY_NAMESPACE) != null) {
+        // String nodeLabelFont = attributeValueUtil.getAttributeNS(graphics, 
"nodeLabelFont", CY_NAMESPACE);
+        // graphStyle.addProperty(nodeAttrs, 
VisualPropertyType.NODE_FONT_FACE, nodeLabelFont);
+        // }
+        //
+        // if (attributeValueUtil.getAttributeNS(graphics,
+        // "borderLineType", CY_NAMESPACE) != null) {
+        // String borderLineType =
+        // attributeValueUtil.getAttributeNS(graphics,
+        // "borderLineType", CY_NAMESPACE);
+        // graphStyle.addProperty(nodeAttrs,
+        // VisualPropertyType.NODE_LINE_STYLE, borderLineType);
+        // }
+        //
+        // String type = attributeValueUtil.getAttribute(graphics, "type");
+        // if (type != null) {
+        // if (type.equals("rhombus"))
+        // graphStyle.addProperty(nodeAttrs,
+        // VisualPropertyType.NODE_SHAPE, "parallelogram");
+        // else
+        // graphStyle.addProperty(nodeAttrs,
+        // VisualPropertyType.NODE_SHAPE, type);
+        // }
     }
 
     /**
@@ -448,83 +412,88 @@
     private void layoutEdgeGraphics(final Attributes graphics,
                                     final View<CyEdge> edgeView,
                                     final VisualStyleBuilder styleBuilder) {
-        // The attributes of this node
-        CyRow row = edgeView.getModel().getCyRow();
 
-        if (styleBuilder != null) {
-            // Color
-            Color edgeColor = attributeValueUtil.getColorAttribute(graphics, 
"fill");
+        layoutGraphics(graphics, edgeView, styleBuilder, edgeGraphics);
 
-            if (edgeColor != null) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.EDGE_PAINT, 
edgeColor);
-            }
+        // TODO fix for new style view
+        // if (attributeValueUtil.getAttributeNS(graphics, "sourceArrow",
+        // CY_NAMESPACE) != null) { Integer arrowType =
+        // attributeValueUtil.getIntegerAttributeNS( graphics,
+        // "sourceArrow", CY_NAMESPACE); ArrowShape shape =
+        // ArrowShape.getArrowShape(arrowType); String arrowName =
+        // shape.getName(); // edgeView.setSourceEdgeEnd(arrowType);
+        // graphStyle.addProperty(edgeAttrs,
+        // VisualPropertyType.EDGE_SRCARROW_SHAPE, arrowName); }
+        // 
+        // if (attributeValueUtil.getAttributeNS(graphics, "targetArrow",
+        // CY_NAMESPACE) != null) { Integer arrowType =
+        // attributeValueUtil.getIntegerAttributeNS( graphics,
+        // "targetArrow", CY_NAMESPACE); ArrowShape shape =
+        // ArrowShape.getArrowShape(arrowType); String arrowName =
+        // shape.getName(); // edgeView.setTargetEdgeEnd(arrowType);
+        // graphStyle.addProperty(edgeAttrs,
+        // VisualPropertyType.EDGE_TGTARROW_SHAPE, arrowName); }
+        // 
+        // if (attributeValueUtil.getAttributeNS(graphics,
+        // "sourceArrowColor", CY_NAMESPACE) != null) { String arrowColor
+        // 
+        // attributeValueUtil.getAttributeNS(graphics, "sourceArrowColor",
+        // CY_NAMESPACE); // edgeView.setSourceEdgeEndPaint(arrowColor);
+        // graphStyle.addProperty(edgeAttrs,
+        // VisualPropertyType.EDGE_SRCARROW_COLOR, arrowColor); }
+        // 
+        // if (attributeValueUtil.getAttributeNS(graphics,
+        // "targetArrowColor", CY_NAMESPACE) != null) { String arrowColor
+        // 
+        // attributeValueUtil.getAttributeNS(graphics, "targetArrowColor",
+        // CY_NAMESPACE); // edgeView.setTargetEdgeEndPaint(arrowColor);
+        // graphStyle.addProperty(edgeAttrs,
+        // VisualPropertyType.EDGE_TGTARROW_COLOR, arrowColor); }
+        // 
+        // if (attributeValueUtil.getAttributeNS(graphics, "edgeLineType",
+        // CY_NAMESPACE) != null) { String value =
+        // attributeValueUtil.getAttributeNS(graphics, "edgeLineType",
+        // CY_NAMESPACE); graphStyle.addProperty(edgeAttrs,
+        // VisualPropertyType.EDGE_LINE_STYLE, value); }
+        // 
+        // if (attributeValueUtil.getAttributeNS(graphics, "curved",
+        // CY_NAMESPACE) != null) { String value =
+        // attributeValueUtil.getAttributeNS(graphics, "curved",
+        // CY_NAMESPACE); if (value.equals("STRAIGHT_LINES")) {
+        // edgeView.setLineType(EdgeView.STRAIGHT_LINES); } else if
+        // (value.equals("CURVED_LINES")) {
+        // edgeView.setLineType(EdgeView.CURVED_LINES); } }
+        // 
+        // if (attributeValueUtil.getAttribute(graphics, "edgeHandleList")
+        // != null) { // System.out.println("See edgeHandleList"); String
+        // handles[] = attributeValueUtil.getAttribute(graphics,
+        // "edgeHandleList").split(";"); for (int i = 0; i <
+        // andles.length;
+        // i++) { String points[] = handles[i].split(","); double x = (new
+        // Double(points[0])).doubleValue(); double y = (new
+        // Double(points[1])).doubleValue(); Point2D.Double point = new
+        // Point2D.Double(); point.setLocation(x, y);
+        // edgeView.getBend().addHandle(point); } }
+    }
 
-            // Width
-            double lineWidth = attributeValueUtil.getDoubleAttribute(graphics, 
"width");
+    private void layoutGraphics(final Attributes graphics,
+                                final View<? extends CyTableEntry> view,
+                                final VisualStyleBuilder styleBuilder,
+                                final List<GraphicsConverter<?>> converters) {
 
-            if (lineWidth >= 0) {
-                styleBuilder.addProperty(row, TwoDVisualLexicon.EDGE_WIDTH, 
lineWidth);
+        // The attributes of this view
+        CyRow row = view.getModel().getCyRow();
+
+        if (styleBuilder != null) {
+            for (GraphicsConverter<?> conv : converters) {
+                String key = conv.getKey();
+                VisualProperty vp = lexicon.lookup(CyNode.class, key);
+
+                if (vp != null) {
+                    Object value = conv.getValue(graphics, attributeValueUtil);
+                    if (value != null) styleBuilder.addProperty(row, vp, 
value);
+                }
             }
-
-            // TODO fix for new style view
-            // if (attributeValueUtil.getAttributeNS(graphics, "sourceArrow",
-            // CY_NAMESPACE) != null) { Integer arrowType =
-            // attributeValueUtil.getIntegerAttributeNS( graphics,
-            // "sourceArrow", CY_NAMESPACE); ArrowShape shape =
-            // ArrowShape.getArrowShape(arrowType); String arrowName =
-            // shape.getName(); // edgeView.setSourceEdgeEnd(arrowType);
-            // graphStyle.addProperty(edgeAttrs,
-            // VisualPropertyType.EDGE_SRCARROW_SHAPE, arrowName); }
-            // 
-            // if (attributeValueUtil.getAttributeNS(graphics, "targetArrow",
-            // CY_NAMESPACE) != null) { Integer arrowType =
-            // attributeValueUtil.getIntegerAttributeNS( graphics,
-            // "targetArrow", CY_NAMESPACE); ArrowShape shape =
-            // ArrowShape.getArrowShape(arrowType); String arrowName =
-            // shape.getName(); // edgeView.setTargetEdgeEnd(arrowType);
-            // graphStyle.addProperty(edgeAttrs,
-            // VisualPropertyType.EDGE_TGTARROW_SHAPE, arrowName); }
-            // 
-            // if (attributeValueUtil.getAttributeNS(graphics,
-            // "sourceArrowColor", CY_NAMESPACE) != null) { String arrowColor
-            // 
-            // attributeValueUtil.getAttributeNS(graphics, "sourceArrowColor",
-            // CY_NAMESPACE); // edgeView.setSourceEdgeEndPaint(arrowColor);
-            // graphStyle.addProperty(edgeAttrs,
-            // VisualPropertyType.EDGE_SRCARROW_COLOR, arrowColor); }
-            // 
-            // if (buildStyle && attributeValueUtil.getAttributeNS(graphics,
-            // "targetArrowColor", CY_NAMESPACE) != null) { String arrowColor
-            // 
-            // attributeValueUtil.getAttributeNS(graphics, "targetArrowColor",
-            // CY_NAMESPACE); // edgeView.setTargetEdgeEndPaint(arrowColor);
-            // graphStyle.addProperty(edgeAttrs,
-            // VisualPropertyType.EDGE_TGTARROW_COLOR, arrowColor); }
-            // 
-            // if (attributeValueUtil.getAttributeNS(graphics, "edgeLineType",
-            // CY_NAMESPACE) != null) { String value =
-            // attributeValueUtil.getAttributeNS(graphics, "edgeLineType",
-            // CY_NAMESPACE); graphStyle.addProperty(edgeAttrs,
-            // VisualPropertyType.EDGE_LINE_STYLE, value); }
-            // 
-            // if (attributeValueUtil.getAttributeNS(graphics, "curved",
-            // CY_NAMESPACE) != null) { String value =
-            // attributeValueUtil.getAttributeNS(graphics, "curved",
-            // CY_NAMESPACE); if (value.equals("STRAIGHT_LINES")) {
-            // edgeView.setLineType(EdgeView.STRAIGHT_LINES); } else if
-            // (value.equals("CURVED_LINES")) {
-            // edgeView.setLineType(EdgeView.CURVED_LINES); } }
-            // 
-            // if (attributeValueUtil.getAttribute(graphics, "edgeHandleList")
-            // != null) { // System.out.println("See edgeHandleList"); String
-            // handles[] = attributeValueUtil.getAttribute(graphics,
-            // "edgeHandleList").split(";"); for (int i = 0; i <
-            // andles.length;
-            // i++) { String points[] = handles[i].split(","); double x = (new
-            // Double(points[0])).doubleValue(); double y = (new
-            // Double(points[1])).doubleValue(); Point2D.Double point = new
-            // Point2D.Double(); point.setLocation(x, y);
-            // edgeView.getBend().addHandle(point); } }
         }
     }
 
@@ -541,3 +510,63 @@
     }
 
 }
+
+class GraphicsConverter<T> {
+
+    public String   key;
+    public Class<T> type;
+    public String   namespace;
+
+    public GraphicsConverter(String key, Class<T> type) {
+        this.key = key;
+        this.type = type;
+    }
+
+    public GraphicsConverter(String key, Class<T> type, String namespace) {
+        this(key, type);
+        this.namespace = namespace;
+    }
+
+    public T getValue(final Attributes graphics, final AttributeValueUtil 
attributeValueUtil) {
+        Object value = null;
+
+        if (graphics != null) {
+            if (type == Integer.class) {
+                if (isTransparency()) {
+                    // Opacity is saved as a float from 0.0-1.0, but 
internally we use 0-255
+                    Double d = attributeValueUtil.getDoubleAttribute(graphics, 
key);
+                    value = new Integer((int) d.doubleValue() * 255);
+                } else {
+                    value = attributeValueUtil.getIntegerAttribute(graphics, 
key);
+                }
+            } else if (type == Double.class) {
+                value = attributeValueUtil.getDoubleAttribute(graphics, key);
+            } else if (type == Color.class) {
+                value = attributeValueUtil.getColorAttribute(graphics, key);
+            } else if (type == Font.class) {
+                value = attributeValueUtil.getAttribute(graphics, key);
+            } else {
+                value = attributeValueUtil.getAttribute(graphics, key);
+            }
+        }
+
+        return (T) value;
+    }
+
+    public boolean isTransparency() {
+        return key.toLowerCase().contains("transparency");
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public Class<T> getType() {
+        return type;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+}

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderFactory.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderFactory.java
   2011-01-25 23:21:02 UTC (rev 23619)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderFactory.java
   2011-01-26 00:01:44 UTC (rev 23620)
@@ -36,6 +36,7 @@
 import org.cytoscape.model.CyNetworkFactory;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyleFactory;
@@ -52,6 +53,7 @@
  */
 public class XGMMLNetworkViewReaderFactory extends 
AbstractNetworkViewReaderFactory {
 
+    private final RenderingEngineManager       renderingEngineManager;
     private VisualStyleFactory                 styleFactory;
     private VisualMappingManager               visMappingManager;
     private final VisualMappingFunctionFactory discreteMappingFactory;
@@ -61,6 +63,7 @@
     private CyProperty<Properties>             properties;
 
     public XGMMLNetworkViewReaderFactory(CyFileFilter filter,
+                                         RenderingEngineManager 
renderingEngineManager,
                                          CyNetworkViewFactory 
cyNetworkViewFactory,
                                          CyNetworkFactory cyNetworkFactory,
                                          ReadDataManager readDataManager,
@@ -71,6 +74,7 @@
                                          XGMMLParser parser,
                                          CyProperty<Properties> properties) {
         super(filter, cyNetworkViewFactory, cyNetworkFactory);
+        this.renderingEngineManager = renderingEngineManager;
         this.readDataManager = readDataManager;
         this.attributeValueUtil = attributeValueUtil;
         this.styleFactory = styleFactory;
@@ -81,9 +85,9 @@
     }
 
     public TaskIterator getTaskIterator() {
-        return new TaskIterator(new XGMMLNetworkViewReader(inputStream, 
cyNetworkViewFactory, cyNetworkFactory,
-                                                           readDataManager, 
attributeValueUtil, styleFactory,
-                                                           visMappingManager, 
discreteMappingFactory, parser,
-                                                           properties));
+        return new TaskIterator(new XGMMLNetworkViewReader(inputStream, 
renderingEngineManager, cyNetworkViewFactory,
+                                                           cyNetworkFactory, 
readDataManager, attributeValueUtil,
+                                                           styleFactory, 
visMappingManager, discreteMappingFactory,
+                                                           parser, 
properties));
     }
 }

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 23:21:02 UTC (rev 23619)
+++ core3/io-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
2011-01-26 00:01:44 UTC (rev 23620)
@@ -324,6 +324,7 @@
        <bean id="xgmmlNetworkViewReaderFactory" 
              
class="org.cytoscape.io.internal.read.xgmml.XGMMLNetworkViewReaderFactory">
                <constructor-arg ref="xgmmlFilter" />
+               <constructor-arg ref="renderingEngineManagerServiceRef" />
                <constructor-arg ref="cyNetworkViewFactoryServiceRef" />
                <constructor-arg ref="cyNetworkFactoryServiceRef" />
                <constructor-arg ref="readDataManager" />

Modified: 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderTest.java
===================================================================
--- 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderTest.java
      2011-01-25 23:21:02 UTC (rev 23619)
+++ 
core3/io-impl/trunk/src/test/java/org/cytoscape/io/internal/read/xgmml/XGMMLNetworkViewReaderTest.java
      2011-01-26 00:01:44 UTC (rev 23620)
@@ -22,6 +22,7 @@
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.presentation.RenderingEngineManager;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyleFactory;
 import org.cytoscape.view.vizmap.mappings.DiscreteMappingFactory;
@@ -35,6 +36,7 @@
 
 public class XGMMLNetworkViewReaderTest extends 
AbstractNetworkViewReaderTester {
 
+    RenderingEngineManager renderingEngineManager;
     ReadDataManager        readDataManager;
     AttributeValueUtil     attributeValueUtil;
     VisualStyleFactory     styleFactory;
@@ -79,10 +81,10 @@
 
     private CyNetworkView[] getViews(String file) throws Exception {
         File f = new File("./src/test/resources/testData/xgmml/" + file);
-        XGMMLNetworkViewReader snvp = new XGMMLNetworkViewReader(new 
FileInputStream(f), viewFactory, netFactory,
-                                                                 
readDataManager, attributeValueUtil, styleFactory,
-                                                                 
visMappingManager, discreteMappingFactory, parser,
-                                                                 properties);
+        XGMMLNetworkViewReader snvp = new XGMMLNetworkViewReader(new 
FileInputStream(f), renderingEngineManager,
+                                                                 viewFactory, 
netFactory, readDataManager,
+                                                                 
attributeValueUtil, styleFactory, visMappingManager,
+                                                                 
discreteMappingFactory, parser, properties);
         snvp.run(taskMonitor);
 
         return snvp.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