001: /*
002: JOpenChart Java Charting Library and Toolkit
003: Copyright (C) 2001 Sebastian Müller
004: http://jopenchart.sourceforge.net
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: EditableChartDataModel.java
021: Created on 9. June 2002, 15:46
022: */
023:
024: package de.progra.charting.model;
025:
026: import de.progra.charting.CoordSystem;
027: import de.progra.charting.ChartUtilities;
028: import java.util.ArrayList;
029: import java.util.Arrays;
030: import java.util.TreeSet;
031: import java.util.Set;
032: import java.util.HashMap;
033:
034: /**
035: * Implements an editable ChartModel. It uses a vector of DataSets and the columns
036: * are numeric.
037: * @author mueller
038: * @version 1.0
039: */
040: public class EditableChartDataModel extends DefaultChartDataModel {
041:
042: /** Creates a new empty EditableChartDataModel.
043: */
044: public EditableChartDataModel() {
045: super ();
046: }
047:
048: /** Creates new EditableChartDataModel with the default axis binding.
049: * @param data the array of values. The first index specifies the
050: * datasets, the last one is the value index.
051: * @param columns the array of x-axis values. The length of the
052: * datasets and the length of the column should be equal and the columns should
053: * be ordered.
054: * @param rows the array of DataSet titles. It has to have the same
055: * length as the number of DataSets.
056: */
057: public EditableChartDataModel(Number[][] data, double[] columns,
058: String[] rows) {
059: this ();
060:
061: columnSet.addAll(Arrays.asList(ChartUtilities
062: .transformArray(columns)));
063:
064: TreeSet set = (TreeSet) valuesbyaxis.get(new Integer(
065: CoordSystem.FIRST_YAXIS));
066:
067: ChartUtilities.addDataToSet(set, data);
068: trimSet(set);
069:
070: for (int i = 0; i < data.length; i++) {
071: this .data.add(new EditableDataSet(data[i], ChartUtilities
072: .transformArray(columns), CoordSystem.FIRST_YAXIS,
073: rows[i]));
074: }
075: }
076:
077: /** Creates new EditableChartDataModel.
078: * @param data the array of values. The first index specifies the
079: * datasets, the last one is the value index.
080: * @param columns the array of x-axis values. The length of the
081: * datasets and the length of the column should be equal and
082: * the columns should be ordered.
083: * @param rows the array of DataSet titles. It has to have the same
084: * length as the number of DataSets.
085: */
086: public EditableChartDataModel(int[][] data, double[] columns,
087: String[] rows) {
088: this ();
089:
090: Number[][] numdata = ChartUtilities.transformArray(data);
091:
092: columnSet.addAll(Arrays.asList(ChartUtilities
093: .transformArray(columns)));
094:
095: TreeSet set = (TreeSet) valuesbyaxis.get(new Integer(
096: CoordSystem.FIRST_YAXIS));
097:
098: ChartUtilities.addDataToSet(set, numdata);
099:
100: trimSet(set);
101:
102: for (int i = 0; i < data.length; i++) {
103: this .data.add(new EditableDataSet(numdata[i],
104: ChartUtilities.transformArray(columns),
105: CoordSystem.FIRST_YAXIS, rows[i]));
106: }
107: }
108:
109: /** Creates new EditableChartDataModel.
110: * @param data the array of values. The first index specifies the
111: * datasets, the last one is the value index.
112: * @param columns the array of x-axis values. The length of the
113: * datasets and the length of the column should be equal and
114: * the columns should be ordered.
115: * @param rows the array of DataSet titles. It has to have the same
116: * length as the number of DataSets.
117: */
118: public EditableChartDataModel(double[][] data, double[] columns,
119: String[] rows) {
120: this ();
121:
122: Number[][] numdata = ChartUtilities.transformArray(data);
123:
124: columnSet.addAll(Arrays.asList(ChartUtilities
125: .transformArray(columns)));
126:
127: TreeSet set = (TreeSet) valuesbyaxis.get(new Integer(
128: CoordSystem.FIRST_YAXIS));
129:
130: ChartUtilities.addDataToSet(set, numdata);
131: trimSet(set);
132: for (int i = 0; i < data.length; i++) {
133: this .data.add(new EditableDataSet(numdata[i],
134: ChartUtilities.transformArray(columns),
135: CoordSystem.FIRST_YAXIS, rows[i]));
136: }
137: }
138:
139: /** Creates a new EditableChartDataModel using the
140: * given array of EditableDataSets, effectively enabling the creation
141: * of DataModels with differently sized DataSets.
142: * @param ds the array of DataSets to be used.
143: */
144: public EditableChartDataModel(EditableDataSet[] ds) {
145: super (ds);
146: }
147:
148: /** Sets the axis binding for a given DataSet.
149: * @param set the DataSet
150: * @param axis the Axis binding
151: */
152: public void setAxisBinding(int set, int axis) {
153: }
154:
155: /** Sets the value in a given DataSet.
156: * @param set the DataSet in which the value should be set
157: * @param index the index in the DataSet where the value should be stored
158: * @param value the value object
159: */
160: public void setValueAt(int set, int index, Object value) {
161: }
162:
163: /** Inserts a value together with its column value at the right position. The
164: * right index is determined by performing a binary search on the columns in the
165: * DataSet. Fires a ChartDataModelChangedEvent.
166: * @param set the DataSet in which the value should be set
167: * @param value the value object
168: * @param column the column value object
169: */
170: public void insertValue(int set, Object value, Object column) {
171: ((EditableDataSet) data.get(set)).insertValue(value, column);
172: columnSet.add(column);
173: TreeSet treeset = (TreeSet) valuesbyaxis.get(new Integer(
174: getAxisBinding(set)));
175: treeset.add(value);
176: trimSet(treeset);
177:
178: fireChartDataModelChangedEvent(this );
179: }
180:
181: /** Removes the value in a given DataSet.
182: * @param set the DataSet in which the value should be set
183: * @param index the index in the DataSet where the value should be stored
184: */
185: public void removeValueAt(int set, int index) {
186: }
187:
188: public void removeDataSet(int set) {
189: }
190:
191: public void addDataSet(EditableDataSet ds) {
192: }
193: }
|