001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.ui.memory;
042:
043: import org.netbeans.lib.profiler.results.memory.AllocMemoryResultsDiff;
044: import org.netbeans.lib.profiler.results.memory.AllocMemoryResultsSnapshot;
045: import org.netbeans.lib.profiler.ui.components.table.ClassNameTableCellRenderer;
046: import org.netbeans.lib.profiler.ui.components.table.CustomBarCellRenderer;
047: import org.netbeans.lib.profiler.ui.components.table.DiffBarCellRenderer;
048: import org.netbeans.lib.profiler.ui.components.table.LabelTableCellRenderer;
049: import java.awt.*;
050: import java.awt.event.ActionEvent;
051: import java.util.ResourceBundle;
052: import javax.swing.*;
053: import javax.swing.table.TableCellRenderer;
054:
055: /**
056: * This panel displays memory allocations diff.
057: *
058: * @author Jiri Sedlacek
059: */
060: public class DiffAllocResultsPanel extends SnapshotAllocResultsPanel {
061: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
062:
063: // -----
064: // I18N String constants
065: private static final ResourceBundle messages = ResourceBundle
066: .getBundle("org.netbeans.lib.profiler.ui.memory.Bundle"); // NOI18N
067: private static final String GO_SOURCE_POPUP_ITEM_NAME = messages
068: .getString("AllocResultsPanel_GoSourcePopupItemName"); // NOI18N
069: // -----
070:
071: //~ Instance fields ----------------------------------------------------------------------------------------------------------
072:
073: private AllocMemoryResultsDiff diff;
074: private JMenuItem popupShowSource;
075: private JPopupMenu memoryResPopupMenu;
076:
077: //~ Constructors -------------------------------------------------------------------------------------------------------------
078:
079: public DiffAllocResultsPanel(AllocMemoryResultsSnapshot snapshot,
080: MemoryResUserActionsHandler actionsHandler) {
081: super (snapshot, actionsHandler);
082: diff = (AllocMemoryResultsDiff) snapshot;
083: }
084:
085: //~ Methods ------------------------------------------------------------------------------------------------------------------
086:
087: public void actionPerformed(ActionEvent e) {
088: if (e.getSource() == popupShowSource) {
089: performDefaultAction(-1);
090: }
091: }
092:
093: protected CustomBarCellRenderer getBarCellRenderer() {
094: return new DiffBarCellRenderer(diff
095: .getMinObjectsSizePerClassDiff(), diff
096: .getMaxObjectsSizePerClassDiff());
097: }
098:
099: protected JPopupMenu getPopupMenu() {
100: if (memoryResPopupMenu == null) {
101: memoryResPopupMenu = new JPopupMenu();
102:
103: Font boldfont = memoryResPopupMenu.getFont().deriveFont(
104: Font.BOLD);
105:
106: popupShowSource = new JMenuItem();
107: popupShowSource.setFont(boldfont);
108: popupShowSource.setText(GO_SOURCE_POPUP_ITEM_NAME);
109: memoryResPopupMenu.add(popupShowSource);
110: popupShowSource.addActionListener(this );
111: }
112:
113: return memoryResPopupMenu;
114: }
115:
116: protected Object computeValueAt(int row, int col) {
117: int index = ((Integer) filteredToFullIndexes.get(row))
118: .intValue();
119:
120: switch (col) {
121: case 0:
122: return sortedClassNames[index];
123: case 1:
124: return new Long(totalAllocObjectsSize[index]);
125: case 2:
126: return ((totalAllocObjectsSize[index] > 0) ? "+" : "")
127: + intFormat.format(totalAllocObjectsSize[index])
128: + " B"; // NOI18N
129: case 3:
130: return ((nTotalAllocObjects[index] > 0) ? "+" : "")
131: + intFormat.format(nTotalAllocObjects[index]); // NOI18N
132: default:
133: return null;
134: }
135: }
136:
137: protected void initColumnsData() {
138: super .initColumnsData();
139:
140: ClassNameTableCellRenderer classNameTableCellRenderer = new ClassNameTableCellRenderer();
141: LabelTableCellRenderer labelTableCellRenderer = new LabelTableCellRenderer(
142: JLabel.TRAILING);
143:
144: columnRenderers = new TableCellRenderer[] {
145: classNameTableCellRenderer, null,
146: labelTableCellRenderer, labelTableCellRenderer };
147: }
148:
149: protected void initDataUponResultsFetch() {
150: super .initDataUponResultsFetch();
151:
152: if (barRenderer != null) {
153: barRenderer
154: .setMinimum(diff.getMinObjectsSizePerClassDiff());
155: barRenderer
156: .setMaximum(diff.getMaxObjectsSizePerClassDiff());
157: }
158: }
159:
160: protected boolean passesValueFilter(int i) {
161: return true;
162: }
163:
164: protected void performDefaultAction(int classId) {
165: String className = null;
166: int selectedRow = resTable.getSelectedRow();
167:
168: if (selectedRow != -1) {
169: className = (String) resTable.getValueAt(selectedRow, 0)
170: .toString().replaceAll("\\[\\]", ""); // NOI18N;
171: }
172:
173: if (className != null) {
174: actionsHandler.showSourceForMethod(className, null, null);
175: }
176: }
177:
178: protected boolean truncateZeroItems() {
179: return false;
180: }
181: }
|