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
package org.gvsig.app.project.documents.view;
2

    
3
import javax.swing.ImageIcon;
4

    
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

    
8
import org.gvsig.andami.PluginServices;
9
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
import org.gvsig.app.project.documents.Document;
14
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
import org.gvsig.app.project.documents.gui.IDocumentWindow;
18
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
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
import org.gvsig.fmap.mapcontext.MapContext;
25
import org.gvsig.fmap.mapcontrol.MapControl;
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dynobject.DynStruct;
28
import org.gvsig.tools.persistence.PersistenceManager;
29

    
30
/**
31
 * Factory of View.
32
 *
33
 * @author 2005-         Vicente Caballero
34
 * @author 2009-         Joaquin del Cerro
35
 * 
36
 */
37
public class ViewManager extends AbstractDocumentManager {
38
    private static final Logger logger = LoggerFactory.getLogger(ViewManager.class);
39
    
40
    private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME =
41
        "DefaultViewDocument";
42
    public static String TYPENAME = "project.document.view2d";
43
    private DynStruct persistenceDefinition;
44
    
45
    public ViewManager() {
46
            // Do nothing
47
    }
48
    
49
    public int getPriority() {
50
        return 0;
51
    }
52

    
53
    public ImageIcon getIcon() {
54
                return PluginServices.getIconTheme().get("document-view-icon");
55
    }
56

    
57
    public ImageIcon getIconSelected() {
58
                return PluginServices.getIconTheme().get("document-view-icon-sel");
59
    }
60

    
61
    public String getTitle() {
62
        return PluginServices.getText(this, "Vista");
63
    }
64

    
65
    public String getTypeName() {
66
        return TYPENAME;
67
    }
68
    
69
    public Class getMainWindowClass() {
70
        return DefaultViewPanel.class;
71
    }
72
    
73
    public AbstractDocument createDocument() {
74
            return new DefaultViewDocument(this);
75
    }
76

    
77
        public IWindow getMainWindow(Document doc, WindowLayout layout) {
78
            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
                        view.setWindowLayout(layout);
88
                }
89
                ((AbstractDocument) doc).raiseEventCreateWindow(view);
90
                return view;
91
        }
92

    
93
        public IWindow getPropertiesWindow(Document doc) {
94
                return new ViewProperties((DefaultViewDocument) doc);
95
        }
96

    
97
    /**
98
     * Registers in the points of extension the Factory with alias.
99
     *
100
     */
101
    public static void register() {
102
        ViewManager factory = new ViewManager();
103
            ProjectManager.getInstance().registerDocumentFactory(factory);
104
            
105
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
106
        manager.registerFactory(factory);
107

    
108

    
109
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
110
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
111
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
112

    
113
        PluginServices.getIconTheme().registerDefault(
114
                        "document-view-icon",
115
                        DefaultViewDocument.class.getClassLoader().getResource("images/Vista.png")
116
                );
117
        PluginServices.getIconTheme().registerDefault(
118
                        "document-view-icon-sel",
119
                        DefaultViewDocument.class.getClassLoader().getResource("images/Vista_sel.png")
120
                );
121

    
122

    
123

    
124
        PluginServices.getIconTheme().registerDefault(
125
                        "cursor-query-distance",
126
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/RulerCursor.gif")
127
                );
128

    
129
        PluginServices.getIconTheme().registerDefault(
130
                        "cursor-query-information",
131
                        MapControl.class.getResource("org/gvsig/fmap/mapcontrol/images/InfoCursor.gif")
132
                );
133
        PluginServices.getIconTheme().registerDefault(
134
                        "cursor-hiperlink",
135
                        MapControl.class.getResource("org/gvsig/fmap/mapcontrol/images/LinkCursor.gif")
136
                );
137
        PluginServices.getIconTheme().registerDefault(
138
                        "cursor-zoom-in",
139
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/ZoomInCursor.gif")
140
                );
141
        PluginServices.getIconTheme().registerDefault(
142
                        "cursor-zoom-out",
143
                        MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/ZoomOutCursor.gif")
144
                );
145

    
146

    
147
        PluginServices.getIconTheme().registerDefault(
148
                           "single-symbol",
149
                           SingleSymbol.class.getClassLoader().getResource("images/single-symbol.png")
150
                   );
151
        PluginServices.getIconTheme().registerDefault(
152
                           "vectorial-interval",
153
                           VectorialInterval.class.getClassLoader().getResource("images/Intervalos.png")
154
                   );
155
        PluginServices.getIconTheme().registerDefault(
156
                           "vectorial-unique-value",
157
                           VectorialUniqueValue.class.getClassLoader().getResource("images/ValoresUnicos.png")
158
                   );
159
        PluginServices.getIconTheme().registerDefault(
160
                           "crux-cursor",
161
                           MapControl.class.getClassLoader().getResource("org/gvsig/fmap/mapcontrol/images/CruxCursor.png")
162
                   );
163

    
164
        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

    
174
            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

    
178
        }
179

    
180

    
181
    }
182

    
183
    @SuppressWarnings("rawtypes")
184
    public DynStruct getDefinition(String className) {
185

    
186
        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

    
196
        return null;
197
    }
198

    
199
    @SuppressWarnings("rawtypes")
200
    protected Class getDocumentClass() {
201
        return DefaultViewDocument.class;
202
    }
203

    
204
    public boolean manages(Object object) {
205
        return object instanceof ViewDocument;
206
    }
207
}