svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionManager.java @ 6192
History | View | Annotate | Download (7.09 KB)
1 | 4144 | fjp | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | import java.util.ArrayList; |
||
4 | 4421 | fjp | import java.util.logging.Logger; |
5 | 4144 | fjp | |
6 | 5014 | caballero | import com.iver.andami.PluginServices; |
7 | 4147 | fjp | import com.iver.cit.gvsig.fmap.MapControl; |
8 | 5063 | jorpiell | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
9 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
10 | 4144 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
11 | 5256 | caballero | import com.iver.cit.gvsig.fmap.layers.FLayers; |
12 | 4366 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
13 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
14 | import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
||
15 | 4144 | fjp | import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
16 | import com.iver.cit.gvsig.fmap.layers.LayerListener; |
||
17 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
18 | import com.iver.cit.gvsig.gui.View; |
||
19 | 4147 | fjp | import com.iver.cit.gvsig.layers.FactoryLayerEdited; |
20 | 4144 | fjp | import com.iver.cit.gvsig.layers.ILayerEdited; |
21 | 4366 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
22 | 4144 | fjp | |
23 | /**
|
||
24 | * @author fjp
|
||
25 | *
|
||
26 | 4366 | caballero | * El prop?sito de esta clase es centralizar el manejo de la
|
27 | 4144 | fjp | * edici?n. Aqu? podemos encontrar una lista con todas
|
28 | * los temas en edici?n, y las propiedades que sean globales
|
||
29 | * e interesantes a la hora de ponerse a editar.
|
||
30 | 4366 | caballero | * Por ejemplo, podemos poner aqu? el Grid que vamos a usar,
|
31 | 4144 | fjp | * el MapControl que tenemos asociado, etc, etc.
|
32 | * Tambi?n ser? el responsable de mantener una lista de
|
||
33 | 4366 | caballero | * listeners interesados en los eventos de edici?n, y
|
34 | 4144 | fjp | * de lanzar los eventos que necesitemos.
|
35 | 4366 | caballero | * Lo principal es una colecci?n de LayerEdited, y cada
|
36 | 4144 | fjp | * LayerEdited es un wrapper alrededor de un tema que guarda
|
37 | * las propiedades de la edici?n.
|
||
38 | 5014 | caballero | *
|
39 | 4834 | fjp | * Nuevo: Llevar aqu? el control de las tablas en edici?n tambi?n
|
40 | * y centralizar los listeners interesados en los eventos de edici?n.
|
||
41 | 4366 | caballero | *
|
42 | 4147 | fjp | * TODO: Poner todo lo referente al EditionManager dentro de una vista.
|
43 | * para permitir tener varias vistas con temas en edici?n
|
||
44 | 4366 | caballero | *
|
45 | 4144 | fjp | */
|
46 | 5227 | caballero | public class EditionManager implements LayerListener,LayerCollectionListener { |
47 | 4144 | fjp | private ArrayList editedLayers = new ArrayList(); |
48 | 4834 | fjp | private ArrayList editedTables = new ArrayList(); |
49 | 5014 | caballero | //private ArrayList activeLayerEdited = new ArrayList();
|
50 | 4147 | fjp | private MapControl mapCtrl = null; |
51 | 5014 | caballero | private ILayerEdited ile=null; |
52 | //private int idActiveLayer=0;
|
||
53 | 4366 | caballero | |
54 | |||
55 | 4147 | fjp | /**
|
56 | * @param lyr
|
||
57 | 4366 | caballero | * @return
|
58 | 4147 | fjp | */
|
59 | 4144 | fjp | public ILayerEdited getLayerEdited(FLayer lyr)
|
60 | { |
||
61 | ILayerEdited aux = null;
|
||
62 | for (int i=0; i < editedLayers.size(); i++) |
||
63 | { |
||
64 | aux = (ILayerEdited) editedLayers.get(i); |
||
65 | if (aux.getLayer() == lyr)
|
||
66 | return aux;
|
||
67 | } |
||
68 | return null; |
||
69 | } |
||
70 | 4366 | caballero | |
71 | 4144 | fjp | public void visibilityChanged(LayerEvent e) { |
72 | } |
||
73 | |||
74 | public void activationChanged(LayerEvent e) { |
||
75 | 5227 | caballero | if (e.getSource().isActive()){
|
76 | 5207 | caballero | ile=getLayerEdited(e.getSource()); |
77 | 5747 | fjp | if (PluginServices.getMDIManager().getActiveView() instanceof View) |
78 | { |
||
79 | View view=(View)PluginServices.getMDIManager().getActiveView(); |
||
80 | if (e.getSource().isEditing()){
|
||
81 | view.showConsole(); |
||
82 | }else{
|
||
83 | view.hideConsole(); |
||
84 | } |
||
85 | 5227 | caballero | } |
86 | |||
87 | } |
||
88 | 5210 | caballero | if (ile==null || ile.getLayer().equals(e.getSource())){ |
89 | 5014 | caballero | |
90 | 5207 | caballero | if (ile!=null && !ile.getLayer().isActive()) { |
91 | 5014 | caballero | VectorialLayerEdited lastVLE = (VectorialLayerEdited)ile; |
92 | lastVLE.activationLost(e); |
||
93 | 4366 | caballero | } |
94 | 5014 | caballero | if (e.getSource() instanceof FLyrVect) { |
95 | VectorialLayerEdited vle = null;
|
||
96 | vle=(VectorialLayerEdited)getLayerEdited(e.getSource()); |
||
97 | // for (int i = 0; i < editedLayers.size(); i++) {
|
||
98 | // vle = (VectorialLayerEdited) editedLayers.get(i);
|
||
99 | // if (vle.getLayer().equals(e.getSource())) {
|
||
100 | // idActiveLayer = i;
|
||
101 | ile=vle; |
||
102 | 5207 | caballero | if (getMapControl()!=null && vle!=null && vle.getLayer().isActive()){ |
103 | 5014 | caballero | getMapControl().setTool("cadtooladapter");
|
104 | vle.activationGained(e); |
||
105 | return;
|
||
106 | } |
||
107 | } |
||
108 | // }
|
||
109 | // idActiveLayer=-1;
|
||
110 | //ile=null;
|
||
111 | if (getMapControl()!=null){ |
||
112 | getMapControl().setTool("zoomIn");
|
||
113 | PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
||
114 | } |
||
115 | 5207 | caballero | } |
116 | 4144 | fjp | } |
117 | |||
118 | public void nameChanged(LayerEvent e) { |
||
119 | } |
||
120 | |||
121 | public void editionChanged(LayerEvent e) { |
||
122 | 4421 | fjp | Logger.global.info(e.toString());
|
123 | 4144 | fjp | ILayerEdited lyrEdit = getLayerEdited(e.getSource()); |
124 | 4366 | caballero | |
125 | 4144 | fjp | // Si no est? en la lista, comprobamos que est? en edici?n
|
126 | // y lo a?adimos
|
||
127 | if ((lyrEdit == null) && e.getSource().isEditing()) |
||
128 | { |
||
129 | 4147 | fjp | lyrEdit = FactoryLayerEdited.createLayerEdited(e.getSource()); |
130 | editedLayers.add(lyrEdit); |
||
131 | 5014 | caballero | if (getMapControl()!=null){ |
132 | getMapControl().setTool("cadtooladapter");
|
||
133 | CADExtension.setCADTool("_selection",true); |
||
134 | } |
||
135 | PluginServices.getMainFrame().setSelectedTool("_selection");
|
||
136 | //idActiveLayer = editedLayers.size() - 1;
|
||
137 | ile=getLayerEdited(e.getSource()); |
||
138 | 4487 | fjp | System.out.println("NUEVA CAPA EN EDICION: " + lyrEdit.getLayer().getName()); |
139 | 5014 | caballero | //activationChanged(e);
|
140 | |||
141 | 4834 | fjp | // Ponemos el resto de temas desactivados
|
142 | if (mapCtrl != null) |
||
143 | mapCtrl.getMapContext().getLayers().setActive(false);
|
||
144 | // y activamos el nuevo.
|
||
145 | e.getSource().setActive(true);
|
||
146 | 5207 | caballero | |
147 | 5063 | jorpiell | if (e.getSource() instanceof FLyrVect){ |
148 | FLyrVect fLyrVect = (FLyrVect)e.getSource(); |
||
149 | 5207 | caballero | VectorialEditableAdapter vea = |
150 | 5063 | jorpiell | (VectorialEditableAdapter)fLyrVect.getSource(); |
151 | 5207 | caballero | vea.addEditionListener(new EditionChangeManager(fLyrVect));
|
152 | 5063 | jorpiell | } |
153 | 5014 | caballero | }else{
|
154 | for (int i = 0; i < editedLayers.size(); i++) { |
||
155 | VectorialLayerEdited vle = (VectorialLayerEdited) editedLayers.get(i); |
||
156 | if (vle.equals(lyrEdit)) {
|
||
157 | editedLayers.remove(i); |
||
158 | ile=null;
|
||
159 | //idActiveLayer=-1;
|
||
160 | return;
|
||
161 | } |
||
162 | } |
||
163 | 4144 | fjp | } |
164 | 5014 | caballero | |
165 | 5207 | caballero | |
166 | |||
167 | 4144 | fjp | } |
168 | 4147 | fjp | |
169 | /**
|
||
170 | * @return Returns the activeLayerEdited. Null if there isn't any active AND edited
|
||
171 | */
|
||
172 | public ILayerEdited getActiveLayerEdited() {
|
||
173 | 5014 | caballero | return ile;
|
174 | 4147 | fjp | } |
175 | |||
176 | /**
|
||
177 | * @return Returns the mapCtrl.
|
||
178 | */
|
||
179 | public MapControl getMapControl() {
|
||
180 | return mapCtrl;
|
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * @param mapCtrl The mapCtrl to set.
|
||
185 | */
|
||
186 | public void setMapControl(MapControl mapCtrl) { |
||
187 | if (mapCtrl != null) |
||
188 | { |
||
189 | this.mapCtrl = mapCtrl;
|
||
190 | mapCtrl.getMapContext().getLayers().addLayerListener(this);
|
||
191 | 5227 | caballero | mapCtrl.getMapContext().getLayers().addLayerCollectionListener(this);
|
192 | 4147 | fjp | } |
193 | } |
||
194 | |||
195 | 5227 | caballero | public void layerAdded(LayerCollectionEvent e) { |
196 | // TODO Auto-generated method stub
|
||
197 | 4366 | caballero | |
198 | 5227 | caballero | } |
199 | |||
200 | public void layerMoved(LayerPositionEvent e) { |
||
201 | // TODO Auto-generated method stub
|
||
202 | |||
203 | } |
||
204 | |||
205 | public void layerRemoved(LayerCollectionEvent e) { |
||
206 | VectorialLayerEdited vle=(VectorialLayerEdited)getActiveLayerEdited(); |
||
207 | 5256 | caballero | if (vle!=null){ |
208 | FLayers layers=getMapControl().getMapContext().getLayers(); |
||
209 | 6173 | caballero | //if (layers.getLayersCount()>0)
|
210 | // layers.getLayer(0).setActive(true);
|
||
211 | 5256 | caballero | vle.clearSelection(); |
212 | FLyrVect lv=(FLyrVect)vle.getLayer(); |
||
213 | if (e.getAffectedLayer().equals(lv)){
|
||
214 | View view=(View)PluginServices.getMDIManager().getActiveView(); |
||
215 | view.hideConsole(); |
||
216 | view.validate(); |
||
217 | view.repaint(); |
||
218 | } |
||
219 | PluginServices.getMainFrame().enableControls(); |
||
220 | 5227 | caballero | } |
221 | |||
222 | } |
||
223 | |||
224 | public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
||
225 | // TODO Auto-generated method stub
|
||
226 | |||
227 | } |
||
228 | |||
229 | public void layerMoving(LayerPositionEvent e) throws CancelationException { |
||
230 | // TODO Auto-generated method stub
|
||
231 | |||
232 | } |
||
233 | |||
234 | public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
||
235 | // TODO Auto-generated method stub
|
||
236 | |||
237 | } |
||
238 | |||
239 | public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
||
240 | // TODO Auto-generated method stub
|
||
241 | |||
242 | } |
||
243 | |||
244 | public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
||
245 | // TODO Auto-generated method stub
|
||
246 | |||
247 | } |
||
248 | |||
249 | |||
250 | 5845 | fjp | |
251 | 4144 | fjp | } |