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.threads;
042:
043: import org.netbeans.lib.profiler.global.CommonConstants;
044: import org.netbeans.lib.profiler.results.threads.ThreadData;
045: import org.netbeans.lib.profiler.ui.components.table.LabelTableCellRenderer;
046: import java.awt.Component;
047: import javax.swing.*;
048:
049: /** A table cell renderer that knows how to display thread names with their state icon
050: *
051: * @author Jiri Sedlacek
052: * @author Ian Formanek
053: */
054: public class ThreadNameCellRenderer extends LabelTableCellRenderer {
055: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
056:
057: private static final int THREAD_ICON_SIZE = 9;
058: private static ThreadStateIcon noneIcon = new ThreadStateIcon(
059: ThreadStateIcon.ICON_NONE, THREAD_ICON_SIZE,
060: THREAD_ICON_SIZE);
061: private static ThreadStateIcon unknownIcon = new ThreadStateIcon(
062: CommonConstants.THREAD_STATUS_UNKNOWN, THREAD_ICON_SIZE,
063: THREAD_ICON_SIZE);
064: private static ThreadStateIcon zombieIcon = new ThreadStateIcon(
065: CommonConstants.THREAD_STATUS_ZOMBIE, THREAD_ICON_SIZE,
066: THREAD_ICON_SIZE);
067: private static ThreadStateIcon runningIcon = new ThreadStateIcon(
068: CommonConstants.THREAD_STATUS_RUNNING, THREAD_ICON_SIZE,
069: THREAD_ICON_SIZE);
070: private static ThreadStateIcon sleepingIcon = new ThreadStateIcon(
071: CommonConstants.THREAD_STATUS_SLEEPING, THREAD_ICON_SIZE,
072: THREAD_ICON_SIZE);
073: private static ThreadStateIcon monitorIcon = new ThreadStateIcon(
074: CommonConstants.THREAD_STATUS_MONITOR, THREAD_ICON_SIZE,
075: THREAD_ICON_SIZE);
076: private static ThreadStateIcon waitIcon = new ThreadStateIcon(
077: CommonConstants.THREAD_STATUS_WAIT, THREAD_ICON_SIZE,
078: THREAD_ICON_SIZE);
079:
080: //~ Instance fields ----------------------------------------------------------------------------------------------------------
081:
082: private ThreadsPanel viewManager; // view manager for this cell
083:
084: //~ Constructors -------------------------------------------------------------------------------------------------------------
085:
086: /**
087: * Creates a new instance of ThreadNameCellRenderer
088: */
089: public ThreadNameCellRenderer(ThreadsPanel viewManager) {
090: this .viewManager = viewManager;
091: }
092:
093: //~ Methods ------------------------------------------------------------------------------------------------------------------
094:
095: public Component getTableCellRendererComponentPersistent(
096: JTable table, Object value, boolean isSelected,
097: boolean hasFocus, int row, int column) {
098: return new ThreadNameCellRenderer(viewManager)
099: .getTableCellRendererComponent(table, value,
100: isSelected, hasFocus, row, column);
101: }
102:
103: protected void setValue(JTable table, Object value, int row,
104: int column) {
105: super .setValue(table, value, row, column);
106:
107: if (value == null) {
108: label.setText(""); // NOI18N
109: label.setIcon(zombieIcon);
110: } else {
111: int index = ((Integer) value).intValue();
112: ThreadData threadData = viewManager.getThreadData(index);
113:
114: label.setText(viewManager.getThreadName(index));
115:
116: if (threadData.size() > 0) {
117: byte state = threadData.getLastState();
118:
119: switch (state) {
120: case CommonConstants.THREAD_STATUS_UNKNOWN:
121: label.setIcon(unknownIcon);
122:
123: break;
124: case CommonConstants.THREAD_STATUS_ZOMBIE:
125: label.setIcon(zombieIcon);
126:
127: break;
128: case CommonConstants.THREAD_STATUS_RUNNING:
129: label.setIcon(runningIcon);
130:
131: break;
132: case CommonConstants.THREAD_STATUS_SLEEPING:
133:
134: if (viewManager.supportsSleepingState()) {
135: label.setIcon(sleepingIcon);
136: } else {
137: label.setIcon(runningIcon);
138: }
139:
140: break;
141: case CommonConstants.THREAD_STATUS_MONITOR:
142: label.setIcon(monitorIcon);
143:
144: break;
145: case CommonConstants.THREAD_STATUS_WAIT:
146: label.setIcon(waitIcon);
147:
148: break;
149: }
150: } else {
151: // No state defined -> THREAD_STATUS_ZOMBIE assumed (thread could finish when monitoring was disabled)
152: label.setIcon(zombieIcon);
153: }
154: }
155: }
156: }
|