01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.gui.tree;
20:
21: import java.awt.Component;
22:
23: import javax.swing.ImageIcon;
24: import javax.swing.JTree;
25: import javax.swing.tree.DefaultTreeCellRenderer;
26:
27: /**
28: * @author Michael Stover
29: * @version $Revision: 493779 $
30: */
31: public class JMeterCellRenderer extends DefaultTreeCellRenderer {
32: public JMeterCellRenderer() {
33: }
34:
35: public Component getTreeCellRendererComponent(JTree tree,
36: Object value, boolean sel, boolean expanded, boolean leaf,
37: int row, boolean p_hasFocus) {
38: super .getTreeCellRendererComponent(tree,
39: ((JMeterTreeNode) value).getName(), sel, expanded,
40: leaf, row, p_hasFocus);
41: boolean enabled = ((JMeterTreeNode) value).isEnabled();
42: ImageIcon ic = ((JMeterTreeNode) value).getIcon(enabled);
43: if (ic != null) {
44: if (enabled) {
45: setIcon(ic);
46: } else {
47: setDisabledIcon(ic);
48: }
49: } else {
50: if (!enabled)// i.e. no disabled icon found
51: {
52: // Must therefore set the enabled icon so there is at least some
53: // icon
54: ic = ((JMeterTreeNode) value).getIcon();
55: if (ic != null)
56: setIcon(ic);
57: }
58: }
59: this.setEnabled(enabled);
60: return this;
61: }
62: }
|