KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Trace2DDebugger.java jchart2d
3  * Copyright (C) Achim Westermann, created on 04.03.2005, 12:33:48
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.Chart2D;
26 import info.monitorenter.gui.chart.ITrace2D;
27 import info.monitorenter.gui.chart.ITracePainter;
28 import info.monitorenter.gui.chart.TracePoint2D;
29 import info.monitorenter.util.Range;
30
31 import java.awt.Color JavaDoc;
32 import java.awt.Stroke JavaDoc;
33 import java.beans.PropertyChangeListener JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.Set JavaDoc;
36
37 /**
38  * <p>
39  * A decorator for any ITrace2D implementation. Useful if your chart looks
40  * unexpected and the problem may be related to the data that is added. It
41  * prints every point added to the console.
42  * </p>
43  * <p>
44  * <p>
45  * Use it by decorating the ITrace2D you normally use:
46  *
47  * <pre>
48  *
49  *
50  * // Create a chart:
51  * Chart2D chart = new Chart2D();
52  * // Create an ITrace:
53  * &lt;b&gt;ITrace2D trace = new Trace2DDebugger(new Trace2DSimple());
54  * // add data...
55  * ...
56  * //
57  * chart.addTrace(trace);
58  *
59  *
60  * </pre>
61  *
62  * </p>
63  * <p>
64  * One can use {@link #setXRange(Range)},{@link #setYRange(Range)} to let this
65  * instance throw an Exception if bounds for legal data are exceeded.
66  * </p>
67  *
68  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
69  *
70  * @version $Revision: 1.2 $
71  */

72 public class Trace2DDebugger implements ITrace2D {
73
74   /**
75    * The instance to debug.
76    */

77   private ITrace2D m_delegate;
78
79   /**
80    * The valid range for x values. If a point breaks these bounds an
81    * {@link IllegalArgumentException} will be thrown.
82    */

83   private Range m_xRange = new Range(-Double.MAX_VALUE, +Double.MAX_VALUE);
84
85   /**
86    * The valid range for y values. If a point breaks these bounds an
87    * {@link IllegalArgumentException} will be thrown.
88    */

89   private Range m_yRange = new Range(-Double.MAX_VALUE, +Double.MAX_VALUE);
90
91   /**
92    * Creates an inistance to debug the given trace for valid points added.
93    * <p>
94    *
95    * @param debug
96    * the trace to debug.
97    */

98   public Trace2DDebugger(final ITrace2D debug) {
99     if (debug == null) {
100       throw new IllegalArgumentException JavaDoc("Argument must not be null.");
101     }
102     this.m_delegate = debug;
103   }
104
105   /**
106    * @param debug
107    * The ITrace to debug.
108    */

109
110   /**
111    * @see ITrace2D#addPoint(double, double)
112    */

113   public boolean addPoint(final double x, final double y) {
114     TracePoint2D p = new TracePoint2D(x, y);
115     return this.addPoint(p);
116   }
117
118   // /////////////////////////////////
119
// Proxy methods
120

121   /**
122    * @see ITrace2D#addPoint(TracePoint2D)
123    */

124   public boolean addPoint(final TracePoint2D p) {
125     double x = p.getX();
126     double y = p.getY();
127     if (!this.m_xRange.isContained(x)) {
128       throw new IllegalArgumentException JavaDoc(p.toString() + " is not within the valid x-range "
129           + this.m_xRange.toString());
130     }
131     if (!this.m_yRange.isContained(y)) {
132       throw new IllegalArgumentException JavaDoc(p.toString() + " is not within the valid x-range "
133           + this.m_xRange.toString());
134     }
135     return this.m_delegate.addPoint(p);
136   }
137
138   /**
139    * @see ITrace2D#addPropertyChangeListener(String, PropertyChangeListener)
140    */

141   public void addPropertyChangeListener(final String JavaDoc propertyName,
142       final PropertyChangeListener JavaDoc listener) {
143     this.m_delegate.addPropertyChangeListener(propertyName, listener);
144   }
145
146   /**
147    * @see info.monitorenter.gui.chart.ITrace2D#addTracePainter(info.monitorenter.gui.chart.ITracePainter)
148    */

149   public boolean addTracePainter(final ITracePainter painter) {
150     return this.m_delegate.addTracePainter(painter);
151   }
152
153   /**
154    * @see info.monitorenter.gui.chart.ITrace2D#containsTracePainter(info.monitorenter.gui.chart.ITracePainter)
155    */

156   public boolean containsTracePainter(final ITracePainter painter) {
157     return this.m_delegate.containsTracePainter(painter);
158   }
159
160   /**
161    * @see java.lang.Object#equals(java.lang.Object)
162    */

163   public boolean equals(final Object JavaDoc obj) {
164     return this.m_delegate.equals(obj);
165   }
166
167   /**
168    * @see ITrace2D#getColor()
169    */

170   public Color JavaDoc getColor() {
171     return this.m_delegate.getColor();
172   }
173
174   /**
175    * @see info.monitorenter.util.collections.IComparableProperty#getComparableProperty()
176    */

177   public Number JavaDoc getComparableProperty() {
178     return this.m_delegate.getComparableProperty();
179   }
180
181   /**
182    * @see ITrace2D#isVisible()
183    */

184   public boolean getisible() {
185     return this.m_delegate.isVisible();
186   }
187
188   /**
189    * @see info.monitorenter.gui.chart.ITrace2D#getLable()
190    */

191   public String JavaDoc getLable() {
192     return this.m_delegate.getLable();
193   }
194
195   /**
196    * @see info.monitorenter.gui.chart.ITrace2D#getMaxSize()
197    */

198   public int getMaxSize() {
199     return this.m_delegate.getMaxSize();
200   }
201
202   /**
203    * @see info.monitorenter.gui.chart.ITrace2D#getMaxX()
204    */

205   public double getMaxX() {
206     return this.m_delegate.getMaxX();
207   }
208
209   /**
210    * @see info.monitorenter.gui.chart.ITrace2D#getMaxY()
211    */

212   public double getMaxY() {
213     return this.m_delegate.getMaxY();
214   }
215
216   /**
217    * @see info.monitorenter.gui.chart.ITrace2D#getMinX()
218    */

219   public double getMinX() {
220     return this.m_delegate.getMinX();
221   }
222
223   /**
224    * @see info.monitorenter.gui.chart.ITrace2D#getMinY()
225    */

226   public double getMinY() {
227     return this.m_delegate.getMinY();
228   }
229
230   /**
231    * @see info.monitorenter.gui.chart.ITrace2D#getName()
232    */

233   public String JavaDoc getName() {
234     return this.m_delegate.getName();
235   }
236
237   /**
238    *
239    * @see info.monitorenter.gui.chart.ITrace2D#getPhysicalUnits()
240    */

241   public String JavaDoc getPhysicalUnits() {
242     return this.m_delegate.getPhysicalUnits();
243   }
244
245   /**
246    * @see info.monitorenter.gui.chart.ITrace2D#getPropertyChangeListeners(java.lang.String)
247    */

248   public PropertyChangeListener JavaDoc[] getPropertyChangeListeners(final String JavaDoc property) {
249     return this.m_delegate.getPropertyChangeListeners(property);
250   }
251
252   /**
253    * @see info.monitorenter.gui.chart.ITrace2D#getRenderer()
254    */

255   public Chart2D getRenderer() {
256     return this.m_delegate.getRenderer();
257   }
258
259   /**
260    * @see info.monitorenter.gui.chart.ITrace2D#getSize()
261    */

262   public int getSize() {
263     return this.m_delegate.getSize();
264   }
265
266   /**
267    * @see info.monitorenter.gui.chart.ITrace2D#getStroke()
268    */

269   public Stroke JavaDoc getStroke() {
270     return this.m_delegate.getStroke();
271   }
272
273   /**
274    * @see info.monitorenter.gui.chart.ITrace2D#getTracePainters()
275    */

276   public final Set JavaDoc getTracePainters() {
277     return this.m_delegate.getTracePainters();
278   }
279
280   /**
281    * @see info.monitorenter.gui.chart.ITrace2D#isVisible()
282    */

283   public boolean isVisible() {
284     return this.m_delegate.isVisible();
285   }
286
287   /**
288    * Returns the range of valid points of the x axis.
289    * <p>
290    *
291    * @return the range of valid points of the x axis.
292    */

293   public Range getXRange() {
294     return this.m_xRange;
295   }
296
297   /**
298    * Returns the range of valid points of the y axis.
299    * <p>
300    *
301    * @return the range of valid points of the y axis.
302    */

303   public Range getYRange() {
304     return this.m_yRange;
305   }
306
307   /**
308    * @see info.monitorenter.gui.chart.ITrace2D#getZIndex()
309    */

310   public Integer JavaDoc getZIndex() {
311     return this.m_delegate.getZIndex();
312   }
313
314   /**
315    * @see java.lang.Object#hashCode()
316    */

317   public int hashCode() {
318     return this.m_delegate.hashCode();
319   }
320
321   /**
322    * @see info.monitorenter.gui.chart.ITrace2D#isEmpty()
323    */

324   public boolean isEmpty() {
325     return this.m_delegate.isEmpty();
326   }
327
328   /**
329    * @see info.monitorenter.gui.chart.ITrace2D#iterator()
330    */

331   public Iterator JavaDoc iterator() {
332     return this.m_delegate.iterator();
333   }
334
335   /**
336    * @see info.monitorenter.gui.chart.ITrace2D#removeAllPoints()
337    */

338   public void removeAllPoints() {
339     this.m_delegate.removeAllPoints();
340   }
341
342   /**
343    * @see info.monitorenter.gui.chart.ITrace2D#removePoint(info.monitorenter.gui.chart.TracePoint2D)
344    */

345   public boolean removePoint(final TracePoint2D point) {
346     return this.m_delegate.removePoint(point);
347   }
348
349   /**
350    * @see info.monitorenter.gui.chart.ITrace2D#removePropertyChangeListener(java.beans.PropertyChangeListener)
351    */

352   public void removePropertyChangeListener(final PropertyChangeListener JavaDoc listener) {
353     this.m_delegate.removePropertyChangeListener(listener);
354   }
355
356   /**
357    * @see info.monitorenter.gui.chart.ITrace2D#removePropertyChangeListener(java.lang.String,
358    * java.beans.PropertyChangeListener)
359    */

360   public void removePropertyChangeListener(final String JavaDoc property,
361       final PropertyChangeListener JavaDoc listener) {
362     this.m_delegate.removePropertyChangeListener(property, listener);
363   }
364
365   /**
366    * @see info.monitorenter.gui.chart.ITrace2D#removeTracePainter(info.monitorenter.gui.chart.ITracePainter)
367    */

368   public boolean removeTracePainter(final ITracePainter painter) {
369     return this.m_delegate.removeTracePainter(painter);
370   }
371
372   /**
373    * @see info.monitorenter.gui.chart.ITrace2D#setColor(java.awt.Color)
374    */

375   public void setColor(final Color JavaDoc color) {
376     this.m_delegate.setColor(color);
377   }
378
379   /**
380    * @see info.monitorenter.util.collections.IComparableProperty#setComparableProperty(java.lang.Number)
381    */

382   public void setComparableProperty(final Number JavaDoc n) {
383     this.m_delegate.setComparableProperty(n);
384   }
385
386   /**
387    * @see info.monitorenter.gui.chart.ITrace2D#setName(java.lang.String)
388    */

389   public void setName(final String JavaDoc name) {
390     this.m_delegate.setName(name);
391   }
392
393   /**
394    * @see info.monitorenter.gui.chart.ITrace2D#setPhysicalUnits(java.lang.String,
395    * java.lang.String)
396    */

397   public void setPhysicalUnits(final String JavaDoc xunit, final String JavaDoc yunit) {
398     this.m_delegate.setPhysicalUnits(xunit, yunit);
399   }
400
401   /**
402    * @see info.monitorenter.gui.chart.ITrace2D#setRenderer(info.monitorenter.gui.chart.Chart2D)
403    */

404   public void setRenderer(final Chart2D renderer) {
405     this.m_delegate.setRenderer(renderer);
406   }
407
408   /**
409    * @see info.monitorenter.gui.chart.ITrace2D#setStroke(java.awt.Stroke)
410    */

411   public void setStroke(final Stroke JavaDoc stroke) {
412     this.m_delegate.setStroke(stroke);
413   }
414
415   /**
416    *
417    * @see info.monitorenter.gui.chart.ITrace2D#setTracePainter(info.monitorenter.gui.chart.ITracePainter)
418    */

419   public final Set JavaDoc setTracePainter(final ITracePainter painter) {
420     return this.m_delegate.setTracePainter(painter);
421   }
422
423   /**
424    * @see info.monitorenter.gui.chart.ITrace2D#setVisible(boolean)
425    */

426   public void setVisible(final boolean visible) {
427     this.m_delegate.setVisible(visible);
428   }
429
430   /**
431    * Set the valid range for x values. If a point breaks these bounds an
432    * {@link IllegalArgumentException} will be thrown.
433    * <p>
434    *
435    * @param range
436    * The xRange to set.
437    */

438   public void setXRange(final Range range) {
439     if (range == null) {
440       throw new IllegalArgumentException JavaDoc("Argument must not be null.");
441     }
442     this.m_xRange = range;
443   }
444
445   /**
446    * Set the valid range for y values. If a point breaks these bounds an
447    * {@link IllegalArgumentException} will be thrown.
448    * <p>
449    *
450    * @param range
451    * The yRange to set.
452    */

453   public void setYRange(final Range range) {
454     if (range == null) {
455       throw new IllegalArgumentException JavaDoc("Argument must not be null.");
456     }
457     this.m_yRange = range;
458   }
459
460   /**
461    * @see info.monitorenter.gui.chart.ITrace2D#setZIndex(java.lang.Integer)
462    */

463   public void setZIndex(final Integer JavaDoc zIndex) {
464     this.m_delegate.setZIndex(zIndex);
465   }
466
467   /**
468    * @see java.lang.Object#toString()
469    */

470   public String JavaDoc toString() {
471     return this.m_delegate.toString();
472   }
473 }
474
Popular Tags