svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / ViewManager.java @ 40558
History | View | Annotate | Download (8.38 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view; |
25 |
|
26 |
import javax.swing.ImageIcon; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.ProjectManager; |
32 |
import org.gvsig.app.project.documents.AbstractDocument; |
33 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
34 |
import org.gvsig.app.project.documents.Document; |
35 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
36 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
37 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
38 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
39 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
40 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
41 |
import org.gvsig.app.project.documents.view.gui.ViewProperties; |
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
43 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
44 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.dynobject.DynStruct; |
47 |
import org.gvsig.tools.persistence.PersistenceManager; |
48 |
import org.slf4j.Logger; |
49 |
import org.slf4j.LoggerFactory; |
50 |
|
51 |
/**
|
52 |
* Factory of View.
|
53 |
*
|
54 |
* @author 2005- Vicente Caballero
|
55 |
* @author 2009- Joaquin del Cerro
|
56 |
*
|
57 |
*/
|
58 |
public class ViewManager extends AbstractDocumentManager { |
59 |
private static final Logger logger = LoggerFactory.getLogger(ViewManager.class); |
60 |
|
61 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME = |
62 |
"DefaultViewDocument";
|
63 |
public static String TYPENAME = "project.document.view2d"; |
64 |
private DynStruct persistenceDefinition;
|
65 |
|
66 |
public ViewManager() {
|
67 |
// Do nothing
|
68 |
} |
69 |
|
70 |
public int getPriority() { |
71 |
return 0; |
72 |
} |
73 |
|
74 |
public ImageIcon getIcon() { |
75 |
return PluginServices.getIconTheme().get("document-view-icon"); |
76 |
} |
77 |
|
78 |
public ImageIcon getIconSelected() { |
79 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
80 |
} |
81 |
|
82 |
public String getTitle() { |
83 |
return PluginServices.getText(this, "Vista"); |
84 |
} |
85 |
|
86 |
public String getTypeName() { |
87 |
return TYPENAME;
|
88 |
} |
89 |
|
90 |
public Class getMainWindowClass() { |
91 |
return DefaultViewPanel.class;
|
92 |
} |
93 |
|
94 |
public AbstractDocument createDocument() { |
95 |
return new DefaultViewDocument(this); |
96 |
} |
97 |
|
98 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
99 |
IDocumentWindow view; |
100 |
|
101 |
view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc); |
102 |
if( view != null ) { |
103 |
// The view window document is already created, return it.
|
104 |
return view;
|
105 |
} |
106 |
view = this.createDocumentWindow(doc);
|
107 |
if ( layout != null && view != null ) { |
108 |
view.setWindowLayout(layout); |
109 |
} |
110 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
111 |
return view;
|
112 |
} |
113 |
|
114 |
public IWindow getPropertiesWindow(Document doc) { |
115 |
return new ViewProperties((DefaultViewDocument) doc); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Registers in the points of extension the Factory with alias.
|
120 |
*
|
121 |
*/
|
122 |
public static void register() { |
123 |
ViewManager factory = new ViewManager();
|
124 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
125 |
|
126 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
127 |
manager.registerFactory(factory); |
128 |
|
129 |
|
130 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
131 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
132 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
133 |
|
134 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
135 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
136 |
|
137 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
138 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
139 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
140 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
141 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
142 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
143 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
144 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
145 |
|
146 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
147 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
148 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
149 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
150 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
151 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
152 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
153 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
154 |
IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class); |
155 |
|
156 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
157 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
158 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
159 |
|
160 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
161 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
162 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
163 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
164 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
165 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
166 |
|
167 |
if (factory.persistenceDefinition == null){ |
168 |
factory.persistenceDefinition = manager.addDefinition( |
169 |
ViewDocument.class, |
170 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
171 |
"Default view document persistence definition",
|
172 |
null,
|
173 |
null
|
174 |
); |
175 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
176 |
|
177 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
178 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
179 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
180 |
|
181 |
} |
182 |
|
183 |
|
184 |
} |
185 |
|
186 |
@SuppressWarnings("rawtypes") |
187 |
public DynStruct getDefinition(String className) { |
188 |
|
189 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
190 |
return this.persistenceDefinition; |
191 |
} |
192 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
193 |
return this.persistenceDefinition; |
194 |
} |
195 |
if( this.getDocumentClass().getName().equals(className) ) { |
196 |
return this.persistenceDefinition; |
197 |
} |
198 |
|
199 |
return null; |
200 |
} |
201 |
|
202 |
@SuppressWarnings("rawtypes") |
203 |
protected Class getDocumentClass() { |
204 |
return DefaultViewDocument.class;
|
205 |
} |
206 |
|
207 |
public boolean manages(Object object) { |
208 |
return object instanceof ViewDocument; |
209 |
} |
210 |
} |