svn-gvsig-desktop / tags / v2_0_0_Build_2061 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / ViewManager.java @ 39431
History | View | Annotate | Download (7.44 KB)
1 |
package org.gvsig.app.project.documents.view; |
---|---|
2 |
|
3 |
import javax.swing.ImageIcon; |
4 |
|
5 |
import org.gvsig.andami.IconThemeHelper; |
6 |
import org.gvsig.andami.PluginServices; |
7 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
8 |
import org.gvsig.app.project.ProjectManager; |
9 |
import org.gvsig.app.project.documents.AbstractDocument; |
10 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
11 |
import org.gvsig.app.project.documents.Document; |
12 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
13 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
14 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
15 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
16 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
17 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
18 |
import org.gvsig.app.project.documents.view.gui.ViewProperties; |
19 |
import org.gvsig.fmap.mapcontext.MapContext; |
20 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
21 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
22 |
import org.gvsig.tools.ToolsLocator; |
23 |
import org.gvsig.tools.dynobject.DynStruct; |
24 |
import org.gvsig.tools.persistence.PersistenceManager; |
25 |
import org.slf4j.Logger; |
26 |
import org.slf4j.LoggerFactory; |
27 |
|
28 |
/**
|
29 |
* Factory of View.
|
30 |
*
|
31 |
* @author 2005- Vicente Caballero
|
32 |
* @author 2009- Joaquin del Cerro
|
33 |
*
|
34 |
*/
|
35 |
public class ViewManager extends AbstractDocumentManager { |
36 |
private static final Logger logger = LoggerFactory.getLogger(ViewManager.class); |
37 |
|
38 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME = |
39 |
"DefaultViewDocument";
|
40 |
public static String TYPENAME = "project.document.view2d"; |
41 |
private DynStruct persistenceDefinition;
|
42 |
|
43 |
public ViewManager() {
|
44 |
// Do nothing
|
45 |
} |
46 |
|
47 |
public int getPriority() { |
48 |
return 0; |
49 |
} |
50 |
|
51 |
public ImageIcon getIcon() { |
52 |
return PluginServices.getIconTheme().get("document-view-icon"); |
53 |
} |
54 |
|
55 |
public ImageIcon getIconSelected() { |
56 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
57 |
} |
58 |
|
59 |
public String getTitle() { |
60 |
return PluginServices.getText(this, "Vista"); |
61 |
} |
62 |
|
63 |
public String getTypeName() { |
64 |
return TYPENAME;
|
65 |
} |
66 |
|
67 |
public Class getMainWindowClass() { |
68 |
return DefaultViewPanel.class;
|
69 |
} |
70 |
|
71 |
public AbstractDocument createDocument() { |
72 |
return new DefaultViewDocument(this); |
73 |
} |
74 |
|
75 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
76 |
IDocumentWindow view; |
77 |
|
78 |
view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc); |
79 |
if( view != null ) { |
80 |
// The view window document is already created, return it.
|
81 |
return view;
|
82 |
} |
83 |
view = this.createDocumentWindow(doc);
|
84 |
if ( layout != null && view != null ) { |
85 |
view.setWindowLayout(layout); |
86 |
} |
87 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
88 |
return view;
|
89 |
} |
90 |
|
91 |
public IWindow getPropertiesWindow(Document doc) { |
92 |
return new ViewProperties((DefaultViewDocument) doc); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* Registers in the points of extension the Factory with alias.
|
97 |
*
|
98 |
*/
|
99 |
public static void register() { |
100 |
ViewManager factory = new ViewManager();
|
101 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
102 |
|
103 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
104 |
manager.registerFactory(factory); |
105 |
|
106 |
|
107 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
108 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
109 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
110 |
|
111 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
112 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
113 |
|
114 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
115 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
116 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
117 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
118 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
119 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
120 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
121 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
122 |
|
123 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
124 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
125 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
126 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
127 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
128 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
129 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
130 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
131 |
IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class); |
132 |
|
133 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
134 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
135 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
136 |
|
137 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
138 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
139 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
140 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
141 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
142 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
143 |
|
144 |
if (factory.persistenceDefinition == null){ |
145 |
factory.persistenceDefinition = manager.addDefinition( |
146 |
ViewDocument.class, |
147 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
148 |
"Default view document persistence definition",
|
149 |
null,
|
150 |
null
|
151 |
); |
152 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
153 |
|
154 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
155 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
156 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
157 |
|
158 |
} |
159 |
|
160 |
|
161 |
} |
162 |
|
163 |
@SuppressWarnings("rawtypes") |
164 |
public DynStruct getDefinition(String className) { |
165 |
|
166 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
167 |
return this.persistenceDefinition; |
168 |
} |
169 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
170 |
return this.persistenceDefinition; |
171 |
} |
172 |
if( this.getDocumentClass().getName().equals(className) ) { |
173 |
return this.persistenceDefinition; |
174 |
} |
175 |
|
176 |
return null; |
177 |
} |
178 |
|
179 |
@SuppressWarnings("rawtypes") |
180 |
protected Class getDocumentClass() { |
181 |
return DefaultViewDocument.class;
|
182 |
} |
183 |
|
184 |
public boolean manages(Object object) { |
185 |
return object instanceof ViewDocument; |
186 |
} |
187 |
} |