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.cpu;
042:
043: import org.netbeans.lib.profiler.TargetAppRunner;
044: import org.netbeans.lib.profiler.ui.LiveResultsPanel;
045: import org.netbeans.lib.profiler.ui.cpu.statistics.StatisticalModule;
046: import java.awt.BorderLayout;
047: import java.awt.CardLayout;
048: import java.awt.image.BufferedImage;
049: import java.util.Collection;
050: import java.util.Iterator;
051: import java.util.ResourceBundle;
052: import javax.swing.BorderFactory;
053: import javax.swing.JLabel;
054: import javax.swing.JPanel;
055: import javax.swing.JPopupMenu;
056:
057: /**
058: * A display containing a flat profile (always appears together with CCT)
059: *
060: * @author Ian Formanek
061: */
062:
063: //public class LiveFlatProfilePanel extends FlatProfilePanel implements LiveResultsPanel {
064: public class LiveFlatProfilePanel extends JPanel implements
065: LiveResultsPanel {
066: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
067:
068: // -----
069: // I18N String constants
070: private static final ResourceBundle messages = ResourceBundle
071: .getBundle("org.netbeans.lib.profiler.ui.cpu.Bundle"); // NOI18N
072: private static final String NO_RESULTS_STRING = messages
073: .getString("LiveFlatProfilePanel_NoResultsString"); // NOI18N
074: // -----
075:
076: //~ Instance fields ----------------------------------------------------------------------------------------------------------
077:
078: private CPUResUserActionsHandler actionsHandler = null;
079: private Collection statModules = null;
080: private CPUSelectionHandler handler = new CPUSelectionHandler() {
081: public void methodSelected(int threadId, int methodId, int view) {
082: for (Iterator it = statModules.iterator(); it.hasNext();) {
083: ((StatisticalModule) it.next())
084: .setSelectedMethodId(methodId);
085: }
086: }
087: };
088:
089: private JPanel noResultsPanel = null;
090: private JPanel resultsTable = null;
091: private LiveFlatProfileCollectorPanel fpCollectorPanel = null;
092: private TargetAppRunner runner;
093:
094: //~ Constructors -------------------------------------------------------------------------------------------------------------
095:
096: // public LiveFlatProfilePanel(TargetAppRunner runner, CPUResUserActionsHandler actionsHandler, DrillDownContext context, List additionalStats) {
097: public LiveFlatProfilePanel(TargetAppRunner runner,
098: CPUResUserActionsHandler actionsHandler,
099: Collection additionalStats) {
100: this .actionsHandler = actionsHandler;
101: this .runner = runner;
102:
103: statModules = additionalStats;
104:
105: // drilldownContext = context;
106: // drilldownContext.update(); // get the latest context state
107: initComponents();
108:
109: setupFlatCollector();
110: }
111:
112: //~ Methods ------------------------------------------------------------------------------------------------------------------
113:
114: public int getSortingColumn() {
115: return fpCollectorPanel.getSortingColumn();
116: }
117:
118: public boolean getSortingOrder() {
119: return fpCollectorPanel.getSortingOrder();
120: }
121:
122: public BufferedImage getViewImage(boolean onlyVisibleArea) {
123: return fpCollectorPanel.getViewImage(onlyVisibleArea);
124: }
125:
126: public String getViewName() {
127: return fpCollectorPanel.getViewName();
128: }
129:
130: public boolean fitsVisibleArea() {
131: return fpCollectorPanel.fitsVisibleArea();
132: }
133:
134: public void handleRemove() {
135: fpCollectorPanel.handleRemove();
136:
137: // CPUResultsDispatcher.getInstance().removePlugin(drillDown);
138: // CPUResultsDispatcher.getInstance().removePlugin(fpCollector);
139: // if (statModules != null) {
140: // for (Iterator it = statModules.iterator(); it.hasNext();) {
141: // ((StatisticalModule) it.next()).unregister(CPUResultsDispatcher.getInstance());
142: // }
143: // }
144: }
145:
146: /**
147: * Called when auto refresh is on and profiling session will finish
148: * to give the panel chance to do some cleanup before asynchrounous
149: * call to updateLiveResults() will happen.
150: *
151: * Currently it closes the context menu if open, which would otherwise
152: * block updating the results.
153: */
154: public void handleShutdown() {
155: handleRemove();
156: fpCollectorPanel.handleShutdown();
157: }
158:
159: // private DrillDownPanel createDrilldownPanel() {
160: //// if (drilldownContext.isValid()) {
161: //// drillDown = new DrillDown(drilldownContext);
162: //
163: // if (!drillDown.isValid()) return null;
164: //
165: // drillDown.addListener(new DrillDownListener() {
166: // public void dataChanged() {
167: // }
168: // public void drillDownPathChanged(java.util.List newDrillDownPath) {
169: // updateLiveResults();
170: // }
171: // });
172: // DrillDownPanel ddPanel = new DrillDownPanel(this.drillDown);
173: //
174: //// if (statModules != null) {
175: //// for (Iterator it = statModules.iterator(); it.hasNext();) {
176: //// StatisticalModule module = (StatisticalModule)it.next();
177: //// if (module instanceof DrillDownStatsModule) {
178: //// ddPanel.addSnippet((DrillDownStatsModule)module);
179: //// }
180: //// }
181: //// }
182: //
183: //
184: // return ddPanel;
185: // }
186: public boolean hasValidDrillDown() {
187: return false;
188: }
189:
190: // --- Save current View action support --------------------------------------
191: public boolean hasView() {
192: return fpCollectorPanel.hasView();
193: }
194:
195: public void reset() {
196: fpCollectorPanel.reset();
197: }
198:
199: public boolean supports(int instrumentationType) {
200: return fpCollectorPanel.supports(instrumentationType);
201: }
202:
203: public void updateLiveResults() {
204: fpCollectorPanel.updateLiveResults();
205:
206: // if (fpCollectorPanel.hasData()) {
207: // ((CardLayout)resultsTable.getLayout()).show(resultsTable, "RESULTS");
208: // } else {
209: // ((CardLayout)resultsTable.getLayout()).show(resultsTable, "NORESULTS");
210: // }
211: }
212:
213: private void initComponents() {
214: setLayout(new BorderLayout());
215:
216: noResultsPanel = new JPanel();
217: noResultsPanel.setLayout(new BorderLayout());
218: noResultsPanel.setBorder(BorderFactory.createEmptyBorder(12,
219: 12, 12, 12));
220:
221: final JLabel noResultsLabel = new JLabel(NO_RESULTS_STRING);
222:
223: noResultsLabel.setFont(noResultsLabel.getFont().deriveFont(14));
224: noResultsLabel.setEnabled(false);
225: noResultsPanel.add(noResultsLabel, BorderLayout.NORTH);
226:
227: resultsTable = new JPanel(new CardLayout());
228: resultsTable.add(noResultsLabel, "NORESULTS"); // NOI18N
229:
230: add(resultsTable, BorderLayout.CENTER);
231: }
232:
233: private void setupFlatCollector() {
234: // fpCollector = new FlatProfileCollector();
235: //
236: // fpCollector.addDataChangeListener(new PropertyChangeListener() {
237: // public void propertyChange(final PropertyChangeEvent evt) {
238: // Runnable runner = new Runnable() {
239: // public void run() {
240: // FlatProfileContainer fpc = (FlatProfileContainer)evt.getNewValue();
241: // if (fpc != null) {
242: // String selectedRowString = fpCollectorPanel.getSelectedRowString();
243: // fpCollectorPanel.setDataToDisplay(fpc);
244: // fpCollectorPanel.prepareResults(true);
245: //
246: // fpCollectorPanel.setSelectedRowString(selectedRowString);
247: // ((CardLayout)resultsTable.getLayout()).show(resultsTable, "RESULTS");
248: // } else {
249: // ((CardLayout)resultsTable.getLayout()).show(resultsTable, "NORESULTS");
250: // }
251: // }
252: // };
253: // if (EventQueue.isDispatchThread()) {
254: // runner.run();
255: // } else {
256: // EventQueue.invokeLater(runner);
257: // }
258: // }
259: // });
260: fpCollectorPanel = new LiveFlatProfileCollectorPanel(runner,
261: actionsHandler, handler);
262: resultsTable.add(fpCollectorPanel, "RESULTS"); // NOI18N
263: // ((CardLayout)resultsTable.getLayout()).show(resultsTable, "NORESULTS");
264:
265: ((CardLayout) resultsTable.getLayout()).show(resultsTable,
266: "RESULTS"); // NOI18N
267:
268: // CPUResultsDispatcher.getInstance().addPlugin(fpCollector);
269: }
270: }
|