-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDatasetManager.java
More file actions
1069 lines (988 loc) · 29.6 KB
/
DatasetManager.java
File metadata and controls
1069 lines (988 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Open Source Physics software is free software as described near the bottom of this code file.
*
* For additional information and documentation on Open Source Physics please see:
* <http://www.opensourcephysics.org/>
*/
package org.opensourcephysics.display;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.table.AbstractTableModel;
import org.opensourcephysics.controls.XML;
import org.opensourcephysics.controls.XMLControl;
import org.opensourcephysics.controls.XMLLoader;
/**
*
* DatasetManager maintains a list of datasets. Datasets are added
* automatically to this DatasetCollection by calling a method in this
* DatasetManager with a dataset index greater than the maximum value for
* the dataset index that has been used previously. For example the statements:
* <code> DatasetManager datasetManager = new DatasetManager();
* datasetManager.append(0,3,4);
* datasetManager.append(1,5,6);</code> appends the point (3,4) to the 0th
* dataset (and creates this dataset automatically) and appends the point (5,6)
* to the 1-st dataset (and also creates this dataset automatically).
*
* @version 1.1
* @author Joshua Gould
* @author Wolfgang Christian
* @created February 17, 2002
*
*/
public class DatasetManager extends AbstractTableModel implements Measurable, LogMeasurable, Data {
ArrayList<Dataset> datasets = new ArrayList<Dataset>();
boolean connected; // default values for new datasets
boolean sorted;
int markerShape;
int stride = 1;
boolean linked = false; // whether x data in datasets is linked. If set to true, then x data for datasets > 0 will not be shown in a table view.
String xColumnName = "x", yColumnName = "y"; // default names for new datasets //$NON-NLS-1$ //$NON-NLS-2$
ArrayList<String> constantNames = new ArrayList<String>();
Map<String, Double> constantValues = new TreeMap<String, Double>();
Map<String, String> constantExpressions = new TreeMap<String, String>();
String name = ""; //$NON-NLS-1$
int datasetID = hashCode();
/**
*
* DatasetManager constructor.
*
*/
public DatasetManager() {
this(false, false, false, Dataset.SQUARE);
}
/**
*
* DatasetManager constructor.
*
* @param linked
*
*/
public DatasetManager(boolean linked) {
this(false, false, linked, Dataset.SQUARE);
}
/**
*
* DatasetManager constructor specifying whether points are connected and
* sorted.
* @param _connected Description of Parameter
*
* @param _sorted Description of Parameter
*
*/
public DatasetManager(boolean _connected, boolean _sorted) {
this(_connected, _sorted, false, Dataset.SQUARE);
}
/**
*
* DatasetManager constructor specifying whether points are connected,
*
* sorted, and the marker shape.
*
*
*
* @param _connected Description of Parameter
*
* @param _sorted Description of Parameter
*
* @param _linked
*
* @param _markerShape Description of Parameter
*
*/
public DatasetManager(boolean _connected, boolean _sorted, boolean _linked, int _markerShape) {
connected = _connected;
sorted = _sorted;
markerShape = _markerShape;
linked = _linked;
}
/**
* Sets the linked flag. X data for datasets > 0 will not be shown in a table view.
*
* @param _linked The new value
*/
public void setXPointsLinked(boolean _linked) {
linked = _linked;
for(int i = 1; i<datasets.size(); i++) {
Dataset dataset = datasets.get(i);
dataset.setXColumnVisible(!linked);
}
}
/**
* Gets the linked flag.
*
* @return true if linked
*/
public boolean isXPointsLinked() {
return linked;
}
/**
*
* Sets the sorted flag. Data is sorted by increasing x.
*
* @param datasetIndex The new sorted value
* @param _sorted <code>true<\code> to sort
*/
public void setSorted(int datasetIndex, boolean _sorted) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setSorted(_sorted);
}
/**
*
* Sets the sorted flag for all datasets.
*
* @param _sorted
*
*/
public void setSorted(boolean _sorted) {
sorted = _sorted; // sorted for future datasets
for(int i = 0; i<datasets.size(); i++) {
(datasets.get(i)).setSorted(_sorted);
}
}
/**
* Sets the data connected flag. Points are connected by straight lines.
*
* @param datasetIndex The new connected value
* @param _connected <code>true<\code> if points are connected
*/
public void setConnected(int datasetIndex, boolean _connected) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setConnected(_connected);
}
/**
* Sets the connected flag for all datasets.
*
* @param _connected true if connected; false otherwise
*/
public void setConnected(boolean _connected) {
connected = _connected; // sorted for future datasets
for(int i = 0; i<datasets.size(); i++) {
(datasets.get(i)).setConnected(_connected);
}
}
/**
*
* Sets the stride for the given dataset.
*
* @param datasetIndex The new markerColor value
* @param stride
*/
public void setStride(int datasetIndex, int stride) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setStride(stride);
}
/**
* Sets the stride for all datasets.
* @param _stride
*/
public void setStride(int _stride) {
stride = _stride; // default stride for future datasets
// set the stride for current datasets
for(int i = 0; i<datasets.size(); i++) {
(datasets.get(i)).setStride(stride);
}
}
/**
* Sets the data point marker color.
*
* @param datasetIndex
* @param _markerColor
*/
public void setMarkerColor(int datasetIndex, Color _markerColor) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setMarkerColor(_markerColor);
}
/**
* Sets the data point marker's fill and edge color.
*
* @param datasetIndex
* @param fillColor
* @param edgeColor
*/
public void setMarkerColor(int datasetIndex, Color fillColor, Color edgeColor) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setMarkerColor(fillColor, edgeColor);
}
/**
* Sets the data point marker shape. Shapes are: NO_MARKER, CIRCLE, SQUARE,
* AREA, PIXEL, BAR, POST
*
* @param datasetIndex
* @param _markerShape
*/
public void setMarkerShape(int datasetIndex, int _markerShape) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setMarkerShape(_markerShape);
}
/**
* Sets a custom marker shape.
*
* @param datasetIndex int
* @param marker Shape
*/
public void setCustomMarker(int datasetIndex, Shape marker) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setCustomMarker(marker);
}
/**
* Sets the visibility of the x column in a table view.
*
* @param datasetIndex
* @param visible
*/
public void setXColumnVisible(int datasetIndex, boolean visible) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setXColumnVisible(visible);
}
/**
* Sets the visibility of the y column in a table view.
*
* @param datasetIndex
* @param visible
*/
public void setYColumnVisible(int datasetIndex, boolean visible) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setYColumnVisible(visible);
}
/**
* Sets the half-width of the data point marker.
*
* @param datasetIndex
* @param _markerSize in pixels
*/
public void setMarkerSize(int datasetIndex, int _markerSize) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setMarkerSize(_markerSize);
}
/**
* Sets the color of the lines connecting data points.
*
* @param datasetIndex
* @param _lineColor
*/
public void setLineColor(int datasetIndex, Color _lineColor) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setLineColor(_lineColor);
}
/**
* Line colors for Data interface.
* @return color array
*/
public java.awt.Color[] getLineColors() {
return null;
}
/**
* Fill colors for Data interface.
* @return color array
*/
public java.awt.Color[] getFillColors() {
return null;
}
/**
* Sets the column names when rendering this dataset in a JTable.
*
* @param datasetIndex
* @param xColumnName
* @param yColumnName
* @param datsetName
*/
public void setXYColumnNames(int datasetIndex, String xColumnName, String yColumnName, String datsetName) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setXYColumnNames(xColumnName, yColumnName, datsetName);
}
/**
* Sets the column names when rendering this dataset in a JTable.
*
* @param datasetIndex
* @param xColumnName
* @param yColumnName
*/
public void setXYColumnNames(int datasetIndex, String xColumnName, String yColumnName) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.setXYColumnNames(xColumnName, yColumnName);
}
/**
* Gets the valid measure flag. The measure is valid if the min and max values
* have been set for at least one dataset.
*
* @return <code>true<\code> if measure is valid
*/
public boolean isMeasured() {
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
return true;
}
}
return false;
}
/**
* Sets the ID number of this Data.
*
* @param id the ID number
*/
public void setID(int id) {
datasetID = id;
}
/**
* Returns a unique identifier for this Data.
*
* @return the ID number
*/
public int getID() {
return datasetID;
}
/**
* Gets the x world coordinate for the left hand side of the panel.
*
* @return xmin
*/
public double getXMin() {
double xmin = Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
xmin = Math.min(xmin, d.getXMin());
}
}
return xmin;
}
public double getXMinLogscale() {
double xmin = Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
xmin = Math.min(xmin, d.getXMinLogscale());
}
}
return Math.max(Float.MIN_VALUE, xmin);
}
/**
* Gets the x world coordinate for the right hand side of the panel.
*
* @return xmax
*/
public double getXMax() {
double xmax = -Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
xmax = Math.max(xmax, d.getXMax());
}
}
return xmax;
}
public double getXMaxLogscale() {
double xmax = -Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
xmax = Math.max(xmax, d.getXMaxLogscale());
}
}
return Math.max(Float.MIN_VALUE, xmax);
}
/**
* Gets y world coordinate for the bottom of the panel.
*
* @return ymin
*/
public double getYMin() {
double ymin = Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
ymin = Math.min(ymin, d.getYMin());
}
}
return ymin;
}
public double getYMinLogscale() {
double ymin = Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
ymin = Math.min(ymin, d.getYMinLogscale());
}
}
return Math.max(Float.MIN_VALUE, ymin);
}
/**
* Gets y world coordinate for the top of the panel.
*
* @return ymax
*/
public double getYMax() {
double ymax = -Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
ymax = Math.max(ymax, d.getYMax());
}
}
return ymax;
}
public double getYMaxLogscale() {
double ymax = -Double.MAX_VALUE;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if(d.isMeasured()) {
ymax = Math.max(ymax, d.getYMaxLogscale());
}
}
return Math.max(Float.MIN_VALUE, ymax);
}
/**
* Gets a copy of the xpoints array.
*
* @param datasetIndex Description of Parameter
* @return xpoints[]
*/
public double[] getXPoints(int datasetIndex) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
return dataset.getXPoints();
}
/**
* Gets a copy of the ypoints array.
*
* @param datasetIndex Description of Parameter
* @return ypoints[]
*/
public double[] getYPoints(int datasetIndex) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
return dataset.getYPoints();
}
/**
* Gets the sorted flag.
*
* @param datasetIndex Description of Parameter
* @return <code>true<\code> if the data is sorted
*/
public boolean isSorted(int datasetIndex) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
return dataset.isSorted();
}
/**
* Gets the data connected flag.
*
* @param datasetIndex Description of Parameter
* @return <code>true<\code> if points are connected
*/
public boolean isConnected(int datasetIndex) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
return dataset.isConnected();
}
/**
* Gets the number of columns for rendering in a JTable.
*
* @return the count
*/
public int getColumnCount() {
int columnCount = 0;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
if (d==null) continue; // added by DB to prevent occasional null pointer exception here
columnCount += d.getColumnCount();
}
return columnCount;
}
/**
* Gets the number of rows for rendering in a JTable.
*
* @return the count
*/
public int getRowCount() {
int rowCount = 0;
for(int i = 0; i<datasets.size(); i++) {
Dataset d = datasets.get(i);
rowCount = Math.max(rowCount, d.getRowCount());
}
return rowCount;
}
/**
* Gets the name of this data.
*
* @return name
*/
public String getName() {
return name;
}
/**
* Sets the name of this data.
*
* @param name
*/
public void setName(String name) {
if(name!=null) {
this.name = TeXParser.parseTeX(name);
}
}
/**
* Gets the name of the column for rendering in a JTable
*
* @param tableColumnIndex
* @return the name
*/
public String getColumnName(int tableColumnIndex) {
if(datasets.size()==0) {
return null;
}
int totalColumns = 0;
for(int i = 0; i<datasets.size(); i++) {
Dataset tableModel = datasets.get(i);
int columnCount = tableModel.getColumnCount();
totalColumns += columnCount;
if(totalColumns>tableColumnIndex) {
int columnIndex = Math.abs(totalColumns-columnCount-tableColumnIndex);
return tableModel.getColumnName(columnIndex);
}
}
return null;
}
/**
* Gets an x or y value for rendering in a JTable.
*
* @param rowIndex
* @param tableColumnIndex
* @return the datum
*/
public Object getValueAt(int rowIndex, int tableColumnIndex) {
if(datasets.size()==0) {
return null;
}
int totalColumns = 0;
for(int i = 0; i<datasets.size(); i++) {
Dataset tableModel = datasets.get(i);
int columnCount = tableModel.getColumnCount();
totalColumns += columnCount;
if(totalColumns>tableColumnIndex) {
if(rowIndex>=tableModel.getRowCount()) {
return null;
}
int columnIndex = Math.abs(totalColumns-columnCount-tableColumnIndex);
return tableModel.getValueAt(rowIndex, columnIndex);
}
}
return null;
}
/**
* Gets the type of object for JTable entry.
*
* @param columnIndex
* @return the class
*/
public Class<Double> getColumnClass(int columnIndex) {
return Double.class;
}
/**
* Appends an (x,y) datum to the Dataset with the given index.
*
* @param x
* @param y
* @param datasetIndex Description of Parameter
*/
public void append(int datasetIndex, double x, double y) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.append(x, y);
}
/**
* Appends a data point and its uncertainty to the Dataset.
*
* @param datasetIndex
* @param x
* @param y
* @param delx
* @param dely
*
*/
public void append(int datasetIndex, double x, double y, double delx, double dely) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.append(x, y, delx, dely);
}
/**
* Appends (x,y) arrays to the Dataset.
*
* @param xpoints
* @param ypoints
* @param datasetIndex Description of Parameter
*/
public void append(int datasetIndex, double[] xpoints, double[] ypoints) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.append(xpoints, ypoints);
}
/**
* Appends arrays of data points and uncertainties to the Dataset.
*
* @param datasetIndex
* @param xpoints
* @param ypoints
* @param delx
* @param dely
*/
public void append(int datasetIndex, double[] xpoints, double[] ypoints, double[] delx, double[] dely) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.append(xpoints, ypoints, delx, dely);
}
/**
* Draws this Dataset in the drawing panel.
*
* @param drawingPanel
* @param g
*/
public void draw(DrawingPanel drawingPanel, Graphics g) {
for(int i = 0; i<datasets.size(); i++) {
(datasets.get(i)).draw(drawingPanel, g);
}
}
/**
* Clears all data from Dataset with the given datasetIndex.
*
* @param datasetIndex Description of Parameter
*/
public void clear(int datasetIndex) {
checkDatasetIndex(datasetIndex);
Dataset dataset = datasets.get(datasetIndex);
dataset.clear();
}
/**
* Clears all data from all Datasets.
*
* Dataset properties are preserved because only the data is cleared.
*/
public void clear() {
for(int i = 0; i<datasets.size(); i++) {
(datasets.get(i)).clear();
}
}
/**
* Removes all Datasets from the manager.
*
* New datasets will be created with default properties as needed.
*/
public void removeDatasets() {
clear();
datasets.clear();
}
/**
* Gets a dataset with the given index.
*
* @param datasetIndex
* @return the index
*
*/
public Dataset getDataset(int datasetIndex) {
checkDatasetIndex(datasetIndex);
return datasets.get(datasetIndex);
}
/**
* Gets a shallow clone of the dataset list. Implements Data.
* @return cloned list
*/
public ArrayList<Dataset> getDatasets() {
return new ArrayList<Dataset>(datasets);
}
/**
* Some objects (eg, a Group) do not contain data, but a list of Data objects that do.
* This method is used by Data displaying tools to create as many pages as needed.
* @return a list of Data objects, or null if this object contains data
*/
public java.util.List<Data> getDataList() {
return null;
}
/**
* The column names to be used in the data display tool
* @return string array
*/
public String[] getColumnNames() {
int n = datasets.size();
String[] names = new String[n];
for(int i = 0; i<n; i++) {
if(datasets.get(i)!=null) {
names[i] = datasets.get(i).getName();
}
}
return names;
}
/**
* Gets a 2D array of data. Implements Data.
*
* @return double[][]
*/
public double[][] getData2D() {
if(isXPointsLinked()) {
int count = datasets.size();
int index = 0;
for(Dataset next : datasets) {
index = Math.max(index, next.getIndex());
}
double[][] data = new double[count+1][index];
double[] d = datasets.get(0).getXPoints();
System.arraycopy(d, 0, data[0], 0, d.length);
for(int i = 0; i<count; i++) {
d = datasets.get(i).getYPoints();
System.arraycopy(d, 0, data[i+1], 0, d.length);
}
return data;
}
return null;
}
/**
* Gets a 3D array of data. Implements Data.
*
* @return double[][][]
*/
public double[][][] getData3D() {
return null;
}
/**
* Adds a dataset.
* Method added by Doug Brown 2007-1-15.
*
* @param dataset the Dataset to add
* @return the index of the added dataset
*/
public int addDataset(Dataset dataset) {
if(linked&&!datasets.isEmpty()) {
dataset.setXColumnVisible(false);
}
datasets.add(dataset);
return datasets.size()-1;
}
/**
* Removes the dataset at the specified index.
* Method added by Doug Brown 1/15/2007.
*
* @param index the index
* @return the removed dataset, or null if none removed
*/
public Dataset removeDataset(int index) {
if((index<0)||(index>datasets.size()-1)) {
return null;
}
return datasets.remove(index);
}
/**
* Returns the index of the first dataset with the specified y column name.
* Method added by Doug Brown 1/15/2007.
*
* @param yColumnName the y column name
* @return the index, or -1 if none found
*/
public int getDatasetIndex(String yColumnName) {
for(int i = 0; i<datasets.size(); i++) {
String name = datasets.get(i).getYColumnName();
if(name.equals(yColumnName)) {
return i;
}
}
return -1;
}
/**
* Returns the constant names.
* Added by Doug Brown 3/24/2011.
*
* @return array of constant names
*/
public String[] getConstantNames() {
return constantNames.toArray(new String[constantNames.size()]);
}
/**
* Returns the value of a constant.
* Added by Doug Brown 3/24/2011.
*
* @param name the name of the constant
* @return Double value of the constant, or null if not defined
*/
public Double getConstantValue(String name) {
return constantValues.get(name);
}
/**
* Returns the expression of a constant.
* Added by Doug Brown 3/24/2011.
*
* @param name the name of the constant
* @return the expression, or null if not defined
*/
public String getConstantExpression(String name) {
return constantExpressions.get(name);
}
/**
* Sets the value of a constant.
* Added by Doug Brown 3/24/2011.
*
* @param name the name of the constant
* @param val the value of the constant
* @param expression the expression that defines the value
*/
public void setConstant(String name, double val, String expression) {
if (!constantNames.contains(name))
constantNames.add(name);
constantValues.put(name, val);
constantExpressions.put(name, expression);
}
/**
* Clears a constant.
* Added by Doug Brown 3/24/2011.
*
* @param name the name of the constant
*/
public void clearConstant(String name) {
constantNames.remove(name);
constantValues.remove(name);
constantExpressions.remove(name);
}
/**
* Create a string representation of the data.
* @return the data
*/
public String toString() {
if(datasets.size()==0) {
return "No data in datasets."; //$NON-NLS-1$
}
StringBuffer b = new StringBuffer();
for(int i = 0; i<datasets.size(); i++) {
b.append("Dataset "); //$NON-NLS-1$
b.append(i);
b.append('\n');
b.append(datasets.get(i).toString());
}
return b.toString();
}
/**
*
* Sets the column names for all datasets when rendering this dataset in a JTable.
*
*
*
* @param _xColumnName
*
* @param _yColumnName
*
*/
public void setXYColumnNames(String _xColumnName, String _yColumnName) {
xColumnName = _xColumnName; // default names for future datasets
yColumnName = _yColumnName; // default names for future datasets
// set the column names for current datasets
for(int i = 0, size = datasets.size(); i<size; i++) {
(datasets.get(i)).setXYColumnNames(_xColumnName, _yColumnName);
}
}
/**
* Ensures capacity
*
* @param datasetIndex
*/
protected void checkDatasetIndex(int datasetIndex) {
while(datasetIndex>=datasets.size()) {
Dataset d = new Dataset(DisplayColors.getMarkerColor(datasetIndex), DisplayColors.getLineColor(datasetIndex), connected); // use specified colors
if(linked&&(datasets.size()>0)) {
d.setXColumnVisible(false); // hide all x points in new datasets (except the 0th dataset)
}
d.setSorted(sorted);
d.setXYColumnNames(xColumnName, yColumnName);
d.setMarkerShape(markerShape);
datasets.add(d);
}
}
/**
* Returns the XML.ObjectLoader for this class.
*
* @return the object loader
*/
public static XML.ObjectLoader getLoader() {
return new Loader();
}
/**
* A class to save and load Dataset data in an XMLControl.
*/
private static class Loader extends XMLLoader {