01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.mail.folder;
18:
19: import java.util.ArrayList;
20: import java.util.Enumeration;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: import javax.swing.tree.TreeNode;
25:
26: /**
27: * Iterate through all children using depth-first search.
28: *
29: * @author tstich
30: */
31: public class FolderChildrenIterator {
32: private List folderList;
33: Iterator folderIterator;
34:
35: public FolderChildrenIterator(IMailFolder parent) {
36: folderList = new ArrayList();
37: Enumeration childEnum = parent.children();
38: while (childEnum.hasMoreElements()) {
39: appendAllChildren(folderList, (TreeNode) childEnum
40: .nextElement());
41: }
42:
43: folderIterator = folderList.iterator();
44: }
45:
46: private void appendAllChildren(List folderList, TreeNode folder) {
47: folderList.add(folder);
48: if (folder.getChildCount() > 0) {
49: Enumeration childEnum = folder.children();
50: while (childEnum.hasMoreElements()) {
51: appendAllChildren(folderList, (TreeNode) childEnum
52: .nextElement());
53: }
54: }
55: }
56:
57: public boolean hasMoreChildren() {
58: return folderIterator.hasNext();
59: }
60:
61: public AbstractFolder nextChild() {
62: return (AbstractFolder) folderIterator.next();
63: }
64:
65: }
|