001: /*
002: * Stingray Software Objective Blend
003: * Copyright (C) 1996 Stingray Software, Inc.
004: * All Rights Reserved
005: *
006: * This source code is only intended as a supplement to
007: * the Stingray Objective Blend product. See the Objective
008: * Blend html help documentation for detailed information regarding
009: * using OB classes.
010: *
011: * Author : Kerry Smith
012: * Description : Node.java - class used to manipulate an individual node in the tree
013: *
014: * CHANGELOG:
015: * 7/09/96 LFW Created
016: * 3/12/97 JDK1.1
017: *
018: */
019:
020: package ob.tree;
021:
022: import java.awt.*;
023: import com.sun.portal.log.common.PortalLogger;
024: import java.util.*;
025: import ob.listbox.*;
026:
027: /**
028: * The Node class is used to describe various properties associated with an individual
029: * level of the tree. It inherits from TreeNodeX and TreeNode to provide much of the
030: * sibling/parent node navigation. The Node class itself is responsible for many of the
031: * properties of the node itself
032: * @see ob.tree.TreeNodeX
033: * @see ob.tree.TreeNode
034: * @see ob.tree.TreeBase
035: */
036:
037: public class Node extends TreeNodeX {
038: //boolean m_bHangingIndent;
039: //String m_strBeforeIndent;
040: //String m_strAfterIndent;
041: //int m_cxTextBeforeIndent;
042: boolean m_bVisible = false;
043: String m_pszText = null;
044: int m_nImage = -1;
045: int m_nExpandedImage = -1;
046: int m_nChildren = 0;
047: boolean m_bExpanded = false;
048: Font m_fonFont = null;
049: Vector m_arrTreeSubItems = new Vector();
050:
051: /**
052: * constructor
053: * @param label the label for the tree node
054: * @param image reference to the image displayed when the node is not expanded
055: * @param expImg reference to the image displayed when the node is expanded
056: */
057: public Node(String label, int image, int expImg) {
058: m_pszText = label;
059: m_nImage = image;
060: m_nExpandedImage = expImg;
061: }
062:
063: /**
064: * appends a sub item to the node. In a multiple column tree control,
065: * the leftmost column is the "main" item, while individual items can be
066: * stored in the columns to the right as subitems.
067: * @param s the String to create the subitem with
068: */
069: public void addSubItem(String s) {
070: m_arrTreeSubItems.addElement(new ListSubItem(s));
071: }
072:
073: /**
074: * retrieves all the subitems of the Node in a Vector list
075: * @return subitems as type Vector
076: */
077: public Vector getSubItems() {
078: return m_arrTreeSubItems;
079: }
080:
081: /**
082: * adds a new sub item to the node
083: * @param s subitem to add
084: * @see ob.listbox.ListSubItem
085: */
086: public void addSubItem(ListSubItem s) {
087: m_arrTreeSubItems.addElement(s);
088: }
089:
090: ///BINA
091: /// These methods were added to add subitems of machine to the
092: /// array and removing those by the parent treeitem
093: public void addSubItem(Node item) {
094: m_arrTreeSubItems.addElement(item);
095: }
096:
097: public void removeSubItem(int nIndex) {
098: m_arrTreeSubItems.removeElementAt(nIndex);
099: }
100:
101: public void removeSubItem(Node item) {
102: m_arrTreeSubItems.removeElement(item);
103: }
104:
105: public void removeAllSubItems() {
106: m_arrTreeSubItems.removeAllElements();
107: }
108:
109: ///BINA
110:
111: /**
112: * constructor
113: */
114: public Node() {
115: this ("", -1, -1);
116: }
117:
118: /**
119: * retrieves the font associated with the node
120: * @return node font as type Font
121: */
122: public Font getFont() {
123: return m_fonFont;
124: }
125:
126: /**
127: * sets the font associated with the node
128: * @param f font to set for the node
129: */
130: public void setFont(Font f) {
131: m_fonFont = f;
132: }
133:
134: /**
135: * sets the text for the node
136: * @param s text as type String
137: */
138: public void setText(String s) {
139: m_pszText = s;
140:
141: }
142:
143: /**
144: * sets the visible state of the node
145: * @param bVisible true if item should be visible, otherwise false
146: */
147: public void setVisible(boolean bVisible) {
148: m_bVisible = bVisible;
149: }
150:
151: /**
152: * retrieves the text of the node
153: * @return text as type String
154: */
155: public String getText() {
156:
157: return m_pszText;
158: }
159:
160: /**
161: * sets the unexpanded image
162: * @param i reference to the unexpanded image
163: */
164: public void setImage(int i) {
165: m_nImage = i;
166: }
167:
168: /**
169: * retrieves the current image displayed
170: * @return reference to the currently displayed image as type int
171: */
172: public int getImage() {
173: if (isExpanded())
174: return m_nExpandedImage;
175: return m_nImage;
176: }
177:
178: /**
179: * sets the reference to the expanded image
180: * @param i reference to the expanded image
181: */
182: public void setExpandedImage(int i) {
183: m_nExpandedImage = i;
184: }
185:
186: /**
187: * retrieves the expanded image reference
188: * @return expanded image reference as type int
189: */
190: public int getExpandedImage() {
191: return m_nExpandedImage;
192: }
193:
194: /**
195: * determines whether the node is currently expanded or not
196: * @return true if expanded, otherwise false
197: */
198: public boolean isExpanded() {
199: return m_bExpanded;
200: }
201:
202: /**
203: * expands the node if currently closed, otherwise collapses
204: * @param bExpand true if you wish to expand, otherwise collapse
205: */
206: public void expand(boolean bExpand) {
207: if (bExpand)
208: m_bExpanded = true;
209: else
210: m_bExpanded = false;
211: }
212:
213: /**
214: * determines whether the node is currently visible
215: * @return true if visible, otherwise false
216: */
217: boolean isVisible() {
218: // assume visible until proved otherwise;
219: Node pNode = this ;
220: if (!m_bVisible)
221: return false;
222: while (pNode.getParent() != null) {
223: pNode = (Node) pNode.getParent();
224: if (!pNode.isExpanded() || !pNode.m_bVisible)
225: return false;
226: }
227: return true;
228: }
229:
230: ///// added by BINA
231: public Node getNodeChild(int index) {
232: int nChild = m_arrTreeSubItems.size();
233: if (index >= 0 && index < nChild) {
234: return (Node) m_arrTreeSubItems.elementAt(index);
235: } else {
236: return null;
237: }
238: }
239:
240: ///// added by BINA
241: }
|