Author: Christian Lopes
Date: 2011-03-08 14:48:55 -0800 (Tue, 08 Mar 2011)
New Revision: 24336
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/ArrowShapeTwoDVisualProperty.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/FontTwoDVisualProperty.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/IntegerTwoDVisualProperty.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/NodeShapeTwoDVisualProperty.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/StrokeTwoDVisualProperty.java
Log:
Added edge style, node and arrow shapes to the lexicon's lookup.
Implemented or improved the parsing code of some Visual Properties, such as
Shapes, Font and Stroke.
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -411,6 +411,7 @@
addIdentifierMapping(CyNode.class,"nodeOpacity",NODE_TRANSPARENCY);
addIdentifierMapping(CyNode.class,"nodeBorderColor",NODE_BORDER_PAINT);
addIdentifierMapping(CyNode.class,"nodeLineWidth",NODE_BORDER_WIDTH);
+ addIdentifierMapping(CyNode.class,"nodeShape",NODE_SHAPE);
addIdentifierMapping(CyNode.class,"nodeFont",NODE_LABEL_FONT_FACE);
addIdentifierMapping(CyNode.class,"nodeFontSize",NODE_LABEL_FONT_SIZE);
addIdentifierMapping(CyNode.class,"nodeToolTip",NODE_TOOLTIP);
@@ -420,7 +421,11 @@
//
addIdentifierMapping(CyNode.class,"nodeLabelWidth",NODE_LABEL_WIDTH);
addIdentifierMapping(CyEdge.class,"edgeColor",EDGE_STROKE_UNSELECTED_PAINT);
-
+ addIdentifierMapping(CyEdge.class,"edgeLineStyle",EDGE_STROKE);
+
addIdentifierMapping(CyEdge.class,"edgeSourceArrowShape",EDGE_SOURCE_ARROW_SHAPE);
+
addIdentifierMapping(CyEdge.class,"edgeSourceArrowColor",EDGE_SOURCE_ARROW_UNSELECTED_PAINT);
+
addIdentifierMapping(CyEdge.class,"edgeTargetArrowShape",EDGE_TARGET_ARROW_SHAPE);
+
addIdentifierMapping(CyEdge.class,"edgeTargetArrowColor",EDGE_TARGET_ARROW_UNSELECTED_PAINT);
addIdentifierMapping(CyEdge.class,"edgeToolTip",EDGE_TOOLTIP);
addIdentifierMapping(CyEdge.class,"edgeFont",EDGE_LABEL_FONT_FACE);
addIdentifierMapping(CyEdge.class,"edgeFontSize",EDGE_LABEL_FONT_SIZE);
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/ArrowShapeTwoDVisualProperty.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/ArrowShapeTwoDVisualProperty.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/ArrowShapeTwoDVisualProperty.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -1,4 +1,3 @@
-
/*
Copyright (c) 2008, The Cytoscape Consortium (www.cytoscape.org)
@@ -32,10 +31,12 @@
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.ding.impl.visualproperty;
+ */
+package org.cytoscape.ding.impl.visualproperty;
import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
import java.util.Set;
import org.cytoscape.ding.ArrowShape;
@@ -44,26 +45,54 @@
import org.cytoscape.view.model.DiscreteRangeImpl;
import org.cytoscape.view.model.Range;
-public class ArrowShapeTwoDVisualProperty extends
AbstractVisualProperty<ArrowShape> {
+public class ArrowShapeTwoDVisualProperty extends
+ AbstractVisualProperty<ArrowShape> {
private static final Range<ArrowShape> ARROW_SHAPE_RANGE;
-
+
+ /** key -> valid_cytoscape_key */
+ private static final Map<String, String> shapeKeys = new
Hashtable<String, String>();
+
static {
final Set<ArrowShape> arrowSet = new HashSet<ArrowShape>();
- for(final ArrowShape arrow: ArrowShape.values())
+ for (final ArrowShape arrow : ArrowShape.values())
arrowSet.add(arrow);
- ARROW_SHAPE_RANGE = new
DiscreteRangeImpl<ArrowShape>(ArrowShape.class, arrowSet);
+ ARROW_SHAPE_RANGE = new
DiscreteRangeImpl<ArrowShape>(ArrowShape.class,
+ arrowSet);
+
+ // We have to support Cytoscape 2.8 XGMML shapes!
+ shapeKeys.put("0", "NONE");
+ shapeKeys.put("3", "DELTA");
+ shapeKeys.put("6", "ARROW");
+ shapeKeys.put("9", "DIAMOND");
+ shapeKeys.put("12", "CIRCLE");
+ shapeKeys.put("15", "T");
+ shapeKeys.put("16", "HALF_ARROW_TOP");
+ shapeKeys.put("17", "HALF_ARROW_BOTTOM");
}
-
- public ArrowShapeTwoDVisualProperty(final ArrowShape def, final String
id, final String name) {
+
+ public ArrowShapeTwoDVisualProperty(final ArrowShape def, final String
id,
+ final String name) {
super(def, ARROW_SHAPE_RANGE, id, name, CyEdge.class);
}
-
+
public String toSerializableString(final ArrowShape value) {
return value.toString();
}
public ArrowShape parseSerializableString(final String text) {
- return ArrowShape.valueOf(text);
+ ArrowShape shape = null;
+
+ if (text != null) {
+ String key = text.trim().toUpperCase();
+ String validKey = shapeKeys.get(key);
+
+ if (validKey == null)
+ validKey = key;
+
+ shape = ArrowShape.valueOf(validKey);
+ }
+
+ return shape;
}
}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/FontTwoDVisualProperty.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/FontTwoDVisualProperty.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/FontTwoDVisualProperty.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -60,12 +60,32 @@
}
public String toSerializableString(final Font value) {
+ // TODO:
return value.toString();
}
public Font parseSerializableString(final String text) {
- // TODO
- return null;
+ Font font = null;
+
+ if (text != null) {
+ String name =
text.replaceAll("(\\.[bB]old)?,[a-zA-Z]+,\\d+(\\.\\d+)?", "");
+
+ boolean bold = text.matches("(?i).*\\.bold,[a-zA-Z]+,.*");
+ int style = bold ? Font.BOLD : Font.PLAIN;
+ int size = 12;
+
+ String sSize = text.replaceAll(".+,[^,]+,", "");
+
+ try {
+ size = Integer.parseInt(sSize);
+ } catch (NumberFormatException nfe) {
+ // TODO: log/warning
+ }
+
+ font = new Font(name, style, size);
+ }
+
+ return font;
}
private static Set<Font> getSystemFonts() {
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/IntegerTwoDVisualProperty.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/IntegerTwoDVisualProperty.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/IntegerTwoDVisualProperty.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -52,6 +52,7 @@
}
public Integer parseSerializableString(final String text) {
- return Integer.valueOf(text);
+ // Cytoscape 2.x serializes integer attributes as decimals
(e.g."1.0")!
+ return Double.valueOf(text).intValue();
}
}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/NodeShapeTwoDVisualProperty.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/NodeShapeTwoDVisualProperty.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/NodeShapeTwoDVisualProperty.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -35,6 +35,8 @@
package org.cytoscape.ding.impl.visualproperty;
import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
import java.util.Set;
import org.cytoscape.ding.NodeShape;
@@ -47,6 +49,9 @@
AbstractVisualProperty<NodeShape> {
private static final Range<NodeShape> NODE_SHAPE_RANGE;
+
+ /** key -> valid_cytoscape_key */
+ private static final Map<String, String> shapeKeys = new
Hashtable<String, String>();
static {
final Set<NodeShape> shapeSet = new HashSet<NodeShape>();
@@ -54,6 +59,18 @@
shapeSet.add(shape);
NODE_SHAPE_RANGE = new
DiscreteRangeImpl<NodeShape>(NodeShape.class,
shapeSet);
+
+ // Let's be nice and also support regular and Cytoscape XGMML
shapes?
+ shapeKeys.put("SQUARE", "RECT");
+ shapeKeys.put("RECTANGLE", "RECT");
+ shapeKeys.put("BOX", "RECT");
+ shapeKeys.put("ROUNDRECT", "ROUND_RECT");
+ shapeKeys.put("ROUND_RECTANGLE", "ROUND_RECT");
+ shapeKeys.put("RHOMBUS", "PARALLELOGRAM");
+ shapeKeys.put("V", "VEE");
+ shapeKeys.put("CIRCLE", "ELLIPSE");
+ shapeKeys.put("VER_ELLIPSIS", "ELLIPSE");
+ shapeKeys.put("HOR_ELLIPSIS", "ELLIPSE");
}
public NodeShapeTwoDVisualProperty(final NodeShape def, final String id,
@@ -66,6 +83,18 @@
}
public NodeShape parseSerializableString(final String text) {
- return NodeShape.valueOf(text);
+ NodeShape shape = null;
+
+ if (text != null) {
+ String key = text.trim().toUpperCase();
+ String validKey = shapeKeys.get(key);
+
+ if (validKey == null)
+ validKey = key;
+
+ shape = NodeShape.valueOf(validKey);
+ }
+
+ return shape;
}
}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/StrokeTwoDVisualProperty.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/StrokeTwoDVisualProperty.java
2011-03-08 22:42:22 UTC (rev 24335)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/visualproperty/StrokeTwoDVisualProperty.java
2011-03-08 22:48:55 UTC (rev 24336)
@@ -71,7 +71,14 @@
}
public Stroke parseSerializableString(final String text) {
- // TODO
- return null;
+ Stroke stroke = null;
+
+ if (text != null) {
+ String key = text.trim().toUpperCase();
+ LineStyle style = LineStyle.parse(key);
+ stroke = style.getStroke(DEFAULT_STROKE_WIDTH);
+ }
+
+ return stroke;
}
}
--
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.