001: /*/////////////////////////////////////////////////////////////////////
002:
003: Copyright (C) 2006 TiVo Inc. All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions are met:
007:
008: + Redistributions of source code must retain the above copyright notice,
009: this list of conditions and the following disclaimer.
010: + Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: + Neither the name of TiVo Inc nor the names of its contributors may be
014: used to endorse or promote products derived from this software without
015: specific prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
021: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
022: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
023: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
025: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
026: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
027: POSSIBILITY OF SUCH DAMAGE.
028:
029: /////////////////////////////////////////////////////////////////////*/
030:
031: package com.tivo.jipviewer;
032:
033: import java.util.ArrayList;
034: import java.util.List;
035: import javax.swing.table.AbstractTableModel;
036:
037: class MethodRowTableModel extends AbstractTableModel {
038:
039: public static final int PERCENT_TOTAL = 0;
040: public static final int TOTAL_TIME = 1;
041: public static final int COUNT = 2;
042: public static final int PERCENT_NET = 3;
043: public static final int NET_TIME = 4;
044: public static final int METHOD_NAME = 5;
045: public static final int CLASS_NAME = 6;
046: public static final int PACKAGE_NAME = 7;
047:
048: List<MethodRow> mvRow = new ArrayList<MethodRow>();
049:
050: public void add(MethodRow row) {
051: mvRow.add(row);
052: int iLast = mvRow.size();
053: fireTableRowsInserted(iLast, iLast);
054: }
055:
056: public void clear() {
057: int iLast = mvRow.size();
058: mvRow.clear();
059: fireTableRowsDeleted(0, iLast);
060: }
061:
062: public MethodRow getRow(int iRow) {
063: return mvRow.get(iRow);
064: }
065:
066: public int getRowCount() {
067: return mvRow.size();
068: }
069:
070: public int getColumnCount() {
071: return 8;
072: }
073:
074: public String getColumnName(int iColumn) {
075: switch (iColumn) {
076: case PERCENT_TOTAL:
077: return "%total";
078: case PERCENT_NET:
079: return "%net";
080: case COUNT:
081: return "count";
082: case TOTAL_TIME:
083: return "total";
084: case NET_TIME:
085: return "net";
086: case METHOD_NAME:
087: return "method";
088: case CLASS_NAME:
089: return "class";
090: case PACKAGE_NAME:
091: return "package";
092: default:
093: throw new RuntimeException("bad column index");
094: }
095: }
096:
097: public Class getColumnClass(int iColumn) {
098: switch (iColumn) {
099: case PERCENT_TOTAL:
100: return Double.class;
101: case PERCENT_NET:
102: return Double.class;
103: case COUNT:
104: return Long.class;
105: case TOTAL_TIME:
106: return Double.class;
107: case NET_TIME:
108: return Double.class;
109: case METHOD_NAME:
110: return String.class;
111: case CLASS_NAME:
112: return String.class;
113: case PACKAGE_NAME:
114: return String.class;
115: default:
116: throw new RuntimeException("bad column index");
117: }
118: }
119:
120: public Object getValueAt(int iRow, int iColumn) {
121: MethodRow row = mvRow.get(iRow);
122:
123: switch (iColumn) {
124: case PERCENT_TOTAL:
125: return new Double(row.getPercentTotal());
126: case PERCENT_NET:
127: return new Double(row.getPercentNet());
128: case COUNT:
129: return new Long(row.getCount());
130: case TOTAL_TIME:
131: return new Double(toMsec(row.getTotalTime()));
132: case NET_TIME:
133: return new Double(toMsec(row.getNetTime()));
134: case METHOD_NAME:
135: return row.getMethod().getMethodName();
136: case CLASS_NAME:
137: return row.getMethod().getClassName();
138: case PACKAGE_NAME:
139: return row.getMethod().getPackageName();
140: default:
141: throw new RuntimeException("bad column index");
142: }
143: }
144:
145: private static double toMsec(long time) {
146: final double timeToMsec = 1000.0 * 1000.0;
147: return Math.floor((time / timeToMsec) * 10) / 10.0;
148: }
149: };
|