1 5 package net.sf.panoptes.view.swing.widgets; 6 7 import java.awt.Color ; 8 import java.awt.event.ActionEvent ; 9 import java.awt.event.ActionListener ; 10 11 import javax.management.ObjectName ; 12 import javax.swing.JLabel ; 13 import javax.swing.Timer ; 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 18 import net.sf.panoptes.component.jmx.model.MBeanWrapper; 19 import net.sf.panoptes.component.jmx.model.MBeanServerNode; 20 21 27 public class AttributeLabel extends JLabel { 28 29 private static Log log = LogFactory.getLog(AttributeLabel.class); 30 31 private String attributeName; 32 private Timer timer = null; 33 34 private int refreshRate; 35 36 private MBeanWrapper node; 37 38 public AttributeLabel(MBeanWrapper node, String attributeName, int refreshRate) { 39 this.node = node; 40 this.attributeName = attributeName; 41 this.refreshRate = refreshRate; 42 setText(getAttributeValue()); 43 setForeground(Color.BLUE); 44 } 45 46 private String getAttributeValue() { 47 try { 48 return node.getAttributeValue(attributeName).toString(); 49 } catch (Exception e) { 50 log.error("Unable to get attribute value", e); 51 return "Unable to get"; 52 } 53 } 54 55 public void addNotify() { 56 super.addNotify(); 57 timer = new Timer (refreshRate, new ActionListener () { 58 public void actionPerformed(ActionEvent e) { 59 setText(getAttributeValue()); 60 } 61 }); 62 timer.start(); 63 } 64 65 public void removeNotify() { 66 super.removeNotify(); 67 timer.stop(); 68 } 69 70 } 71 | Popular Tags |