KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > console > lib > gui > InjectorsGraph


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 *
24 * @authors: Julien Buret
25 * @authors: Nicolas Droze
26 */

27 package org.objectweb.clif.console.lib.gui;
28
29 import java.awt.Color JavaDoc;
30 import java.awt.geom.Point2D JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * This structure represents a host with all its associated points, name and color
35  */

36 public class InjectorsGraph {
37     // The name of the host
38
public String JavaDoc name;
39     // The graph color
40
public Color JavaDoc color;
41     // A vector containing all the points for a given type of data
42
public Vector JavaDoc[] points;
43     // True means that the graph has a limited number of points
44
private boolean isLimited;
45     // The number of maximum points to store
46
public int maxElements;
47     // The number of graph for each host
48
private int size;
49
50     /**
51      * The constructor, which create all the vectors that will contain the points to store.
52      * @param size The number of graphs for each host
53      * @param isLimited True means that the number of points to store is limited.
54      */

55     public InjectorsGraph(int size, boolean isLimited) {
56         this.isLimited = isLimited;
57         this.size = size;
58         // The default maximum number of points to store is 5
59
maxElements = 5;
60
61         // Initialize all the graphs for this host
62
points = new Vector JavaDoc[size];
63         for (int i = 0; i < size; i++) {
64             points[i] = new Vector JavaDoc();
65         }
66     }
67
68
69     /**
70      * This method adds a point to a specific graph of this host.
71      * @param point The point to add.
72      * @param type The type of graph this point belongs to.
73      */

74     public void addPoint(Point2D.Double JavaDoc point, int type)
75     {
76         points[type].addElement(point);
77         if (isLimited && points[type].size() > maxElements)
78         {
79             points[type].removeElementAt(0);
80         }
81     }
82
83
84     /**
85      * Remove all the points for this host.
86      */

87     public void clearAllPoints() {
88         // For each graph of this host,
89
// we remove all the points, and add the only point (0,0)
90
for (int i = 0; i < points.length; i++) {
91             points[i].removeAllElements();
92 // points[i].addElement(new Point2D.Double(0, 0));
93
}
94     }
95
96
97     /**
98      * Set the maximum number of points to store for the graph of this host.
99      * (Useful only if the graph is limited)
100      * @param nbPoints The number of maximum points to store.
101      */

102     public void setMaxElements(int nbPoints)
103     {
104         if (nbPoints < maxElements)
105         {
106             for (int i = 0; i < size; i++)
107             {
108                 while (points[i].size() > nbPoints)
109                 {
110                     points[i].removeElementAt(0);
111                 }
112             }
113         }
114         maxElements = nbPoints;
115     }
116
117     public int getMaxElements() {
118         return maxElements;
119     }
120
121 }
122
Popular Tags