Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewFactory.java @ 35756

History | View | Annotate | Download (9.82 KB)

1
package com.iver.cit.gvsig.project.documents.view;
2

    
3
import java.awt.Component;
4
import java.text.DateFormat;
5
import java.util.Date;
6
import java.util.Enumeration;
7
import java.util.Hashtable;
8

    
9
import javax.swing.ImageIcon;
10
import javax.swing.JOptionPane;
11

    
12
import com.iver.andami.PluginServices;
13
import com.iver.cit.gvsig.fmap.MapContext;
14
import com.iver.cit.gvsig.fmap.MapControl;
15
import com.iver.cit.gvsig.fmap.ViewPort;
16
import com.iver.cit.gvsig.project.Project;
17
import com.iver.cit.gvsig.project.documents.ProjectDocument;
18
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory;
19
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CopyDocumentContextMenuAction;
20
import com.iver.cit.gvsig.project.documents.contextMenu.actions.CutDocumentContextMenuAction;
21
import com.iver.cit.gvsig.project.documents.contextMenu.actions.PasteDocumentContextMenuAction;
22
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
23
import com.iver.cit.gvsig.project.documents.view.gui.View;
24
import com.iver.cit.gvsig.project.documents.view.legend.gui.SingleSymbol;
25
import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialInterval;
26
import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialUniqueValue;
27
import com.iver.utiles.XMLEntity;
28

    
29

    
30
/**
31
 * Factory of View.
32
 *
33
 * @author Vicente Caballero Navarro
34
 */
35
public class ProjectViewFactory extends ProjectDocumentFactory {
36
    public static String registerName = "ProjectView";
37

    
38

    
39
    /**
40
     * Returns image of button.
41
     *
42
     * @return Image button.
43
     */
44
    public ImageIcon getButtonIcon() {
45
                return PluginServices.getIconTheme().get("document-view-icon");
46
    }
47

    
48
    /**
49
     * Returns image of selected button.
50
     *
51
     * @return Image button.
52
     */
53
    public ImageIcon getSelectedButtonIcon() {
54
                return PluginServices.getIconTheme().get("document-view-icon-sel");
55
    }
56

    
57
    /**
58
     * Create a new ProjectDocument.
59
     *
60
     * @param project Opened project.
61
     *
62
     * @return ProjectDocument.
63
     */
64
    public ProjectDocument create(Project project) {
65
        String viewName = "";
66
        String aux = PluginServices.getText(this, "untitled");
67
        int numViews=((Integer)ProjectDocument.NUMS.get(registerName)).intValue();
68

    
69
        viewName = aux + " - " + numViews++;
70

    
71
        if (project != null) {
72
            // Buscamos si alguna vista ya ten�a este nombre:
73
            while (existName(project, viewName)) {
74
                viewName = aux + " - " + numViews++;
75
            }
76
        }
77
        ProjectDocument.NUMS.put(registerName,new Integer(numViews));
78
        ProjectView vista = createView(viewName);
79
        vista.setProject(project, 0);
80
        vista.setProjectDocumentFactory(this);
81

    
82
        return vista;
83
    }
84

    
85
    /**
86
     * Create a new ProjectView.
87
     *
88
     * @param baseName name
89
     *
90
     * @return ProjectView.
91
     */
92
    private static ProjectView createView(String viewName) {
93
            ProjectView v = new ProjectView();
94
                MapContext viewMapContext = new MapContext(new ViewPort(Project
95
                                .getDefaultProjection()));
96
                ViewPort vp = viewMapContext.getViewPort();
97
                vp.setBackColor(View.getDefaultBackColor());
98
                vp.setDistanceUnits(Project.getDefaultDistanceUnits());
99
                vp.setDistanceArea(Project.getDefaultDistanceArea());
100
                vp.setMapUnits(Project.getDefaultMapUnits());
101

    
102
                v.setMapContext(viewMapContext);
103
                v.setMapOverViewContext(new MapContext(null));
104

    
105
                /*
106
                 * jaume. ?no puedo definir color de fondo en localizador?
107
                 *
108
                 * v.getMapOverViewContext().setProjection(v.getMapContext().getProjection());
109
                 * v.getMapOverViewContext(). getViewPort(). setBackColor(
110
                 * Project.getDefaultMapOverViewBackColor() );
111
                 *
112
                 */
113
                v.setName(viewName);
114
                v.setCreationDate(DateFormat.getInstance().format(new Date()));
115

    
116
        return v;
117
    }
118

    
119

    
120

    
121
    /**
122
     * Returns the name of registration in the point of extension.
123
     *
124
     * @return Name of registration
125
     */
126
    public String getRegisterName() {
127
        return registerName;
128
    }
129

    
130
    /**
131
     * Returns the name of ProjectDocument.
132
     *
133
     * @return Name of ProjectDocument.
134
     */
135
    public String getNameType() {
136
        return PluginServices.getText(this, "Vista");
137
    }
138

    
139
    /**
140
     * Registers in the points of extension the Factory with alias.
141
     *
142
     */
143
    public static void register() {
144
        register(registerName, new ProjectViewFactory(),
145
            "com.iver.cit.gvsig.project.ProjectView");
146

    
147
        registerAction(registerName,"copy",new CopyDocumentContextMenuAction());
148
        registerAction(registerName,"cut",new CutDocumentContextMenuAction());
149
        registerAction(registerName,"paste",new PasteDocumentContextMenuAction());
150

    
151
        PluginServices.getIconTheme().registerDefault(
152
                        "document-view-icon",
153
                        ProjectView.class.getClassLoader().getResource("images/Vista.png")
154
                );
155
        PluginServices.getIconTheme().registerDefault(
156
                        "document-view-icon-sel",
157
                        ProjectView.class.getClassLoader().getResource("images/Vista_sel.png")
158
                );
159

    
160

    
161

    
162
        PluginServices.getIconTheme().registerDefault(
163
                        "cursor-query-distance",
164
                        MapControl.class.getClassLoader().getResource("images/RulerCursor.gif")
165
                );
166

    
167
        PluginServices.getIconTheme().registerDefault(
168
                        "cursor-query-information",
169
                        MapControl.class.getResource("images/InfoCursor.gif")
170
                );
171
        PluginServices.getIconTheme().registerDefault(
172
                        "cursor-hiperlink",
173
                        MapControl.class.getResource("images/LinkCursor.gif")
174
                );
175
        PluginServices.getIconTheme().registerDefault(
176
                        "cursor-zoom-in",
177
                        MapControl.class.getClassLoader().getResource("images/ZoomInCursor.gif")
178
                );
179
        PluginServices.getIconTheme().registerDefault(
180
                        "cursor-zoom-in",
181
                        MapControl.class.getClassLoader().getResource("images/ZoomInCursor.gif")
182
                );
183

    
184

    
185
        PluginServices.getIconTheme().registerDefault(
186
                           "single-symbol",
187
                           SingleSymbol.class.getClassLoader().getResource("images/single-symbol.png")
188
                   );
189
        PluginServices.getIconTheme().registerDefault(
190
                           "vectorial-interval",
191
                           VectorialInterval.class.getClassLoader().getResource("images/Intervalos.png")
192
                   );
193
        PluginServices.getIconTheme().registerDefault(
194
                           "vectorial-unique-value",
195
                           VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
196
                   );
197
        PluginServices.getIconTheme().registerDefault(
198
                           "vectorial-unique-value",
199
                           VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
200
                   );
201
        PluginServices.getIconTheme().registerDefault(
202
                           "crux-cursor",
203
                           MapControl.class.getClassLoader().getResource("images/CruxCursor.png")
204
                   );
205

    
206

    
207
    }
208

    
209
    /**
210
     * Returns the priority of de ProjectDocument.
211
     *
212
     * @return Priority.
213
     */
214
    public int getPriority() {
215
        return 0;
216
    }
217

    
218
        public boolean resolveImportXMLConflicts(XMLEntity root, Project project, Hashtable conflicts) {
219
                Hashtable viewsConflits = (Hashtable)conflicts.get(this.getRegisterName());
220
                Hashtable tablesConflits = (Hashtable)conflicts.get(ProjectTableFactory.registerName);
221
                XMLEntity xmlTables = root.firstChild("type",ProjectTableFactory.registerName);
222

    
223

    
224
                if (viewsConflits != null && viewsConflits.size() > 0) {
225
                        int option = JOptionPane.showConfirmDialog(
226
                                        (Component)PluginServices.getMainFrame(),
227
                                        "<html>"+
228
                                                PluginServices.getText(this,"conflicto_de_nombres_de_vistas_al_pegar") + "<br>" +
229
                                                PluginServices.getText(this,"debera_introducir_nombres_para_las_vistas_a_pegar") + "<br>" +
230
                                                PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" +
231
                                                PluginServices.getText(this,"desea_continuar") +
232
                                        "</html>",
233
                                        PluginServices.getText(this,"pegar_vistas"),
234
                                        JOptionPane.YES_NO_OPTION
235
                                        );
236
                        if (option != JOptionPane.YES_OPTION) {
237
                                return false;
238
                        }
239
                        Enumeration en = viewsConflits.elements();
240
                        while (en.hasMoreElements()) {
241
                                XMLEntity view = (XMLEntity)en.nextElement();
242
                                String newName = JOptionPane.showInputDialog(
243
                                                (Component)PluginServices.getMainFrame(),
244
                                                "<html>"+
245
                                                        PluginServices.getText(this,"introduzca_nuevo_nombre_para_la_vista") +" "+  view.getStringProperty("name") + ":" +
246
                                                "</html>", //Mensaje
247
                                                view.getStringProperty("name") //Valor por defecto
248
                                                );
249
                                if (newName == null) {
250
                                        JOptionPane.showMessageDialog(
251
                                                        (Component)PluginServices.getMainFrame(),
252
                                                        "<html>"+PluginServices.getText(this,"operacion_cancelada")+"</html>",//Mensaje
253
                                                        PluginServices.getText(this,"pegar_vistas"),//titulo
254
                                                        JOptionPane.ERROR_MESSAGE
255
                                                        );
256
                                } else if (newName.equalsIgnoreCase(view.getStringProperty("name")) ) {
257
                                        JOptionPane.showMessageDialog(
258
                                                        (Component)PluginServices.getMainFrame(),
259
                                                        "<html>"+
260
                                                                PluginServices.getText(this,"operacion_cancelada") +":<br>" +
261
                                                                PluginServices.getText(this,"nombre_no_valido")+
262
                                                        "</html>",//Mensaje
263
                                                        PluginServices.getText(this,"pegar_vistas"),//FIXME: getText
264
                                                        JOptionPane.ERROR_MESSAGE
265
                                                        );
266
                                        return false;
267
                                }
268
                                view.setName(newName);
269
                        }
270
                        if (xmlTables != null) xmlTables.removeAllChildren();
271
                        tablesConflits = null;
272
                }
273

    
274
                if (tablesConflits != null && tablesConflits.size() > 0) {
275
                        int option = JOptionPane.showConfirmDialog(
276
                                        (Component)PluginServices.getMainFrame(),
277
                                        "<html>" +
278
                                                PluginServices.getText(this,"conflicto_de_nombres_de_tablas_al_pegar") + "<br>" +
279
                                                PluginServices.getText(this,"no_se_pegaran_las_tablas") + "<br>" +
280
                                                PluginServices.getText(this,"desea_continuar") +
281
                                        "</html>", //Mensaje
282
                                        PluginServices.getText(this,"pegar_vistas"),//FIXME: getText
283
                                        JOptionPane.YES_NO_OPTION
284
                                        );
285
                        if (option != JOptionPane.YES_OPTION) {
286
                                return false;
287
                        }
288
                        xmlTables.removeAllChildren();
289
                }
290

    
291
                return true;
292
        }
293
}