KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > management > browser > ui > statistics > StatisticCustomizer


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.management.browser.ui.statistics;
8
9 import java.awt.GridBagConstraints JavaDoc;
10 import java.awt.GridBagLayout JavaDoc;
11 import java.awt.Insets JavaDoc;
12 import java.awt.event.ActionEvent JavaDoc;
13 import java.awt.event.ActionListener JavaDoc;
14 import java.util.ResourceBundle JavaDoc;
15
16 import javax.management.j2ee.statistics.Statistic JavaDoc;
17 import javax.swing.BorderFactory JavaDoc;
18 import javax.swing.JButton JavaDoc;
19 import javax.swing.JLabel JavaDoc;
20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.SwingConstants JavaDoc;
22 import javax.swing.border.TitledBorder JavaDoc;
23
24 import org.ejtools.management.browser.ui.ManagedObjectStatsViewer;
25
26 /**
27  * @author letiemble
28  * @version $Revision: 1.3 $
29  */

30 public abstract class StatisticCustomizer extends JPanel JavaDoc
31 {
32    /** Description of the Field */
33    protected TitledBorder JavaDoc borderTitle = null;
34    /** Description of the Field */
35    protected GridBagConstraints JavaDoc gridbagconstraints;
36    /** Description of the Field */
37    protected JLabel JavaDoc lblDescription = null;
38    /** Description of the Field */
39    protected JLabel JavaDoc lblLastSampleTime = null;
40    /** Description of the Field */
41    protected JLabel JavaDoc lblStartTime = null;
42    /** Description of the Field */
43    protected transient ManagedObjectStatsViewer mediator = null;
44    /** Description of the Field */
45    protected Statistic JavaDoc statistic;
46    /** Description of the Field */
47    protected static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.management.browser.Resources");
48
49
50    /**
51     *Constructor for the StatisticCustomizer object
52     *
53     * @param statistic Description of the Parameter
54     */

55    protected StatisticCustomizer(Statistic JavaDoc statistic)
56    {
57       super(new GridBagLayout JavaDoc());
58       this.statistic = statistic;
59
60       this.gridbagconstraints = new GridBagConstraints JavaDoc();
61       this.gridbagconstraints.insets = new Insets JavaDoc(1, 1, 1, 1);
62       this.gridbagconstraints.anchor = GridBagConstraints.NORTH;
63       this.gridbagconstraints.weightx = 1.0D;
64       this.gridbagconstraints.weighty = 0.0D;
65       this.gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
66       this.gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
67
68       String JavaDoc title = this.statistic.getName() + " (" + this.statistic.getUnit() + ")";
69       this.borderTitle = BorderFactory.createTitledBorder(title);
70       this.setBorder(this.borderTitle);
71
72       this.lblDescription = new JLabel JavaDoc(this.statistic.getDescription());
73       this.addItem(
74          resources.getString("customizer.tab.statistics.text.description"),
75          resources.getString("customizer.tab.statistics.tooltip.description"),
76          this.lblDescription);
77       this.lblStartTime = new JLabel JavaDoc("");
78       this.addItem(
79          resources.getString("customizer.tab.statistics.text.start.time"),
80          resources.getString("customizer.tab.statistics.tooltip.start.time"),
81          this.lblStartTime);
82       this.lblLastSampleTime = new JLabel JavaDoc("");
83       this.addItem(
84          resources.getString("customizer.tab.statistics.text.last.sample.time"),
85          resources.getString("customizer.tab.statistics.tooltip.last.sample.time"),
86          this.lblLastSampleTime);
87    }
88
89
90    /** Description of the Method */
91    public void refresh()
92    {
93       if (this.statistic != null)
94       {
95          this.lblStartTime.setText("" + this.statistic.getStartTime());
96          this.lblLastSampleTime.setText("" + this.statistic.getLastSampleTime());
97
98          this.validate();
99          this.repaint();
100       }
101    }
102
103
104    /**
105     * Sets the mediator.
106     *
107     * @param mediator The mediator to set
108     */

109    public void setMediator(ManagedObjectStatsViewer mediator)
110    {
111       this.mediator = mediator;
112    }
113
114
115    /**
116     * Description of the Method
117     *
118     * @param statistic The new statistic value
119     */

120    public void setStatistic(Statistic JavaDoc statistic)
121    {
122       this.statistic = statistic;
123    }
124
125
126    /**
127     * Adds a feature to the GraphItem attribute of the StatisticCustomizer object
128     *
129     * @param label The feature to be added to the GraphItem attribute
130     * @param value The feature to be added to the GraphItem attribute
131     * @param tooltip The feature to be added to the GraphItem attribute
132     * @param propertyName The feature to be added to the GraphItem attribute
133     */

134    protected void addGraphItem(String JavaDoc label, String JavaDoc tooltip, String JavaDoc propertyName, JLabel JavaDoc value)
135    {
136       JLabel JavaDoc lbl = new JLabel JavaDoc(label + " : ", SwingConstants.RIGHT);
137       lbl.setToolTipText(tooltip);
138       this.gridbagconstraints.weightx = 0.0d;
139       this.gridbagconstraints.gridwidth = 1;
140       this.add(lbl, this.gridbagconstraints);
141
142       this.gridbagconstraints.weightx = 1.0d;
143       this.gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
144       this.add(value, this.gridbagconstraints);
145
146       JButton JavaDoc button = this.getGraphButton(this.statistic.getName(), propertyName);
147       this.gridbagconstraints.weightx = 0.0d;
148       this.gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
149       this.add(button, this.gridbagconstraints);
150    }
151
152
153    /**
154     * Description of the Method
155     *
156     * @param label Description of the Parameter
157     * @param value Description of the Parameter
158     * @param tooltip The feature to be added to the Item attribute
159     */

160    protected void addItem(String JavaDoc label, String JavaDoc tooltip, JLabel JavaDoc value)
161    {
162       JLabel JavaDoc lbl = new JLabel JavaDoc(label + " : ", SwingConstants.RIGHT);
163       lbl.setToolTipText(tooltip);
164       this.gridbagconstraints.weightx = 0.0d;
165       this.gridbagconstraints.gridwidth = 1;
166       this.add(lbl, this.gridbagconstraints);
167
168       this.gridbagconstraints.weightx = 1.0d;
169       this.gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
170       this.add(value, this.gridbagconstraints);
171    }
172
173
174    /**
175     * Adds a feature to the GraphButton attribute of the StatisticCustomizer object
176     *
177     * @param statisticName The feature to be added to the GraphButton attribute
178     * @param statisticProperty The feature to be added to the GraphButton attribute
179     * @return Description of the Return Value
180     */

181    protected JButton JavaDoc getGraphButton(final String JavaDoc statisticName, final String JavaDoc statisticProperty)
182    {
183       JButton JavaDoc button = new JButton JavaDoc(resources.getString("customizer.tab.statistics.button.graph"));
184       button.addActionListener(
185          new ActionListener JavaDoc()
186          {
187             public void actionPerformed(ActionEvent JavaDoc arg0)
188             {
189                StatisticCustomizer.this.mediator.addStatisticToGraph(statisticName, statisticProperty);
190             }
191
192          });
193       return button;
194    }
195 }
196
Popular Tags