[graphl-cvs] graphl/src/org/mediavirus/graphl/painter ImageNodePainter.java StraightLineEdgePainter.
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2005-12-18 11:12:28
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2618/src/org/mediavirus/graphl/painter Modified Files: ImageNodePainter.java StraightLineEdgePainter.java BoxNodePainter.java ShapeNodePainter.java LineEdgePainter.java ManhattanEdgePainter.java Log Message: - FEATURE: RXPath landed! you can assign properties of facets through XPath-like expressions based on the currently rendered node - CODE: Remove LabelGenerator classes - this can now done with RXPath - CODE: migrated to JDK 1.5, added class specifiers for all collections (generics) - CODE: added a singleton GraphlRegistry, currently only holding the vocabularyRegistry instance Index: LineEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/LineEdgePainter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** LineEdgePainter.java 17 Aug 2005 15:52:51 -0000 1.9 --- LineEdgePainter.java 18 Dec 2005 11:11:40 -0000 1.10 *************** *** 12,20 **** import java.awt.Rectangle; import java.awt.Stroke; import org.mediavirus.graphl.GraphlPane; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; - import org.mediavirus.graphl.view.LabelGenerator; import org.mediavirus.graphl.vocabulary.NS; import org.mediavirus.util.ParseUtils; --- 12,22 ---- import java.awt.Rectangle; import java.awt.Stroke; + import java.util.HashMap; + import org.apache.commons.jxpath.ClassFunctions; + import org.apache.commons.jxpath.JXPathContext; import org.mediavirus.graphl.GraphlPane; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.vocabulary.NS; import org.mediavirus.util.ParseUtils; *************** *** 33,43 **** * @uml.property name="invertArrow" */ ! protected boolean invertArrow = false; ! ! Stroke stroke; Stroke highlightedStroke; Stroke selectedStroke; Font font; --- 35,46 ---- * @uml.property name="invertArrow" */ ! protected boolean invertArrow = false; Stroke stroke; Stroke highlightedStroke; Stroke selectedStroke; + + String widthExpr; + String labelExpr; Font font; *************** *** 45,49 **** Color labelColor = Color.BLACK; ! LabelGenerator labelGenerator; /** --- 48,53 ---- Color labelColor = Color.BLACK; ! HashMap<Edge, Stroke> strokeCache = new HashMap<Edge, Stroke>(); ! HashMap<Edge, String> labelCache = new HashMap<Edge, String>(); /** *************** *** 62,67 **** this.color = color; this.font = font; - - labelGenerator = new LabelGenerator(LabelGenerator.TYPE,"",true); } --- 66,69 ---- *************** *** 69,75 **** //DraggingManipulator draggingManipulator = (DraggingManipulator)graphPane.getManipulator(DraggingManipulator.NAME); //boolean isDragging = draggingManipulator!=null && draggingManipulator.getDraggedEdge()==edge; ! ! boolean isDragging = false; ! doPaintEdge(graphPane, g, edge, selected, highlighted); } --- 71,100 ---- //DraggingManipulator draggingManipulator = (DraggingManipulator)graphPane.getManipulator(DraggingManipulator.NAME); //boolean isDragging = draggingManipulator!=null && draggingManipulator.getDraggedEdge()==edge; ! ! Stroke oldStroke = getStroke(); ! ! if (widthExpr != null) { ! Stroke dynStroke = strokeCache.get(edge); ! if (dynStroke == null) { ! JXPathContext context = JXPathContext.newContext(edge); ! context.setLenient(true); ! Object widthO = context.getValue(widthExpr); ! try { ! double width = ((Double)widthO).doubleValue(); ! BasicStroke bs = (BasicStroke)stroke; ! dynStroke = new BasicStroke((float) width, bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), bs.getDashArray(), bs.getDashPhase()); ! strokeCache.put(edge, dynStroke); ! } ! catch (Exception ex) {} ! } ! if (dynStroke != null) setStroke(dynStroke); ! doPaintEdge(graphPane, g, edge, selected, highlighted); ! setStroke(oldStroke); ! } ! else { ! doPaintEdge(graphPane, g, edge, selected, highlighted); ! } ! ! } *************** *** 173,188 **** } /** - * @return Returns the labelGenerator. - */ - public LabelGenerator getLabelGenerator() { - return labelGenerator; - } - /** - * @param labelGenerator The labelGenerator to set. - */ - public void setLabelGenerator(LabelGenerator labelGenerator) { - this.labelGenerator = labelGenerator; - } - /** * @param stroke The stroke to set. */ --- 198,201 ---- *************** *** 236,239 **** --- 249,268 ---- return stroke; } + + public String getLabel(Edge edge) { + String label = labelCache.get(edge); + if (label == null) { + if (labelExpr != null) { + JXPathContext context = JXPathContext.newContext(edge); + context.setFunctions(new ClassFunctions(ParseUtils.class, "graphl")); + context.setLenient(true); + Object labelO = context.getValue(labelExpr); + if (labelO instanceof String) { + label = (String) labelO; + } + } + } + return label; + } public abstract boolean isPointInLabel(GraphlPane graphPane, Edge edge, Point point); *************** *** 267,270 **** --- 296,322 ---- if (stroke != null) setStroke(stroke); + widthExpr = node.getProperty(NS.graphl + "width"); + labelExpr = node.getProperty(NS.graphl + "label"); + } + + + public String getLabelExpr() { + return labelExpr; + } + + + public void setLabelExpr(String labelExpr) { + this.labelExpr = labelExpr; + } + + + public String getWidthExpr() { + return widthExpr; + } + + + public void setWidthExpr(String widthExpr) { + this.widthExpr = widthExpr; + } } Index: ImageNodePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/ImageNodePainter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ImageNodePainter.java 17 Aug 2005 15:52:51 -0000 1.7 --- ImageNodePainter.java 18 Dec 2005 11:11:40 -0000 1.8 *************** *** 48,52 **** int height = 20; ! static Hashtable images = new Hashtable(); public ImageNodePainter() { --- 48,52 ---- int height = 20; ! static Hashtable<Node, Image> images = new Hashtable<Node, Image>(); public ImageNodePainter() { *************** *** 179,183 **** public boolean isEdgeDragPoint(GraphlPane graphPane, Node node, Point p) { ! // TODO (2) implement this return false; } --- 179,183 ---- public boolean isEdgeDragPoint(GraphlPane graphPane, Node node, Point p) { ! // TODO (2) implement ImageNodePainter.isEdgeDragPoint() return false; } Index: StraightLineEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/StraightLineEdgePainter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** StraightLineEdgePainter.java 5 Sep 2005 15:48:39 -0000 1.8 --- StraightLineEdgePainter.java 18 Dec 2005 11:11:40 -0000 1.9 *************** *** 142,146 **** if (isPaintLabel()){ g.setColor(getLabelColor()); ! String label = labelGenerator.getLabel(edge); if (label != null){ Font oldfont = g.getFont(); --- 142,146 ---- if (isPaintLabel()){ g.setColor(getLabelColor()); ! String label = getLabel(edge); if (label != null){ Font oldfont = g.getFont(); *************** *** 304,315 **** return (p instanceof StraightLineEdgePainter); } - - /* - * Overrides @see org.mediavirus.graphl.view.GraphlEdgePainter#getLength(org.mediavirus.graphl.RDFEdge) - */ - public double getLength(Edge edge) { - return edge.getLength(); - } - - } --- 304,306 ---- Index: ShapeNodePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/ShapeNodePainter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ShapeNodePainter.java 17 Aug 2005 15:52:51 -0000 1.6 --- ShapeNodePainter.java 18 Dec 2005 11:11:40 -0000 1.7 *************** *** 206,212 **** setShape(CROSS); } ! else if (str.equalsIgnoreCase("circle")) { ! setShape(CIRCLE); ! } } --- 206,215 ---- setShape(CROSS); } ! else if (str.equalsIgnoreCase("circle")) { ! setShape(CIRCLE); ! } ! else if (str.equalsIgnoreCase("square")) { ! setShape(SQUARE); ! } } Index: ManhattanEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/ManhattanEdgePainter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ManhattanEdgePainter.java 30 Nov 2004 09:38:34 -0000 1.5 --- ManhattanEdgePainter.java 18 Dec 2005 11:11:40 -0000 1.6 *************** *** 12,16 **** import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; - import org.mediavirus.graphl.graph.rdf.RDFEdge; /** --- 12,15 ---- *************** *** 135,145 **** } - /* - * @see org.mediavirus.graphl.view.GraphlEdgePainter#getLength(org.mediavirus.graphl.RDFEdge) - */ - public double getLength(RDFEdge edge) { - return edge.getLength(); - } - - } --- 134,136 ---- Index: BoxNodePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/BoxNodePainter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** BoxNodePainter.java 17 Aug 2005 15:52:51 -0000 1.10 --- BoxNodePainter.java 18 Dec 2005 11:11:40 -0000 1.11 *************** *** 13,21 **** import java.awt.Rectangle; import java.awt.Stroke; import org.mediavirus.graphl.GraphlPane; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; - import org.mediavirus.graphl.view.LabelGenerator; import org.mediavirus.graphl.vocabulary.NS; import org.mediavirus.util.ParseUtils; --- 13,24 ---- import java.awt.Rectangle; import java.awt.Stroke; + import java.util.HashMap; + import java.util.Map; + import org.apache.commons.jxpath.ClassFunctions; + import org.apache.commons.jxpath.JXPathContext; import org.mediavirus.graphl.GraphlPane; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.vocabulary.NS; import org.mediavirus.util.ParseUtils; *************** *** 38,42 **** int cornerRadius = 8; ! LabelGenerator labelGenerator; public BoxNodePainter(){ --- 41,47 ---- int cornerRadius = 8; ! //LabelGenerator labelGenerator; ! String labelExpr; ! Map<Node, String> labelCache = new HashMap<Node, String>(); public BoxNodePainter(){ *************** *** 47,51 **** baseColor = new Color(255,250,168); textColor = Color.BLACK; ! labelGenerator = new LabelGenerator(); } --- 52,56 ---- baseColor = new Color(255,250,168); textColor = Color.BLACK; ! //labelGenerator = new LabelGenerator(); } *************** *** 79,82 **** --- 84,97 ---- } + + public String getLabelExpr() { + return labelExpr; + } + + + public void setLabelExpr(String labelExpr) { + this.labelExpr = labelExpr; + } + /** * @return Returns the borderStroke. *************** *** 205,209 **** public void paintNode(GraphlPane graphPane,Graphics2D g,Node node, boolean selected, boolean highlighted) { //DraggingManipulator draggingManipulator=(DraggingManipulator)graphPane.getManipulator(DraggingManipulator.NAME); ! boolean isDragging=false; //draggingManipulator!=null && draggingManipulator.getDraggedNode()==node; Point nodePoint=graphPane.getScreenPointForNode(node); int width=1; --- 220,224 ---- public void paintNode(GraphlPane graphPane,Graphics2D g,Node node, boolean selected, boolean highlighted) { //DraggingManipulator draggingManipulator=(DraggingManipulator)graphPane.getManipulator(DraggingManipulator.NAME); ! //boolean isDragging=false; //draggingManipulator!=null && draggingManipulator.getDraggedNode()==node; Point nodePoint=graphPane.getScreenPointForNode(node); int width=1; *************** *** 211,215 **** int textX=0; int textY=0; ! String label = labelGenerator.getLabel(node); g.setStroke(borderStroke); if (label!=null) { --- 226,232 ---- int textX=0; int textY=0; ! ! String label = getLabel(node); ! g.setStroke(borderStroke); if (label!=null) { *************** *** 261,265 **** public void getNodeScreenBounds(GraphlPane graphPane,Node node,Rectangle nodeScreenRectangle) { Point nodePoint=graphPane.getScreenPointForNode(node); ! String label = labelGenerator.getLabel(node); int width=1; int height=1; --- 278,282 ---- public void getNodeScreenBounds(GraphlPane graphPane,Node node,Rectangle nodeScreenRectangle) { Point nodePoint=graphPane.getScreenPointForNode(node); ! String label = getLabel(node); int width=1; int height=1; *************** *** 276,279 **** --- 293,312 ---- } + private String getLabel(Node node) { + String label = labelCache.get(node); + if (label == null) { + if (labelExpr != null) { + JXPathContext context = JXPathContext.newContext(node); + context.setFunctions(new ClassFunctions(ParseUtils.class, "graphl")); + context.setLenient(true); + Object labelO = context.getValue(labelExpr); + if (labelO instanceof String) { + label = (String) labelO; + } + } + } + return label; + } + public boolean isEdgeDragPoint(GraphlPane graphPane,Node node,Point p) { Rectangle r = new Rectangle(); *************** *** 336,346 **** if (font != null) setFont(font); ! try { ! Node labelGeneratorNode = (Node)node.getNeighbours(NS.graphl + "labelGenerator", true).get(0); ! labelGenerator.setConfigurationNode(labelGeneratorNode); ! } ! catch (IndexOutOfBoundsException ioobex) { ! // no such neighbour found ! } Stroke stroke = ParseUtils.parseStroke(node.getProperty(NS.graphl + "borderStroke")); --- 369,379 ---- if (font != null) setFont(font); ! // try { ! // Node labelGeneratorNode = (Node)node.getNeighbours(NS.graphl + "labelGenerator", true).get(0); ! // labelGenerator.setConfigurationNode(labelGeneratorNode); ! // } ! // catch (IndexOutOfBoundsException ioobex) { ! // // no such neighbour found ! // } Stroke stroke = ParseUtils.parseStroke(node.getProperty(NS.graphl + "borderStroke")); *************** *** 353,358 **** if (str != null) setUseBorderColor(str.equalsIgnoreCase("true")); ! str = node.getProperty(NS.graphl + "cornerRadius"); ! if (str != null) setCornerRadius(Integer.parseInt(str)); } --- 386,394 ---- if (str != null) setUseBorderColor(str.equalsIgnoreCase("true")); ! str = node.getProperty(NS.graphl + "cornerRadius"); ! if (str != null) setCornerRadius(Integer.parseInt(str)); ! ! str = node.getProperty(NS.graphl + "label"); ! if (str != null) setLabelExpr(str); } |