KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > graph > CompositeTrack


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.graph;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Graphics JavaDoc;
11 import java.awt.GridLayout JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import javax.swing.JComponent JavaDoc;
17 import javax.swing.JPanel JavaDoc;
18
19 /**
20  * Description of the Class
21  *
22  * @author Laurent Etiemble
23  * @version $Revision: 1.8 $
24  * @todo Javadoc to complete
25  */

26 public class CompositeTrack implements GraphElement, LabelElement
27 {
28    /** Description of the Field */
29    protected JPanel JavaDoc component;
30    /** Description of the Field */
31    protected GridLayout JavaDoc layout;
32    /** Description of the Field */
33    protected Collection JavaDoc tracks = new Vector JavaDoc();
34
35
36    /** Constructor for the Track object */
37    public CompositeTrack()
38    {
39       this.layout = new GridLayout JavaDoc(1, 1, 1, 1);
40       this.component = new JPanel JavaDoc(this.layout);
41    }
42
43
44    /**
45     * Adds a feature to the Track attribute of the CompositeTrack object
46     *
47     * @param t The feature to be added to the Track attribute
48     */

49    public void addTrack(Track t)
50    {
51       this.tracks.add(t);
52       this.layout.setRows(this.tracks.size());
53       this.component.add(t.getComponent());
54    }
55
56
57    /** Description of the Method */
58    public void clear()
59    {
60       synchronized (this.tracks)
61       {
62          for (Iterator JavaDoc it = this.tracks.iterator(); it.hasNext(); )
63          {
64             ((Track) it.next()).clear();
65          }
66       }
67    }
68
69
70    /**
71     * @param graphics Description of the Parameter
72     * @param scaleX Description of the Parameter
73     * @param offsetX Description of the Parameter
74     * @param scaleY Description of the Parameter
75     * @param offsetY Description of the Parameter
76     */

77    public void draw(Graphics JavaDoc graphics, double scaleX, double offsetX, double scaleY, double offsetY)
78    {
79       synchronized (this.tracks)
80       {
81          for (Iterator JavaDoc it = this.tracks.iterator(); it.hasNext(); )
82          {
83             ((GraphElement) it.next()).draw(graphics, scaleX, offsetX, scaleY, offsetY);
84          }
85       }
86    }
87
88
89    /**
90     * @return The color value
91     */

92    public Color JavaDoc getColor()
93    {
94       return Color.black;
95    }
96
97
98    /**
99     * @return The component value
100     */

101    public JComponent JavaDoc getComponent()
102    {
103       return this.component;
104    }
105
106
107    /**
108     * @return The xRange value
109     */

110    public Range getXRange()
111    {
112       synchronized (this.tracks)
113       {
114          Range result = new Range(Double.MAX_VALUE, Double.MIN_VALUE);
115          for (Iterator JavaDoc it = this.tracks.iterator(); it.hasNext(); )
116          {
117             result = result.compose(((GraphElement) it.next()).getXRange());
118          }
119          return result;
120       }
121    }
122
123
124    /**
125     * @return The yRange value
126     */

127    public Range getYRange()
128    {
129       synchronized (this.tracks)
130       {
131          Range result = new Range(Double.MAX_VALUE, Double.MIN_VALUE);
132          for (Iterator JavaDoc it = this.tracks.iterator(); it.hasNext(); )
133          {
134             result = result.compose(((GraphElement) it.next()).getYRange());
135          }
136          return result;
137       }
138    }
139
140
141    /**
142     * Description of the Method
143     *
144     * @param t Description of the Parameter
145     */

146    public void removeTrack(Track t)
147    {
148       if (this.tracks.contains(t))
149       {
150          this.component.remove(t.getComponent());
151          this.tracks.remove(t);
152          this.layout.setRows(this.tracks.size());
153       }
154    }
155 }
156
Popular Tags