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 : TreeNodeX.java - tree control node data structure
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.io.Serializable;
023: import com.sun.portal.log.common.PortalLogger;
024:
025: /**
026: * This class describes an individual node in the tree which can contain
027: * other children nodes. The ob.tree.Node class further extends the TreeNodeX
028: * class to provide further methods to customize the nodes. Many of these methods
029: * are used internally and will not need to be manipulated by the developer.
030: * @see ob.tree.TreeBase
031: * @see ob.tree.Node
032: * @see ob.listbox.ListBox
033: */
034:
035: public class TreeNodeX extends TreeNode {
036:
037: int m_root_nFilterLevel = 0; // only valid in root node
038:
039: /**
040: * sets the filter level
041: * @param nLevel which level to filter
042: * @return whether filter was successful
043: */
044: public boolean setFilterLevel(int nLevel) {
045: ((TreeNodeX) getRoot()).m_root_nFilterLevel = nLevel;
046: return true;
047: }
048:
049: /**
050: * retrieves the filter level
051: * @return filter level as type int
052: */
053: public int getFilterLevel() {
054: return ((TreeNodeX) getRoot()).m_root_nFilterLevel;
055: }
056:
057: /**
058: * retrieves the unfiltered distance from the root
059: * @return unfiltered distance as type int
060: */
061: public int getUnfilteredDistanceFromRoot() {
062: int w;
063: TreeNode pNode = m_pParent;
064:
065: for (w = 0; pNode != null; w++)
066: pNode = pNode.m_pParent;
067:
068: return w;
069: }
070:
071: /**
072: * retrieves the parent node
073: * @return parent node as type TreeNode
074: */
075: public TreeNode getParent() {
076: if (getFilterLevel() > 0 && m_pParent != null) {
077: if (getUnfilteredDistanceFromRoot() == (getFilterLevel() + 1)) {
078: return m_pParent.m_pParent;
079: }
080: }
081: return m_pParent;
082: }
083:
084: /**
085: * retrieves the next sibling node
086: * @return next sibling node as type TreeNode
087: */
088: public TreeNode getNextSibling() {
089: if (getFilterLevel() > 0) {
090: if (getUnfilteredDistanceFromRoot() == (getFilterLevel() + 1)) {
091: if (m_pNextSibling == null) {
092: TreeNode pNode = m_pParent;
093: if (pNode == null)
094: return null;
095: pNode = pNode.m_pNextSibling;
096: if (pNode == null)
097: return null;
098:
099: pNode = pNode.m_pFirstChild;
100: return pNode;
101: }
102: }
103: }
104: return m_pNextSibling;
105:
106: }
107:
108: /**
109: * retrieves the previous sibling node
110: * @return previous sibling as type TreeNode
111: */
112: public TreeNode getPrevSibling() {
113: if (getFilterLevel() > 0) {
114: if (getUnfilteredDistanceFromRoot() == (getFilterLevel() + 1)) {
115: if (m_pPrevSibling == null) {
116: TreeNode pNode = m_pParent;
117: if (pNode == null)
118: return null;
119: pNode = pNode.m_pPrevSibling;
120: if (pNode == null)
121: return null;
122:
123: pNode = pNode.m_pFirstChild;
124: if (pNode == null)
125: return null;
126: while (pNode.m_pNextSibling != null)
127: pNode = pNode.m_pNextSibling;
128:
129: return pNode;
130: }
131: }
132: }
133: return m_pPrevSibling;
134: }
135:
136: /**
137: * gets the first child node
138: * @return first child as type TreeNode
139: */
140: public TreeNode getFirstChild() {
141: if (m_pFirstChild != null && getFilterLevel() > 0) {
142: if (getUnfilteredDistanceFromRoot() == (getFilterLevel() - 1))
143: return m_pFirstChild.m_pFirstChild;
144: }
145:
146: return m_pFirstChild;
147: }
148: }
|