svn-gvsig-desktop / tags / v1_0_2_Build_909 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectionSupport.java @ 11150
History | View | Annotate | Download (4.65 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 | 8765 | jjdelcerro | if (!listeners.contains(listener))
|
104 | listeners.add(listener); |
||
105 | 461 | fernando | } |
106 | |||
107 | 1034 | vcaballero | /**
|
108 | * Borra el SelectionListener que se le pasa como par?metro del ArrayList
|
||
109 | * de Listener.
|
||
110 | *
|
||
111 | * @param listener SlectionListener a borrar.
|
||
112 | */
|
||
113 | 461 | fernando | public void removeSelectionListener(SelectionListener listener) { |
114 | listeners.remove(listener); |
||
115 | } |
||
116 | |||
117 | /**
|
||
118 | 1034 | vcaballero | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
119 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
120 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
121 | * "r?faga" de eventos
|
||
122 | 461 | fernando | */
|
123 | public void fireSelectionEvents() { |
||
124 | for (Iterator iter = listeners.iterator(); iter.hasNext();) { |
||
125 | SelectionListener listener = (SelectionListener) iter.next(); |
||
126 | 1034 | vcaballero | |
127 | 461 | fernando | listener.selectionChanged(new SelectionEvent());
|
128 | } |
||
129 | } |
||
130 | 1034 | vcaballero | |
131 | /**
|
||
132 | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir un
|
||
133 | * objeto igual al actual.
|
||
134 | *
|
||
135 | * @return XMLEntity.
|
||
136 | */
|
||
137 | public XMLEntity getXMLEntity() {
|
||
138 | XMLEntity xml = new XMLEntity();
|
||
139 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
140 | 1034 | vcaballero | |
141 | if (selection != null) { |
||
142 | xml.putProperty("numBitSet", selection.cardinality());
|
||
143 | |||
144 | int n = 0; |
||
145 | |||
146 | for (int i = 0; i < selection.length(); i++) { |
||
147 | if (selection.get(i)) {
|
||
148 | xml.putProperty(String.valueOf(n), i);
|
||
149 | n++; |
||
150 | 581 | vcaballero | } |
151 | } |
||
152 | } |
||
153 | 1034 | vcaballero | |
154 | 581 | vcaballero | return xml;
|
155 | } |
||
156 | 1034 | vcaballero | |
157 | /**
|
||
158 | * A partir del XMLEntity reproduce la selecci?n.
|
||
159 | *
|
||
160 | * @param xml DOCUMENT ME!
|
||
161 | */
|
||
162 | public void setXMLEntity(XMLEntity xml) { |
||
163 | int numBitSet = xml.getIntProperty("numBitSet"); |
||
164 | |||
165 | if (numBitSet != 0) { |
||
166 | for (int i = 0; i < numBitSet; i++) { |
||
167 | selection.set(xml.getIntProperty(String.valueOf(i)));
|
||
168 | } |
||
169 | 581 | vcaballero | } |
170 | } |
||
171 | 2183 | fernando | |
172 | /**
|
||
173 | * A partir del XMLEntity reproduce la selecci?n.
|
||
174 | *
|
||
175 | * @param xml DOCUMENT ME!
|
||
176 | */
|
||
177 | public void setXMLEntity03(XMLEntity xml) { |
||
178 | int numBitSet = xml.getIntProperty("numBitSet"); |
||
179 | |||
180 | if (numBitSet != 0) { |
||
181 | for (int i = 0; i < numBitSet; i++) { |
||
182 | selection.set(xml.getIntProperty(String.valueOf(i)));
|
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | |||
187 | public void removeLinkSelectionListener() { |
||
188 | for (int i=0;i<listeners.size();i++){ |
||
189 | if (listeners.get(i) instanceof LinkSelectionListener) |
||
190 | listeners.remove(listeners.get(i)); |
||
191 | } |
||
192 | } |
||
193 | 461 | fernando | } |