01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2002, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program is distributed in the hope that it will be useful,
10: // but WITHOUT ANY WARRANTY; without even the implied warranty of
11: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: // GNU General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20: package com.salmonllc.html.treeControl;
21:
22: /////////////////////////
23: //$Archive: /JADE/SourceCode/com/salmonllc/html/treeControl/TreeEnumerator.java $
24: //$Author: Dan $
25: //$Revision: 8 $
26: //$Modtime: 10/30/02 2:58p $
27: /////////////////////////
28:
29: import java.util.*;
30:
31: /**
32: * Enumerates through all the items on a tree
33: */
34: public class TreeEnumerator implements java.util.Enumeration {
35: Vector _list;
36: int _index = 0;
37:
38: /**
39: * Creates a new enumerator
40: */
41:
42: public TreeEnumerator(Vector items) {
43: _list = items;
44: }
45:
46: /**
47: * Returns the handle of the current element
48: */
49:
50: public int getHandle() {
51: return (_index - 1);
52: }
53:
54: /**
55: * Returns true if there are more elements in the enumeration.
56: */
57:
58: public boolean hasMoreElements() {
59: while (true) {
60: if (_index >= _list.size())
61: return false;
62:
63: if (_list.elementAt(_index) instanceof TreeNode)
64: return true;
65:
66: _index++;
67: }
68: }
69:
70: /**
71: * Returns the next element in the enumeration. It returns the key component for the tree node.
72: */
73:
74: public Object nextElement() {
75: TreeNode t = (TreeNode) _list.elementAt(_index);
76: _index++;
77: return t.getKey();
78: }
79: }
|