svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / ProjectMapFactory.java @ 24962
History | View | Annotate | Download (17.1 KB)
1 |
package com.iver.cit.gvsig.project.documents.layout; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.text.DateFormat; |
5 |
import java.util.Arrays; |
6 |
import java.util.Comparator; |
7 |
import java.util.Date; |
8 |
import java.util.Enumeration; |
9 |
import java.util.Hashtable; |
10 |
|
11 |
import javax.swing.ImageIcon; |
12 |
import javax.swing.JOptionPane; |
13 |
|
14 |
import org.gvsig.fmap.mapcontrol.MapControl; |
15 |
import org.gvsig.project.document.table.FeatureTableDocumentFactory; |
16 |
|
17 |
import com.iver.andami.PluginServices; |
18 |
import com.iver.cit.gvsig.AddLayer; |
19 |
import com.iver.cit.gvsig.project.Project; |
20 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
21 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
22 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CopyDocumentContextMenuAction; |
23 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CutDocumentContextMenuAction; |
24 |
import com.iver.cit.gvsig.project.documents.contextMenu.actions.PasteDocumentContextMenuAction; |
25 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
26 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
27 |
import com.iver.utiles.XMLEntity; |
28 |
|
29 |
|
30 |
/**
|
31 |
* Factory of maps.
|
32 |
*
|
33 |
* @author Vicente Caballero Navarro
|
34 |
*/
|
35 |
public class ProjectMapFactory extends ProjectDocumentFactory { |
36 |
public static String registerName = "ProjectMap"; |
37 |
|
38 |
/**
|
39 |
* Returns image of button.
|
40 |
*
|
41 |
* @return Image button.
|
42 |
*/
|
43 |
public ImageIcon getButtonIcon() { |
44 |
// return new ImageIcon(ProjectMap.class.getClassLoader().getResource("images/mapas.png"));
|
45 |
return PluginServices.getIconTheme().get("document-map-icon"); |
46 |
} |
47 |
|
48 |
/**
|
49 |
* Returns image of selected button.
|
50 |
*
|
51 |
* @return Image button.
|
52 |
*/
|
53 |
public ImageIcon getSelectedButtonIcon() { |
54 |
// return new ImageIcon(ProjectMap.class.getClassLoader().getResource("images/mapas_sel.png"));
|
55 |
return PluginServices.getIconTheme().get("document-map-icon-sel"); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Create a new ProjectDocument.
|
60 |
*
|
61 |
* @param project Opened project.
|
62 |
*
|
63 |
* @return ProjectDocument.
|
64 |
*/
|
65 |
// public ProjectDocument create(Project project) {
|
66 |
// String layoutName = "";
|
67 |
// String aux = PluginServices.getText(this, "untitled");
|
68 |
// layoutName = aux + " - " + ProjectMap.numMaps++;
|
69 |
//
|
70 |
// if (project != null) {
|
71 |
// // Buscamos si alguna vista ya ten?a este nombre:
|
72 |
// while (existLayoutName(project, layoutName)) {
|
73 |
// layoutName = aux + " - " + ProjectView.numViews++;
|
74 |
// }
|
75 |
// }
|
76 |
//
|
77 |
// ProjectMap map = createMap(layoutName);
|
78 |
// map.setModel(new Layout());
|
79 |
// map.getModel().setProjectMap(map);
|
80 |
// map.setProject(project, 0);
|
81 |
// map.setProjectDocumentFactory(this);
|
82 |
//
|
83 |
// return map;
|
84 |
// }
|
85 |
public ProjectDocument create(Project project) {
|
86 |
String mapName = ""; |
87 |
String aux = PluginServices.getText(this, "untitled"); |
88 |
int numMaps=((Integer)ProjectDocument.NUMS.get(registerName)).intValue(); |
89 |
mapName = aux + " - " + numMaps++;
|
90 |
if (project != null) { |
91 |
while (existName(project, mapName)) {
|
92 |
mapName = aux + " - " + numMaps++;
|
93 |
} |
94 |
} |
95 |
ProjectDocument.NUMS.put(registerName,new Integer(numMaps)); |
96 |
ProjectMap map = createMap(mapName); |
97 |
map.setModel(new Layout());
|
98 |
map.getModel().setProjectMap(map); |
99 |
map.setProject(project, 0);
|
100 |
map.setProjectDocumentFactory(this);
|
101 |
|
102 |
return map;
|
103 |
} |
104 |
/**
|
105 |
* Returns the name of registration in the point of extension.
|
106 |
*
|
107 |
* @return Name of registration
|
108 |
*/
|
109 |
public String getRegisterName() { |
110 |
return registerName;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Returns the name of ProjectDocument.
|
115 |
*
|
116 |
* @return Name of ProjectDocument.
|
117 |
*/
|
118 |
public String getNameType() { |
119 |
return PluginServices.getText(this, "Mapa"); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Create a ne ProjectMap
|
124 |
*
|
125 |
* @param baseName name
|
126 |
*
|
127 |
* @return ProjectMap.
|
128 |
*/
|
129 |
private static ProjectMap createMap(String baseName) { |
130 |
ProjectMap m = new ProjectMap();
|
131 |
m.setName(baseName); |
132 |
m.setCreationDate(DateFormat.getInstance().format(new Date())); |
133 |
return m;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Registers in the points of extension the Factory with alias.
|
138 |
*
|
139 |
*/
|
140 |
public static void register() { |
141 |
register(registerName, new ProjectMapFactory(),
|
142 |
"com.iver.cit.gvsig.project.ProjectMap");
|
143 |
|
144 |
registerAction(registerName,"copy",new CopyDocumentContextMenuAction()); |
145 |
registerAction(registerName,"cut",new CutDocumentContextMenuAction()); |
146 |
registerAction(registerName,"paste",new PasteDocumentContextMenuAction()); |
147 |
|
148 |
PluginServices.getIconTheme().registerDefault( |
149 |
"document-map-icon",
|
150 |
AddLayer.class.getClassLoader().getResource("images/mapas.png")
|
151 |
); |
152 |
PluginServices.getIconTheme().registerDefault( |
153 |
"document-map-icon-sel",
|
154 |
AddLayer.class.getClassLoader().getResource("images/mapas_sel.png")
|
155 |
); |
156 |
PluginServices.getIconTheme().registerDefault( |
157 |
"neresize-icon",
|
158 |
AddLayer.class.getClassLoader().getResource("images/NEResize.png")
|
159 |
); |
160 |
PluginServices.getIconTheme().registerDefault( |
161 |
"eresize-icon",
|
162 |
AddLayer.class.getClassLoader().getResource("images/EResize.png")
|
163 |
); |
164 |
PluginServices.getIconTheme().registerDefault( |
165 |
"nresize-icon",
|
166 |
AddLayer.class.getClassLoader().getResource("images/NResize.png")
|
167 |
); |
168 |
PluginServices.getIconTheme().registerDefault( |
169 |
"move-icon",
|
170 |
AddLayer.class.getClassLoader().getResource("images/Move.png")
|
171 |
); |
172 |
PluginServices.getIconTheme().registerDefault( |
173 |
"sereresize-icon",
|
174 |
AddLayer.class.getClassLoader().getResource("images/SEResize.png")
|
175 |
); |
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"symboltag-icon",
|
178 |
AddLayer.class.getClassLoader().getResource("images/symbolTag.gif")
|
179 |
); |
180 |
PluginServices.getIconTheme().registerDefault( |
181 |
"move-icon",
|
182 |
AddLayer.class.getClassLoader().getResource("images/Move.png")
|
183 |
); |
184 |
PluginServices.getIconTheme().registerDefault( |
185 |
"numero-icon",
|
186 |
AddLayer.class.getClassLoader().getResource("images/numero.png")
|
187 |
); |
188 |
PluginServices.getIconTheme().registerDefault( |
189 |
"barra1-icon",
|
190 |
AddLayer.class.getClassLoader().getResource("images/barra1.png")
|
191 |
); |
192 |
PluginServices.getIconTheme().registerDefault( |
193 |
"barra2-icon",
|
194 |
AddLayer.class.getClassLoader().getResource("images/barra2.png")
|
195 |
); |
196 |
PluginServices.getIconTheme().registerDefault( |
197 |
"barra3-icon",
|
198 |
AddLayer.class.getClassLoader().getResource("images/barra3.png")
|
199 |
); |
200 |
PluginServices.getIconTheme().registerDefault( |
201 |
"text-left-icon",
|
202 |
AddLayer.class.getClassLoader().getResource("images/left.PNG")
|
203 |
); |
204 |
PluginServices.getIconTheme().registerDefault( |
205 |
"text-center-v-icon",
|
206 |
AddLayer.class.getClassLoader().getResource("images/centerV.PNG")
|
207 |
); |
208 |
PluginServices.getIconTheme().registerDefault( |
209 |
"text-right-icon",
|
210 |
AddLayer.class.getClassLoader().getResource("images/right.PNG")
|
211 |
); |
212 |
PluginServices.getIconTheme().registerDefault( |
213 |
"left-rotation-icon",
|
214 |
AddLayer.class.getClassLoader().getResource("images/leftrotation.png")
|
215 |
); |
216 |
PluginServices.getIconTheme().registerDefault( |
217 |
"text-up-icon",
|
218 |
AddLayer.class.getClassLoader().getResource("images/up.PNG")
|
219 |
); |
220 |
PluginServices.getIconTheme().registerDefault( |
221 |
"text-center-h-icon",
|
222 |
AddLayer.class.getClassLoader().getResource("images/centerH.PNG")
|
223 |
); |
224 |
PluginServices.getIconTheme().registerDefault( |
225 |
"text-down-icon",
|
226 |
AddLayer.class.getClassLoader().getResource("images/down.PNG")
|
227 |
); |
228 |
PluginServices.getIconTheme().registerDefault( |
229 |
"text-distup-icon",
|
230 |
AddLayer.class.getClassLoader().getResource("images/distUp.PNG")
|
231 |
); |
232 |
PluginServices.getIconTheme().registerDefault( |
233 |
"text-distcenterh-icon",
|
234 |
AddLayer.class.getClassLoader().getResource("images/distCenterH.PNG")
|
235 |
); |
236 |
PluginServices.getIconTheme().registerDefault( |
237 |
"text-distdown-icon",
|
238 |
AddLayer.class.getClassLoader().getResource("images/distDown.PNG")
|
239 |
); |
240 |
PluginServices.getIconTheme().registerDefault( |
241 |
"text-distleft-icon",
|
242 |
AddLayer.class.getClassLoader().getResource("images/distLeft.PNG")
|
243 |
); |
244 |
PluginServices.getIconTheme().registerDefault( |
245 |
"text-distcenterv-icon",
|
246 |
AddLayer.class.getClassLoader().getResource("images/distCenterV.PNG")
|
247 |
); |
248 |
PluginServices.getIconTheme().registerDefault( |
249 |
"text-distright-icon",
|
250 |
AddLayer.class.getClassLoader().getResource("images/distRight.PNG")
|
251 |
); |
252 |
PluginServices.getIconTheme().registerDefault( |
253 |
"text-size-width-icon",
|
254 |
AddLayer.class.getClassLoader().getResource("images/sizeWidth.PNG")
|
255 |
); |
256 |
PluginServices.getIconTheme().registerDefault( |
257 |
"text-size-height-icon",
|
258 |
AddLayer.class.getClassLoader().getResource("images/sizeHeight.PNG")
|
259 |
); |
260 |
PluginServices.getIconTheme().registerDefault( |
261 |
"text-size-other-icon",
|
262 |
AddLayer.class.getClassLoader().getResource("images/sizeOther.PNG")
|
263 |
); |
264 |
PluginServices.getIconTheme().registerDefault( |
265 |
"text-space-right-icon",
|
266 |
AddLayer.class.getClassLoader().getResource("images/spaceRight.PNG")
|
267 |
); |
268 |
PluginServices.getIconTheme().registerDefault( |
269 |
"text-inlayout-icon",
|
270 |
AddLayer.class.getClassLoader().getResource("images/inLayout.PNG")
|
271 |
); |
272 |
|
273 |
//Tools
|
274 |
PluginServices.getIconTheme().registerDefault( |
275 |
"rect-select-cursor",
|
276 |
MapControl.class.getResource("images/RectSelectCursor.gif")
|
277 |
); |
278 |
|
279 |
PluginServices.getIconTheme().registerDefault( |
280 |
"circle-cursor",
|
281 |
AddLayer.class.getClassLoader().getResource("images/CircleCursor.png")
|
282 |
); |
283 |
PluginServices.getIconTheme().registerDefault( |
284 |
"line-cursor",
|
285 |
AddLayer.class.getClassLoader().getResource("images/LineCursor.png")
|
286 |
); |
287 |
PluginServices.getIconTheme().registerDefault( |
288 |
"point-cursor",
|
289 |
AddLayer.class.getClassLoader().getResource("images/PointCursor.png")
|
290 |
); |
291 |
PluginServices.getIconTheme().registerDefault( |
292 |
"poligon-cursor",
|
293 |
AddLayer.class.getClassLoader().getResource("images/PoligonCursor.png")
|
294 |
); |
295 |
PluginServices.getIconTheme().registerDefault( |
296 |
"rectangle-cursor",
|
297 |
AddLayer.class.getClassLoader().getResource("images/RectangleCursor.png")
|
298 |
); |
299 |
PluginServices.getIconTheme().registerDefault( |
300 |
"crux-cursor",
|
301 |
AddLayer.class.getClassLoader().getResource("images/CruxCursor.png")
|
302 |
); |
303 |
PluginServices.getIconTheme().registerDefault( |
304 |
"layout-hand-icon",
|
305 |
AddLayer.class.getClassLoader().getResource("images/LayoutHand.gif")
|
306 |
); |
307 |
PluginServices.getIconTheme().registerDefault( |
308 |
"zoom-in-cursor",
|
309 |
AddLayer.class.getClassLoader().getResource("images/ZoomInCursor.gif")
|
310 |
); |
311 |
PluginServices.getIconTheme().registerDefault( |
312 |
"hand-icon",
|
313 |
AddLayer.class.getClassLoader().getResource("images/Hand.gif")
|
314 |
); |
315 |
PluginServices.getIconTheme().registerDefault( |
316 |
"zoom-out-cursor",
|
317 |
AddLayer.class.getClassLoader().getResource("images/ZoomOutCursor.gif")
|
318 |
); |
319 |
PluginServices.getIconTheme().registerDefault( |
320 |
"layout-zoom-in-cursor",
|
321 |
AddLayer.class.getClassLoader().getResource("images/LayoutZoomInCursor.gif")
|
322 |
); |
323 |
PluginServices.getIconTheme().registerDefault( |
324 |
"layout-zoom-out-cursor",
|
325 |
AddLayer.class.getClassLoader().getResource("images/LayoutZoomOutCursor.gif")
|
326 |
); |
327 |
PluginServices.getIconTheme().registerDefault( |
328 |
"right-rotation-icon",
|
329 |
AddLayer.class.getClassLoader().getResource("images/rightrotation.png")
|
330 |
); |
331 |
PluginServices.getIconTheme().registerDefault( |
332 |
"point-select-cursor",
|
333 |
MapControl.class.getResource("images/PointSelectCursor.gif")
|
334 |
); |
335 |
|
336 |
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* Returns the priority of de ProjectDocument.
|
341 |
*
|
342 |
* @return Priority.
|
343 |
*/
|
344 |
public int getPriority() { |
345 |
return 2; |
346 |
} |
347 |
|
348 |
public boolean resolveImportXMLConflicts(XMLEntity root, Project project, Hashtable conflicts) { |
349 |
XMLEntity xmlMaps = root.firstChild("type",this.getRegisterName()); |
350 |
XMLEntity xmlViews = root.firstChild("type",ProjectViewFactory.registerName);
|
351 |
XMLEntity xmlTables = root.firstChild("type",FeatureTableDocumentFactory.registerName);
|
352 |
|
353 |
Hashtable mapsConflits = (Hashtable)conflicts.get(ProjectMapFactory.registerName); |
354 |
|
355 |
Hashtable viewsConflits = (Hashtable)conflicts.get(ProjectViewFactory.registerName); |
356 |
|
357 |
Hashtable tablesConflits = (Hashtable)conflicts.get(FeatureTableDocumentFactory.registerName); |
358 |
|
359 |
|
360 |
if (mapsConflits != null && mapsConflits.size() > 0) { |
361 |
int option = JOptionPane.showConfirmDialog( |
362 |
(Component)PluginServices.getMainFrame(),
|
363 |
"<html>"+
|
364 |
PluginServices.getText(this,"conflicto_de_nombres_de_mapas_al_pegar") + "<br>" + |
365 |
PluginServices.getText(this,"debera_introducir_nombres_para_los_mapas_a_pegar") + "<br>" + |
366 |
"</html>", //Mensaje |
367 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
368 |
JOptionPane.YES_NO_OPTION
|
369 |
); |
370 |
if (option != JOptionPane.YES_OPTION) { |
371 |
return false; |
372 |
} |
373 |
Enumeration en = mapsConflits.elements();
|
374 |
while (en.hasMoreElements()) {
|
375 |
XMLEntity map = (XMLEntity)en.nextElement(); |
376 |
String newName = JOptionPane.showInputDialog( |
377 |
(Component)PluginServices.getMainFrame(),
|
378 |
"<html>"+
|
379 |
PluginServices.getText(this,"nuevo_nombre_para_el_mapa") +" "+ map.getStringProperty("name") + ":" + |
380 |
"</html>", //Mensaje |
381 |
map.getStringProperty("name") //Valor por defecto |
382 |
); |
383 |
if (newName == null) { |
384 |
JOptionPane.showMessageDialog(
|
385 |
(Component)PluginServices.getMainFrame(),
|
386 |
"<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje |
387 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
388 |
JOptionPane.ERROR_MESSAGE
|
389 |
); |
390 |
} else if (newName.equalsIgnoreCase(map.getStringProperty("name")) ) { |
391 |
JOptionPane.showMessageDialog(
|
392 |
(Component)PluginServices.getMainFrame(),
|
393 |
"<html>"+
|
394 |
PluginServices.getText(this,"operacion_cancelada") +":<br>" + |
395 |
PluginServices.getText(this,"nombre_no_valido")+ |
396 |
"</html>",//Mensaje |
397 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
398 |
JOptionPane.ERROR_MESSAGE
|
399 |
); |
400 |
return false; |
401 |
} |
402 |
map.setName(newName); |
403 |
} |
404 |
} |
405 |
|
406 |
if (viewsConflits != null && viewsConflits.size() > 0) { |
407 |
int option = JOptionPane.showConfirmDialog( |
408 |
(Component)PluginServices.getMainFrame(),
|
409 |
"<html>"+
|
410 |
PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" + |
411 |
PluginServices.getText(this,"no_se_pegaran_las_vistas_del_conflicto") + "<br>" + |
412 |
PluginServices.getText(this,"desea_continuar") + |
413 |
"</html>",
|
414 |
PluginServices.getText(this,"pegar_mapas"),//titulo |
415 |
JOptionPane.YES_NO_OPTION
|
416 |
); |
417 |
if (option != JOptionPane.YES_OPTION) { |
418 |
return false; |
419 |
} |
420 |
// Eliminamos las vistas del xml que no vamos a importar
|
421 |
|
422 |
// Esto me devuelve los indices en orden inverso
|
423 |
int[] indexes = this.getIndexOfConflict(viewsConflits); |
424 |
for (int i=0;i < indexes.length;i++) { |
425 |
xmlViews.removeChild(indexes[i]); |
426 |
} |
427 |
viewsConflits = null;
|
428 |
|
429 |
} |
430 |
|
431 |
|
432 |
if (tablesConflits != null && tablesConflits.size() > 0) { |
433 |
int option = JOptionPane.showConfirmDialog( |
434 |
(Component)PluginServices.getMainFrame(),
|
435 |
"<html>" +
|
436 |
PluginServices.getText(this,"conflito_de_nombres_de_tablas_al_pegar") + "<br>" + |
437 |
PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
438 |
PluginServices.getText(this,"desea_continuar") + |
439 |
"</html>", //Mensaje |
440 |
PluginServices.getText(this,"pegar_mapas"), |
441 |
JOptionPane.YES_NO_OPTION
|
442 |
); |
443 |
if (option != JOptionPane.YES_OPTION) { |
444 |
return false; |
445 |
} |
446 |
xmlTables.removeAllChildren(); |
447 |
} |
448 |
|
449 |
|
450 |
return true; |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Devuelve las claves de conflits ordenados
|
455 |
* en orden inverso. Las claves se esperan que
|
456 |
* sean instancias de Integer
|
457 |
*/
|
458 |
private int[] getIndexOfConflict(Hashtable conflits) { |
459 |
Object[] tmpArray = conflits.keySet().toArray(); |
460 |
Arrays.sort(tmpArray,new Comparator() { |
461 |
public int compare(Object o1, Object o2) { |
462 |
return ((Integer)o2).intValue() - ((Integer)o1).intValue(); |
463 |
} |
464 |
} |
465 |
); |
466 |
int[] indexes = new int[] {tmpArray.length}; |
467 |
for (int i = 0;i< tmpArray.length;i++) { |
468 |
indexes[i] = ((Integer)tmpArray[i]).intValue();
|
469 |
} |
470 |
return indexes;
|
471 |
|
472 |
|
473 |
} |
474 |
} |