Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / PrimitiveTreeNode.java
1 package jde.debugger.gui;
2
3 import java.util.Enumeration;
4 import java.util.Vector;
5 import javax.swing.tree.DefaultTreeModel;
6 import javax.swing.tree.TreeNode;
7
8 import com.sun.jdi.PrimitiveType;
9 import com.sun.jdi.PrimitiveValue;
10 import com.sun.jdi.Value;
11 import jde.debugger.JDEException;
12
13
14
15 /** A TreeNode for primitive variables.
16  * @author <a href="mailto:udalrich@carolingia.org">Troy Daniels</a>
17  * @since 2.3.2
18  * @version $Revision: 1.2 $
19  */
20 class PrimitiveTreeNode extends LVTreeNode {
21   /**  Constructor
22    * @param name The name of the variable
23    * @param type The Type of the variable
24    * @param val The value of the variable.
25    * @param model The TreeModel.
26    */
27   protected PrimitiveTreeNode(String name,
28                               String typeName,
29                               Value val,
30                               DefaultTreeModel model) throws JDEException {
31     super(name, typeName, val, model);
32     if (!(m_type instanceof PrimitiveType))
33       throw new JDEException("PrimitiveTreeNode received non-primitive Type " + m_type.name());
34     if (!(val instanceof PrimitiveValue))
35       throw new JDEException("PrimitiveTreeNode received non-primitive value " + val.type().name());
36     m_value = val;
37   }
38
39
40   /** Get the number of children.
41    * @return Zero, since primitives do not have children.
42    */
43   public int getChildCount() {
44     return 0;
45   }
46
47   /** Returns if the node allows children
48    * @return false, since primitives do not have children. */
49   public boolean getAllowsChildren() {
50     return false;
51   }
52
53   /** Get the child at the given index.
54    * @throws IllegalArgumentException since primitives do not have children. */
55   public TreeNode getChildAt(int index) {
56     throw new IllegalArgumentException("Attempt to create a child of a Primitive");
57   }
58
59   /** Get the index of the tree node
60    * @return -1 since primitives do not have children */
61   public int getIndex(TreeNode node) { return -1; }
62
63   /** Get a string to represent the value of the variable */
64   String getValue() {
65     return m_value.toString();
66   }
67
68   /** Asks if the node is a leaf node */
69   public boolean isLeaf() { return true; }
70
71   /** Returns an enumeration of the children */
72   public Enumeration children() {
73     return new Vector().elements();
74   }
75
76   /** Called when the value changes
77    * @param val The new value
78    */
79   void valueChanged(Value val) {
80     m_value = val;
81   }
82
83   private Value m_value;
84 }