001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.tree.util;
017:
018: import java.io.File;
019: import java.util.List;
020: import java.util.StringTokenizer;
021: import java.util.Vector;
022:
023: import javax.swing.tree.TreePath;
024:
025: public class TreeNodeList {
026: protected List list;
027:
028: public TreeNodeList() {
029: list = new Vector();
030: }
031:
032: public TreeNodeList(Vector v) {
033: list = v;
034: }
035:
036: public TreeNodeList(String[] str) {
037: for (int i = 0; i < str.length; i++) {
038: list.add(str[i]);
039: }
040: }
041:
042: public TreeNodeList(String s) {
043: list = new Vector();
044:
045: StringTokenizer tok = new StringTokenizer(s, "/");
046:
047: while (tok.hasMoreTokens()) {
048: String next = tok.nextToken();
049:
050: list.add(next);
051: }
052: }
053:
054: public TreePath getTreePath() {
055: TreePath path = new TreePath(get(0));
056:
057: for (int i = 1; i < count(); i++) {
058: Object o = get(i);
059: path = path.pathByAddingChild(o);
060: }
061:
062: return path;
063: }
064:
065: public void removeElementAt(int index) {
066: list.remove(index);
067: }
068:
069: public List getList() {
070: return list;
071: }
072:
073: public void setElementAt(String s, int i) {
074: list.set(i, s);
075: }
076:
077: public void add(String s) {
078: list.add(s);
079: }
080:
081: public String get(int i) {
082: if (count() > 0) {
083: return (String) list.get(i);
084: } else {
085: return "";
086: }
087: }
088:
089: public int count() {
090: return list.size();
091: }
092:
093: public void clear() {
094: list.clear();
095: }
096:
097: public String lastElement() {
098: return (String) list.get(list.size() - 1);
099: }
100:
101: public void removeLastElement() {
102: list.remove(list.size() - 1);
103: }
104:
105: public boolean equals(TreeNodeList v) {
106: String s1;
107: String s2;
108:
109: if ((count() == 0) && (v.count() == 0)) {
110: return true;
111: }
112:
113: if (count() != v.count()) {
114: return false;
115: }
116:
117: for (int i = 0; i < count(); i++) {
118: s1 = get(i);
119: s2 = v.get(i);
120:
121: if (!s1.equals(s2)) {
122: return false;
123: }
124: }
125:
126: return true;
127: }
128:
129: public File getFile(File programDirectory) {
130: File file = programDirectory;
131:
132: for (int i = 0; i < count(); i++) {
133: file = new File(file, get(i));
134: }
135:
136: return file;
137: }
138: }
|