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.LivenessMemoryResultsDiff;
044: import org.netbeans.lib.profiler.results.memory.LivenessMemoryResultsSnapshot;
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 org.netbeans.lib.profiler.utils.StringUtils;
050: import java.awt.*;
051: import java.awt.event.ActionEvent;
052: import java.util.ResourceBundle;
053: import javax.swing.*;
054: import javax.swing.table.TableCellRenderer;
055:
056: /**
057: * This panel displays memory liveness diff.
058: *
059: * @author Jiri Sedlacek
060: */
061: public class DiffLivenessResultsPanel extends
062: SnapshotLivenessResultsPanel {
063: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
064:
065: // -----
066: // I18N String constants
067: private static final ResourceBundle messages = ResourceBundle
068: .getBundle("org.netbeans.lib.profiler.ui.memory.Bundle"); // NOI18N
069: private static final String GO_SOURCE_POPUP_ITEM = messages
070: .getString("SnapshotLivenessResultsPanel_GoSourcePopupItem"); // NOI18N
071: // -----
072:
073: //~ Instance fields ----------------------------------------------------------------------------------------------------------
074:
075: private JMenuItem popupShowSource;
076: private JPopupMenu popup;
077: private LivenessMemoryResultsDiff diff;
078:
079: //~ Constructors -------------------------------------------------------------------------------------------------------------
080:
081: public DiffLivenessResultsPanel(
082: LivenessMemoryResultsSnapshot snapshot,
083: MemoryResUserActionsHandler actionsHandler,
084: int allocTrackEvery) {
085: super (snapshot, actionsHandler, allocTrackEvery);
086: diff = (LivenessMemoryResultsDiff) snapshot;
087: }
088:
089: //~ Methods ------------------------------------------------------------------------------------------------------------------
090:
091: public void actionPerformed(ActionEvent e) {
092: if (e.getSource() == popupShowSource) {
093: performDefaultAction(-1);
094: }
095: }
096:
097: protected CustomBarCellRenderer getBarCellRenderer() {
098: return new DiffBarCellRenderer(diff
099: .getMinTrackedLiveObjectsSizeDiff(), diff
100: .getMaxTrackedLiveObjectsSizeDiff());
101: }
102:
103: protected JPopupMenu getPopupMenu() {
104: if (popup == null) {
105: popup = new JPopupMenu();
106:
107: Font boldfont = popup.getFont().deriveFont(Font.BOLD);
108:
109: popupShowSource = new JMenuItem();
110: popupShowSource.setText(GO_SOURCE_POPUP_ITEM);
111: popupShowSource.setFont(boldfont);
112: popup.add(popupShowSource);
113: popupShowSource.addActionListener(this );
114: }
115:
116: return popup;
117: }
118:
119: protected Object computeValueAt(int row, int col) {
120: int index = ((Integer) filteredToFullIndexes.get(row))
121: .intValue();
122:
123: switch (col) {
124: case 0:
125: return sortedClassNames[index];
126: case 1:
127: return new Long(trackedLiveObjectsSize[index]);
128: case 2:
129: return ((trackedLiveObjectsSize[index] > 0) ? "+" : "")
130: + intFormat.format(trackedLiveObjectsSize[index])
131: + " B"; // NOI18N
132: case 3:
133: return ((nTrackedLiveObjects[index] > 0) ? "+" : "")
134: + intFormat.format(nTrackedLiveObjects[index]); // NOI18N
135: case 4:
136: return ((nTrackedAllocObjects[index] > 0) ? "+" : "")
137: + intFormat.format(nTrackedAllocObjects[index]); // NOI18N
138: case 5:
139: // NOTE: StringUtils.floatPerCentToString() doesn't handle correctly negative values!
140: return ((avgObjectAge[index] > 0) ? "+" : "-")
141: + StringUtils.floatPerCentToString(Math
142: .abs(avgObjectAge[index])); // NOI18N
143: case 6:
144: return ((maxSurvGen[index] > 0) ? "+" : "")
145: + intFormat.format(maxSurvGen[index]); // NOI18N
146: case 7:
147: return ((nTotalAllocObjects[index] > 0) ? "+" : "")
148: + intFormat.format(nTotalAllocObjects[index]); // NOI18N
149: default:
150: return null;
151: }
152: }
153:
154: protected void initColumnsData() {
155: super .initColumnsData();
156:
157: ClassNameTableCellRenderer classNameTableCellRenderer = new ClassNameTableCellRenderer();
158: LabelTableCellRenderer labelTableCellRenderer = new LabelTableCellRenderer(
159: JLabel.TRAILING);
160:
161: columnRenderers = new TableCellRenderer[] {
162: classNameTableCellRenderer, null,
163: labelTableCellRenderer, labelTableCellRenderer,
164: labelTableCellRenderer, labelTableCellRenderer,
165: labelTableCellRenderer, labelTableCellRenderer };
166: }
167:
168: protected void initDataUponResultsFetch() {
169: super .initDataUponResultsFetch();
170:
171: if (barRenderer != null) {
172: barRenderer.setMinimum(diff
173: .getMinTrackedLiveObjectsSizeDiff());
174: barRenderer.setMaximum(diff
175: .getMaxTrackedLiveObjectsSizeDiff());
176: }
177: }
178:
179: protected boolean passesValueFilter(int i) {
180: return true;
181: }
182:
183: protected void performDefaultAction(int classId) {
184: String className = null;
185: int selectedRow = resTable.getSelectedRow();
186:
187: if (selectedRow != -1) {
188: className = (String) resTable.getValueAt(selectedRow, 0)
189: .toString().replaceAll("\\[\\]", ""); // NOI18N;
190: }
191:
192: if (className != null) {
193: actionsHandler.showSourceForMethod(className, null, null);
194: }
195: }
196:
197: protected boolean truncateZeroItems() {
198: return false;
199: }
200: }
|