KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > progra > charting > model > EditableChartDataModel


1 /*
2     JOpenChart Java Charting Library and Toolkit
3     Copyright (C) 2001 Sebastian Müller
4     http://jopenchart.sourceforge.net
5
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Lesser General Public
8     License as published by the Free Software Foundation; either
9     version 2.1 of the License, or (at your option) any later version.
10
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     Lesser General Public License for more details.
15
16     You should have received a copy of the GNU Lesser General Public
17     License along with this library; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20     EditableChartDataModel.java
21     Created on 9. June 2002, 15:46
22 */

23
24 package de.progra.charting.model;
25
26
27 import de.progra.charting.CoordSystem;
28 import de.progra.charting.ChartUtilities;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.TreeSet JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.HashMap JavaDoc;
34
35 /**
36  * Implements an editable ChartModel. It uses a vector of DataSets and the columns
37  * are numeric.
38  * @author mueller
39  * @version 1.0
40  */

41 public class EditableChartDataModel extends DefaultChartDataModel {
42
43     /** Creates a new empty EditableChartDataModel.
44      */

45     public EditableChartDataModel() {
46         super();
47     }
48     
49     /** Creates new EditableChartDataModel with the default axis binding.
50      * @param data the array of values. The first index specifies the
51      * datasets, the last one is the value index.
52      * @param columns the array of x-axis values. The length of the
53      * datasets and the length of the column should be equal and the columns should
54      * be ordered.
55      * @param rows the array of DataSet titles. It has to have the same
56      * length as the number of DataSets.
57      */

58     public EditableChartDataModel(Number JavaDoc[][] data,
59                                  double[] columns,
60                                  String JavaDoc[] rows) {
61         this();
62         
63         columnSet.addAll(Arrays.asList(ChartUtilities.transformArray(columns)));
64         
65         TreeSet JavaDoc set = (TreeSet JavaDoc)valuesbyaxis.get(new Integer JavaDoc(CoordSystem.FIRST_YAXIS));
66                 
67         ChartUtilities.addDataToSet(set, data);
68         trimSet(set);
69         
70         for(int i = 0; i < data.length; i++) {
71             this.data.add(new EditableDataSet(data[i],
72                                               ChartUtilities.transformArray(columns),
73                                               CoordSystem.FIRST_YAXIS,
74                                               rows[i]));
75         }
76     }
77
78     /** Creates new EditableChartDataModel.
79      * @param data the array of values. The first index specifies the
80      * datasets, the last one is the value index.
81      * @param columns the array of x-axis values. The length of the
82      * datasets and the length of the column should be equal and
83      * the columns should be ordered.
84      * @param rows the array of DataSet titles. It has to have the same
85      * length as the number of DataSets.
86      */

87     public EditableChartDataModel(int[][] data,
88                                  double[] columns,
89                                  String JavaDoc[] rows) {
90         this();
91         
92         Number JavaDoc[][] numdata = ChartUtilities.transformArray(data);
93         
94         columnSet.addAll(Arrays.asList(ChartUtilities.transformArray(columns)));
95         
96         TreeSet JavaDoc set =
97             (TreeSet JavaDoc)valuesbyaxis.get(new Integer JavaDoc(CoordSystem.FIRST_YAXIS));
98         
99         ChartUtilities.addDataToSet(set, numdata);
100
101         trimSet(set);
102         
103         for(int i = 0; i < data.length; i++) {
104             this.data.add(new EditableDataSet(numdata[i],
105                                               ChartUtilities.transformArray(columns),
106                                               CoordSystem.FIRST_YAXIS,
107                                               rows[i]));
108         }
109     }
110     
111     /** Creates new EditableChartDataModel.
112      * @param data the array of values. The first index specifies the
113      * datasets, the last one is the value index.
114      * @param columns the array of x-axis values. The length of the
115      * datasets and the length of the column should be equal and
116      * the columns should be ordered.
117      * @param rows the array of DataSet titles. It has to have the same
118      * length as the number of DataSets.
119      */

120     public EditableChartDataModel(double[][] data,
121                                  double[] columns,
122                                  String JavaDoc[] rows) {
123         this();
124         
125         Number JavaDoc[][] numdata = ChartUtilities.transformArray(data);
126         
127         columnSet.addAll(Arrays.asList(ChartUtilities.transformArray(columns)));
128         
129         TreeSet JavaDoc set =
130             (TreeSet JavaDoc)valuesbyaxis.get(new Integer JavaDoc(CoordSystem.FIRST_YAXIS));
131         
132         ChartUtilities.addDataToSet(set, numdata);
133         trimSet(set);
134         for(int i = 0; i < data.length; i++) {
135             this.data.add(new EditableDataSet(numdata[i],
136                                               ChartUtilities.transformArray(columns),
137                                               CoordSystem.FIRST_YAXIS,
138                                               rows[i]));
139         }
140     }
141     
142     /** Creates a new EditableChartDataModel using the
143      * given array of EditableDataSets, effectively enabling the creation
144      * of DataModels with differently sized DataSets.
145      * @param ds the array of DataSets to be used.
146      */

147     public EditableChartDataModel(EditableDataSet[] ds) {
148         super(ds);
149     }
150     
151     /** Sets the axis binding for a given DataSet.
152      * @param set the DataSet
153      * @param axis the Axis binding
154      */

155     public void setAxisBinding(int set, int axis) {
156     }
157     
158     /** Sets the value in a given DataSet.
159      * @param set the DataSet in which the value should be set
160      * @param index the index in the DataSet where the value should be stored
161      * @param value the value object
162      */

163     public void setValueAt(int set, int index, Object JavaDoc value) {
164     }
165     
166     /** Inserts a value together with its column value at the right position. The
167      * right index is determined by performing a binary search on the columns in the
168      * DataSet. Fires a ChartDataModelChangedEvent.
169      * @param set the DataSet in which the value should be set
170      * @param value the value object
171      * @param column the column value object
172      */

173     public void insertValue(int set, Object JavaDoc value, Object JavaDoc column) {
174         ((EditableDataSet)data.get(set)).insertValue(value, column);
175         columnSet.add(column);
176         TreeSet JavaDoc treeset = (TreeSet JavaDoc)valuesbyaxis.get(new Integer JavaDoc(getAxisBinding(set)));
177         treeset.add(value);
178         trimSet(treeset);
179         
180         fireChartDataModelChangedEvent(this);
181     }
182     
183     /** Removes the value in a given DataSet.
184      * @param set the DataSet in which the value should be set
185      * @param index the index in the DataSet where the value should be stored
186      */

187     public void removeValueAt(int set, int index) {
188     }
189     
190     public void removeDataSet(int set) {}
191     
192     public void addDataSet(EditableDataSet ds) {}
193 }
194
Popular Tags