KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > traces > painters > TracePainterPolyline


1 /*
2  * TracePainterFill.java, <enter purpose here>.
3  * Copyright (C) 2005 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 package info.monitorenter.gui.chart.traces.painters;
23
24
25 import java.awt.Graphics2D JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 /**
31  * A trace painter that increases performance by summing up all points to render
32  * for a paint iteration ({@link #startPaintIteration()},
33  * {@link #endPaintIteration()}) and only invoking only one polyliine paint for
34  * a paint call of the corresponding {@link info.monitorenter.gui.chart.Chart2D}.
35  * <p>
36  *
37  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
38  *
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class TracePainterPolyline extends ATracePainter {
43
44   /** The list of x coordinates collected in one paint iteration. */
45   private List JavaDoc m_xPoints;
46
47   /** The list of y coordinates collected in one paint iteration. */
48   private List JavaDoc m_yPoints;
49
50   /**
51    * Default Constructor.
52    * <p>
53    *
54    */

55   public TracePainterPolyline() {
56   }
57
58   /**
59    * @see info.monitorenter.gui.chart.ITracePainter#endPaintIteration()
60    */

61   public void endPaintIteration() {
62     if (this.getGraphics() != null) {
63
64       int[] x = new int[this.m_xPoints.size() + 1];
65       Iterator JavaDoc it = this.m_xPoints.iterator();
66       int count = 0;
67       while (it.hasNext()) {
68         x[count] = ((Integer JavaDoc) it.next()).intValue();
69         count++;
70       }
71       x[count] = this.getPreviousX();
72
73       int[] y = new int[this.m_yPoints.size() + 1];
74       it = this.m_yPoints.iterator();
75       count = 0;
76       while (it.hasNext()) {
77         y[count] = ((Integer JavaDoc) it.next()).intValue();
78         count++;
79       }
80       y[count] = this.getPreviousY();
81
82       this.getGraphics().drawPolyline(x, y, x.length);
83     }
84   }
85
86   /**
87    * @see info.monitorenter.gui.chart.ITracePainter#paintPoint(int, int, int, int,
88    * java.awt.Graphics2D)
89    */

90   public void paintPoint(final int absoluteX, final int absoluteY, final int nextX,
91       final int nextY, final Graphics2D JavaDoc g) {
92     super.paintPoint(absoluteX, absoluteY, nextX, nextY, g);
93     this.m_xPoints.add(new Integer JavaDoc(absoluteX));
94     this.m_yPoints.add(new Integer JavaDoc(absoluteY));
95
96   }
97
98   /**
99    * @see info.monitorenter.gui.chart.ITracePainter#startPaintIteration()
100    */

101   public void startPaintIteration() {
102     super.startPaintIteration();
103     this.m_xPoints = new LinkedList JavaDoc();
104     this.m_yPoints = new LinkedList JavaDoc();
105   }
106
107 }
108
Popular Tags