1 7 package org.ejtools.management.browser.ui.statistics; 8 9 import java.awt.GridBagConstraints ; 10 import java.awt.GridBagLayout ; 11 import java.awt.Insets ; 12 import java.awt.event.ActionEvent ; 13 import java.awt.event.ActionListener ; 14 import java.util.ResourceBundle ; 15 16 import javax.management.j2ee.statistics.Statistic ; 17 import javax.swing.BorderFactory ; 18 import javax.swing.JButton ; 19 import javax.swing.JLabel ; 20 import javax.swing.JPanel ; 21 import javax.swing.SwingConstants ; 22 import javax.swing.border.TitledBorder ; 23 24 import org.ejtools.management.browser.ui.ManagedObjectStatsViewer; 25 26 30 public abstract class StatisticCustomizer extends JPanel 31 { 32 33 protected TitledBorder borderTitle = null; 34 35 protected GridBagConstraints gridbagconstraints; 36 37 protected JLabel lblDescription = null; 38 39 protected JLabel lblLastSampleTime = null; 40 41 protected JLabel lblStartTime = null; 42 43 protected transient ManagedObjectStatsViewer mediator = null; 44 45 protected Statistic statistic; 46 47 protected static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.management.browser.Resources"); 48 49 50 55 protected StatisticCustomizer(Statistic statistic) 56 { 57 super(new GridBagLayout ()); 58 this.statistic = statistic; 59 60 this.gridbagconstraints = new GridBagConstraints (); 61 this.gridbagconstraints.insets = new Insets (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 title = this.statistic.getName() + " (" + this.statistic.getUnit() + ")"; 69 this.borderTitle = BorderFactory.createTitledBorder(title); 70 this.setBorder(this.borderTitle); 71 72 this.lblDescription = new JLabel (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 (""); 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 (""); 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 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 109 public void setMediator(ManagedObjectStatsViewer mediator) 110 { 111 this.mediator = mediator; 112 } 113 114 115 120 public void setStatistic(Statistic statistic) 121 { 122 this.statistic = statistic; 123 } 124 125 126 134 protected void addGraphItem(String label, String tooltip, String propertyName, JLabel value) 135 { 136 JLabel lbl = new JLabel (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 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 160 protected void addItem(String label, String tooltip, JLabel value) 161 { 162 JLabel lbl = new JLabel (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 181 protected JButton getGraphButton(final String statisticName, final String statisticProperty) 182 { 183 JButton button = new JButton (resources.getString("customizer.tab.statistics.button.graph")); 184 button.addActionListener( 185 new ActionListener () 186 { 187 public void actionPerformed(ActionEvent arg0) 188 { 189 StatisticCustomizer.this.mediator.addStatisticToGraph(statisticName, statisticProperty); 190 } 191 192 }); 193 return button; 194 } 195 } 196 | Popular Tags |