001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.html.treeControl;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/treeControl/TreeNode.java $
024: //$Author: Dan $
025: //$Revision: 10 $
026: //$Modtime: 8/28/03 10:58a $
027: /////////////////////////
028:
029: import java.util.*;
030:
031: class TreeNode implements java.io.Serializable {
032: Integer _image;
033: Integer _expImage;
034: Integer _index;
035: Integer _level;
036: String _text;
037: String _URL;
038: String _imageURL;
039: boolean _expanded = false;
040: TreeNode _parent, _firstChild, _lastChild, _nextNode, _priorNode;
041: boolean _hasChildren = false;
042: Vector _additionalImages;
043: Vector _additionalText;
044: Vector _additionalURL;
045: Object _keyValue;
046: boolean _selected = false;
047: boolean _selectable = true;
048: int _dsRowNo = -1;
049:
050: TreeNode(int image, int expImage, String text, String url,
051: String imageURL, Object key) {
052: super ();
053: _image = new Integer(image);
054: _expImage = new Integer(expImage);
055: _text = text;
056: _URL = url;
057: _expanded = false;
058: _imageURL = imageURL;
059: _keyValue = key;
060: }
061:
062: void setImages(int image, int expImage) {
063: _image = new Integer(image);
064: _expImage = new Integer(expImage);
065: }
066:
067: int addAdditionalImage(int imageNo, String text, String url) {
068: if (_additionalImages == null) {
069: _additionalImages = new Vector();
070: _additionalText = new Vector();
071: _additionalURL = new Vector();
072: }
073:
074: _additionalImages.addElement(new Integer(imageNo));
075: _additionalText.addElement(text);
076: _additionalURL.addElement(url);
077:
078: return (_additionalImages.size() - 1);
079: }
080:
081: boolean areThereChildren() {
082: return _hasChildren;
083: }
084:
085: void clearAdditionalImages() {
086: _additionalImages = null;
087: _additionalText = null;
088: }
089:
090: int getAdditionalImage(int index) {
091: return ((Integer) _additionalImages.elementAt(index))
092: .intValue();
093: }
094:
095: int getAdditionalImageCount() {
096: if (_additionalImages == null)
097: return 0;
098:
099: return _additionalImages.size();
100: }
101:
102: String getAdditionalText(int index) {
103: return (String) _additionalText.elementAt(index);
104: }
105:
106: String getAdditionalURL(int index) {
107: return (String) _additionalURL.elementAt(index);
108: }
109:
110: TreeNode getFirstChild() {
111: return _firstChild;
112: }
113:
114: int getHandle() {
115: return _index.intValue();
116: }
117:
118: int getImage() {
119: if (_expanded)
120: return _expImage.intValue();
121: else
122: return _image.intValue();
123: }
124:
125: String getImageURL() {
126: return _imageURL;
127: }
128:
129: Object getKey() {
130: return _keyValue;
131: }
132:
133: TreeNode getLastChild() {
134: return _lastChild;
135: }
136:
137: int getLevel() {
138: return _level.intValue();
139: }
140:
141: TreeNode getNextNode() {
142: return _nextNode;
143: }
144:
145: TreeNode getParent() {
146: return _parent;
147: }
148:
149: TreeNode getPriorNode() {
150: return _priorNode;
151: }
152:
153: boolean getSelectable() {
154: return _selectable;
155: }
156:
157: boolean getSelected() {
158: return _selected;
159: }
160:
161: String getText() {
162: return _text;
163: }
164:
165: String getURL() {
166: return _URL;
167: }
168:
169: boolean isExpanded() {
170: return _expanded;
171: }
172:
173: void reset() {
174: _parent = null;
175: _firstChild = null;
176: _lastChild = null;
177: _nextNode = null;
178: _priorNode = null;
179: }
180:
181: void setExpanded(boolean expanded) {
182: _expanded = expanded;
183: }
184:
185: void setFirstChild(TreeNode firstChild) {
186: _firstChild = firstChild;
187: }
188:
189: void setHandle(int handle) {
190: _index = new Integer(handle);
191: }
192:
193: void setHasChildren(boolean h) {
194: _hasChildren = h;
195: }
196:
197: void setKey(Object key) {
198: _keyValue = key;
199: }
200:
201: void setLastChild(TreeNode lastChild) {
202: _lastChild = lastChild;
203: }
204:
205: void setLevel(int level) {
206: _level = new Integer(level);
207: }
208:
209: void setNextNode(TreeNode nextNode) {
210: _nextNode = nextNode;
211: }
212:
213: void setParent(TreeNode parent) {
214: _parent = parent;
215: }
216:
217: void setPriorNode(TreeNode t) {
218: _priorNode = t;
219: }
220:
221: void setSelectable(boolean trueFalse) {
222: _selectable = trueFalse;
223: }
224:
225: void setSelected(boolean selected) {
226: _selected = selected;
227: }
228:
229: void setText(String text) {
230: _text = text;
231: }
232:
233: void setURL(String url) {
234: _URL = url;
235: }
236:
237: public int getDsRowNo() {
238: return _dsRowNo;
239: }
240:
241: public void setDsRowNo(int i) {
242: _dsRowNo = i;
243: }
244:
245: public String getFullPath() {
246: StringBuffer ret = new StringBuffer();
247: TreeNode n = this ;
248: if (_firstChild == null)
249: n = _parent;
250:
251: while (n != null) {
252: ret.insert(0, n.getText());
253: ret.insert(0, "|");
254: n = n.getParent();
255: }
256: ret.insert(0, new Integer(getLevel()).toString());
257: return ret.toString();
258: }
259:
260: }
|