KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > list > AddressbookListModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.gui.list;
19
20 import java.util.List JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import javax.swing.AbstractListModel JavaDoc;
24
25 import org.columba.addressbook.model.IBasicModelPartial;
26
27 /**
28  * @version 1.0
29  * @author
30  */

31
32 public class AddressbookListModel extends AbstractListModel JavaDoc {
33     private List JavaDoc<IBasicModelPartial> list;
34
35     private String JavaDoc patternString = "";
36
37     public AddressbookListModel() {
38         super();
39         list = new Vector JavaDoc<IBasicModelPartial>();
40
41     }
42
43     public Object JavaDoc getElementAt(int index) {
44         return (IBasicModelPartial) list.get(index);
45     }
46
47     public int getSize() {
48         return list.size();
49     }
50
51     public String JavaDoc getPatternString() {
52         return patternString;
53     }
54
55     public void setPatternString(String JavaDoc s) throws Exception JavaDoc {
56         patternString = s;
57
58         // manipulateModel(TableModelPlugin.STRUCTURE_CHANGE);
59
}
60
61     public void clear() {
62         list.clear();
63     }
64
65     public void addElement(IBasicModelPartial item) {
66         list.add(item);
67
68         int index = list.indexOf(item);
69
70         fireIntervalAdded(this, index, index);
71     }
72
73     public void setHeaderItemList(List JavaDoc<IBasicModelPartial> l) {
74
75         this.list = l;
76
77         fireContentsChanged(this, 0, list.size() - 1);
78     }
79
80     public IBasicModelPartial get(int i) {
81         return (IBasicModelPartial) list.get(i);
82     }
83
84     public boolean addItem(IBasicModelPartial header) {
85         boolean result1 = false;
86
87         Object JavaDoc o = header.getName();
88
89         if (o != null) {
90             if (o instanceof String JavaDoc) {
91                 String JavaDoc item = (String JavaDoc) o;
92
93                 // System.out.println("add item?:"+item);
94
item = item.toLowerCase();
95
96                 String JavaDoc pattern = getPatternString().toLowerCase();
97
98                 if (item.indexOf(pattern) != -1) {
99                     result1 = true;
100                 } else {
101                     result1 = false;
102                 }
103             } else {
104                 result1 = false;
105             }
106         } else {
107             result1 = false;
108         }
109
110         return result1;
111     }
112
113     public Object JavaDoc[] toArray() {
114         return list.toArray();
115     }
116
117     public void remove(int index) {
118         list.remove(index);
119         fireIntervalRemoved(this, index, index);
120     }
121
122     public void removeElement(IBasicModelPartial item) {
123         int index = list.indexOf(item);
124
125         remove(index);
126     }
127 }
128
Popular Tags