KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > util > TreeNodeList


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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
package org.columba.mail.gui.tree.util;
17
18 import java.io.File JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.StringTokenizer JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import javax.swing.tree.TreePath JavaDoc;
24
25
26 public class TreeNodeList {
27     protected List JavaDoc list;
28
29     public TreeNodeList() {
30         list = new Vector JavaDoc();
31     }
32
33     public TreeNodeList(Vector JavaDoc v) {
34         list = v;
35     }
36
37     public TreeNodeList(String JavaDoc[] str) {
38         for (int i = 0; i < str.length; i++) {
39             list.add(str[i]);
40         }
41     }
42
43     public TreeNodeList(String JavaDoc s) {
44         list = new Vector JavaDoc();
45
46         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(s, "/");
47
48         while (tok.hasMoreTokens()) {
49             String JavaDoc next = tok.nextToken();
50
51             list.add(next);
52         }
53     }
54
55     public TreePath JavaDoc getTreePath() {
56         TreePath JavaDoc path = new TreePath JavaDoc(get(0));
57
58         for (int i = 1; i < count(); i++) {
59             Object JavaDoc o = get(i);
60             path = path.pathByAddingChild(o);
61         }
62
63         return path;
64     }
65
66     public void removeElementAt(int index) {
67         list.remove(index);
68     }
69
70     public List JavaDoc getList() {
71         return list;
72     }
73
74     public void setElementAt(String JavaDoc s, int i) {
75         list.set(i, s);
76     }
77
78     public void add(String JavaDoc s) {
79         list.add(s);
80     }
81
82     public String JavaDoc get(int i) {
83         if (count() > 0) {
84             return (String JavaDoc) list.get(i);
85         } else {
86             return "";
87         }
88     }
89
90     public int count() {
91         return list.size();
92     }
93
94     public void clear() {
95         list.clear();
96     }
97
98     public String JavaDoc lastElement() {
99         return (String JavaDoc) list.get(list.size() - 1);
100     }
101
102     public void removeLastElement() {
103         list.remove(list.size() - 1);
104     }
105
106     public boolean equals(TreeNodeList v) {
107         String JavaDoc s1;
108         String JavaDoc s2;
109
110         if ((count() == 0) && (v.count() == 0)) {
111             return true;
112         }
113
114         if (count() != v.count()) {
115             return false;
116         }
117
118         for (int i = 0; i < count(); i++) {
119             s1 = get(i);
120             s2 = v.get(i);
121
122             if (!s1.equals(s2)) {
123                 return false;
124             }
125         }
126
127         return true;
128     }
129
130     public File JavaDoc getFile(File JavaDoc programDirectory) {
131         File JavaDoc file = programDirectory;
132
133         for (int i = 0; i < count(); i++) {
134             file = new File JavaDoc(file, get(i));
135         }
136
137         return file;
138     }
139 }
140
Popular Tags