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: DefaultDataSet.java
021: Created on 1. Juli 2001, 21:20
022: */
023:
024: package de.progra.charting.model;
025:
026: import de.progra.charting.CoordSystem;
027: import java.util.ArrayList;
028: import java.util.Arrays;
029:
030: /**
031: * This is a default DataSet implementation.
032: * @author mueller
033: * @version 1.0
034: */
035: public class DefaultDataSet implements DataSet {
036:
037: protected ArrayList data = new ArrayList();
038:
039: protected ArrayList columns = new ArrayList();
040:
041: protected int axis = CoordSystem.FIRST_YAXIS;
042:
043: protected String title = "";
044:
045: /** Creates a new empty DefaultDataSet with default axis binding. */
046: public DefaultDataSet() {
047: }
048:
049: /** Creates a new empty DefaultDataSet with the given
050: * Axis binding.
051: */
052: public DefaultDataSet(int axis) {
053: this ();
054: setYAxis(axis);
055: }
056:
057: /** Creates a new DefaultDataSet with the given data and
058: * the Axis binding.
059: * @param data the DataSet values
060: * @param columns the DataSet columns, the value and the column array should
061: * have the same length. The columns have to be sorted.
062: * @param axis the Axis binding
063: */
064: public DefaultDataSet(Object[] data, Object[] columns, int axis) {
065: this (axis);
066: this .data.addAll(Arrays.asList(data));
067: this .columns.addAll(Arrays.asList(columns));
068: }
069:
070: /** Creates a new DefaultDataSet with the given data and
071: * the Axis binding.
072: * @param data the DataSet values
073: * @param columns the DataSet columns, the value and the column array should
074: * have the same length. The columns have to be sorted.
075: * @param axis the Axis binding
076: */
077: public DefaultDataSet(Object[] data, Object[] columns, int axis,
078: String title) {
079: this (data, columns, axis);
080: this .title = title;
081: }
082:
083: /** Returns the length of this data set, ie the minimum of the columns and the
084: * data array length.
085: * @return the length of the DataSet
086: */
087: public int getDataSetLength() {
088: return Math.min(data.size(), columns.size());
089: }
090:
091: /** Returns the data at the specified index.
092: * @param index the data index
093: * @return the Object value
094: */
095: public Object getValueAt(int index) {
096: return data.get(index);
097: }
098:
099: /** Returns the Axis binding.
100: * @return the axis binding constant
101: */
102: public int getYAxis() {
103: return axis;
104: }
105:
106: /** Sets the given value at the specified index.
107: * @param index the value index
108: * @param val the Object value
109: */
110: public void setValueAt(int index, Object val) {
111: data.set(index, val);
112: }
113:
114: /** Sets the Axis binding.
115: * @param yaxis the axis binding constant
116: */
117: public void setYAxis(int yaxis) {
118: if (yaxis == CoordSystem.FIRST_YAXIS
119: || yaxis == CoordSystem.SECOND_YAXIS)
120: axis = yaxis;
121: }
122:
123: /** Returns the column value.
124: * @param index the column index
125: * @return the column value
126: */
127: public Object getColumnValueAt(int index) {
128: return columns.get(index);
129: }
130:
131: /** Sets a column value.
132: * @param index the column index
133: * @param col the column value
134: */
135: public void setColumnValueAt(int index, Object col) {
136: columns.set(index, col);
137: }
138:
139: /** Sets the title of this DataSet.
140: * @param title the String title
141: */
142: public void setTitle(String title) {
143: this .title = title;
144: }
145:
146: /** Returns the title of this DataSet.
147: * @return the String title
148: */
149: public String getTitle() {
150: return title;
151: }
152: }
|