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.statistics.drilldown;
042:
043: import org.netbeans.lib.profiler.results.cpu.cct.nodes.RuntimeCPUCCTNode;
044: import org.netbeans.lib.profiler.results.cpu.marking.Mark;
045: import org.netbeans.lib.profiler.ui.charts.PieChart;
046: import org.netbeans.lib.profiler.ui.components.HTMLTextArea;
047: import org.netbeans.lib.profiler.ui.cpu.StatisticsPanel;
048: import org.netbeans.lib.profiler.ui.cpu.statistics.StatisticalModule;
049: import java.awt.BorderLayout;
050: import java.util.Iterator;
051: import java.util.List;
052: import javax.swing.event.HyperlinkEvent;
053: import javax.swing.event.HyperlinkListener;
054:
055: /**
056: *
057: * @author Jaroslav Bachorik
058: */
059: public class DrillDownPanel extends StatisticalModule {
060: //~ Instance fields ----------------------------------------------------------------------------------------------------------
061:
062: private DrillDownListener listener = new DrillDownListener() {
063: public void dataChanged() {
064: }
065:
066: public void drillDownPathChanged(List list) {
067: updateCrumbNav();
068: }
069: };
070:
071: private HTMLTextArea crumbNav;
072: private IDrillDown ddModel;
073: private PieChart pieChart;
074: private ProjectPieChartModel pieModel = null;
075: private StatisticsPanel panel = null;
076: private int lastNavigableCategory;
077:
078: //~ Constructors -------------------------------------------------------------------------------------------------------------
079:
080: /** Creates a new instance of DrillDownPanel */
081: public DrillDownPanel(IDrillDown model) {
082: ddModel = model;
083: ddModel.addListener(listener);
084: initComponents();
085: }
086:
087: //~ Methods ------------------------------------------------------------------------------------------------------------------
088:
089: public void addSnippet(StatisticalModule component) {
090: panel.addSnippet(component);
091: }
092:
093: public void pause() {
094: // ddModel.pause();
095: }
096:
097: public void refresh(RuntimeCPUCCTNode appNode) {
098: // TODO
099: }
100:
101: public void removeSnippet(StatisticalModule component) {
102: panel.removeSnippet(component);
103: }
104:
105: public void resume() {
106: // ddModel.resume();
107: }
108:
109: private synchronized HTMLTextArea getCrumbNav() {
110: if (crumbNav == null) {
111: crumbNav = new HTMLTextArea();
112: crumbNav.setOpaque(false);
113: crumbNav.addHyperlinkListener(new HyperlinkListener() {
114: public void hyperlinkUpdate(HyperlinkEvent e) {
115: String query = e.getURL().getQuery();
116:
117: if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
118: return;
119: }
120:
121: int index = e.getURL().getQuery().lastIndexOf('='); // NOI18N
122:
123: if (index <= -1) {
124: return;
125: }
126:
127: int catIndex = Integer.parseInt(query
128: .substring(index + 1));
129: ddModel.drillup((Mark) ddModel.getDrillDownPath()
130: .get(catIndex));
131: }
132: });
133: updateCrumbNav();
134: }
135:
136: return crumbNav;
137: }
138:
139: private synchronized PieChart getPieChart() {
140: if (pieChart == null) {
141: pieChart = new PieChart();
142: pieModel = new ProjectPieChartModel(ddModel);
143: pieChart.setModel(pieModel);
144: }
145:
146: return pieChart;
147: }
148:
149: private void initComponents() {
150: this .setLayout(new BorderLayout());
151: panel = new StatisticsPanel(getCrumbNav(), getPieChart(),
152: new Runnable() {
153: public void run() {
154: navigateOneLevelBack();
155: }
156: });
157: panel.addListener(new StatisticsPanel.Listener() {
158: public void itemClicked(int itemIndex) {
159: pieModel.drilldown(itemIndex);
160: }
161: });
162: add(panel, BorderLayout.CENTER);
163: }
164:
165: private void navigateOneLevelBack() {
166: if (lastNavigableCategory != -1) {
167: ddModel.drillup((Mark) ddModel.getDrillDownPath().get(
168: lastNavigableCategory));
169: }
170: }
171:
172: private synchronized void updateCrumbNav() {
173: StringBuilder sb = new StringBuilder();
174: int counter = 0;
175: lastNavigableCategory = -1;
176:
177: for (Iterator it = ddModel.getDrillDownPath().iterator(); it
178: .hasNext(); counter++) {
179: final Mark mark = (Mark) it.next();
180:
181: if (it.hasNext()) {
182: sb.append("<a href=\"http://localhost/category?id=")
183: .append(counter).append("\">").append(
184: mark.description).append("</a>")
185: .append("/"); // NOI18N
186: lastNavigableCategory = counter;
187: } else {
188: sb.append(mark.description);
189: }
190:
191: crumbNav.setText(sb.toString());
192: }
193: }
194: }
|