[graphl-cvs] graphl/src/org/mediavirus/graphl/painter XPathGraphWalker.java StraightLineEdgePainter
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2006-06-30 14:32:14
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv11488/src/org/mediavirus/graphl/painter Modified Files: StraightLineEdgePainter.java LineEdgePainter.java ManhattanEdgePainter.java BoxNodePainter.java NodePainter.java Added Files: XPathGraphWalker.java Removed Files: ImageNodePainter.java ImageNodePainterBeanInfo.java BoxNodePainterBeanInfo.java Log Message: - migrated from jxpath to jaxen, which gives a much cleaner implementation of custom axes Index: LineEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/LineEdgePainter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** LineEdgePainter.java 8 Jun 2006 13:14:58 -0000 1.11 --- LineEdgePainter.java 30 Jun 2006 14:31:35 -0000 1.12 *************** *** 14,22 **** import java.util.HashMap; - 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.jxpath.JXPathFactory; import org.mediavirus.graphl.vocabulary.NS; import org.mediavirus.util.ParseUtils; --- 14,20 ---- *************** *** 28,69 **** public abstract class LineEdgePainter extends AbstractEdgePainter { ! protected boolean paintArrow = true; ! protected boolean paintLabel = true; ! ! /** ! * ! * @uml.property name="invertArrow" ! */ ! protected boolean invertArrow = false; ! ! Stroke stroke; ! Stroke highlightedStroke; ! Stroke selectedStroke; ! ! String widthExpr; ! String labelExpr; ! ! Font font; ! Color color; ! Color labelColor = Color.BLACK; - HashMap<Edge, Stroke> strokeCache = new HashMap<Edge, Stroke>(); - HashMap<Edge, String> labelCache = new HashMap<Edge, String>(); - - /** - * - */ public LineEdgePainter() { - this(new BasicStroke(0.7f), Color.BLACK, new Font(null, Font.PLAIN, 9), true, true); - } - - public LineEdgePainter(Stroke stroke, Color color, Font font, boolean paintingArrow, boolean paintingLabel) { - - this.paintArrow = paintingArrow; - this.paintLabel = paintingLabel; - - setStroke(stroke); - this.color = color; - this.font = font; } --- 26,33 ---- public abstract class LineEdgePainter extends AbstractEdgePainter { ! Stroke defaultStroke = new BasicStroke(0.7f); ! Font defaultFont = new Font(null, Font.PLAIN, 9); public LineEdgePainter() { } *************** *** 72,98 **** //boolean isDragging = draggingManipulator!=null && draggingManipulator.getDraggedEdge()==edge; ! Stroke oldStroke = getStroke(); ! if (widthExpr != null) { ! Stroke dynStroke = strokeCache.get(edge); ! if (dynStroke == null) { ! JXPathContext context = JXPathFactory.createContext(edge); ! 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); ! } } --- 36,48 ---- //boolean isDragging = draggingManipulator!=null && draggingManipulator.getDraggedEdge()==edge; ! Stroke oldStroke = g.getStroke(); ! Stroke stroke = getStrokeProperty(NS.graphl + "stroke", edge); ! if (stroke == null) stroke = defaultStroke; + g.setStroke(stroke); + doPaintEdge(graphPane, g, edge, selected, highlighted); + + g.setStroke(oldStroke); } *************** *** 117,236 **** } - /** - * @return A boolean value, indicating if an arrow indicating the direction of the Edge - * will be painted. - */ - public boolean isPaintArrow() { - return paintArrow; - } - - /** - * @param b A boolean value, indicating whether an arrow indicating the direction of the - * Edge should be painted. - */ - public void setPaintArrow(boolean b) { - paintArrow = b; - } - - /** - * @return Returns the invertArrow. - * - * @uml.property name="invertArrow" - */ - public boolean isInvertArrow() { - return invertArrow; - } - - /** - * @param invertArrow The invertArrow to set. - * - * @uml.property name="invertArrow" - */ - public void setInvertArrow(boolean invertArrow) { - this.invertArrow = invertArrow; - } - - - /** - * @return The Stroke currently set for rendering the Edge. - */ - public Stroke getStroke(boolean selected, boolean highlighted) { - if (highlighted) { - return highlightedStroke; - } - if (selected) { - return selectedStroke; - } - return stroke; - } - - /** - * @return A boolean value, indicating if a label should be painted next to the Edge. - */ - public boolean isPaintLabel() { - return paintLabel; - } - - /** - * @return Returns the labelColor. - */ - public Color getLabelColor() { - return labelColor; - } - /** - * @param textColor The text color to set. - */ - public void setLabelColor(Color textColor) { - this.labelColor = textColor; - } - /** - * @return Returns the color. - */ - public Color getColor() { - return color; - } - /** - * @param color The color to set. - */ - public void setColor(Color color) { - this.color = color; - } - /** - * @param stroke The stroke to set. - */ - public void setStroke(Stroke stroke) { - this.stroke = stroke; - BasicStroke bs; - if (stroke instanceof BasicStroke){ - bs = (BasicStroke)stroke; - highlightedStroke = new BasicStroke(bs.getLineWidth() * 2, bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), bs.getDashArray(), bs.getDashPhase()); - selectedStroke = new BasicStroke(bs.getLineWidth() * 3, bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), bs.getDashArray(), bs.getDashPhase()); - } - else { - highlightedStroke = new BasicStroke(2.0f); - selectedStroke = new BasicStroke(3.0f); - } - } - /** - * @param b - */ - public void setPaintLabel(boolean b) { - paintLabel = b; - } - - /** - * @return The Font that is currently set for rendering the label. - */ - public Font getFont() { - return font; - } - - /** - * @param font The Font to use for rendering the label. - */ - public void setFont(Font font) { - this.font = font; - } - public abstract Object clone(); --- 67,70 ---- *************** *** 241,270 **** public abstract double screenDistanceFromEdge(GraphlPane graphPane, Edge edge, Point point); - /** - * @return Returns the stroke. - */ - public Stroke getStroke() { - - return stroke; - } - - public String getLabel(Edge edge) { - String label = labelCache.get(edge); - if (label == null) { - if (labelExpr != null) { - JXPathContext context = JXPathFactory.createContext(edge); - Object labelO = context.getValue(labelExpr); - if (labelO != null) { - label = labelO.toString(); - labelCache.put(edge, label); - } - else { - labelCache.put(edge,""); - } - } - } - return label; - } - public abstract boolean isPointInLabel(GraphlPane graphPane, Edge edge, Point point); --- 75,78 ---- *************** *** 273,329 **** public abstract boolean isSameClass(Object o); - public void setConfigurationNode(Node node) { - - String str = node.getProperty(NS.graphl + "paintArrow"); - if (str != null) { - setPaintArrow(str.equalsIgnoreCase("true")); - } - str = node.getProperty(NS.graphl + "paintLabel"); - if (str != null) { - setPaintLabel(str.equalsIgnoreCase("true")); - } - str = node.getProperty(NS.graphl + "invertArrow"); - if (str != null) { - setInvertArrow(str.equalsIgnoreCase("true")); - } - - Color col = ParseUtils.parseColor(node.getProperty(NS.graphl + "color")); - if (col != null) setColor(col); - - col = ParseUtils.parseColor(node.getProperty(NS.graphl + "labelColor")); - if (col != null) setLabelColor(col); - - Stroke stroke = ParseUtils.parseStroke(node.getProperty(NS.graphl + "stroke")); - 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; - } - - public void refresh() { - strokeCache.clear(); - labelCache.clear(); - } } --- 81,84 ---- Index: StraightLineEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/StraightLineEdgePainter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** StraightLineEdgePainter.java 18 Dec 2005 11:11:40 -0000 1.9 --- StraightLineEdgePainter.java 30 Jun 2006 14:31:34 -0000 1.10 *************** *** 18,21 **** --- 18,22 ---- import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; + import org.mediavirus.graphl.vocabulary.NS; /** *************** *** 28,36 **** //TODO (2, 2h) add settings and controller to choose arrow position (begin, middle, end) - - public StraightLineEdgePainter() { - super(); - } - /** --- 29,32 ---- *************** *** 41,47 **** * @param paintingLabel */ ! public StraightLineEdgePainter(Stroke stroke, Color color, Font font, ! boolean paintingArrow, boolean paintingLabel) { ! super(stroke, color, font, paintingArrow, paintingLabel); } --- 37,42 ---- * @param paintingLabel */ ! public StraightLineEdgePainter() { ! super(); } *************** *** 87,92 **** Rectangle sourceNodeRectangle = new Rectangle(); sourceNodePainter.getNodeScreenBounds(graphPane, sourceNode, sourceNodeRectangle); ! if (isPaintArrow()) { targetNodeRectangle.grow(2,2); //sourceNodeRectangle.grow(-3,-3); --- 82,89 ---- Rectangle sourceNodeRectangle = new Rectangle(); sourceNodePainter.getNodeScreenBounds(graphPane, sourceNode, sourceNodeRectangle); + + Integer arrowPosition = getIntProperty(NS.graphl + "arrowPosition", edge); ! if (arrowPosition != null && arrowPosition > 0) { targetNodeRectangle.grow(2,2); //sourceNodeRectangle.grow(-3,-3); *************** *** 101,116 **** Color oldColor = g.getColor(); ! g.setStroke(getStroke(selected, highlighted)); ! if (selected) { ! g.setColor(getColor().brighter()); } else { ! g.setColor(getColor()); } g.drawLine(from.x,from.y, to.x,to.y); g.setStroke(oldStroke); ! ! if (isPaintArrow() || isPaintLabel()) { int x = (from.x+to.x)/2; --- 98,121 ---- Color oldColor = g.getColor(); ! Stroke stroke = getStrokeProperty(NS.graphl + "stroke", edge); ! if (stroke == null) stroke = defaultStroke; ! g.setStroke(stroke); ! ! Color color = getColorProperty(NS.graphl + "color", edge); ! if (color == null) color = Color.BLACK; ! if (selected || highlighted) { ! g.setColor(color.brighter()); } else { ! g.setColor(color); } g.drawLine(from.x,from.y, to.x,to.y); g.setStroke(oldStroke); ! ! String label = getStringProperty(NS.graphl + "label", edge); ! boolean invertArrow = getBoolProperty(NS.graphl + "invertArrow", edge); ! ! if ((arrowPosition != null && arrowPosition > 0) || label != null) { int x = (from.x+to.x)/2; *************** *** 132,136 **** g.rotate(angle,x,y); ! if (isPaintArrow()) { if (flipped) { paintArrow(g,x+5,y,x-5,y); --- 137,141 ---- g.rotate(angle,x,y); ! if (arrowPosition != null && arrowPosition > 0) { if (flipped) { paintArrow(g,x+5,y,x-5,y); *************** *** 140,153 **** } } ! if (isPaintLabel()){ ! g.setColor(getLabelColor()); ! String label = getLabel(edge); ! if (label != null){ ! Font oldfont = g.getFont(); ! g.setFont(getFont()); ! g.translate(-g.getFontMetrics().stringWidth(label)/2,-2); ! g.drawString(label,x,y); ! g.setFont(oldfont); ! } } g.setTransform(oldxf); --- 145,158 ---- } } ! if (label != null){ ! color = getColorProperty(NS.graphl + "labelColor", edge); ! if (color == null) color = Color.BLACK; ! g.setColor(color); ! Font oldfont = g.getFont(); ! ! g.setFont(getFontProperty(NS.graphl + "font", edge)); ! g.translate(-g.getFontMetrics().stringWidth(label)/2,-2); ! g.drawString(label,x,y); ! g.setFont(oldfont); } g.setTransform(oldxf); *************** *** 297,301 **** public Object clone() { ! StraightLineEdgePainter p = new StraightLineEdgePainter(getStroke(), getColor(), getFont(), isPaintArrow(), isPaintLabel()); return p; } --- 302,307 ---- public Object clone() { ! // todo: implement this ! StraightLineEdgePainter p = new StraightLineEdgePainter(); return p; } --- ImageNodePainterBeanInfo.java DELETED --- --- ImageNodePainter.java DELETED --- Index: NodePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/NodePainter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NodePainter.java 8 Jun 2006 13:14:58 -0000 1.5 --- NodePainter.java 30 Jun 2006 14:31:36 -0000 1.6 *************** *** 52,56 **** */ public Point getEdgePin(Node node, Edge edge); - - public String getLabel(Node node); } --- 52,54 ---- Index: ManhattanEdgePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/ManhattanEdgePainter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ManhattanEdgePainter.java 18 Dec 2005 11:11:40 -0000 1.6 --- ManhattanEdgePainter.java 30 Jun 2006 14:31:35 -0000 1.7 *************** *** 24,28 **** void doPaintEdge(GraphlPane graphPane, Graphics2D g, Edge edge, boolean selected, boolean highlighted) { - g.setStroke(getStroke(selected, highlighted)); Point points[] = getVertices(graphPane, edge); if (points != null) { --- 24,27 ---- Index: BoxNodePainter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/painter/BoxNodePainter.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** BoxNodePainter.java 8 Jun 2006 13:14:57 -0000 1.12 --- BoxNodePainter.java 30 Jun 2006 14:31:35 -0000 1.13 *************** *** 10,26 **** import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.Stroke; ! import java.util.HashMap; ! import java.util.Map; - 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.jxpath.JXPathFactory; import org.mediavirus.graphl.vocabulary.NS; - import org.mediavirus.util.ParseUtils; /** --- 10,24 ---- import java.awt.FontMetrics; import java.awt.Graphics2D; + import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import java.awt.Stroke; ! import java.awt.image.ImageObserver; ! import java.net.URL; import org.mediavirus.graphl.GraphlPane; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.vocabulary.NS; /** *************** *** 28,214 **** * @author Flo Ledermann <led...@im...> */ ! public class BoxNodePainter extends AbstractNodePainter{ ! ! Stroke borderStroke = null; ! Font font = null; ! private Color baseColor = null; ! Color borderColor = null; ! boolean useBorderColor = false; ! Color textColor = null; ! float transparency = 0.2f; ! ! boolean roundRect = true; ! int cornerRadius = 8; ! ! //LabelGenerator labelGenerator; ! String labelExpr; ! Map<Node, String> labelCache = new HashMap<Node, String>(); ! ! public BoxNodePainter(){ ! super(); ! ! borderStroke = new BasicStroke(1.0f); ! font = new Font(null, Font.PLAIN, 10); ! baseColor = new Color(255,250,168); ! textColor = Color.BLACK; ! //labelGenerator = new LabelGenerator(); ! } ! ! protected Color getBackgroundColor( ! boolean isHighlighted, ! boolean isSelected, ! boolean isDragging) { ! ! if (isSelected) return baseColor.darker(); ! return baseColor; ! } ! ! ! protected Color getBorderColor( ! boolean isHighlighted, ! boolean isSelected, ! boolean isDragging) { ! ! if (borderColor != null) { ! return borderColor; ! } ! return baseColor.darker(); ! } ! ! protected Color getTextColor( ! boolean isHighlighted, ! boolean isSelected, ! boolean isDragging) { ! ! return textColor; ! } ! ! ! public String getLabelExpr() { ! return labelExpr; ! } ! ! public void setLabelExpr(String labelExpr) { ! this.labelExpr = labelExpr; ! } ! /** ! * @return Returns the borderStroke. ! */ ! public Stroke getBorderStroke() { ! return borderStroke; ! } ! /** ! * @param stroke The borderStroke to set. ! */ ! public void setBorderStroke(Stroke stroke) { ! this.borderStroke = stroke; ! } ! /** ! * @return A boolean value indicating whether the border color will be used. If ! * <code>false</code>, the border color will be calculated from the base color. ! */ ! public boolean isUseBorderColor() { ! return useBorderColor; ! } ! /** ! * @param useBorderColor A boolean value indicating whether the border color will be used. If ! * <code>false</code>, the border color will be calculated from the base color. ! */ ! public void setUseBorderColor(boolean useBorderColor) { ! this.useBorderColor = useBorderColor; } - /** - * @return Returns the baseColor. - */ - public Color getBaseColor() { - return baseColor; - } - - /** - * @param baseColor The baseColor to set. - */ - public void setBaseColor(Color baseColor) { - this.baseColor = baseColor; - } - - /** - * @return Returns the borderColor. - */ - public Color getBorderColor() { - return borderColor; - } - - /** - * Sets the border color. A custom border color will only be used if useBorderColor - * is <code>true</code>. Otherwise, the border color will be calculated from the - * current base color. - * @param borderColor The borderColor to set. - */ - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } - /** - * @return Returns the font. - */ - public Font getFont() { - return font; - } - /** - * @param font The font to set. - */ - public void setFont(Font font) { - this.font = font; - } - /** - * @return Returns the textColor. - */ - public Color getTextColor() { - return textColor; - } - /** - * @param textColor The textColor to set. - */ - public void setTextColor(Color textColor) { - this.textColor = textColor; - } - /** - * @return Returns the transparency. - */ - public float getTransparency() { - return transparency; - } - /** - * @param transparency The transparency to set. - */ - public void setTransparency(float transparency) { - this.transparency = transparency; - } - /** - * @return Returns the cornerRadius. - */ - public int getCornerRadius() { - return cornerRadius; - } - /** - * @param cornerRadius The cornerRadius to set. - */ - public void setCornerRadius(int cornerRadius) { - this.cornerRadius = cornerRadius; - } - /** - * @return Returns the roundRect. - */ - public boolean isRoundRect() { - return roundRect; - } - /** - * @param roundRect The roundRect to set. - */ - public void setRoundRect(boolean roundRect) { - this.roundRect = roundRect; - } /** * Paints the supplied node. --- 26,39 ---- * @author Flo Ledermann <led...@im...> */ ! public class BoxNodePainter extends AbstractNodePainter implements ImageObserver { ! Color defaultColor = new Color(255, 250, 168); ! Font defaultFont = new Font(null, Font.PLAIN, 10); ! Stroke defaultStroke = new BasicStroke(1.0f); ! public BoxNodePainter() { ! super(); } /** * Paints the supplied node. *************** *** 218,272 **** * @param node the node to paint */ ! 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; ! int height=1; ! int textX=0; ! int textY=0; ! String label = getLabel(node); ! g.setStroke(borderStroke); ! if (label!=null) { ! FontMetrics fontMetrics=graphPane.getFontMetrics(font); ! int stringWidth=fontMetrics.stringWidth(label); ! width+=stringWidth+6; ! height+=fontMetrics.getAscent()+fontMetrics.getDescent()+4; ! textX=nodePoint.x-stringWidth/2; ! textY=nodePoint.y+(fontMetrics.getAscent()-fontMetrics.getDescent())/2; } else { ! width+=40; ! height+=20; } node.setWidth(width); node.setHeight(height); ! Color oldColor=g.getColor(); ! g.setColor(getBackgroundColor(highlighted, selected, false)); ! if (roundRect) { ! g.fillRoundRect(nodePoint.x-width/2,nodePoint.y-height/2,width,height,cornerRadius, cornerRadius); } else { ! g.fillRect(nodePoint.x-width/2,nodePoint.y-height/2,width,height); } ! if (label!=null) { ! Font oldFont=g.getFont(); g.setFont(font); ! g.setColor(getTextColor(highlighted, selected, false)); ! g.drawString(label,textX,textY); g.setFont(oldFont); } ! g.setColor(getBorderColor(highlighted, selected, false)); ! if (roundRect) { ! g.drawRoundRect(nodePoint.x-width/2,nodePoint.y-height/2,width,height,cornerRadius,cornerRadius); } else { ! g.drawRect(nodePoint.x-width/2,nodePoint.y-height/2,width,height); } g.setColor(oldColor); } ! /** * Returns the outer rectangle of the node on screen. --- 43,147 ---- * @param node the node to paint */ ! 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; ! int height = 1; ! int textX = 0; ! int textY = 0; ! Font font = getFontProperty(NS.graphl + "font", node); ! if (font == null) font = defaultFont; ! Stroke oldStroke = g.getStroke(); ! Stroke stroke = getStrokeProperty(NS.graphl + "borderStroke", node); ! if (stroke == null) stroke = defaultStroke; ! ! String label = getStringProperty(NS.graphl + "label", node); ! ! g.setStroke(stroke); ! if (label != null) { ! FontMetrics fontMetrics = graphPane.getFontMetrics(font); ! int stringWidth = fontMetrics.stringWidth(label); ! width += stringWidth + 6; ! height += fontMetrics.getAscent() + fontMetrics.getDescent() + 4; ! textX = nodePoint.x - stringWidth / 2; ! textY = nodePoint.y + (fontMetrics.getAscent() - fontMetrics.getDescent()) / 2; } else { ! width += 40; ! height += 20; ! } ! ! URL baseURL = null; ! try { ! baseURL = new URL(node.getFirstNeighbour(NS.graphl + "definedIn", Node.FORWARD).getId()); ! } ! catch (Exception ex) { ! // do nothing } + Image img = getImageProperty(NS.graphl + "image", node, baseURL); + if (img != null) { + if (node.getWidth() > 0) { + width = (int)node.getWidth(); + } + else { + width = img.getWidth(this); + } + if (node.getHeight() > 0) { + height = (int) node.getHeight(); + } + else { + height = img.getHeight(this); + } + } + node.setWidth(width); node.setHeight(height); ! ! Color oldColor = g.getColor(); ! Color baseColor = getColorProperty(NS.graphl + "baseColor", node); ! if (baseColor == null) baseColor = defaultColor; ! Color borderColor = baseColor.darker(); ! if (selected) baseColor = borderColor; ! ! g.setColor(baseColor); ! ! Integer cornerRadius = getIntProperty(NS.graphl + "cornerRadius", node); ! if (img != null) { ! g.drawImage(img, (int)node.getCenterX()-width/2, (int)node.getCenterY()-height/2, width, height, this); } else { ! if (cornerRadius != null && cornerRadius > 0) { ! g.fillRoundRect(nodePoint.x - width / 2, nodePoint.y - height / 2, width, height, cornerRadius, cornerRadius); ! } ! else { ! g.fillRect(nodePoint.x - width / 2, nodePoint.y - height / 2, width, height); ! } } ! if (label != null) { ! Font oldFont = g.getFont(); g.setFont(font); ! Color color = getColorProperty(NS.graphl + "labelColor", node); ! if (color == null) color = Color.BLACK; ! g.setColor(color); ! g.drawString(label, textX, textY); g.setFont(oldFont); } ! ! g.setColor(borderColor); ! if (cornerRadius != null && cornerRadius > 0) { ! g.drawRoundRect(nodePoint.x - width / 2, nodePoint.y - height / 2, width, height, cornerRadius, cornerRadius); } else { ! g.drawRect(nodePoint.x - width / 2, nodePoint.y - height / 2, width, height); } + + // restore previous state g.setColor(oldColor); + g.setStroke(oldStroke); } ! /** * Returns the outer rectangle of the node on screen. *************** *** 276,326 **** * @param nodeScreenRectangle the rectangle receiving the node's coordinates */ ! public void getNodeScreenBounds(GraphlPane graphPane,Node node,Rectangle nodeScreenRectangle) { ! Point nodePoint=graphPane.getScreenPointForNode(node); ! String label = getLabel(node); ! int width=1; ! int height=1; ! if (label!=null) { ! FontMetrics fontMetrics=graphPane.getFontMetrics(font); ! width+=fontMetrics.stringWidth(label)+6; ! height+=fontMetrics.getAscent()+fontMetrics.getDescent()+4; } else { ! width+=40; ! height+=20; } ! nodeScreenRectangle.setBounds(nodePoint.x-width/2,nodePoint.y-height/2,width,height); } ! public String getLabel(Node node) { ! String label = labelCache.get(node); ! if (label == null) { ! label = "XXX"; ! if (labelExpr != null) { ! JXPathContext context = JXPathFactory.createContext(node); ! Object labelO = context.getValue(labelExpr); ! if (labelO instanceof String) { ! label = (String) labelO; ! } ! } ! labelCache.put(node, label); } ! return label; } - public boolean isEdgeDragPoint(GraphlPane graphPane,Node node,Point p) { - Rectangle r = new Rectangle(); - getNodeScreenBounds(graphPane, node, r); - if ((p.getX() < r.getMinX()+5) || - (p.getX() > r.getMaxX()-5) || - (p.getY() < r.getMinY()+4) || - (p.getY() > r.getMaxY()-4)) { - return true; - } - return false; - } - public Point getEdgePin(Node node, Edge edge) { ! return new Point((int)node.getCenterX(), (int)node.getCenterY()); } --- 151,210 ---- * @param nodeScreenRectangle the rectangle receiving the node's coordinates */ ! public void getNodeScreenBounds(GraphlPane graphPane, Node node, Rectangle nodeScreenRectangle) { ! Point nodePoint = graphPane.getScreenPointForNode(node); ! int width = 1; ! int height = 1; ! ! URL baseURL = null; ! try { ! baseURL = new URL(node.getFirstNeighbour(NS.graphl + "definedIn", Node.FORWARD).getId()); } + catch (Exception ex) { + // do nothing + } + Image img = getImageProperty(NS.graphl + "image", node, baseURL); + if (img != null) { + if (node.getWidth() > 0) { + width = (int)node.getWidth(); + } + else { + width = img.getWidth(this); + } + if (node.getHeight() > 0) { + height = (int) node.getHeight(); + } + else { + height = img.getHeight(this); + } + } else { ! String label = getStringProperty(NS.graphl + "label", node); ! Font font = getFontProperty(NS.graphl + "font", node); ! if (font == null) font = defaultFont; ! ! if (label != null) { ! FontMetrics fontMetrics = graphPane.getFontMetrics(font); ! width += fontMetrics.stringWidth(label) + 6; ! height += fontMetrics.getAscent() + fontMetrics.getDescent() + 4; ! } ! else { ! width += 40; ! height += 20; ! } } ! nodeScreenRectangle.setBounds(nodePoint.x - width / 2, nodePoint.y - height / 2, width, height); } ! public boolean isEdgeDragPoint(GraphlPane graphPane, Node node, Point p) { ! Rectangle r = new Rectangle(); ! getNodeScreenBounds(graphPane, node, r); ! if ((p.getX() < r.getMinX() + 5) || (p.getX() > r.getMaxX() - 5) || (p.getY() < r.getMinY() + 4) || (p.getY() > r.getMaxY() - 4)) { ! return true; } ! return false; } public Point getEdgePin(Node node, Edge edge) { ! return new Point((int) node.getCenterX(), (int) node.getCenterY()); } *************** *** 330,334 **** public String toString() { ! return getName(); } --- 214,218 ---- public String toString() { ! return getName(); } *************** *** 343,397 **** public Object clone() { BoxNodePainter b2 = new BoxNodePainter(); ! b2.setBaseColor(baseColor); ! b2.setBorderColor(borderColor); ! BasicStroke stroke = (BasicStroke)borderStroke; ! b2.setBorderStroke(new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase())); ! b2.setCornerRadius(cornerRadius); ! b2.setFont(font); ! b2.setRoundRect(roundRect); ! b2.setTextColor(textColor); ! b2.setTransparency(transparency); ! b2.setUseBorderColor(useBorderColor); return b2; } - - public void setConfigurationNode(Node node) { - Color col = ParseUtils.parseColor(node.getProperty(NS.graphl + "baseColor")); - if (col != null) baseColor = col; - - col = ParseUtils.parseColor(node.getProperty(NS.graphl + "borderColor")); - if (col != null) borderColor = col; - - col = ParseUtils.parseColor(node.getProperty(NS.graphl + "textColor")); - if (col != null) textColor = col; - - Font font = ParseUtils.parseFont(node.getProperty(NS.graphl + "font")); - 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")); - if (stroke != null) setBorderStroke(stroke); - - String str = node.getProperty(NS.graphl + "roundRect"); - if (str != null) setRoundRect(str.equalsIgnoreCase("true")); - - str = node.getProperty(NS.graphl + "useBorderColor"); - 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); - } - - } - --- 227,236 ---- public Object clone() { BoxNodePainter b2 = new BoxNodePainter(); ! //todo: setConfigurationNode return b2; } + public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + return true; + } + } \ No newline at end of file --- BoxNodePainterBeanInfo.java DELETED --- --- NEW FILE: XPathGraphWalker.java --- /* * Created on 26.06.2006 */ package org.mediavirus.graphl.painter; import java.util.ArrayList; import java.util.List; import org.jaxen.saxpath.Axis; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathHandler; import org.mediavirus.graphl.graph.Graph; import org.mediavirus.graphl.graph.GraphElement; public class XPathGraphWalker implements XPathHandler { List<? extends Object> context = null; public XPathGraphWalker(GraphElement context) { ArrayList<GraphElement> list = new ArrayList<GraphElement>(); list.add(context); this.context = list; } public XPathGraphWalker(Graph graph) { this.context = graph.getNodes(); } public XPathGraphWalker(List<? extends Object> context) { this.context = context; } public List<? extends Object> getContext() { return context; } public void startXPath() throws SAXPathException { } public void endXPath() throws SAXPathException { } public void startPathExpr() throws SAXPathException { } public void endPathExpr() throws SAXPathException { } public void startAbsoluteLocationPath() throws SAXPathException { } public void endAbsoluteLocationPath() throws SAXPathException { } public void startRelativeLocationPath() throws SAXPathException { } public void endRelativeLocationPath() throws SAXPathException { } public void startNameStep(int axis, String prefix, String localName) throws SAXPathException { System.out.println("Name step : " + Axis.lookup(axis) + "::" + prefix + ":" + localName); } public void endNameStep() throws SAXPathException { } public void startCommentNodeStep(int axis) throws SAXPathException { } public void endCommentNodeStep() throws SAXPathException { } public void startAllNodeStep(int axis) throws SAXPathException { System.out.println("AllNode step: " + Axis.lookup(axis)); } public void endAllNodeStep() throws SAXPathException { } public void startPredicate() throws SAXPathException { } public void endPredicate() throws SAXPathException { } public void startFilterExpr() throws SAXPathException { } public void endFilterExpr() throws SAXPathException { } public void startOrExpr() throws SAXPathException { } public void endOrExpr(boolean create) throws SAXPathException { } public void startAndExpr() throws SAXPathException { } public void endAndExpr(boolean create) throws SAXPathException { } public void startEqualityExpr() throws SAXPathException { } public void endEqualityExpr(int equalityOperator) throws SAXPathException { } public void startRelationalExpr() throws SAXPathException { } public void endRelationalExpr(int relationalOperator) throws SAXPathException { } public void startAdditiveExpr() throws SAXPathException { } public void endAdditiveExpr(int additiveOperator) throws SAXPathException { } public void startMultiplicativeExpr() throws SAXPathException { } public void endMultiplicativeExpr(int multiplicativeOperator) throws SAXPathException { } public void startUnaryExpr() throws SAXPathException { } public void endUnaryExpr(int unaryOperator) throws SAXPathException { } public void startUnionExpr() throws SAXPathException { } public void endUnionExpr(boolean create) throws SAXPathException { } public void number(int number) throws SAXPathException { System.out.println("Number : " + number); } public void number(double number) throws SAXPathException { System.out.println("Number : " + number); } public void literal(String literal) throws SAXPathException { System.out.println("Literal : " + literal); } public void startFunction(String prefix, String functionName) throws SAXPathException { System.out.println("Function : " + prefix + ":" + functionName); } public void endFunction() throws SAXPathException { System.out.println("EndFunc +"); } // unsupported right now public void variableReference(String prefix, String variableName) throws SAXPathException { } public void startProcessingInstructionNodeStep(int axis, String name) throws SAXPathException { System.out.println("PI step: " + axis + "::" + name); } public void endProcessingInstructionNodeStep() throws SAXPathException { } public void startTextNodeStep(int axis) throws SAXPathException { System.out.println("Text step : " + axis); } public void endTextNodeStep() throws SAXPathException { } } |