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.marking.Mark;
044: import java.text.MessageFormat;
045: import java.util.ResourceBundle;
046:
047: /**
048: *
049: * @author Jaroslav Bachorik
050: */
051: public class ProjectPieChartModel extends DrillDownPieChartModel {
052: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
053:
054: // -----
055: // I18N String constants
056: private static final ResourceBundle messages = ResourceBundle
057: .getBundle("org.netbeans.lib.profiler.ui.cpu.statistics.drilldown.Bundle"); // NOI18N
058: private static final String SELF_BADGE_TEXT = messages
059: .getString("ProjectPieChartModel_SelfBadgeText"); // NOI18N
060:
061: // -----
062:
063: //~ Constructors -------------------------------------------------------------------------------------------------------------
064:
065: /**
066: * Creates a new instance of ProjectPieChartModel
067: */
068: public ProjectPieChartModel(IDrillDown model) {
069: super (model);
070: }
071:
072: //~ Methods ------------------------------------------------------------------------------------------------------------------
073:
074: @Override
075: public String getItemName(int index) {
076: return getItemNameAt(getMappedIndex(index));
077: }
078:
079: @Override
080: public double getItemValue(int index) {
081: double ret = getItemValueAt(getMappedIndex(index));
082: System.out.println("Getting value for category n." + index
083: + " : " + ret); // NOI18N
084:
085: return ret;
086: }
087:
088: @Override
089: public double getItemValueRel(int index) {
090: long allTime = drillDown.getCurrentTime(false);
091:
092: // long netSelfTime = drillDown.getCurrentTime(true);
093: long allTimeCalc = 0;
094:
095: for (int i = 0; i < drillDown.getSubmarks().size(); i++) {
096: allTimeCalc += getItemValueAt(i);
097: }
098:
099: // allTimeCalc = allTimeCalc - allTime + netSelfTime; // compensation for gross time of the current category; it gets its way in as one of the submark times (self submark time)
100: if (allTimeCalc != allTime) {
101: System.err.println("time mismatch: " + allTime + " != "
102: + allTimeCalc); // NOI18N
103: }
104:
105: if (allTime == 0) {
106: return 1;
107: }
108:
109: // System.out.println("Ratio for mark " + index + " = " + getItemValueAt(getMappedIndex(index)) + "/" + allTime);
110: return getItemValueAt(getMappedIndex(index)) / (double) allTime;
111: }
112:
113: public boolean isSelectable(int index) {
114: if (drillDown.getSubmarks().size() <= index) {
115: return false;
116: }
117:
118: if (index != -1) {
119: return drillDown.canDrilldown((Mark) drillDown
120: .getSubmarks().get(index));
121: }
122:
123: return false;
124: }
125:
126: private String getItemNameAt(int index) {
127: if (drillDown.getSubmarks().size() <= index) {
128: return ""; // NOI18N
129: }
130:
131: if (((index == -1) || drillDown.isCurrent((Mark) drillDown
132: .getSubmarks().get(index)))
133: && !drillDown.isInSelf()) {
134: return MessageFormat
135: .format(SELF_BADGE_TEXT,
136: new Object[] { ((Mark) drillDown
137: .getCurrentMark()).description });
138: } else {
139: return ((Mark) drillDown.getSubmarks().get(index)).description;
140: }
141: }
142:
143: private double getItemValueAt(int index) {
144: if (drillDown.getSubmarks().size() <= index) {
145: return 0d;
146: }
147:
148: if (((index == -1) || drillDown.isCurrent((Mark) drillDown
149: .getSubmarks().get(index)))
150: && !drillDown.isInSelf()) {
151: return (double) drillDown.getCurrentTime(true);
152: } else {
153: return (double) drillDown.getMarkTime((Mark) drillDown
154: .getSubmarks().get(index), false);
155: }
156: }
157: }
|