001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.common;
005:
006: import java.awt.Toolkit;
007: import java.awt.event.MouseEvent;
008:
009: import javax.swing.ActionMap;
010: import javax.swing.Icon;
011: import javax.swing.InputMap;
012: import javax.swing.JPopupMenu;
013: import javax.swing.KeyStroke;
014: import javax.swing.event.TreeSelectionEvent;
015: import javax.swing.tree.DefaultMutableTreeNode;
016: import javax.swing.tree.DefaultTreeModel;
017: import javax.swing.tree.TreeCellRenderer;
018: import javax.swing.tree.TreeNode;
019:
020: public class XTreeNode extends DefaultMutableTreeNode {
021: private TreeCellRenderer m_renderer;
022: private Icon m_icon;
023: private ActionMap m_actionMap;
024: private InputMap m_inputMap;
025:
026: protected static final int MENU_SHORTCUT_KEY_MASK = Toolkit
027: .getDefaultToolkit().getMenuShortcutKeyMask();
028:
029: public XTreeNode() {
030: super ();
031: }
032:
033: public XTreeNode(Object userObject) {
034: super (userObject);
035: }
036:
037: public TreeCellRenderer getRenderer() {
038: return m_renderer;
039: }
040:
041: public void setRenderer(TreeCellRenderer renderer) {
042: m_renderer = renderer;
043: }
044:
045: public Icon getIcon() {
046: return m_icon;
047: }
048:
049: public void setIcon(Icon icon) {
050: m_icon = icon;
051: }
052:
053: public JPopupMenu getPopupMenu() {
054: return null;
055: }
056:
057: public void tearDownChildren() {
058: if (children != null) {
059: XTreeNode node;
060:
061: for (int i = getChildCount() - 1; i >= 0; i--) {
062: if ((node = (XTreeNode) children.get(i)) != null) {
063: node.tearDown();
064: node.removeFromParent();
065: }
066: }
067: }
068: }
069:
070: public void tearDown() {
071: tearDownChildren();
072: setUserObject(null);
073: setIcon(null);
074: }
075:
076: public ActionMap getActionMap() {
077: return m_actionMap;
078: }
079:
080: public ActionMap ensureActionMap() {
081: if (m_actionMap == null) {
082: m_actionMap = new ActionMap();
083: }
084:
085: return m_actionMap;
086: }
087:
088: public void setActionMap(ActionMap actionMap) {
089: m_actionMap = actionMap;
090: }
091:
092: public InputMap getInputMap() {
093: return m_inputMap;
094: }
095:
096: public InputMap ensureInputMap() {
097: if (m_inputMap == null) {
098: m_inputMap = new InputMap();
099: }
100:
101: return m_inputMap;
102: }
103:
104: public void setInputMap(InputMap inputMap) {
105: m_inputMap = inputMap;
106: }
107:
108: public void addActionBinding(Object binding, XAbstractAction action) {
109: ensureActionMap().put(binding, action);
110:
111: KeyStroke ks = action.getAccelerator();
112: if (ks != null) {
113: ensureInputMap().put(ks, binding);
114: }
115: }
116:
117: public XTreeModel getModel() {
118: TreeNode 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 e) {/**/
134: }
135:
136: public void nodeClicked(MouseEvent me) {/**/
137: }
138:
139: protected void nodeChanged() {
140: DefaultTreeModel model = getModel();
141: if (model != null) {
142: model.nodeChanged(this );
143: }
144: }
145:
146: protected void nodeStructureChanged() {
147: DefaultTreeModel model = getModel();
148: if (model != null) {
149: model.nodeStructureChanged(this);
150: }
151: }
152: }
|