KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Trace2DReplacing, a list- based 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.TracePoint2D;
26
27
28 /**
29  * Has the behaviour of <code>Trace2DBijective</code> and an additional
30  * features: <br>
31  * <ul>
32  * <li>All tracepoints that are added are stored unchanged in a LinkedList.
33  * </li>
34  * <li>All traceoints added whose x- values are not already contained are added
35  * to the end.</li>
36  * <li>If a tracepoint is inserted whose x - value already exists in the List,
37  * the old tracepoint with that value will be replaced by the new tracepoint.
38  * </li>
39  * </UL>
40  *
41  * @see Trace2DBijective
42  *
43  * @author <a HREF='mailto:Achim.Westermann@gmx.de'>Achim Westermann </a>
44  *
45  * @version $Revision: 1.1 $
46  */

47 public class Trace2DReplacing extends Trace2DSimple {
48
49   /**
50    * Defcon.
51    */

52   public Trace2DReplacing() {
53     // nop
54
}
55
56   /**
57    * In case p has an x- value already contained, the old tracepoint with that
58    * value will be replaced by the new one. Else the new tracepoint will be
59    * added to the end, not caring wether tracepoints with a higher x- value are
60    * contained.
61    * <p>
62    *
63    * @param p
64    * the point to add.
65    *
66    * @return true if the point wathe maximum amount of points that will be
67    * showns successfully added.
68    */

69   public boolean addPointInternal(final TracePoint2D p) {
70     int index = -1;
71     TracePoint2D old;
72     index = this.m_points.indexOf(p);
73     if (index != -1) {
74       // already contained.
75
old = (TracePoint2D) this.m_points.get(index);
76       // fires property changes with bound checks
77
old.setLocation(old.getX(), p.getY());
78       // we don't need further bound checks and property change events from
79
// calling
80
// addPoint method.
81
return false;
82     } else {
83       this.m_points.add(p);
84       return true;
85     }
86   }
87 }
88
Popular Tags