source: src/main/java/weka/gui/ensembleLibraryEditor/tree/ModelTreeNodeRenderer.java @ 20

Last change on this file since 20 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 3.6 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    ModelTreeNodeRenderer.java
19 *    Copyright (C) 2006 Robert Jung
20 *
21 */
22
23package weka.gui.ensembleLibraryEditor.tree;
24
25import weka.gui.EnsembleLibraryEditor;
26
27import java.awt.Component;
28import java.beans.PropertyEditor;
29
30import javax.swing.JComponent;
31import javax.swing.JLabel;
32import javax.swing.JTree;
33import javax.swing.tree.TreeCellRenderer;
34
35/**
36 * This class renders a tree nodes. It determines which type of node the m_Tree
37 * is trying to render and then returns the approapriate gui widget. It is
38 * basically the same thing as the ModelTreeNodeEditor class except it does not
39 * have to.
40 *
41 * @author  Robert Jung (mrbobjung@gmail.com)
42 * @version $Revision: 1.1 $
43 */
44public class ModelTreeNodeRenderer
45  implements TreeCellRenderer {
46 
47  /**
48   * empty Constructor
49   */
50  public ModelTreeNodeRenderer() {
51    super();
52  }
53 
54  /**
55   * This is the method of this class that is responsible for figuring out how
56   * to display each of the tree nodes. All it does is figure out the type of
57   * the node and then return a new instance of the apropriate editor type for
58   * the node.
59   *
60   * @param tree        the associated tree
61   * @param value       the value
62   * @param selected    true if item is selected
63   * @param expanded    true if node is expanded
64   * @param leaf        true if node is leaf
65   * @param row         the row in the tree
66   * @param hasFocus    true if item has the focus
67   * @return            the rendering component
68   */
69  public Component getTreeCellRendererComponent(JTree tree, Object value,
70      boolean selected, boolean expanded, boolean leaf, int row,
71      boolean hasFocus) {
72   
73    JComponent customRenderer = null;
74   
75    if (value instanceof GenericObjectNode) {
76     
77      GenericObjectNode node = (GenericObjectNode) value;
78      customRenderer = new GenericObjectNodeEditor(node);
79      customRenderer.setToolTipText(node.getToolTipText());
80     
81    } else if (value instanceof PropertyNode) {
82      PropertyNode node = (PropertyNode) value;
83      JLabel label = new JLabel(node.getName());
84      label.setToolTipText(node.getToolTipText());
85      customRenderer = label;
86      customRenderer.setToolTipText(node.getToolTipText());
87     
88    } else if (value instanceof CheckBoxNode) {
89     
90      CheckBoxNode node = (CheckBoxNode) value;
91      customRenderer = new CheckBoxNodeEditor(node);
92      customRenderer.setToolTipText(node.getToolTipText());
93     
94    } else if (value instanceof NumberNode) {
95     
96      NumberNode node = (NumberNode) value;
97      customRenderer = new NumberNodeEditor(node);
98      customRenderer.setToolTipText(node.getToolTipText());
99     
100    } else if (value instanceof DefaultNode) {
101     
102      DefaultNode node = (DefaultNode) value;
103      PropertyEditor nodeEditor = node.getEditor();
104      customRenderer = (JComponent) EnsembleLibraryEditor
105      .getDefaultRenderer(nodeEditor);
106      customRenderer.setToolTipText(node.getToolTipText());
107     
108    }
109   
110    return customRenderer;
111  }
112}
Note: See TracBrowser for help on using the repository browser.