svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / filterPanel / filterQueryPanel / jLabelAsCell / DefaultListModelForJLabelAsCell.java @ 40561
History | View | Annotate | Download (8.24 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.filterPanel.filterQueryPanel.jLabelAsCell; |
25 |
|
26 |
import java.io.Serializable; |
27 |
|
28 |
import javax.swing.DefaultListModel; |
29 |
import javax.swing.JLabel; |
30 |
|
31 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
32 |
*
|
33 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
34 |
*
|
35 |
* This program is free software; you can redistribute it and/or
|
36 |
* modify it under the terms of the GNU General Public License
|
37 |
* as published by the Free Software Foundation; either version 2
|
38 |
* of the License, or (at your option) any later version.
|
39 |
*
|
40 |
* This program is distributed in the hope that it will be useful,
|
41 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
42 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
43 |
* GNU General Public License for more details.
|
44 |
*
|
45 |
* You should have received a copy of the GNU General Public License
|
46 |
* along with this program; if not, write to the Free Software
|
47 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
48 |
*
|
49 |
* For more information, contact:
|
50 |
*
|
51 |
* Generalitat Valenciana
|
52 |
* Conselleria d'Infraestructures i Transport
|
53 |
* Av. Blasco Ib??ez, 50
|
54 |
* 46010 VALENCIA
|
55 |
* SPAIN
|
56 |
*
|
57 |
* +34 963862235
|
58 |
* gvsig@gva.es
|
59 |
* www.gvsig.gva.es
|
60 |
*
|
61 |
* or
|
62 |
*
|
63 |
* IVER T.I. S.A
|
64 |
* Salamanca 50
|
65 |
* 46005 Valencia
|
66 |
* Spain
|
67 |
*
|
68 |
* +34 963163400
|
69 |
* dac@iver.es
|
70 |
*/
|
71 |
|
72 |
|
73 |
/**
|
74 |
* This class reimplements the "contains()" method of "DefaultListModel" for
|
75 |
*
|
76 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
77 |
*
|
78 |
*/
|
79 |
public class DefaultListModelForJLabelAsCell extends DefaultListModel implements Serializable { |
80 |
private static final long serialVersionUID = 4410627738805243864L; |
81 |
|
82 |
/**
|
83 |
* Represents the start index of the group of not loaded values (that should be after the group of loaded values)
|
84 |
* -2 -> if elements aren't grouped (in two lists: first for loaded, after for not loaded)
|
85 |
* -1 -> if there isn't elements
|
86 |
* 0 -> if there are only not loaded elements
|
87 |
* = (capacity() -1) -> if there are only loaded elements
|
88 |
*/
|
89 |
private int startIndexOfNotLoadedValues; |
90 |
|
91 |
/**
|
92 |
* Default constructor without parameters
|
93 |
*/
|
94 |
public DefaultListModelForJLabelAsCell() {
|
95 |
super();
|
96 |
startIndexOfNotLoadedValues = -1;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Method that returns true if there is a inner JLabel that has as inner text the same text as 'patternText'
|
101 |
*
|
102 |
* @param patternText
|
103 |
* @return A boolean value
|
104 |
*/
|
105 |
public boolean containsJLabelText(String patternText) { |
106 |
for (int i = 0; i < super.getSize(); i++) { |
107 |
if (((JLabel)super.get(i)).getText().compareTo(patternText) == 0) |
108 |
return true; |
109 |
} |
110 |
|
111 |
return false; |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Returns the position of first JLabel that has as text the same text as 'patternText', or -1 if no JLabel has that text
|
116 |
*
|
117 |
* @param patternText An String
|
118 |
* @return An integer value
|
119 |
*/
|
120 |
public int getIndexOfJLabelText(String patternText) { |
121 |
for (int i = 0; i < super.getSize(); i++) { |
122 |
if (((JLabel)super.get(i)).getText().compareTo(patternText) == 0) |
123 |
return i;
|
124 |
} |
125 |
|
126 |
return -1; // If not found |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Replaces first element which has the text 'patternText' to a JLabelValueLoaded new one element with the same text
|
131 |
*
|
132 |
* @param patternText Text of the component
|
133 |
*/
|
134 |
public void changeElementThatHasTextToJLabelLoadedValue(String patternText) { |
135 |
int index = getIndexOfJLabelText(patternText);
|
136 |
|
137 |
if (index != -1) |
138 |
super.set(index, new JLabelAsCellValueLoaded(patternText)); |
139 |
} |
140 |
|
141 |
/**
|
142 |
* Sets all elements to 'JLabelValueNotLoaded'
|
143 |
*/
|
144 |
public void setAllElementsToNotLoaded() { |
145 |
if (startIndexOfNotLoadedValues == -1) { |
146 |
for (int i = 0; i < super.getSize(); i++) { |
147 |
if (super.get(i) instanceof JLabelAsCellValueLoaded) { |
148 |
JLabelAsCellValueNotLoaded jL = new JLabelAsCellValueNotLoaded(((JLabelAsCellValueLoaded)super.get(i)).getText()); |
149 |
super.remove(i);
|
150 |
super.add(i, jL);///// REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' ///// |
151 |
} |
152 |
} |
153 |
} |
154 |
else {
|
155 |
for (int i = 0; i < startIndexOfNotLoadedValues; i++) { |
156 |
if (super.get(i) instanceof JLabelAsCellValueLoaded) { |
157 |
JLabelAsCellValueNotLoaded jL = new JLabelAsCellValueNotLoaded(((JLabelAsCellValueLoaded)super.get(i)).getText()); |
158 |
super.set(i, jL); // replacement |
159 |
} |
160 |
} |
161 |
} |
162 |
|
163 |
startIndexOfNotLoadedValues = 0;
|
164 |
} |
165 |
|
166 |
///// REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' /////
|
167 |
|
168 |
/*
|
169 |
* (non-Javadoc)
|
170 |
* @see javax.swing.DefaultListModel#clear()
|
171 |
*/
|
172 |
public void clear() { |
173 |
super.clear();
|
174 |
startIndexOfNotLoadedValues = -1;
|
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
* @see javax.swing.DefaultListModel#insertElementAt(java.lang.Object, int)
|
180 |
*/
|
181 |
public void insertElementAt(Object obj, int index) { |
182 |
super.insertElementAt(obj, index);
|
183 |
|
184 |
if ((obj instanceof JLabelAsCellValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
185 |
startIndexOfNotLoadedValues = index; |
186 |
} |
187 |
|
188 |
/*
|
189 |
* (non-Javadoc)
|
190 |
* @see javax.swing.DefaultListModel#remove(int)
|
191 |
*/
|
192 |
public Object remove(int index) { |
193 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
194 |
startIndexOfNotLoadedValues = -1;
|
195 |
} |
196 |
|
197 |
return super.remove(index); |
198 |
} |
199 |
|
200 |
/*
|
201 |
* (non-Javadoc)
|
202 |
* @see javax.swing.DefaultListModel#removeAllElements()
|
203 |
*/
|
204 |
public void removeAllElements() { |
205 |
super.removeAllElements();
|
206 |
startIndexOfNotLoadedValues = -1;
|
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see javax.swing.DefaultListModel#removeElement(java.lang.Object)
|
212 |
*/
|
213 |
public boolean removeElement(Object obj) { |
214 |
int index = super.indexOf(obj); |
215 |
|
216 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
217 |
startIndexOfNotLoadedValues = -1;
|
218 |
} |
219 |
|
220 |
return super.removeElement(obj); |
221 |
} |
222 |
|
223 |
/*
|
224 |
* (non-Javadoc)
|
225 |
* @see javax.swing.DefaultListModel#removeElementAt(int)
|
226 |
*/
|
227 |
public void removeElementAt(int index) { |
228 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
229 |
startIndexOfNotLoadedValues = -1;
|
230 |
} |
231 |
|
232 |
super.removeElementAt(index);
|
233 |
} |
234 |
|
235 |
/*
|
236 |
* (non-Javadoc)
|
237 |
* @see javax.swing.DefaultListModel#removeRange(int, int)
|
238 |
*/
|
239 |
public void removeRange(int fromIndex, int toIndex) { |
240 |
super.removeRange(fromIndex, toIndex);
|
241 |
|
242 |
// Try to find any element of type 'JLabelNotLoadedValue'
|
243 |
for (int i = 0; i < super.capacity(); i++) { |
244 |
if (super.get(i) instanceof JLabelAsCellValueNotLoaded) { |
245 |
if ( ( (i == (super.capacity() -1) || (i < (super.capacity() -1)) && (super.get(super.capacity() -1) instanceof JLabelAsCellValueNotLoaded) ) ) ) |
246 |
startIndexOfNotLoadedValues = i; |
247 |
else
|
248 |
startIndexOfNotLoadedValues = -1;
|
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
/*
|
254 |
* (non-Javadoc)
|
255 |
* @see javax.swing.DefaultListModel#set(int, java.lang.Object)
|
256 |
*/
|
257 |
public Object set(int index, Object element) { |
258 |
if ((element instanceof JLabelAsCellValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
259 |
startIndexOfNotLoadedValues = index; |
260 |
|
261 |
return super.set(index, element); |
262 |
} |
263 |
|
264 |
/*
|
265 |
* (non-Javadoc)
|
266 |
* @see javax.swing.DefaultListModel#setElementAt(java.lang.Object, int)
|
267 |
*/
|
268 |
public void setElementAt(Object obj, int index) { |
269 |
super.setElementAt(obj, index);
|
270 |
|
271 |
if ((obj instanceof JLabelAsCellValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
272 |
startIndexOfNotLoadedValues = index; |
273 |
} |
274 |
|
275 |
///// END REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' /////
|
276 |
} |