src/share/classes/sun/tools/jconsole/inspector/XPlottingViewer.java

Print this page




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.util.*;
  31 import java.util.Timer;
  32 
  33 import javax.swing.*;
  34 
  35 import sun.tools.jconsole.*;

  36 
  37 @SuppressWarnings("serial")
  38 public class XPlottingViewer extends PlotterPanel implements ActionListener {
  39     // TODO: Make number of decimal places customizable
  40     private static final int PLOTTER_DECIMALS = 4;
  41 
  42     private JButton plotButton;
  43     // The plotter cache holds Plotter instances for the various attributes
  44     private static HashMap<String, XPlottingViewer> plotterCache =
  45         new HashMap<String, XPlottingViewer>();
  46      private static HashMap<String, Timer> timerCache =
  47          new HashMap<String, Timer>();
  48     private JPanel bordered;
  49     private Number value;
  50     private MBeansTab tab;
  51     private XMBean mbean;
  52     private String attributeName;
  53     private String key;
  54     private JTable table;
  55     private XPlottingViewer(String key,
  56                             XMBean mbean,
  57                             String attributeName,
  58                             Object value,
  59                             JTable table,
  60                             MBeansTab tab) {
  61         super(null);
  62 
  63         this.tab = tab;
  64         this.key = key;
  65         this.mbean = mbean;
  66         this.table = table;
  67         this.attributeName = attributeName;
  68         Plotter plotter = createPlotter(mbean, attributeName, key, table);
  69         setupDisplay(plotter);
  70     }
  71 
  72     static void dispose(MBeansTab tab) {
  73         Iterator it = plotterCache.keySet().iterator();
  74         while(it.hasNext()) {
  75             String key = (String) it.next();
  76             if(key.startsWith(String.valueOf(tab.hashCode()))) {
  77                 it.remove();
  78             }
  79         }
  80         //plotterCache.clear();
  81         it = timerCache.keySet().iterator();
  82         while(it.hasNext()) {
  83             String key = (String) it.next();
  84             if(key.startsWith(String.valueOf(tab.hashCode()))) {
  85                 Timer t = timerCache.get(key);
  86                 t.cancel();
  87                 it.remove();
  88             }
  89         }
  90     }
  91 
  92     public static boolean isViewableValue(Object value) {
  93         return (value instanceof Number);
  94     }
  95 


 170                                     // Should have a trace logged with proper
 171                                     // trace mecchanism
 172                                 }
 173                             }
 174                         });
 175                 }
 176             };
 177 
 178         String timerName = "Timer-" + key;
 179         Timer timer = new Timer(timerName, true);
 180         timer.schedule(timerTask, 0, tab.getUpdateInterval());
 181         timerCache.put(key, timer);
 182         return plotter;
 183     }
 184 
 185     private void setupDisplay(Plotter plotter) {
 186         final JPanel buttonPanel = new JPanel();
 187         final GridBagLayout gbl = new GridBagLayout();
 188         buttonPanel.setLayout(gbl);
 189         setLayout(new BorderLayout());
 190         plotButton = new JButton(Resources.getText("Discard chart"));
 191         plotButton.addActionListener(this);
 192         plotButton.setEnabled(true);
 193 
 194         GridBagConstraints buttonConstraints = new GridBagConstraints();
 195         buttonConstraints.gridx = 0;
 196         buttonConstraints.gridy = 0;
 197         buttonConstraints.fill = GridBagConstraints.VERTICAL;
 198         buttonConstraints.anchor = GridBagConstraints.CENTER;
 199         gbl.setConstraints(plotButton, buttonConstraints);
 200         buttonPanel.add(plotButton);
 201 
 202         if (attributeName != null && attributeName.length()!=0) {
 203             final JPanel plotterLabelPanel = new JPanel();
 204             final JLabel label = new JLabel(attributeName);
 205             final GridBagLayout gbl2 = new GridBagLayout();
 206             plotterLabelPanel.setLayout(gbl2);
 207             final GridBagConstraints labelConstraints = new GridBagConstraints();
 208             labelConstraints.gridx = 0;
 209             labelConstraints.gridy = 0;
 210             labelConstraints.fill = GridBagConstraints.VERTICAL;


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.util.*;
  31 import java.util.Timer;
  32 
  33 import javax.swing.*;
  34 
  35 import sun.tools.jconsole.*;
  36 import sun.tools.jconsole.resources.Messages;
  37 
  38 @SuppressWarnings("serial")
  39 public class XPlottingViewer extends PlotterPanel implements ActionListener {
  40     // TODO: Make number of decimal places customizable
  41     private static final int PLOTTER_DECIMALS = 4;
  42 
  43     private JButton plotButton;
  44     // The plotter cache holds Plotter instances for the various attributes
  45     private static HashMap<String, XPlottingViewer> plotterCache =
  46         new HashMap<String, XPlottingViewer>();
  47      private static HashMap<String, Timer> timerCache =
  48          new HashMap<String, Timer>();


  49     private MBeansTab tab;

  50     private String attributeName;
  51     private String key;
  52     private JTable table;
  53     private XPlottingViewer(String key,
  54                             XMBean mbean,
  55                             String attributeName,
  56                             Object value,
  57                             JTable table,
  58                             MBeansTab tab) {
  59         super(null);
  60 
  61         this.tab = tab;
  62         this.key = key;

  63         this.table = table;
  64         this.attributeName = attributeName;
  65         Plotter plotter = createPlotter(mbean, attributeName, key, table);
  66         setupDisplay(plotter);
  67     }
  68 
  69     static void dispose(MBeansTab tab) {
  70         Iterator<String> it = plotterCache.keySet().iterator();
  71         while(it.hasNext()) {
  72             String key = it.next();
  73             if(key.startsWith(String.valueOf(tab.hashCode()))) {
  74                 it.remove();
  75             }
  76         }
  77         //plotterCache.clear();
  78         it = timerCache.keySet().iterator();
  79         while(it.hasNext()) {
  80             String key = (String) it.next();
  81             if(key.startsWith(String.valueOf(tab.hashCode()))) {
  82                 Timer t = timerCache.get(key);
  83                 t.cancel();
  84                 it.remove();
  85             }
  86         }
  87     }
  88 
  89     public static boolean isViewableValue(Object value) {
  90         return (value instanceof Number);
  91     }
  92 


 167                                     // Should have a trace logged with proper
 168                                     // trace mecchanism
 169                                 }
 170                             }
 171                         });
 172                 }
 173             };
 174 
 175         String timerName = "Timer-" + key;
 176         Timer timer = new Timer(timerName, true);
 177         timer.schedule(timerTask, 0, tab.getUpdateInterval());
 178         timerCache.put(key, timer);
 179         return plotter;
 180     }
 181 
 182     private void setupDisplay(Plotter plotter) {
 183         final JPanel buttonPanel = new JPanel();
 184         final GridBagLayout gbl = new GridBagLayout();
 185         buttonPanel.setLayout(gbl);
 186         setLayout(new BorderLayout());
 187         plotButton = new JButton(Messages.DISCARD_CHART);
 188         plotButton.addActionListener(this);
 189         plotButton.setEnabled(true);
 190 
 191         GridBagConstraints buttonConstraints = new GridBagConstraints();
 192         buttonConstraints.gridx = 0;
 193         buttonConstraints.gridy = 0;
 194         buttonConstraints.fill = GridBagConstraints.VERTICAL;
 195         buttonConstraints.anchor = GridBagConstraints.CENTER;
 196         gbl.setConstraints(plotButton, buttonConstraints);
 197         buttonPanel.add(plotButton);
 198 
 199         if (attributeName != null && attributeName.length()!=0) {
 200             final JPanel plotterLabelPanel = new JPanel();
 201             final JLabel label = new JLabel(attributeName);
 202             final GridBagLayout gbl2 = new GridBagLayout();
 203             plotterLabelPanel.setLayout(gbl2);
 204             final GridBagConstraints labelConstraints = new GridBagConstraints();
 205             labelConstraints.gridx = 0;
 206             labelConstraints.gridy = 0;
 207             labelConstraints.fill = GridBagConstraints.VERTICAL;