1 44 45 package org.jfree.chart.renderer.xy; 46 47 import java.awt.BasicStroke ; 48 import java.awt.Color ; 49 import java.awt.Paint ; 50 import java.awt.Stroke ; 51 import java.awt.geom.Line2D ; 52 import java.awt.geom.Rectangle2D ; 53 54 61 public class HighLow { 62 63 64 public static final int OPEN = 0; 65 66 67 public static final int CLOSE = 1; 68 69 70 private Line2D line; 71 72 73 private Rectangle2D bounds; 74 75 76 private double open; 77 78 79 private double close; 80 81 82 private Stroke stroke; 83 84 85 private Paint paint; 86 87 88 private double tickSize = 2; 89 90 98 public HighLow(double x, double high, double low) { 99 this(x, high, low, high, low, new BasicStroke (), Color.blue); 100 } 101 102 111 public HighLow(double x, double high, double low, double open, 112 double close) { 113 this(x, high, low, open, close, new BasicStroke (), Color.blue); 114 } 115 116 127 public HighLow(double x, double high, double low, double open, double close, 128 Stroke stroke, Paint paint) { 129 130 this.line = new Line2D.Double (x, high, x, low); 131 this.bounds = new Rectangle2D.Double (x - this.tickSize, high, 132 2 * this.tickSize, low - high); 133 this.open = open; 134 this.close = close; 135 this.stroke = stroke; 136 this.paint = paint; 137 138 } 139 140 145 public void setTickSize(double newSize) { 146 this.tickSize = newSize; 147 } 148 149 154 public double getTickSize() { 155 return this.tickSize; 156 } 157 158 163 public Line2D getLine() { 164 return this.line; 165 } 166 167 172 public Rectangle2D getBounds() { 173 return this.bounds; 174 } 175 176 184 public double getValue(int valueType) { 185 if (valueType == OPEN) { 186 return this.open; 187 } 188 else { 189 return this.close; 190 } 191 } 192 193 199 public void setValue(int type, double value) { 200 if (type == OPEN) { 201 this.open = value; 202 } 203 else { 204 this.close = value; 205 } 206 } 207 208 213 public Line2D getOpenTickLine() { 214 return getTickLine( 215 getLine().getX1(), getValue(OPEN), (-1) * getTickSize() 216 ); 217 } 218 219 224 public Line2D getCloseTickLine() { 225 return getTickLine(getLine().getX1(), getValue(CLOSE), getTickSize()); 226 } 227 228 237 private Line2D getTickLine(double x, double value, double width) { 238 return new Line2D.Double (x, value, x + width, value); 239 } 240 241 246 public Stroke getStroke() { 247 return this.stroke; 248 } 249 250 255 public Paint getPaint() { 256 return this.paint; 257 } 258 259 } 260 | Popular Tags |