KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Trace2DLtdReplcacing, an array- based fast implementation of an ITrace2D
3  * that only allows a single tracepoint with a certain x- value.
4  * Copyright (C) 2002 Achim Westermann, Achim.Westermann@gmx.de
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  */

23 package info.monitorenter.gui.chart.traces;
24
25
26 import info.monitorenter.gui.chart.TracePoint2D;
27
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * In addition to the <code> Trace2DLtd</code> this class offers the guarantee
32  * only to allow a single tracepoint with a certain x- value. If a new
33  * tracepoint is added whose x- value is already contained, the new tracepoints
34  * values will get assigned to the certain old tracepoint respecting the fact
35  * that only an additional changed y- value occurs. <br>
36  * The <code>add</code> methods increase complexity to factor n but some event -
37  * handling may be saved (no change of x and y). <br>
38  * Tracepoints with x- values not contained before will be appended to the end
39  * of the internal data- structure. <br>
40  *
41  * @author <a HREF='mailto:Achim.Westermann@gmx.de'>Achim Westerman </a>
42  *
43  * @version $Revision: 1.2 $
44  */

45 public class Trace2DLtdReplacing extends Trace2DLtd {
46   /**
47    * Constructs a <code>Trace2DLtdReplacing</code> with a default buffer size
48    * of 100.
49    */

50   public Trace2DLtdReplacing() {
51     this(100);
52   }
53
54   /**
55    * Constructs an instance with a buffer size of bufsize.
56    * <p>
57    *
58    * @param bufsize
59    * the maximum amount of points that will be displayed.
60    */

61   public Trace2DLtdReplacing(final int bufsize) {
62     super(bufsize);
63   }
64
65   /**
66    * @see ATrace2D#addPointInternal(info.monitorenter.gui.chart.TracePoint2D)
67    */

68   public boolean addPointInternal(final TracePoint2D p) {
69     TracePoint2D tmp;
70     double tmpx, tmpy;
71     Iterator JavaDoc it = this.m_buffer.iteratorF2L();
72     while (it.hasNext()) {
73       tmp = (TracePoint2D) it.next();
74       tmpx = tmp.getX();
75       if (tmpx == p.getX()) {
76         tmpy = p.getY();
77         if (tmpy == tmp.getY()) {
78           // performs bound checks and fires property changes
79
tmp.setLocation(tmpx, tmpy);
80           // don't need bound checks of calling addPoint.
81
return false;
82         }
83       }
84     }
85     return super.addPointInternal(p);
86   }
87 }
88
Popular Tags