001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package view;
028:
029: import javax.swing.*;
030: import javax.swing.table.*;
031: import java.awt.*;
032: import java.awt.event.*;
033: import com.sun.cldchi.tools.memoryprofiler.data.*;
034:
035: public class StatisticsDialog extends JDialog implements ActionListener {
036: public static void showDialog(Component frameComp, Object[] objects) {
037: Frame frame = JOptionPane.getFrameForComponent(frameComp);
038: StatisticsDialog dialog = new StatisticsDialog(frame,
039: "Heap Statistics", true, objects);
040: dialog.setVisible(true);
041: }
042:
043: public StatisticsDialog(Frame frame, String title, boolean param,
044: Object[] objects) {
045: super (frame, title, param);
046: JButton closeButton = new JButton("Close");
047: JScrollPane pane = new JScrollPane();
048: closeButton.addActionListener(this );
049: JTable tbl = new JTable(new StatTableModel(objects));
050: pane.getViewport().setView(tbl);
051: getContentPane().add(pane, BorderLayout.CENTER);
052: getContentPane().add(closeButton, BorderLayout.PAGE_END);
053: pack();
054: getRootPane().setDefaultButton(closeButton);
055: }
056:
057: public Dimension getPrefferedSize() {
058: return new Dimension(800, 400);
059: }
060:
061: public void actionPerformed(ActionEvent e) {
062: setVisible(false);
063: }
064: }
065:
066: class StatTableModel extends AbstractTableModel {
067: private Object[] _data;
068:
069: public StatTableModel(Object[] data) {
070: _data = data;
071: }
072:
073: public int getColumnCount() {
074: return 7;
075: }
076:
077: private static String columnNames[] = { "Class name",
078: "Object number", "Size", "Av. Size", "heap %", "live %",
079: "old gen. %" };
080:
081: public Object getValueAt(int row, int col) {
082: if (_data == null)
083: return null;
084: if (row >= _data.length)
085: return null;
086: ClassStatistics obj = (ClassStatistics) _data[row];
087: if (col == 0) {
088: return obj._class_name;
089: } else if (col == 1) {
090: return new Integer(obj.getCount());
091: } else if (col == 2) {
092: return new Integer(obj.getTotalSize());
093: } else if (col == 3) {
094: return new Integer(obj.getAverageSize());
095: } else if (col == 4) {
096: return displayPerctentage(obj.getHeapPercentage());
097: } else if (col == 5) {
098: return displayPerctentage(obj.getLivePercentage());
099: } else if (col == 6) {
100: return displayPerctentage(obj.getOldGenPercentage());
101: } else {
102: return null;
103: }
104: }
105:
106: public String displayPerctentage(int p) {
107: return "" + (p / 100) + "." + (p % 100) + "%";
108: }
109:
110: public int getRowCount() {
111: if (_data == null) {
112: return 0;
113: } else {
114: return _data.length;
115: }
116: }
117:
118: public String getColumnName(int i) {
119: return columnNames[i];
120: }
121: }
|