KickJava   Java API By Example, From Geeks To Geeks.

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


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     DefaultDataSet.java
21     Created on 1. Juli 2001, 21:20
22 */

23
24 package de.progra.charting.model;
25
26 import de.progra.charting.CoordSystem;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 /**
31  * This is a default DataSet implementation.
32  * @author mueller
33  * @version 1.0
34  */

35 public class DefaultDataSet implements DataSet {
36
37     protected ArrayList JavaDoc data = new ArrayList JavaDoc();
38     
39     protected ArrayList JavaDoc columns = new ArrayList JavaDoc();
40     
41     protected int axis = CoordSystem.FIRST_YAXIS;
42     
43     protected String JavaDoc title = "";
44     
45     /** Creates a new empty DefaultDataSet with default axis binding. */
46     public DefaultDataSet() {
47     }
48     
49     /** Creates a new empty DefaultDataSet with the given
50      * Axis binding.
51      */

52     public DefaultDataSet(int axis) {
53         this();
54         setYAxis(axis);
55     }
56     
57     /** Creates a new DefaultDataSet with the given data and
58      * the Axis binding.
59      * @param data the DataSet values
60      * @param columns the DataSet columns, the value and the column array should
61      * have the same length. The columns have to be sorted.
62      * @param axis the Axis binding
63      */

64     public DefaultDataSet(Object JavaDoc[] data, Object JavaDoc[] columns, int axis) {
65         this(axis);
66         this.data.addAll(Arrays.asList(data));
67         this.columns.addAll(Arrays.asList(columns));
68     }
69     
70     /** Creates a new DefaultDataSet with the given data and
71      * the Axis binding.
72      * @param data the DataSet values
73      * @param columns the DataSet columns, the value and the column array should
74      * have the same length. The columns have to be sorted.
75      * @param axis the Axis binding
76      */

77     public DefaultDataSet(Object JavaDoc[] data, Object JavaDoc[] columns, int axis, String JavaDoc title) {
78         this(data, columns, axis);
79         this.title = title;
80     }
81
82     /** Returns the length of this data set, ie the minimum of the columns and the
83      * data array length.
84      * @return the length of the DataSet
85      */

86     public int getDataSetLength() {
87         return Math.min(data.size(), columns.size());
88     }
89     
90     /** Returns the data at the specified index.
91      * @param index the data index
92      * @return the Object value
93      */

94     public Object JavaDoc getValueAt(int index) {
95         return data.get(index);
96     }
97     
98     /** Returns the Axis binding.
99      * @return the axis binding constant
100      */

101     public int getYAxis() {
102         return axis;
103     }
104     
105     /** Sets the given value at the specified index.
106      * @param index the value index
107      * @param val the Object value
108      */

109     public void setValueAt(int index, Object JavaDoc val) {
110         data.set(index, val);
111     }
112     
113     /** Sets the Axis binding.
114      * @param yaxis the axis binding constant
115      */

116     public void setYAxis(int yaxis) {
117         if(yaxis == CoordSystem.FIRST_YAXIS || yaxis == CoordSystem.SECOND_YAXIS)
118             axis = yaxis;
119     }
120     
121     /** Returns the column value.
122      * @param index the column index
123      * @return the column value
124      */

125     public Object JavaDoc getColumnValueAt(int index) {
126         return columns.get(index);
127     }
128     
129     /** Sets a column value.
130      * @param index the column index
131      * @param col the column value
132      */

133     public void setColumnValueAt(int index, Object JavaDoc col) {
134         columns.set(index, col);
135     }
136     
137     /** Sets the title of this DataSet.
138      * @param title the String title
139      */

140     public void setTitle(String JavaDoc title) {
141         this.title = title;
142     }
143     
144     /** Returns the title of this DataSet.
145      * @return the String title
146      */

147     public String JavaDoc getTitle() {
148         return title;
149     }
150 }
Popular Tags