src/share/classes/sun/tools/jconsole/ClassTab.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;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.io.*;
  31 import java.lang.management.*;
  32 import java.lang.reflect.*;
  33 
  34 import javax.swing.*;
  35 import javax.swing.border.*;
  36 import javax.swing.event.*;
  37 import javax.swing.text.*;
  38 
  39 import java.util.*;
  40 import java.util.List;
  41 import java.util.concurrent.*;
  42 
  43 import sun.awt.*;
  44 
  45 import static sun.tools.jconsole.Formatter.*;
  46 import static sun.tools.jconsole.Resources.*;
  47 import static sun.tools.jconsole.Utilities.*;
  48 
  49 
  50 @SuppressWarnings("serial")
  51 class ClassTab extends Tab implements ActionListener {
  52     PlotterPanel loadedClassesMeter;
  53     TimeComboBox timeComboBox;
  54     private JCheckBox verboseCheckBox;
  55     private HTMLPane details;
  56     private ClassOverviewPanel overviewPanel;
  57     private boolean plotterListening = false;
  58 
  59     private static final String loadedPlotterKey        = "loaded";
  60     private static final String totalLoadedPlotterKey   = "totalLoaded";
  61     private static final String loadedPlotterName       = Resources.getText("Loaded");
  62     private static final String totalLoadedPlotterName  = Resources.getText("Total Loaded");
  63     private static final Color  loadedPlotterColor      = Plotter.defaultColor;
  64     private static final Color  totalLoadedPlotterColor = Color.red;
  65 
  66     private static final String infoLabelFormat = "ClassTab.infoLabelFormat";
  67 
  68     /*
  69       Hierarchy of panels and layouts for this tab:
  70 
  71         ClassTab (BorderLayout)
  72 
  73             North:  topPanel (BorderLayout)
  74 
  75                         Center: controlPanel (FlowLayout)
  76                                     timeComboBox
  77 
  78                         East:   topRightPanel (FlowLayout)
  79                                     verboseCheckBox
  80 
  81             Center: plotterPanel (BorderLayout)
  82 
  83                         Center: plotter
  84 
  85             South:  bottomPanel (BorderLayout)
  86 
  87                         Center: details
  88     */
  89 
  90     public static String getTabName() {
  91         return Resources.getText("Classes");
  92     }
  93 
  94     public ClassTab(VMPanel vmPanel) {
  95         super(vmPanel, getTabName());
  96 
  97         setLayout(new BorderLayout(0, 0));
  98         setBorder(new EmptyBorder(4, 4, 3, 4));
  99 
 100         JPanel topPanel     = new JPanel(new BorderLayout());
 101         JPanel plotterPanel = new JPanel(new BorderLayout());
 102         JPanel bottomPanel  = new JPanel(new BorderLayout());
 103 
 104         add(topPanel,     BorderLayout.NORTH);
 105         add(plotterPanel, BorderLayout.CENTER);
 106         add(bottomPanel,  BorderLayout.SOUTH);
 107 
 108         JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));
 109         topPanel.add(controlPanel, BorderLayout.CENTER);
 110 
 111         verboseCheckBox = new JCheckBox(Resources.getText("Verbose Output"));
 112         verboseCheckBox.addActionListener(this);
 113         verboseCheckBox.setToolTipText(getText("Verbose Output.toolTip"));
 114         JPanel topRightPanel = new JPanel();
 115         topRightPanel.setBorder(new EmptyBorder(0, 65-8, 0, 70));
 116         topRightPanel.add(verboseCheckBox);
 117         topPanel.add(topRightPanel, BorderLayout.AFTER_LINE_ENDS);
 118 
 119         loadedClassesMeter = new PlotterPanel(Resources.getText("Number of Loaded Classes"),
 120                                               Plotter.Unit.NONE, false);
 121         loadedClassesMeter.plotter.createSequence(loadedPlotterKey,
 122                                                   loadedPlotterName,
 123                                                   loadedPlotterColor,
 124                                                   true);
 125         loadedClassesMeter.plotter.createSequence(totalLoadedPlotterKey,
 126                                                   totalLoadedPlotterName,
 127                                                   totalLoadedPlotterColor,
 128                                                   true);
 129         setAccessibleName(loadedClassesMeter.plotter,
 130                           getText("ClassTab.loadedClassesPlotter.accessibleName"));
 131         plotterPanel.add(loadedClassesMeter);
 132 
 133         timeComboBox = new TimeComboBox(loadedClassesMeter.plotter);
 134         controlPanel.add(new LabeledComponent(Resources.getText("Time Range:"),
 135                                               getMnemonicInt("Time Range:"),
 136                                               timeComboBox));
 137 
 138         LabeledComponent.layout(plotterPanel);
 139 
 140         bottomPanel.setBorder(new CompoundBorder(new TitledBorder(Resources.getText("Details")),
 141                                                   new EmptyBorder(10, 10, 10, 10)));
 142 
 143         details = new HTMLPane();
 144         setAccessibleName(details, getText("Details"));
 145         JScrollPane scrollPane = new JScrollPane(details);
 146         scrollPane.setPreferredSize(new Dimension(0, 150));
 147         bottomPanel.add(scrollPane, BorderLayout.SOUTH);
 148 
 149     }
 150 
 151     public void actionPerformed(ActionEvent ev) {
 152         final boolean b = verboseCheckBox.isSelected();
 153         workerAdd(new Runnable() {
 154             public void run() {
 155                 ProxyClient proxyClient = vmPanel.getProxyClient();
 156                 try {
 157                     proxyClient.getClassLoadingMXBean().setVerbose(b);
 158                 } catch (UndeclaredThrowableException e) {
 159                     proxyClient.markAsDead();
 160                 } catch (IOException ex) {
 161                     // Ignore
 162                 }
 163             }
 164         });


 209                             overviewPanel.getPlotter().addValues(timeStamp, clCount);
 210                         }
 211 
 212                         loadedClassesMeter.setValueLabel(clCount + "");
 213                         verboseCheckBox.setSelected(isVerbose);
 214                         details.setText(detailsStr);
 215                     }
 216                 } catch (InterruptedException ex) {
 217                 } catch (ExecutionException ex) {
 218                     if (JConsole.isDebug()) {
 219                         ex.printStackTrace();
 220                     }
 221                 }
 222             }
 223 
 224             private String formatDetails() {
 225                 String text = "<table cellspacing=0 cellpadding=0>";
 226 
 227                 long time = System.currentTimeMillis();
 228                 String timeStamp = formatDateTime(time);
 229                 text += newRow(Resources.getText("Time"), timeStamp);
 230                 text += newRow(Resources.getText("Current classes loaded"), justify(clCount, 5));
 231                 text += newRow(Resources.getText("Total classes loaded"),   justify(ctCount, 5));
 232                 text += newRow(Resources.getText("Total classes unloaded"), justify(cuCount, 5));
 233 
 234                 return text;
 235             }
 236         };
 237     }
 238 
 239 
 240     OverviewPanel[] getOverviewPanels() {
 241         if (overviewPanel == null) {
 242             overviewPanel = new ClassOverviewPanel();
 243         }
 244         return new OverviewPanel[] { overviewPanel };
 245     }
 246 
 247     private static class ClassOverviewPanel extends OverviewPanel {
 248         ClassOverviewPanel() {
 249             super(getText("Classes"), loadedPlotterKey, loadedPlotterName, null);
 250         }
 251 
 252         private void updateClassInfo(long total, long loaded) {
 253             long unloaded = (total - loaded);
 254             getInfoLabel().setText(getText(infoLabelFormat, loaded, unloaded, total));

 255         }
 256     }
 257 }


  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;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.io.*;
  31 import java.lang.management.*;
  32 import java.lang.reflect.*;
  33 
  34 import javax.swing.*;
  35 import javax.swing.border.*;


  36 
  37 import sun.tools.jconsole.resources.Messages;


  38 
  39 import java.util.concurrent.*;
  40 
  41 import static sun.tools.jconsole.Formatter.*;

  42 import static sun.tools.jconsole.Utilities.*;
  43 
  44 
  45 @SuppressWarnings("serial")
  46 class ClassTab extends Tab implements ActionListener {
  47     PlotterPanel loadedClassesMeter;
  48     TimeComboBox timeComboBox;
  49     private JCheckBox verboseCheckBox;
  50     private HTMLPane details;
  51     private ClassOverviewPanel overviewPanel;
  52     private boolean plotterListening = false;
  53 
  54     private static final String loadedPlotterKey        = "loaded";
  55     private static final String totalLoadedPlotterKey   = "totalLoaded";


  56     private static final Color  loadedPlotterColor      = Plotter.defaultColor;
  57     private static final Color  totalLoadedPlotterColor = Color.red;
  58 


  59     /*
  60       Hierarchy of panels and layouts for this tab:
  61 
  62         ClassTab (BorderLayout)
  63 
  64             North:  topPanel (BorderLayout)
  65 
  66                         Center: controlPanel (FlowLayout)
  67                                     timeComboBox
  68 
  69                         East:   topRightPanel (FlowLayout)
  70                                     verboseCheckBox
  71 
  72             Center: plotterPanel (BorderLayout)
  73 
  74                         Center: plotter
  75 
  76             South:  bottomPanel (BorderLayout)
  77 
  78                         Center: details
  79     */
  80 
  81     public static String getTabName() {
  82         return Messages.CLASSES;
  83     }
  84 
  85     public ClassTab(VMPanel vmPanel) {
  86         super(vmPanel, getTabName());
  87 
  88         setLayout(new BorderLayout(0, 0));
  89         setBorder(new EmptyBorder(4, 4, 3, 4));
  90 
  91         JPanel topPanel     = new JPanel(new BorderLayout());
  92         JPanel plotterPanel = new JPanel(new BorderLayout());
  93         JPanel bottomPanel  = new JPanel(new BorderLayout());
  94 
  95         add(topPanel,     BorderLayout.NORTH);
  96         add(plotterPanel, BorderLayout.CENTER);
  97         add(bottomPanel,  BorderLayout.SOUTH);
  98 
  99         JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));
 100         topPanel.add(controlPanel, BorderLayout.CENTER);
 101 
 102         verboseCheckBox = new JCheckBox(Messages.VERBOSE_OUTPUT);
 103         verboseCheckBox.addActionListener(this);
 104         verboseCheckBox.setToolTipText(Messages.VERBOSE_OUTPUT_TOOLTIP);
 105         JPanel topRightPanel = new JPanel();
 106         topRightPanel.setBorder(new EmptyBorder(0, 65-8, 0, 70));
 107         topRightPanel.add(verboseCheckBox);
 108         topPanel.add(topRightPanel, BorderLayout.AFTER_LINE_ENDS);
 109 
 110         loadedClassesMeter = new PlotterPanel(Messages.NUMBER_OF_LOADED_CLASSES,
 111                                               Plotter.Unit.NONE, false);
 112         loadedClassesMeter.plotter.createSequence(loadedPlotterKey,
 113                                                   Messages.LOADED,
 114                                                   loadedPlotterColor,
 115                                                   true);
 116         loadedClassesMeter.plotter.createSequence(totalLoadedPlotterKey,
 117                                                   Messages.TOTAL_LOADED,
 118                                                   totalLoadedPlotterColor,
 119                                                   true);
 120         setAccessibleName(loadedClassesMeter.plotter,
 121                 Messages.CLASS_TAB_LOADED_CLASSES_PLOTTER_ACCESSIBLE_NAME);
 122         plotterPanel.add(loadedClassesMeter);
 123 
 124         timeComboBox = new TimeComboBox(loadedClassesMeter.plotter);
 125         controlPanel.add(new LabeledComponent(Messages.TIME_RANGE_COLON,
 126                                               Resources.getMnemonicInt(Messages.TIME_RANGE_COLON),
 127                                               timeComboBox));
 128 
 129         LabeledComponent.layout(plotterPanel);
 130 
 131         bottomPanel.setBorder(new CompoundBorder(new TitledBorder(Messages.DETAILS),
 132                                                   new EmptyBorder(10, 10, 10, 10)));
 133 
 134         details = new HTMLPane();
 135         setAccessibleName(details, Messages.DETAILS);
 136         JScrollPane scrollPane = new JScrollPane(details);
 137         scrollPane.setPreferredSize(new Dimension(0, 150));
 138         bottomPanel.add(scrollPane, BorderLayout.SOUTH);
 139 
 140     }
 141 
 142     public void actionPerformed(ActionEvent ev) {
 143         final boolean b = verboseCheckBox.isSelected();
 144         workerAdd(new Runnable() {
 145             public void run() {
 146                 ProxyClient proxyClient = vmPanel.getProxyClient();
 147                 try {
 148                     proxyClient.getClassLoadingMXBean().setVerbose(b);
 149                 } catch (UndeclaredThrowableException e) {
 150                     proxyClient.markAsDead();
 151                 } catch (IOException ex) {
 152                     // Ignore
 153                 }
 154             }
 155         });


 200                             overviewPanel.getPlotter().addValues(timeStamp, clCount);
 201                         }
 202 
 203                         loadedClassesMeter.setValueLabel(clCount + "");
 204                         verboseCheckBox.setSelected(isVerbose);
 205                         details.setText(detailsStr);
 206                     }
 207                 } catch (InterruptedException ex) {
 208                 } catch (ExecutionException ex) {
 209                     if (JConsole.isDebug()) {
 210                         ex.printStackTrace();
 211                     }
 212                 }
 213             }
 214 
 215             private String formatDetails() {
 216                 String text = "<table cellspacing=0 cellpadding=0>";
 217 
 218                 long time = System.currentTimeMillis();
 219                 String timeStamp = formatDateTime(time);
 220                 text += newRow(Messages.TIME, timeStamp);
 221                 text += newRow(Messages.CURRENT_CLASSES_LOADED, justify(clCount, 5));
 222                 text += newRow(Messages.TOTAL_CLASSES_LOADED,   justify(ctCount, 5));
 223                 text += newRow(Messages.TOTAL_CLASSES_UNLOADED, justify(cuCount, 5));
 224 
 225                 return text;
 226             }
 227         };
 228     }
 229 
 230 
 231     OverviewPanel[] getOverviewPanels() {
 232         if (overviewPanel == null) {
 233             overviewPanel = new ClassOverviewPanel();
 234         }
 235         return new OverviewPanel[] { overviewPanel };
 236     }
 237 
 238     private static class ClassOverviewPanel extends OverviewPanel {
 239         ClassOverviewPanel() {
 240             super(Messages.CLASSES, loadedPlotterKey, Messages.LOADED, null);
 241         }
 242 
 243         private void updateClassInfo(long total, long loaded) {
 244             long unloaded = (total - loaded);
 245             getInfoLabel().setText(Resources.format(
 246                     Messages.CLASS_TAB_INFO_LABEL_FORMAT, loaded, unloaded, total));
 247         }
 248     }
 249 }