KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > traces > Trace2DSimple


1 /*
2  * Trace2DSimple, a list- based simple implementation of a ITrace2D.
3  * Copyright (C) 2002 Achim Westermann, Achim.Westermann@gmx.de
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  */

22
23 package info.monitorenter.gui.chart.traces;
24
25 import info.monitorenter.gui.chart.ITrace2D;
26 import info.monitorenter.gui.chart.TracePoint2D;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30
31 /**
32  * <p>
33  * A basic <code>{@link info.monitorenter.gui.chart.ITrace2D}</code> implementation that
34  * stores the internal <code>{@link info.monitorenter.gui.chart.TracePoint2D}</code>
35  * instances in a <code>{@link java.util.List}</code>.
36  * </p>
37  * <p>
38  * </p>
39  * <p>
40  * This class has the following behaviour: <br>
41  * <ul>
42  * <li>All tracepoints that are added are stored unchanged in a LinkedList.
43  * </li>
44  * <li>All traceoints that are added are added to the end.</li>
45  * <li>If a tracepoint is inserted whose x - value already exists in the List,
46  * it is ok - the old point may remain. (no bijective assigement of X and Y)
47  * </li>
48  * </ul>
49  * </p>
50  *
51  * @author <a HREF='mailto:Achim.Westermann@gmx.de'>Achim Westermann </a>
52  *
53  * @version $Revision: 1.2 $
54  */

55 public class Trace2DSimple extends ATrace2D implements ITrace2D {
56
57   /** Internal List &lt;ITracePoint2D&gt;. */
58   protected LinkedList JavaDoc m_points = new LinkedList JavaDoc();
59
60   /**
61    * Creates an empty trace.
62    * <p>
63    */

64   public Trace2DSimple() {
65     this(Trace2DSimple.class.getName() + "-" + ATrace2D.getInstanceCount());
66   }
67
68   /**
69    * Creates an emtpy trace with the given name.
70    * <p>
71    *
72    * @param name
73    * the name that will be displayed below the chart.
74    */

75   public Trace2DSimple(final String JavaDoc name) {
76     this.setName(name);
77   }
78
79   /**
80    * @see ATrace2D#addPointInternal(info.monitorenter.gui.chart.TracePoint2D)
81    */

82   protected boolean addPointInternal(final TracePoint2D p) {
83     this.m_points.add(p);
84     return true;
85   }
86
87   /**
88    * @see info.monitorenter.gui.chart.ITrace2D#getMaxSize()
89    */

90   public final int getMaxSize() {
91     return Integer.MAX_VALUE;
92   }
93
94   /**
95    * @see info.monitorenter.gui.chart.ITrace2D#getSize()
96    */

97   public final int getSize() {
98     return this.m_points.size();
99   }
100
101   /**
102    * @see info.monitorenter.gui.chart.ITrace2D#isEmpty()
103    */

104   public boolean isEmpty() {
105     return this.m_points.size() == 0;
106   }
107
108   /**
109    * @see info.monitorenter.gui.chart.ITrace2D#iterator()
110    */

111   public Iterator JavaDoc iterator() {
112     return this.m_points.iterator();
113   }
114
115   /**
116    * @see ATrace2D#removeAllPointsInternal()
117    */

118   public final void removeAllPointsInternal() {
119     this.m_points.clear();
120   }
121
122   /**
123    * @see ATrace2D#removePointInternal(info.monitorenter.gui.chart.TracePoint2D)
124    */

125   protected boolean removePointInternal(final TracePoint2D point) {
126     return this.m_points.remove(point);
127   }
128
129 }
130
Popular Tags