1 39 40 package org.krysalis.jcharts.chartData; 41 42 43 import org.krysalis.jcharts.chartData.interfaces.IScatterPlotDataSet; 44 import org.krysalis.jcharts.properties.ChartTypeProperties; 45 import org.krysalis.jcharts.properties.ScatterPlotProperties; 46 import org.krysalis.jcharts.test.HTMLGenerator; 47 import org.krysalis.jcharts.test.HTMLTestable; 48 import org.krysalis.jcharts.types.ChartType; 49 50 import java.awt.*; 51 import java.awt.geom.Point2D ; 52 import java.util.ArrayList ; 53 54 55 public class ScatterPlotDataSet implements IScatterPlotDataSet, HTMLTestable 56 { 57 private static Point2D.Double POINT= new Point2D.Double (); 59 60 private ArrayList data; 61 private ArrayList legendLabels; 62 private ArrayList paints; 63 private ScatterPlotProperties scatterPlotProperties; 64 65 private int numDataItems= -1; 66 67 68 73 public ScatterPlotDataSet( ScatterPlotProperties scatterPlotProperties ) 74 { 75 this.data = new ArrayList (); 76 this.legendLabels = new ArrayList (); 77 this.paints = new ArrayList (); 78 this.scatterPlotProperties = scatterPlotProperties; 79 } 80 81 82 87 public final ChartType getChartType() 88 { 89 return ChartType.SCATTER_PLOT; 90 } 91 92 93 99 public void addDataPoints( Point2D.Double [] points, Paint paint, String legendLabel ) 100 { 101 this.data.add( points ); 102 this.paints.add( paint ); 103 this.legendLabels.add( legendLabel ); 104 105 this.numDataItems= points.length; 106 } 107 108 109 114 public void validate() throws ChartDataException 115 { 116 Point2D.Double [] points; 117 for( int i=0; i < this.data.size(); i++ ) 118 { 119 points= (Point2D.Double []) this.data.get( i ); 120 if( points.length != this.numDataItems ) 121 { 122 throw new ChartDataException( "All Arrays of Point Objects must have the same length." ); 123 } 124 125 if( this.paints.get( i ) == null ) 126 { 127 throw new ChartDataException( "The 'Paint' implementation can not be NULL." ); 128 } 129 } 130 131 if( this.scatterPlotProperties == null ) 132 { 133 throw new ChartDataException( "ScatterPlotProperties can not be NULL." ); 134 } 135 } 136 137 138 145 public Point2D.Double getValue( int dataset, int index ) 146 { 147 return ( (Point2D.Double []) this.data.get( dataset ) )[ index ]; 148 } 149 150 151 158 public final String getLegendLabel( int index ) 159 { 160 if( this.legendLabels == null ) 161 { 162 return null; 163 } 164 else 165 { 166 return (String ) this.legendLabels.get( index ); 167 } 168 } 169 170 171 177 public int getNumberOfLegendLabels() 178 { 179 if( this.legendLabels == null ) 180 { 181 return 0; 182 } 183 else 184 { 185 return this.legendLabels.size(); 186 } 187 } 188 189 190 197 public Paint getPaint( int index ) 198 { 199 return (Paint) this.paints.get( index ); 200 } 201 202 203 207 public ChartTypeProperties getChartTypeProperties() 208 { 209 return this.scatterPlotProperties; 210 } 211 212 213 218 public int getNumberOfDataSets() 219 { 220 return this.data.size(); 221 } 222 223 224 229 public int getNumberOfDataItems() 230 { 231 return this.numDataItems; 232 } 233 234 235 241 public static final Point2D.Double createPoint2DDouble() 242 { 243 return (Point2D.Double ) POINT.clone(); 244 } 245 246 247 252 public void toHTML( HTMLGenerator htmlGenerator ) 253 { 254 htmlGenerator.propertiesTableStart( this.getClass().getName() ); 255 htmlGenerator.addTableRow( "data", HTMLGenerator.arrayToString( this.data.toArray( new Point2D.Double [ this.legendLabels.size() ] ) ) ); 256 257 if( this.legendLabels != null ) 258 { 259 htmlGenerator.addTableRow( "legendLabels", HTMLGenerator.arrayToString( this.legendLabels.toArray( new String [ this.legendLabels.size() ] ) ) ); 260 } 261 htmlGenerator.addTableRow( "paints", HTMLGenerator.arrayToString( this.paints.toArray( new Paint[ this.paints.size() ] ) ) ); 262 htmlGenerator.propertiesTableEnd(); 263 264 htmlGenerator.chartTableRowStart(); 265 this.scatterPlotProperties.toHTML( htmlGenerator ); 266 htmlGenerator.chartTableRowEnd(); 267 } 268 269 } 270 | Popular Tags |