svn-gvsig-desktop / tags / v1_0_2_Build_906 / extensions / extCAD / src / com / iver / cit / gvsig / EditionManager.java @ 10972
History | View | Annotate | Download (7.25 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 | 10398 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
8 | 4147 | fjp | import com.iver.cit.gvsig.fmap.MapControl; |
9 | 5063 | jorpiell | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
10 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
11 | 4144 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
12 | 5256 | caballero | import com.iver.cit.gvsig.fmap.layers.FLayers; |
13 | 4366 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
14 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
15 | import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
||
16 | 4144 | fjp | import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
17 | import com.iver.cit.gvsig.fmap.layers.LayerListener; |
||
18 | 5227 | caballero | import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
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 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
23 | 4144 | fjp | |
24 | /**
|
||
25 | * @author fjp
|
||
26 | *
|
||
27 | 4366 | caballero | * El prop?sito de esta clase es centralizar el manejo de la
|
28 | 4144 | fjp | * edici?n. Aqu? podemos encontrar una lista con todas
|
29 | * los temas en edici?n, y las propiedades que sean globales
|
||
30 | * e interesantes a la hora de ponerse a editar.
|
||
31 | 4366 | caballero | * Por ejemplo, podemos poner aqu? el Grid que vamos a usar,
|
32 | 4144 | fjp | * el MapControl que tenemos asociado, etc, etc.
|
33 | * Tambi?n ser? el responsable de mantener una lista de
|
||
34 | 4366 | caballero | * listeners interesados en los eventos de edici?n, y
|
35 | 4144 | fjp | * de lanzar los eventos que necesitemos.
|
36 | 4366 | caballero | * Lo principal es una colecci?n de LayerEdited, y cada
|
37 | 4144 | fjp | * LayerEdited es un wrapper alrededor de un tema que guarda
|
38 | * las propiedades de la edici?n.
|
||
39 | 5014 | caballero | *
|
40 | 4834 | fjp | * Nuevo: Llevar aqu? el control de las tablas en edici?n tambi?n
|
41 | * y centralizar los listeners interesados en los eventos de edici?n.
|
||
42 | 4366 | caballero | *
|
43 | 4147 | fjp | * TODO: Poner todo lo referente al EditionManager dentro de una vista.
|
44 | * para permitir tener varias vistas con temas en edici?n
|
||
45 | 4366 | caballero | *
|
46 | 4144 | fjp | */
|
47 | 5227 | caballero | public class EditionManager implements LayerListener,LayerCollectionListener { |
48 | 4144 | fjp | private ArrayList editedLayers = new ArrayList(); |
49 | 4834 | fjp | private ArrayList editedTables = new ArrayList(); |
50 | 5014 | caballero | //private ArrayList activeLayerEdited = new ArrayList();
|
51 | 4147 | fjp | private MapControl mapCtrl = null; |
52 | 5014 | caballero | private ILayerEdited ile=null; |
53 | //private int idActiveLayer=0;
|
||
54 | 4366 | caballero | |
55 | |||
56 | 4147 | fjp | /**
|
57 | * @param lyr
|
||
58 | 4366 | caballero | * @return
|
59 | 4147 | fjp | */
|
60 | 4144 | fjp | public ILayerEdited getLayerEdited(FLayer lyr)
|
61 | { |
||
62 | ILayerEdited aux = null;
|
||
63 | for (int i=0; i < editedLayers.size(); i++) |
||
64 | { |
||
65 | aux = (ILayerEdited) editedLayers.get(i); |
||
66 | if (aux.getLayer() == lyr)
|
||
67 | return aux;
|
||
68 | } |
||
69 | return null; |
||
70 | } |
||
71 | 4366 | caballero | |
72 | 4144 | fjp | public void visibilityChanged(LayerEvent e) { |
73 | } |
||
74 | |||
75 | public void activationChanged(LayerEvent e) { |
||
76 | 5227 | caballero | if (e.getSource().isActive()){
|
77 | 5207 | caballero | ile=getLayerEdited(e.getSource()); |
78 | 10398 | caballero | } |
79 | 10714 | caballero | // IWindow window=PluginServices.getMDIManager().getActiveWindow();
|
80 | // if (window instanceof View){
|
||
81 | // View view=(View)window;
|
||
82 | // if (e.getSource().isEditing()){
|
||
83 | // view.showConsole();
|
||
84 | // }else{
|
||
85 | // view.hideConsole();
|
||
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 | 6305 | caballero | //FLayers layers=getMapControl().getMapContext().getLayers();
|
209 | 6173 | caballero | //if (layers.getLayersCount()>0)
|
210 | // layers.getLayer(0).setActive(true);
|
||
211 | 5256 | caballero | vle.clearSelection(); |
212 | 6305 | caballero | editedLayers.remove(vle); |
213 | getMapControl().setTool("zoomIn");
|
||
214 | 5256 | caballero | FLyrVect lv=(FLyrVect)vle.getLayer(); |
215 | 10890 | caballero | if (e.getAffectedLayer().equals(lv) && PluginServices.getMDIManager().getActiveWindow() instanceof View){ |
216 | 6880 | cesar | View view=(View)PluginServices.getMDIManager().getActiveWindow(); |
217 | 5256 | caballero | view.hideConsole(); |
218 | view.validate(); |
||
219 | view.repaint(); |
||
220 | } |
||
221 | PluginServices.getMainFrame().enableControls(); |
||
222 | 5227 | caballero | } |
223 | |||
224 | } |
||
225 | |||
226 | public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
||
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 | } |