1 40 41 package org.jfree.chart.renderer; 42 43 import java.awt.BasicStroke ; 44 import java.awt.Color ; 45 import java.awt.Paint ; 46 import java.awt.Stroke ; 47 import java.awt.geom.Line2D ; 48 import java.awt.geom.Rectangle2D ; 49 50 57 public class HighLow { 58 59 60 public static final int OPEN = 0; 61 62 63 public static final int CLOSE = 1; 64 65 66 private Line2D line; 67 68 69 private Rectangle2D bounds; 70 71 72 private double open; 73 74 75 private double close; 76 77 78 private Stroke stroke; 79 80 81 private Paint paint; 82 83 84 private double tickSize = 2; 85 86 94 public HighLow(double x, double high, double low) { 95 this(x, high, low, high, low, new BasicStroke (), Color.blue); 96 } 97 98 107 public HighLow(double x, double high, double low, double open, double close) { 108 this(x, high, low, open, close, new BasicStroke (), Color.blue); 109 } 110 111 122 public HighLow(double x, double high, double low, double open, double close, 123 Stroke stroke, Paint paint) { 124 125 this.line = new Line2D.Double (x, high, x, low); 126 this.bounds = new Rectangle2D.Double (x - this.tickSize, high, 127 2 * this.tickSize, low - high); 128 this.open = open; 129 this.close = close; 130 this.stroke = stroke; 131 this.paint = paint; 132 133 } 134 135 140 public void setTickSize(double newSize) { 141 tickSize = newSize; 142 } 143 144 149 public double getTickSize() { 150 return tickSize; 151 } 152 153 158 public Line2D getLine() { 159 return line; 160 } 161 162 167 public Rectangle2D getBounds() { 168 return this.bounds; 169 } 170 171 179 public double getValue(int valueType) { 180 if (valueType == OPEN) { 181 return open; 182 } 183 else { 184 return close; 185 } 186 } 187 188 194 public void setValue(int type, double value) { 195 if (type == OPEN) { 196 open = value; 197 } 198 else { 199 close = value; 200 } 201 } 202 203 208 public Line2D getOpenTickLine() { 209 return getTickLine(getLine().getX1(), getValue(OPEN), (-1) * getTickSize()); 210 } 211 212 217 public Line2D getCloseTickLine() { 218 return getTickLine(getLine().getX1(), getValue(CLOSE), getTickSize()); 219 } 220 221 230 private Line2D getTickLine(double x, double value, double width) { 231 return new Line2D.Double (x, value, x + width, value); 232 } 233 234 239 public Stroke getStroke() { 240 return stroke; 241 } 242 243 248 public Paint getPaint() { 249 return paint; 250 } 251 252 } 253 | Popular Tags |