1 package prefuse.render; 2 3 import java.awt.Shape ; 4 import java.awt.geom.GeneralPath ; 5 6 import prefuse.Constants; 7 import prefuse.data.Schema; 8 import prefuse.util.GraphicsLib; 9 import prefuse.visual.VisualItem; 10 11 12 36 public class PolygonRenderer extends AbstractShapeRenderer { 37 38 41 public static final String POLYGON = "_polygon"; 42 45 public static final Schema POLYGON_SCHEMA = new Schema(); 46 static { 47 POLYGON_SCHEMA.addColumn(POLYGON, float[].class); 48 } 49 50 private int m_polyType = Constants.POLY_TYPE_LINE; 51 private float m_slack = 0.08f; 52 private float m_epsilon = 0.1f; 53 private boolean m_closed = true; 54 private String m_polyfield = POLYGON; 55 56 private GeneralPath m_path = new GeneralPath (); 57 58 61 public PolygonRenderer() { 62 this(Constants.EDGE_TYPE_LINE); 63 } 64 65 72 public PolygonRenderer(int polyType) { 73 m_polyType = polyType; 74 } 75 76 83 public int getPolyType() { 84 return m_polyType; 85 } 86 87 94 public void setPolyType(int polyType) { 95 if ( polyType < 0 || polyType >= Constants.POLY_TYPE_COUNT ) { 96 throw new IllegalArgumentException ("Unknown edge type: "+polyType); 97 } 98 m_polyType = polyType; 99 } 100 101 107 public boolean isClosePath() { 108 return m_closed; 109 } 110 111 116 public void setClosePath(boolean closePath) { 117 m_closed = closePath; 118 } 119 120 128 public float getCurveSlack() { 129 return m_slack; 130 } 131 132 140 public void setCurveSlack(float slack) { 141 m_slack = slack; 142 } 143 144 147 protected Shape getRawShape(VisualItem item) { 148 float[] poly = (float[])item.get(m_polyfield); 149 if ( poly == null ) { return null; } 150 151 float x = (float)item.getX(); 152 float y = (float)item.getY(); 153 154 m_path.reset(); 156 m_path.moveTo(x+poly[0],y+poly[1]); 157 158 if ( m_polyType == Constants.POLY_TYPE_LINE ) 159 { 160 for ( int i=2; i<poly.length; i+=2 ) { 162 if ( Float.isNaN(poly[i]) ) break; 163 m_path.lineTo(x+poly[i],y+poly[i+1]); 164 } 165 } 166 else if ( m_polyType == Constants.POLY_TYPE_CURVE ) 167 { 168 return GraphicsLib.cardinalSpline(m_path, poly, 170 m_slack, m_closed, x, y); 171 } 172 else if ( m_polyType == Constants.POLY_TYPE_STACK ) 173 { 174 return GraphicsLib.stackSpline(m_path, poly, 176 m_epsilon, m_slack, m_closed, x, y); 177 } 178 if ( m_closed ) m_path.closePath(); 179 return m_path; 180 } 181 182 } | Popular Tags |