Source code: org/meowers/cide/edcide/EdCideTreeNode.java
1 /*
2 * GameDataTreeNode.java
3 *
4 * Created on January 19, 2002, 4:11 AM
5 */
6
7 package org.meowers.cide.edcide;
8
9 import org.meowers.cide.data.*;
10
11 import javax.swing.tree.*;
12
13 /**
14 * This class provides the structure of a tree node for the various types of
15 * <code>GameObject</code> data.
16 * @author Adam Miezianko
17 * @version %I%, %G%
18 */
19 public class EdCideTreeNode extends DefaultMutableTreeNode {
20
21 /** This stores the <code>GameObject</code> associated with the tree node
22 */
23 protected GameObject gameObj;
24 /**
25 * This is <code>true</code> when this tree node is a group of other nodes.
26 */
27 protected boolean group = false;
28 /**
29 * This specifies the type of <code>GameObject</code> stored under this
30 * node if we are a group.
31 */
32 protected int gameObjType = 0;
33 /**
34 * This is the name of the node when we are a group.
35 */
36 protected String name;
37
38 /**
39 * Creates a new <code>GameDataTreeNode</code> and sets the <code>
40 * GameObject</code> associated with this tree node to the one specified.
41 *
42 * @param gameObj the <code>GameObject</code> to associate with this tree
43 * node.
44 */
45 public EdCideTreeNode(GameObject gameObj) {
46 super (gameObj);
47 this.gameObj = gameObj;
48 }
49
50 /**
51 * Creates a new <code>GameDataTreeNode</code> that represents a group of
52 * objects.
53 *
54 * @param name the name of this group.
55 * @param gameObjType the type of <code>GameData</code> objects in this
56 * group.
57 */
58 public EdCideTreeNode(String name, int gameObjType) {
59 super (name);
60 group = true;
61 this.gameObjType = gameObjType;
62 this.name = name;
63 }
64
65 /**
66 * Returns the type of tree node this is or the type of objects in this
67 * group if this node is a group.
68 *
69 * @return the type of tree node or object type in this group.
70 */
71 public int getGameDataType() {
72 if (group == true) {
73 return gameObjType;
74 }
75 return gameObj.getType();
76 }
77
78 /**
79 * Returns the <code>GameObject</code> associated with this tree node, or
80 * <code>null</code> if this node is a group.
81 *
82 * @return the <code>GameObject</code> associated with this tree node, or
83 * <code>null</code> if this node is a group.
84 */
85 public GameObject getGameObject() {
86 return (group ? null : gameObj);
87 }
88
89 /**
90 * Used to determine if this node is a group or individual game object.
91 *
92 * @return <code>true</code> if this node is a group, <code>false</code>
93 * otherwise.
94 */
95 public boolean isGroup() {
96 return group;
97 }
98
99 /**
100 * Refreshes the text displayed in the tree to the current name of the
101 * <code>GameObject</code> associated with this tree node.
102 */
103 public void updateText() {
104 setUserObject(gameObj.getName());
105 }
106 }