root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewFactory.java @ 23383
History | View | Annotate | Download (9.83 KB)
1 | 7343 | caballero | package com.iver.cit.gvsig.project.documents.view; |
---|---|---|---|
2 | |||
3 | 7758 | jmvivo | import java.awt.Component; |
4 | 7738 | jaume | import java.text.DateFormat; |
5 | import java.util.Date; |
||
6 | 7758 | jmvivo | import java.util.Enumeration; |
7 | import java.util.Hashtable; |
||
8 | 7343 | caballero | |
9 | 7738 | jaume | import javax.swing.ImageIcon; |
10 | 7758 | jmvivo | import javax.swing.JOptionPane; |
11 | 7738 | jaume | |
12 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
13 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
14 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
15 | |||
16 | 7738 | jaume | import com.iver.andami.PluginServices; |
17 | 7343 | caballero | import com.iver.cit.gvsig.project.Project; |
18 | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
||
19 | import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
||
20 | 7758 | jmvivo | import com.iver.cit.gvsig.project.documents.contextMenu.actions.CopyDocumentContextMenuAction; |
21 | import com.iver.cit.gvsig.project.documents.contextMenu.actions.CutDocumentContextMenuAction; |
||
22 | import com.iver.cit.gvsig.project.documents.contextMenu.actions.PasteDocumentContextMenuAction; |
||
23 | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
||
24 | 7854 | jaume | import com.iver.cit.gvsig.project.documents.view.gui.View; |
25 | 14821 | jmvivo | import com.iver.cit.gvsig.project.documents.view.legend.gui.SingleSymbol; |
26 | import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialInterval; |
||
27 | import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialUniqueValue; |
||
28 | 7758 | jmvivo | import com.iver.utiles.XMLEntity; |
29 | 7343 | caballero | |
30 | |||
31 | /**
|
||
32 | * Factory of View.
|
||
33 | *
|
||
34 | * @author Vicente Caballero Navarro
|
||
35 | */
|
||
36 | public class ProjectViewFactory extends ProjectDocumentFactory { |
||
37 | 7379 | caballero | public static String registerName = "ProjectView"; |
38 | 7343 | caballero | |
39 | |||
40 | /**
|
||
41 | * Returns image of button.
|
||
42 | *
|
||
43 | * @return Image button.
|
||
44 | */
|
||
45 | public ImageIcon getButtonIcon() { |
||
46 | 15945 | jmvivo | return PluginServices.getIconTheme().get("document-view-icon"); |
47 | 7343 | caballero | } |
48 | |||
49 | /**
|
||
50 | * Returns image of selected button.
|
||
51 | *
|
||
52 | * @return Image button.
|
||
53 | */
|
||
54 | public ImageIcon getSelectedButtonIcon() { |
||
55 | 15945 | jmvivo | return PluginServices.getIconTheme().get("document-view-icon-sel"); |
56 | 7343 | caballero | } |
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 viewName = ""; |
||
67 | String aux = PluginServices.getText(this, "untitled"); |
||
68 | 9690 | caballero | int numViews=((Integer)ProjectDocument.NUMS.get(registerName)).intValue(); |
69 | 7343 | caballero | |
70 | 9690 | caballero | viewName = aux + " - " + numViews++;
|
71 | |||
72 | 7343 | caballero | if (project != null) { |
73 | 14821 | jmvivo | // Buscamos si alguna vista ya ten�a este nombre:
|
74 | 9690 | caballero | while (existName(project, viewName)) {
|
75 | viewName = aux + " - " + numViews++;
|
||
76 | 7343 | caballero | } |
77 | } |
||
78 | 9690 | caballero | ProjectDocument.NUMS.put(registerName,new Integer(numViews)); |
79 | 7343 | caballero | ProjectView vista = createView(viewName); |
80 | vista.setProject(project, 0);
|
||
81 | 7758 | jmvivo | vista.setProjectDocumentFactory(this);
|
82 | 7343 | caballero | |
83 | return vista;
|
||
84 | } |
||
85 | |||
86 | /**
|
||
87 | * Create a new ProjectView.
|
||
88 | *
|
||
89 | * @param baseName name
|
||
90 | *
|
||
91 | * @return ProjectView.
|
||
92 | */
|
||
93 | private static ProjectView createView(String viewName) { |
||
94 | 7787 | jaume | ProjectView v = new ProjectView();
|
95 | MapContext viewMapContext = new MapContext(new ViewPort(Project |
||
96 | .getDefaultProjection())); |
||
97 | ViewPort vp = viewMapContext.getViewPort(); |
||
98 | 7854 | jaume | vp.setBackColor(View.getDefaultBackColor());
|
99 | 7787 | jaume | vp.setDistanceUnits(Project.getDefaultDistanceUnits()); |
100 | 20334 | vcaballero | vp.setDistanceArea(Project.getDefaultDistanceArea()); |
101 | 7787 | jaume | vp.setMapUnits(Project.getDefaultMapUnits()); |
102 | 7343 | caballero | |
103 | 7787 | jaume | v.setMapContext(viewMapContext); |
104 | v.setMapOverViewContext(new MapContext(null)); |
||
105 | |||
106 | /*
|
||
107 | * jaume. ?no puedo definir color de fondo en localizador?
|
||
108 | *
|
||
109 | * v.getMapOverViewContext().setProjection(v.getMapContext().getProjection());
|
||
110 | * v.getMapOverViewContext(). getViewPort(). setBackColor(
|
||
111 | * Project.getDefaultMapOverViewBackColor() );
|
||
112 | *
|
||
113 | */
|
||
114 | v.setName(viewName); |
||
115 | v.setCreationDate(DateFormat.getInstance().format(new Date())); |
||
116 | |||
117 | 7343 | caballero | return v;
|
118 | } |
||
119 | |||
120 | |||
121 | |||
122 | /**
|
||
123 | * Returns the name of registration in the point of extension.
|
||
124 | *
|
||
125 | * @return Name of registration
|
||
126 | */
|
||
127 | public String getRegisterName() { |
||
128 | return registerName;
|
||
129 | } |
||
130 | |||
131 | /**
|
||
132 | * Returns the name of ProjectDocument.
|
||
133 | *
|
||
134 | * @return Name of ProjectDocument.
|
||
135 | */
|
||
136 | public String getNameType() { |
||
137 | return PluginServices.getText(this, "Vista"); |
||
138 | } |
||
139 | |||
140 | /**
|
||
141 | * Registers in the points of extension the Factory with alias.
|
||
142 | *
|
||
143 | */
|
||
144 | public static void register() { |
||
145 | register(registerName, new ProjectViewFactory(),
|
||
146 | "com.iver.cit.gvsig.project.ProjectView");
|
||
147 | 7787 | jaume | |
148 | 7758 | jmvivo | registerAction(registerName,"copy",new CopyDocumentContextMenuAction()); |
149 | registerAction(registerName,"cut",new CutDocumentContextMenuAction()); |
||
150 | registerAction(registerName,"paste",new PasteDocumentContextMenuAction()); |
||
151 | 14821 | jmvivo | |
152 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
153 | 15956 | jmvivo | "document-view-icon",
|
154 | 14821 | jmvivo | ProjectView.class.getClassLoader().getResource("images/Vista.png")
|
155 | ); |
||
156 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
157 | 15956 | jmvivo | "document-view-icon-sel",
|
158 | 14821 | jmvivo | ProjectView.class.getClassLoader().getResource("images/Vista_sel.png")
|
159 | ); |
||
160 | |||
161 | |||
162 | 20334 | vcaballero | |
163 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
164 | 14821 | jmvivo | "cursor-query-distance",
|
165 | MapControl.class.getClassLoader().getResource("images/RulerCursor.gif")
|
||
166 | ); |
||
167 | |||
168 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
169 | 14821 | jmvivo | "cursor-query-information",
|
170 | MapControl.class.getResource("images/InfoCursor.gif")
|
||
171 | ); |
||
172 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
173 | 14821 | jmvivo | "cursor-hiperlink",
|
174 | MapControl.class.getResource("images/LinkCursor.gif")
|
||
175 | ); |
||
176 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
177 | 14821 | jmvivo | "cursor-zoom-in",
|
178 | MapControl.class.getClassLoader().getResource("images/ZoomInCursor.gif")
|
||
179 | ); |
||
180 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
181 | 14821 | jmvivo | "cursor-zoom-in",
|
182 | MapControl.class.getClassLoader().getResource("images/ZoomInCursor.gif")
|
||
183 | ); |
||
184 | 18623 | jdominguez | |
185 | |||
186 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
187 | 14821 | jmvivo | "single-symbol",
|
188 | SingleSymbol.class.getClassLoader().getResource("images/single-symbol.png")
|
||
189 | ); |
||
190 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
191 | 14821 | jmvivo | "vectorial-interval",
|
192 | VectorialInterval.class.getClassLoader().getResource("images/Intervalos.png")
|
||
193 | ); |
||
194 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
195 | 14821 | jmvivo | "vectorial-unique-value",
|
196 | VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
|
||
197 | ); |
||
198 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
199 | 14821 | jmvivo | "vectorial-unique-value",
|
200 | VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
|
||
201 | ); |
||
202 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
203 | 14821 | jmvivo | "crux-cursor",
|
204 | MapControl.class.getClassLoader().getResource("images/CruxCursor.png")
|
||
205 | ); |
||
206 | |||
207 | |||
208 | 7343 | caballero | } |
209 | |||
210 | /**
|
||
211 | * Returns the priority of de ProjectDocument.
|
||
212 | *
|
||
213 | * @return Priority.
|
||
214 | */
|
||
215 | public int getPriority() { |
||
216 | return 0; |
||
217 | } |
||
218 | 7758 | jmvivo | |
219 | public boolean resolveImportXMLConflicts(XMLEntity root, Project project, Hashtable conflicts) { |
||
220 | Hashtable viewsConflits = (Hashtable)conflicts.get(this.getRegisterName()); |
||
221 | Hashtable tablesConflits = (Hashtable)conflicts.get(ProjectTableFactory.registerName); |
||
222 | XMLEntity xmlTables = root.firstChild("type",ProjectTableFactory.registerName);
|
||
223 | 7787 | jaume | |
224 | |||
225 | 7758 | jmvivo | if (viewsConflits != null && viewsConflits.size() > 0) { |
226 | int option = JOptionPane.showConfirmDialog( |
||
227 | (Component)PluginServices.getMainFrame(),
|
||
228 | "<html>"+
|
||
229 | PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" + |
||
230 | PluginServices.getText(this,"debera_introducir_nombres_para_las_vistas_a_pegar") + "<br>" + |
||
231 | PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
||
232 | PluginServices.getText(this,"desea_continuar") + |
||
233 | "</html>",
|
||
234 | PluginServices.getText(this,"pegar_vistas"), |
||
235 | JOptionPane.YES_NO_OPTION
|
||
236 | ); |
||
237 | if (option != JOptionPane.YES_OPTION) { |
||
238 | return false; |
||
239 | } |
||
240 | Enumeration en = viewsConflits.elements();
|
||
241 | while (en.hasMoreElements()) {
|
||
242 | XMLEntity view = (XMLEntity)en.nextElement(); |
||
243 | String newName = JOptionPane.showInputDialog( |
||
244 | (Component)PluginServices.getMainFrame(),
|
||
245 | "<html>"+
|
||
246 | PluginServices.getText(this,"introduzca_nuevo_nombre_para_la_vista") +" "+ view.getStringProperty("name") + ":" + |
||
247 | "</html>", //Mensaje |
||
248 | view.getStringProperty("name") //Valor por defecto |
||
249 | ); |
||
250 | if (newName == null) { |
||
251 | JOptionPane.showMessageDialog(
|
||
252 | (Component)PluginServices.getMainFrame(),
|
||
253 | "<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje |
||
254 | PluginServices.getText(this,"pegar_vistas"),//titulo |
||
255 | JOptionPane.ERROR_MESSAGE
|
||
256 | ); |
||
257 | } else if (newName.equalsIgnoreCase(view.getStringProperty("name")) ) { |
||
258 | JOptionPane.showMessageDialog(
|
||
259 | (Component)PluginServices.getMainFrame(),
|
||
260 | "<html>"+
|
||
261 | PluginServices.getText(this,"operacion_cancelada") +":<br>" + |
||
262 | PluginServices.getText(this,"nombre_no_valido")+ |
||
263 | "</html>",//Mensaje |
||
264 | PluginServices.getText(this,"pegar_vistas"),//FIXME: getText |
||
265 | JOptionPane.ERROR_MESSAGE
|
||
266 | ); |
||
267 | return false; |
||
268 | } |
||
269 | view.setName(newName); |
||
270 | } |
||
271 | if (xmlTables != null) xmlTables.removeAllChildren(); |
||
272 | tablesConflits = null;
|
||
273 | } |
||
274 | |||
275 | if (tablesConflits != null && tablesConflits.size() > 0) { |
||
276 | int option = JOptionPane.showConfirmDialog( |
||
277 | (Component)PluginServices.getMainFrame(),
|
||
278 | "<html>" +
|
||
279 | PluginServices.getText(this,"conflicto_de_nombres_de_tablas_al_pegar") + "<br>" + |
||
280 | PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" + |
||
281 | PluginServices.getText(this,"desea_continuar") + |
||
282 | "</html>", //Mensaje |
||
283 | PluginServices.getText(this,"pegar_vistas"),//FIXME: getText |
||
284 | JOptionPane.YES_NO_OPTION
|
||
285 | ); |
||
286 | if (option != JOptionPane.YES_OPTION) { |
||
287 | return false; |
||
288 | } |
||
289 | xmlTables.removeAllChildren(); |
||
290 | } |
||
291 | 7787 | jaume | |
292 | 7758 | jmvivo | return true; |
293 | } |
||
294 | 7343 | caballero | } |