KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > common > XTreeNode


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.common;
5
6 import java.awt.Toolkit JavaDoc;
7 import java.awt.event.MouseEvent JavaDoc;
8
9 import javax.swing.ActionMap JavaDoc;
10 import javax.swing.Icon JavaDoc;
11 import javax.swing.InputMap JavaDoc;
12 import javax.swing.JPopupMenu JavaDoc;
13 import javax.swing.KeyStroke JavaDoc;
14 import javax.swing.event.TreeSelectionEvent JavaDoc;
15 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
16 import javax.swing.tree.DefaultTreeModel JavaDoc;
17 import javax.swing.tree.TreeCellRenderer JavaDoc;
18 import javax.swing.tree.TreeNode JavaDoc;
19
20 public class XTreeNode extends DefaultMutableTreeNode JavaDoc {
21   private TreeCellRenderer JavaDoc m_renderer;
22   private Icon JavaDoc m_icon;
23   private ActionMap JavaDoc m_actionMap;
24   private InputMap JavaDoc m_inputMap;
25
26   protected static final int MENU_SHORTCUT_KEY_MASK =
27     Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
28
29   public XTreeNode() {
30     super();
31   }
32
33   public XTreeNode(Object JavaDoc userObject) {
34     super(userObject);
35   }
36
37   public TreeCellRenderer JavaDoc getRenderer() {
38     return m_renderer;
39   }
40   
41   public void setRenderer(TreeCellRenderer JavaDoc renderer) {
42     m_renderer = renderer;
43   }
44   
45   public Icon JavaDoc getIcon() {
46     return m_icon;
47   }
48
49   public void setIcon(Icon JavaDoc icon) {
50     m_icon = icon;
51   }
52
53   public JPopupMenu JavaDoc getPopupMenu() {
54     return null;
55   }
56
57   public void tearDownChildren() {
58     if(children != null) {
59       XTreeNode node;
60
61       for(int i = getChildCount()-1; i >= 0; i--) {
62         if((node = (XTreeNode)children.get(i)) != null) {
63           node.tearDown();
64           node.removeFromParent();
65         }
66       }
67     }
68   }
69
70   public void tearDown() {
71     tearDownChildren();
72     setUserObject(null);
73     setIcon(null);
74   }
75
76   public ActionMap JavaDoc getActionMap() {
77     return m_actionMap;
78   }
79
80   public ActionMap JavaDoc ensureActionMap() {
81     if(m_actionMap == null) {
82       m_actionMap = new ActionMap JavaDoc();
83     }
84
85     return m_actionMap;
86   }
87
88   public void setActionMap(ActionMap JavaDoc actionMap) {
89     m_actionMap = actionMap;
90   }
91
92   public InputMap JavaDoc getInputMap() {
93     return m_inputMap;
94   }
95
96   public InputMap JavaDoc ensureInputMap() {
97     if(m_inputMap == null) {
98       m_inputMap = new InputMap JavaDoc();
99     }
100
101     return m_inputMap;
102   }
103
104   public void setInputMap(InputMap JavaDoc inputMap) {
105     m_inputMap = inputMap;
106   }
107
108   public void addActionBinding(Object JavaDoc binding, XAbstractAction action) {
109     ensureActionMap().put(binding, action);
110
111     KeyStroke JavaDoc ks = action.getAccelerator();
112     if(ks != null) {
113       ensureInputMap().put(ks, binding);
114     }
115   }
116
117   public XTreeModel getModel() {
118     TreeNode JavaDoc root = getRoot();
119     XTreeModel model = null;
120     
121     if(root instanceof XRootNode) {
122       model = ((XRootNode)getRoot()).getModel();
123     }
124     
125     return model;
126   }
127
128   public int getIndex() {
129     XTreeNode parentNode = (XTreeNode)getParent();
130     return (parentNode != null) ? parentNode.getIndex(this) : -1;
131   }
132
133   public void nodeSelected(TreeSelectionEvent JavaDoc e) {/**/}
134   public void nodeClicked(MouseEvent JavaDoc me) {/**/}
135   
136   protected void nodeChanged() {
137     DefaultTreeModel JavaDoc model = getModel();
138     if(model != null) {
139       model.nodeChanged(this);
140     }
141   }
142   
143   protected void nodeStructureChanged() {
144     DefaultTreeModel JavaDoc model = getModel();
145     if(model != null) {
146       model.nodeStructureChanged(this);
147     }
148   }
149 }
150
Popular Tags