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.modules.profiler;
042:
043: import org.netbeans.lib.profiler.results.ResultsSnapshot;
044: import org.netbeans.lib.profiler.results.coderegion.CodeRegionResultsSnapshot;
045: import org.netbeans.lib.profiler.ui.UIUtils;
046: import org.netbeans.lib.profiler.ui.cpu.CodeRegionSnapshotPanel;
047: import org.netbeans.lib.profiler.utils.StringUtils;
048: import org.openide.util.NbBundle;
049: import java.awt.*;
050: import java.awt.event.ActionEvent;
051: import java.awt.event.InputEvent;
052: import java.awt.event.KeyEvent;
053: import java.text.MessageFormat;
054: import java.util.Date;
055: import javax.swing.*;
056: import javax.swing.event.ChangeEvent;
057: import javax.swing.event.ChangeListener;
058:
059: /**
060: * A display for snapshot of CPU profiling results
061: *
062: * @author Tomas Hurka
063: * @author Ian Formanek
064: */
065: public class FragmentSnapshotPanel extends SnapshotPanel implements
066: ChangeListener {
067: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
068:
069: // -----
070: // I18N String constants
071: private static final String CALLS_TAB_NAME = NbBundle.getMessage(
072: FragmentSnapshotPanel.class,
073: "FragmentSnapshotPanel_CallsTabName"); //NOI18N
074: private static final String INFO_TAB_NAME = NbBundle.getMessage(
075: FragmentSnapshotPanel.class,
076: "FragmentSnapshotPanel_InfoTabName"); //NOI18N
077: private static final String CALLS_TAB_DESCR = NbBundle.getMessage(
078: FragmentSnapshotPanel.class,
079: "FragmentSnapshotPanel_CallsTabDescr"); //NOI18N
080: private static final String INFO_TAB_DESCR = NbBundle.getMessage(
081: FragmentSnapshotPanel.class,
082: "FragmentSnapshotPanel_InfoTabDescr"); //NOI18N
083: private static final String PANEL_TITLE = NbBundle.getMessage(
084: FragmentSnapshotPanel.class,
085: "FragmentSnapshotPanel_PanelTitle"); // NOI18N
086: // -----
087:
088: //~ Instance fields ----------------------------------------------------------------------------------------------------------
089:
090: private CodeRegionResultsSnapshot snapshot;
091: private JTabbedPane tabs = new JTabbedPane(JTabbedPane.BOTTOM);
092: private SaveSnapshotAction saveAction;
093: private SnapshotInfoPanel infoPanel;
094:
095: //~ Constructors -------------------------------------------------------------------------------------------------------------
096:
097: public FragmentSnapshotPanel(LoadedSnapshot ls) {
098: this .snapshot = (CodeRegionResultsSnapshot) ls.getSnapshot();
099:
100: setLayout(new BorderLayout());
101:
102: infoPanel = new SnapshotInfoPanel(ls);
103:
104: CodeRegionSnapshotPanel crsPanel = new CodeRegionSnapshotPanel(
105: snapshot);
106:
107: infoPanel.updateInfo();
108:
109: tabs.addTab(CALLS_TAB_NAME, null, crsPanel, CALLS_TAB_DESCR);
110: tabs.addTab(INFO_TAB_NAME, null, infoPanel, INFO_TAB_DESCR);
111: add(tabs, BorderLayout.CENTER);
112:
113: tabs.addChangeListener(this );
114:
115: JToolBar toolBar = new JToolBar() {
116: public Component add(Component comp) {
117: if (comp instanceof JButton) {
118: UIUtils.fixButtonUI((JButton) comp);
119: }
120:
121: return super .add(comp);
122: }
123: };
124:
125: toolBar.setFloatable(false);
126: toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
127: toolBar.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
128:
129: toolBar.add(saveAction = new SaveSnapshotAction(ls));
130: toolBar.add(new ExportSnapshotAction(ls));
131:
132: add(toolBar, BorderLayout.NORTH);
133:
134: // support for traversing subtabs using Ctrl-Alt-PgDn/PgUp
135: getActionMap().put("PreviousViewAction", new AbstractAction() {
136: public void actionPerformed(ActionEvent e) {
137: moveToPreviousSubTab();
138: }
139: }); // NOI18N
140: getActionMap().put("NextViewAction", new AbstractAction() {
141: public void actionPerformed(ActionEvent e) {
142: moveToNextSubTab();
143: }
144: }); // NOI18N
145: }
146:
147: //~ Methods ------------------------------------------------------------------------------------------------------------------
148:
149: public ResultsSnapshot getSnapshot() {
150: return snapshot;
151: }
152:
153: public String getTitle() {
154: return MessageFormat.format(PANEL_TITLE,
155: new Object[] { StringUtils.formatUserDate(new Date(
156: snapshot.getTimeTaken())) });
157: }
158:
159: public void stateChanged(ChangeEvent e) {
160: updateToolbar();
161: }
162:
163: public void updateSavedState() {
164: infoPanel.updateInfo();
165: saveAction.updateState();
166: }
167:
168: private void moveToNextSubTab() {
169: tabs.setSelectedIndex(UIUtils.getNextSubTabIndex(tabs, tabs
170: .getSelectedIndex()));
171: }
172:
173: private void moveToPreviousSubTab() {
174: tabs.setSelectedIndex(UIUtils.getPreviousSubTabIndex(tabs, tabs
175: .getSelectedIndex()));
176: }
177:
178: private void updateToolbar() {
179: // update the toolbar if selected tab changed
180: }
181: }
|