Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / ViewManager.java @ 38562

History | View | Annotate | Download (7.41 KB)

1 29598 jpiera
package org.gvsig.app.project.documents.view;
2 7343 caballero
3 7738 jaume
import javax.swing.ImageIcon;
4
5 35193 jjdelcerro
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7
8 29598 jpiera
import org.gvsig.andami.PluginServices;
9 31496 jjdelcerro
import org.gvsig.andami.ui.mdiManager.IWindow;
10
import org.gvsig.app.project.ProjectManager;
11
import org.gvsig.app.project.documents.AbstractDocument;
12
import org.gvsig.app.project.documents.AbstractDocumentManager;
13 33659 fdiaz
import org.gvsig.app.project.documents.Document;
14 31496 jjdelcerro
import org.gvsig.app.project.documents.actions.CopyDocumentAction;
15
import org.gvsig.app.project.documents.actions.CutDocumentAction;
16
import org.gvsig.app.project.documents.actions.PasteDocumentAction;
17 35193 jjdelcerro
import org.gvsig.app.project.documents.gui.IDocumentWindow;
18 31496 jjdelcerro
import org.gvsig.app.project.documents.gui.WindowLayout;
19
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
20
import org.gvsig.app.project.documents.view.gui.ViewProperties;
21 29598 jpiera
import org.gvsig.app.project.documents.view.legend.gui.SingleSymbol;
22
import org.gvsig.app.project.documents.view.legend.gui.VectorialInterval;
23
import org.gvsig.app.project.documents.view.legend.gui.VectorialUniqueValue;
24 33659 fdiaz
import org.gvsig.fmap.mapcontext.MapContext;
25 20994 jmvivo
import org.gvsig.fmap.mapcontrol.MapControl;
26 33659 fdiaz
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dynobject.DynStruct;
28
import org.gvsig.tools.persistence.PersistenceManager;
29 20994 jmvivo
30 7343 caballero
/**
31
 * Factory of View.
32
 *
33 31496 jjdelcerro
 * @author 2005-         Vicente Caballero
34
 * @author 2009-         Joaquin del Cerro
35
 *
36 7343 caballero
 */
37 31496 jjdelcerro
public class ViewManager extends AbstractDocumentManager {
38 35193 jjdelcerro
    private static final Logger logger = LoggerFactory.getLogger(ViewManager.class);
39
40 33659 fdiaz
    private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME =
41
        "DefaultViewDocument";
42 31496 jjdelcerro
    public static String TYPENAME = "project.document.view2d";
43 33659 fdiaz
    private DynStruct persistenceDefinition;
44 31496 jjdelcerro
45
    public ViewManager() {
46
            // Do nothing
47
    }
48
49
    public int getPriority() {
50
        return 0;
51
    }
52 7343 caballero
53 31496 jjdelcerro
    public ImageIcon getIcon() {
54 15945 jmvivo
                return PluginServices.getIconTheme().get("document-view-icon");
55 7343 caballero
    }
56
57 31496 jjdelcerro
    public ImageIcon getIconSelected() {
58 15945 jmvivo
                return PluginServices.getIconTheme().get("document-view-icon-sel");
59 7343 caballero
    }
60
61 31496 jjdelcerro
    public String getTitle() {
62
        return PluginServices.getText(this, "Vista");
63
    }
64 7343 caballero
65 31496 jjdelcerro
    public String getTypeName() {
66
        return TYPENAME;
67 7343 caballero
    }
68 35193 jjdelcerro
69
    public Class getMainWindowClass() {
70
        return DefaultViewPanel.class;
71
    }
72
73 31496 jjdelcerro
    public AbstractDocument createDocument() {
74
            return new DefaultViewDocument(this);
75 7343 caballero
    }
76
77 31496 jjdelcerro
        public IWindow getMainWindow(Document doc, WindowLayout layout) {
78 35193 jjdelcerro
            IDocumentWindow view;
79
80
            view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc);
81
            if( view != null ) {
82
                // The view window document is already created, return it.
83
                return view;
84
            }
85
            view = this.createDocumentWindow(doc);
86
                if ( layout != null && view != null ) {
87 31496 jjdelcerro
                        view.setWindowLayout(layout);
88
                }
89
                ((AbstractDocument) doc).raiseEventCreateWindow(view);
90
                return view;
91
        }
92 7343 caballero
93 31496 jjdelcerro
        public IWindow getPropertiesWindow(Document doc) {
94
                return new ViewProperties((DefaultViewDocument) doc);
95
        }
96 7343 caballero
97
    /**
98
     * Registers in the points of extension the Factory with alias.
99
     *
100
     */
101
    public static void register() {
102 33659 fdiaz
        ViewManager factory = new ViewManager();
103
            ProjectManager.getInstance().registerDocumentFactory(factory);
104
105
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
106
        manager.registerFactory(factory);
107 7787 jaume
108 33659 fdiaz
109 31496 jjdelcerro
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
110
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
111
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
112 14821 jmvivo
113 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
114 15956 jmvivo
                        "document-view-icon",
115 31496 jjdelcerro
                        DefaultViewDocument.class.getClassLoader().getResource("images/Vista.png")
116 14821 jmvivo
                );
117 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
118 15956 jmvivo
                        "document-view-icon-sel",
119 31496 jjdelcerro
                        DefaultViewDocument.class.getClassLoader().getResource("images/Vista_sel.png")
120 14821 jmvivo
                );
121
122
123 20334 vcaballero
124 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
125 14821 jmvivo
                        "cursor-query-distance",
126 36684 jpiera
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/RulerCursor.gif")
127 14821 jmvivo
                );
128
129 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
130 14821 jmvivo
                        "cursor-query-information",
131 36684 jpiera
                        MapControl.class.getResource("org/gvsig/fmap/mapcontrol/images/InfoCursor.gif")
132 14821 jmvivo
                );
133 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
134 14821 jmvivo
                        "cursor-hiperlink",
135 36684 jpiera
                        MapControl.class.getResource("org/gvsig/fmap/mapcontrol/images/LinkCursor.gif")
136 14821 jmvivo
                );
137 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
138 14821 jmvivo
                        "cursor-zoom-in",
139 36684 jpiera
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/ZoomInCursor.gif")
140 14821 jmvivo
                );
141 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
142 36684 jpiera
                        "cursor-zoom-out",
143
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/ZoomOutCursor.gif")
144 14821 jmvivo
                );
145 18623 jdominguez
146
147 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
148 14821 jmvivo
                           "single-symbol",
149
                           SingleSymbol.class.getClassLoader().getResource("images/single-symbol.png")
150
                   );
151 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
152 14821 jmvivo
                           "vectorial-interval",
153
                           VectorialInterval.class.getClassLoader().getResource("images/Intervalos.png")
154
                   );
155 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
156 14821 jmvivo
                           "vectorial-unique-value",
157
                           VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
158
                   );
159 15640 jmvivo
        PluginServices.getIconTheme().registerDefault(
160 14821 jmvivo
                           "crux-cursor",
161 36684 jpiera
                           MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/CruxCursor.png")
162 14821 jmvivo
                   );
163
164 33659 fdiaz
        if (factory.persistenceDefinition == null){
165
            factory.persistenceDefinition = manager.addDefinition(
166
                ViewDocument.class,
167
                PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME,
168
                "Default view document persistence definition",
169
                null,
170
                null
171
            );
172
            factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
173 14821 jmvivo
174 33659 fdiaz
            factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true);
175
            factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true);
176
            factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false);
177 7343 caballero
178 33659 fdiaz
        }
179 7758 jmvivo
180 7787 jaume
181 33659 fdiaz
    }
182 7787 jaume
183 33659 fdiaz
    @SuppressWarnings("rawtypes")
184
    public DynStruct getDefinition(String className) {
185 7758 jmvivo
186 33659 fdiaz
        if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
187
            return this.persistenceDefinition;
188
        }
189
        if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) {
190
            return this.persistenceDefinition;
191
        }
192
        if( this.getDocumentClass().getName().equals(className) ) {
193
            return this.persistenceDefinition;
194
        }
195 7787 jaume
196 33659 fdiaz
        return null;
197
    }
198
199
    @SuppressWarnings("rawtypes")
200
    protected Class getDocumentClass() {
201
        return DefaultViewDocument.class;
202
    }
203
204 36443 cordinyana
    public boolean manages(Object object) {
205
        return object instanceof ViewDocument;
206
    }
207 7343 caballero
}