svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectionSupport.java @ 4939
History | View | Annotate | Download (4.61 KB)
1 | 1100 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 461 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 2183 | fernando | import com.iver.cit.gvsig.fmap.operations.selection.LinkSelectionListener; |
44 | 1034 | vcaballero | import com.iver.utiles.XMLEntity; |
45 | |||
46 | 461 | fernando | import java.util.ArrayList; |
47 | import java.util.Iterator; |
||
48 | |||
49 | |||
50 | 1034 | vcaballero | /**
|
51 | * Clase que gestiona las operaci?nes sobre la selecci?n.
|
||
52 | *
|
||
53 | * @author Vicente Caballero Navarro
|
||
54 | */
|
||
55 | 461 | fernando | public class SelectionSupport { |
56 | 683 | fernando | private FBitSet selection = new FBitSet(); |
57 | 1034 | vcaballero | private ArrayList listeners = new ArrayList(); |
58 | |||
59 | 461 | fernando | /**
|
60 | 1034 | vcaballero | * Inserta una nueva selecci?n.
|
61 | *
|
||
62 | * @param selection FBitSet con la selecci?n.
|
||
63 | 461 | fernando | */
|
64 | 1034 | vcaballero | public void setSelection(FBitSet selection) { |
65 | 461 | fernando | this.selection = selection;
|
66 | 1076 | fjp | fireSelectionEvents(); |
67 | 461 | fernando | } |
68 | 1034 | vcaballero | |
69 | /**
|
||
70 | * Devuelve un FBitSet con los ?ndices de los elementos seleccionados.
|
||
71 | *
|
||
72 | * @return FBitSet.
|
||
73 | */
|
||
74 | public FBitSet getSelection() {
|
||
75 | 461 | fernando | return selection;
|
76 | } |
||
77 | 1034 | vcaballero | |
78 | /**
|
||
79 | * Devuelve true si el elemento est? seleccionado.
|
||
80 | *
|
||
81 | * @param recordIndex ?ndice del registro.
|
||
82 | *
|
||
83 | * @return True si est? seleccionado.
|
||
84 | */
|
||
85 | public boolean isSelected(int recordIndex) { |
||
86 | 461 | fernando | return selection.get(recordIndex);
|
87 | } |
||
88 | 1034 | vcaballero | |
89 | /**
|
||
90 | * Elimina la selecci?n.
|
||
91 | */
|
||
92 | public void clearSelection() { |
||
93 | 2554 | jmorell | this.selection.clear();
|
94 | fireSelectionEvents(); |
||
95 | } |
||
96 | 461 | fernando | |
97 | 1034 | vcaballero | /**
|
98 | * A?ade un SelectionListener al ArrayList de Listeners.
|
||
99 | *
|
||
100 | * @param listener SelectionListener a a?adir.
|
||
101 | */
|
||
102 | 461 | fernando | public void addSelectionListener(SelectionListener listener) { |
103 | listeners.add(listener); |
||
104 | } |
||
105 | |||
106 | 1034 | vcaballero | /**
|
107 | * Borra el SelectionListener que se le pasa como par?metro del ArrayList
|
||
108 | * de Listener.
|
||
109 | *
|
||
110 | * @param listener SlectionListener a borrar.
|
||
111 | */
|
||
112 | 461 | fernando | public void removeSelectionListener(SelectionListener listener) { |
113 | listeners.remove(listener); |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | 1034 | vcaballero | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
118 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
119 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
120 | * "r?faga" de eventos
|
||
121 | 461 | fernando | */
|
122 | public void fireSelectionEvents() { |
||
123 | for (Iterator iter = listeners.iterator(); iter.hasNext();) { |
||
124 | SelectionListener listener = (SelectionListener) iter.next(); |
||
125 | 1034 | vcaballero | |
126 | 461 | fernando | listener.selectionChanged(new SelectionEvent());
|
127 | } |
||
128 | } |
||
129 | 1034 | vcaballero | |
130 | /**
|
||
131 | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir un
|
||
132 | * objeto igual al actual.
|
||
133 | *
|
||
134 | * @return XMLEntity.
|
||
135 | */
|
||
136 | public XMLEntity getXMLEntity() {
|
||
137 | XMLEntity xml = new XMLEntity();
|
||
138 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
139 | 1034 | vcaballero | |
140 | if (selection != null) { |
||
141 | xml.putProperty("numBitSet", selection.cardinality());
|
||
142 | |||
143 | int n = 0; |
||
144 | |||
145 | for (int i = 0; i < selection.length(); i++) { |
||
146 | if (selection.get(i)) {
|
||
147 | xml.putProperty(String.valueOf(n), i);
|
||
148 | n++; |
||
149 | 581 | vcaballero | } |
150 | } |
||
151 | } |
||
152 | 1034 | vcaballero | |
153 | 581 | vcaballero | return xml;
|
154 | } |
||
155 | 1034 | vcaballero | |
156 | /**
|
||
157 | * A partir del XMLEntity reproduce la selecci?n.
|
||
158 | *
|
||
159 | * @param xml DOCUMENT ME!
|
||
160 | */
|
||
161 | public void setXMLEntity(XMLEntity xml) { |
||
162 | int numBitSet = xml.getIntProperty("numBitSet"); |
||
163 | |||
164 | if (numBitSet != 0) { |
||
165 | for (int i = 0; i < numBitSet; i++) { |
||
166 | selection.set(xml.getIntProperty(String.valueOf(i)));
|
||
167 | } |
||
168 | 581 | vcaballero | } |
169 | } |
||
170 | 2183 | fernando | |
171 | /**
|
||
172 | * A partir del XMLEntity reproduce la selecci?n.
|
||
173 | *
|
||
174 | * @param xml DOCUMENT ME!
|
||
175 | */
|
||
176 | public void setXMLEntity03(XMLEntity xml) { |
||
177 | int numBitSet = xml.getIntProperty("numBitSet"); |
||
178 | |||
179 | if (numBitSet != 0) { |
||
180 | for (int i = 0; i < numBitSet; i++) { |
||
181 | selection.set(xml.getIntProperty(String.valueOf(i)));
|
||
182 | } |
||
183 | } |
||
184 | } |
||
185 | |||
186 | public void removeLinkSelectionListener() { |
||
187 | for (int i=0;i<listeners.size();i++){ |
||
188 | if (listeners.get(i) instanceof LinkSelectionListener) |
||
189 | listeners.remove(listeners.get(i)); |
||
190 | } |
||
191 | } |
||
192 | 461 | fernando | } |