1 39 40 package org.jfree.chart; 41 42 import java.awt.Polygon ; 43 import java.awt.Shape ; 44 import java.awt.geom.Ellipse2D ; 45 import java.awt.geom.Rectangle2D ; 46 47 56 public class SeriesShapeFactory implements ShapeFactory { 57 58 59 private static final int SHAPE_COUNT = 11; 60 61 72 public Shape getShape(int series, int item, double x, double y, double scale) { 73 74 return getShape(series, null, x, y, scale); 75 76 } 77 78 89 public Shape getShape(int series, Object category, double x, double y, double scale) { 90 91 double delta = 0.5 * scale; 92 int index = series % SHAPE_COUNT; 93 int[] xpoints = null; 94 int[] ypoints = null; 95 switch (index) { 96 case 0: 97 return new Rectangle2D.Double (x - delta, y - delta, scale, scale); 99 case 1: 100 return new Ellipse2D.Double (x - delta, y - delta, scale, scale); 102 case 2: 103 xpoints = intArray(x, x + delta, x - delta); 105 ypoints = intArray(y - delta, y + delta, y + delta); 106 return new Polygon (xpoints, ypoints, 3); 107 case 3: 108 xpoints = intArray(x, x + delta, x, x - delta); 110 ypoints = intArray(y - delta, y, y + delta, y); 111 return new Polygon (xpoints, ypoints, 4); 112 case 4: 113 return new Rectangle2D.Double (x - delta, y - delta / 2, scale, scale / 2); 115 case 5: 116 xpoints = intArray(x - delta, x + delta, x); 118 ypoints = intArray(y - delta, y - delta, y + delta); 119 return new Polygon (xpoints, ypoints, 3); 120 case 6: 121 return new Ellipse2D.Double (x - delta, y - delta / 2, scale, scale / 2); 123 case 7: 124 xpoints = intArray(x - delta, x + delta, x - delta); 126 ypoints = intArray(y - delta, y, y + delta); 127 return new Polygon (xpoints, ypoints, 3); 128 case 8: 129 return new Rectangle2D.Double (x - delta / 2, y - delta, scale / 2, scale); 131 case 9: 132 xpoints = intArray(x - delta, x + delta, x + delta); 134 ypoints = intArray(y, y - delta, y + delta); 135 return new Polygon (xpoints, ypoints, 3); 136 default: 137 return new Ellipse2D.Double (x - delta / 2, y - delta, scale / 2, scale); 139 } 140 141 } 142 143 153 private static int[] intArray(double a, double b, double c) { 154 return new int[] {(int) a, (int) b, (int) c}; 155 } 156 157 168 private static int[] intArray(double a, double b, double c, double d) { 169 return new int[] {(int) a, (int) b, (int) c, (int) d}; 170 } 171 172 } 173 | Popular Tags |