| 1 39 40 package org.krysalis.jcharts.chartData; 41 42 43 import org.krysalis.jcharts.chartData.interfaces.IStockChartDataSet; 44 import org.krysalis.jcharts.properties.*; 45 import org.krysalis.jcharts.test.HTMLGenerator; 46 import org.krysalis.jcharts.test.HTMLTestable; 47 import org.krysalis.jcharts.types.ChartType; 48 import org.krysalis.jcharts.types.StockChartDataType; 49 50 import java.awt.*; 51 52 53 public class StockChartDataSet implements IStockChartDataSet, HTMLTestable 54 { 55 private ChartType chartType=ChartType.STOCK; 56 57 private double[] high; 58 private double[] low; 59 private double[] open; 60 private double[] close; 61 62 private int numberOfDataSets=2; 64 65 private String [] legendLabels; 66 private Paint[] paints; 67 private StockChartProperties stockChartProperties; 68 69 70 80 public StockChartDataSet( double[] high, 81 String highLegendLabel, 82 double[] low, 83 String lowLegendLabel, 84 Paint highLowPaint, 85 StockChartProperties stockChartProperties ) throws ChartDataException 86 { 87 this.high=high; 88 this.low=low; 89 90 this.legendLabels=new String [ 5 ]; 91 this.legendLabels[ StockChartDataType.HIGH.getInt() ]=highLegendLabel; 92 this.legendLabels[ StockChartDataType.LOW.getInt() ]=lowLegendLabel; 93 94 this.paints=new Paint[ 5 ]; 95 this.paints[ StockChartDataType.HIGH.getInt() ]=highLowPaint; 96 this.paints[ StockChartDataType.LOW.getInt() ]=highLowPaint; 97 98 this.stockChartProperties=stockChartProperties; 99 } 100 101 102 108 public void validate() throws ChartDataException, PropertyException 109 { 110 if( high == null || low == null ) 111 { 112 throw new ChartDataException( "The Hi/Low values can not be NULL." ); 113 } 114 115 if( high.length != low.length ) 116 { 117 throw new ChartDataException( "The Hi/Low Arrays must have equal length." ); 118 } 119 120 if( this.paints[ StockChartDataType.HIGH.getInt() ] == null ) 121 { 122 throw new ChartDataException( "The Hi/Low Paint implementation can not be NULL." ); 123 } 124 125 this.stockChartProperties.validate( this ); 126 } 127 128 129 136 public String getLegendLabel( int index ) 137 { 138 return this.legendLabels[ index ]; 139 } 140 141 142 147 public int getNumberOfLegendLabels() 148 { 149 return this.legendLabels.length; 150 } 151 152 153 159 public int getNumberOfDataItems() 160 { 161 return this.high.length; 163 } 164 165 166 173 public void setCloseValues( double[] data, String legendLabel, Paint paint ) 174 { 175 this.numberOfDataSets++; 176 this.close=data; 177 this.legendLabels[ StockChartDataType.CLOSE.getInt() ]=legendLabel; 178 this.paints[ StockChartDataType.CLOSE.getInt() ]=paint; 179 } 180 181 182 189 public void setOpenValues( double[] data, String legendLabel, Paint paint ) 190 { 191 this.numberOfDataSets++; 192 this.open=data; 193 this.legendLabels[ StockChartDataType.OPEN.getInt() ]=legendLabel; 194 this.paints[ StockChartDataType.OPEN.getInt() ]=paint; 195 } 196 197 198 213 214 219 public double getHighValue( int index ) 220 { 221 return this.high[ index ]; 222 } 223 224 225 230 public double getLowValue( int index ) 231 { 232 return this.low[ index ]; 233 } 234 235 236 241 public double getCloseValue( int index ) 242 { 243 return this.close[ index ]; 244 } 245 246 247 251 public boolean hasCloseValues() 252 { 253 return ( this.close != null ); 254 } 255 256 257 262 public double getOpenValue( int index ) 263 { 264 return this.open[ index ]; 265 } 266 267 268 272 public boolean hasOpenValues() 273 { 274 return ( this.open != null ); 275 } 276 277 278 288 289 298 299 305 public ChartType getChartType() 306 { 307 return this.chartType; 308 } 309 310 311 316 public ChartTypeProperties getChartTypeProperties() 317 { 318 return this.stockChartProperties; 319 } 320 321 322 327 public int getNumberOfDataSets() 328 { 329 return this.numberOfDataSets; 330 } 331 332 333 338 public Paint getPaint( int index ) 339 { 340 return this.paints[ index ]; 341 } 342 343 344 349 public void toHTML( HTMLGenerator htmlGenerator ) 350 { 351 353 362 } 363 364 365 } 366 | Popular Tags |