1 19 20 package org.netbeans.modules.xml.nbprefuse.render; 21 22 import java.awt.BasicStroke ; 23 import java.awt.Color ; 24 import java.awt.Graphics2D ; 25 import java.awt.Polygon ; 26 import java.awt.Shape ; 27 import java.awt.geom.AffineTransform ; 28 import java.awt.geom.CubicCurve2D ; 29 import java.awt.geom.GeneralPath ; 30 import java.awt.geom.Line2D ; 31 import java.awt.geom.Point2D ; 32 import java.awt.geom.Rectangle2D ; 33 34 import prefuse.Constants; 35 import prefuse.render.AbstractShapeRenderer; 36 import prefuse.render.EdgeRenderer; 37 import prefuse.util.ColorLib; 38 import prefuse.util.GraphicsLib; 39 import prefuse.util.StrokeLib; 40 import prefuse.visual.EdgeItem; 41 import prefuse.visual.VisualItem; 42 43 44 54 public class ReferenceEdgeRenderer extends EdgeRenderer { 55 56 protected GeneralPath m_arrowHead = new GeneralPath (); 58 59 62 public ReferenceEdgeRenderer() { 63 super(); 64 m_arrowHead.moveTo(-6, -14); 67 m_arrowHead.lineTo(0,0); 68 m_arrowHead.lineTo(6,-14); 69 } 70 71 72 75 protected Shape getRawShape(VisualItem item) { 76 EdgeItem edge = (EdgeItem)item; 77 VisualItem item1 = edge.getSourceItem(); 78 VisualItem item2 = edge.getTargetItem(); 79 80 int type = m_edgeType; 81 82 getAlignedPoint(m_tmpPoints[0], item1.getBounds(), 83 m_xAlign1, m_yAlign1); 84 getAlignedPoint(m_tmpPoints[1], item2.getBounds(), 85 m_xAlign2, m_yAlign2); 86 m_curWidth = (float)(m_width * getLineWidth(item)); 87 88 EdgeItem e = (EdgeItem)item; 90 if ( e.isDirected() && m_edgeArrow != Constants.EDGE_ARROW_NONE ) { 91 boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD); 93 Point2D start = null, end = null; 94 start = m_tmpPoints[forward?0:1]; 95 end = m_tmpPoints[forward?1:0]; 96 97 VisualItem dest = forward ? e.getTargetItem() : e.getSourceItem(); 99 int i = GraphicsLib.intersectLineRectangle(start, end, 100 dest.getBounds(), m_isctPoints); 101 if ( i > 0 ) end = m_isctPoints[0]; 102 103 AffineTransform at = getArrowTrans(start, end, m_curWidth); 105 m_curArrow = at.createTransformedShape(m_arrowHead); 106 107 109 } else { 115 m_curArrow = null; 116 } 117 118 Shape shape = null; 120 double n1x = m_tmpPoints[0].getX(); 121 double n1y = m_tmpPoints[0].getY(); 122 double n2x = m_tmpPoints[1].getX(); 123 double n2y = m_tmpPoints[1].getY(); 124 switch ( type ) { 125 case Constants.EDGE_TYPE_LINE: 126 m_line.setLine(n1x, n1y, n2x, n2y); 127 shape = m_line; 128 break; 129 case Constants.EDGE_TYPE_CURVE: 130 getCurveControlPoints(edge, m_ctrlPoints,n1x,n1y,n2x,n2y); 131 m_cubic.setCurve(n1x, n1y, 132 m_ctrlPoints[0].getX(), m_ctrlPoints[0].getY(), 133 m_ctrlPoints[1].getX(), m_ctrlPoints[1].getY(), 134 n2x, n2y); 135 shape = m_cubic; 136 break; 137 default: 138 throw new IllegalStateException ("Unknown edge type"); 139 } 140 141 return shape; 143 } 144 145 148 public void render(Graphics2D g, VisualItem item) { 149 Shape shape = getShape(item); 151 if (shape != null) 152 drawShape(g, item, shape); 153 154 157 if ( m_curArrow != null ) { 159 g.setPaint(ColorLib.getColor(item.getFillColor())); 162 g.draw(m_curArrow); 164 } 165 } 166 167 168 169 170 } | Popular Tags |