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.LivenessMemoryResultsSnapshot;
044: import org.netbeans.lib.profiler.ui.UIUtils;
045: import java.awt.*;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import java.util.ResourceBundle;
049: import javax.swing.*;
050:
051: /**
052: * This class implements presentation frames for Object Liveness Profiling.
053: *
054: * @author Misha Dmitriev
055: * @author Ian Formanek
056: * @author Jiri Sedlacek
057: */
058: public class SnapshotLivenessResultsPanel extends LivenessResultsPanel
059: implements ActionListener {
060: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
061:
062: // -----
063: // I18N String constants
064: private static final ResourceBundle messages = ResourceBundle
065: .getBundle("org.netbeans.lib.profiler.ui.memory.Bundle"); // NOI18N
066: private static final String GO_SOURCE_POPUP_ITEM = messages
067: .getString("SnapshotLivenessResultsPanel_GoSourcePopupItem"); // NOI18N
068: private static final String STACK_TRACES_POPUP_ITEM = messages
069: .getString("SnapshotLivenessResultsPanel_StackTracesPopupItem"); // NOI18N
070: // -----
071:
072: //~ Instance fields ----------------------------------------------------------------------------------------------------------
073:
074: private JMenuItem popupShowSource;
075: private JMenuItem popupShowStacks;
076: private JPopupMenu popup;
077: private LivenessMemoryResultsSnapshot snapshot;
078: private int allocTrackEvery;
079:
080: //~ Constructors -------------------------------------------------------------------------------------------------------------
081:
082: public SnapshotLivenessResultsPanel(
083: LivenessMemoryResultsSnapshot snapshot,
084: MemoryResUserActionsHandler actionsHandler,
085: int allocTrackEvery) {
086: super (actionsHandler);
087: this .snapshot = snapshot;
088: this .allocTrackEvery = allocTrackEvery;
089:
090: fetchResultsFromSnapshot();
091: //prepareResults();
092: initColumnsData();
093: }
094:
095: //~ Methods ------------------------------------------------------------------------------------------------------------------
096:
097: public void actionPerformed(ActionEvent e) {
098: Object source = e.getSource();
099:
100: if (source == popupShowStacks) {
101: actionsHandler.showStacksForClass(selectedClassId,
102: getSortingColumn(), getSortingOrder());
103: } else if (source == popupShowSource) {
104: showSourceForClass(selectedClassId);
105: }
106: }
107:
108: protected String getClassName(int classId) {
109: return snapshot.getClassName(classId);
110: }
111:
112: protected String[] getClassNames() {
113: return snapshot.getClassNames();
114: }
115:
116: protected int getPercentsTracked() {
117: return 100 / allocTrackEvery;
118: }
119:
120: protected JPopupMenu getPopupMenu() {
121: if (popup == null) {
122: popup = new JPopupMenu();
123:
124: Font boldfont = popup.getFont().deriveFont(Font.BOLD);
125:
126: popupShowSource = new JMenuItem();
127: popupShowSource.setText(GO_SOURCE_POPUP_ITEM);
128: popupShowSource.setFont(boldfont);
129: popup.add(popupShowSource);
130: popupShowSource.addActionListener(this );
131:
132: if (snapshot.containsStacks()) {
133: popup.addSeparator();
134: popupShowStacks = new JMenuItem();
135: popupShowStacks.setText(STACK_TRACES_POPUP_ITEM);
136: popup.add(popupShowStacks);
137: popupShowStacks.addActionListener(this );
138: }
139: }
140:
141: return popup;
142: }
143:
144: protected void performDefaultAction(int classId) {
145: showSourceForClass(classId);
146: }
147:
148: private void fetchResultsFromSnapshot() {
149: nTrackedAllocObjects = UIUtils.copyArray(snapshot
150: .getNTrackedAllocObjects());
151: nTrackedLiveObjects = UIUtils.copyArray(snapshot
152: .getNTrackedLiveObjects());
153: trackedLiveObjectsSize = UIUtils.copyArray(snapshot
154: .getTrackedLiveObjectsSize());
155: nTotalAllocObjects = UIUtils.copyArray(snapshot
156: .getnTotalAllocObjects());
157: avgObjectAge = UIUtils.copyArray(snapshot.getAvgObjectAge());
158: maxSurvGen = UIUtils.copyArray(snapshot.getMaxSurvGen());
159: nInstrClasses = snapshot.getNInstrClasses();
160:
161: nTrackedItems = snapshot.getNTrackedItems();
162: // Operations necessary for correct bar representation of results
163: maxValue = snapshot.getMaxValue();
164: nTotalTrackedBytes = snapshot.getNTotalTrackedBytes();
165: nTotalTracked = snapshot.getNTotalTracked();
166:
167: initDataUponResultsFetch();
168: }
169: }
|