svn-document-layout / trunk / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / extension / LayoutMainExtension.java @ 5
History | View | Annotate | Download (13.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.app.extension; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.io.File; |
26 |
import java.io.FileInputStream; |
27 |
import java.io.FileNotFoundException; |
28 |
import java.text.MessageFormat; |
29 |
import java.util.prefs.Preferences; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.messages.NotificationManager; |
33 |
import org.gvsig.andami.plugins.Extension; |
34 |
import org.gvsig.app.ApplicationLocator; |
35 |
import org.gvsig.app.project.Project; |
36 |
import org.gvsig.app.project.ProjectManager; |
37 |
import org.gvsig.app.project.documents.layout.DefaultLayoutManager; |
38 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
39 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
40 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.BeforeLayoutMenuEntry; |
41 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.BehindLayoutMenuEntry; |
42 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.CancelLayoutMenuEntry; |
43 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.CopyLayoutMenuEntry; |
44 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.CutLayoutMenuEntry; |
45 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.PasteLayoutMenuEntry; |
46 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.PositionLayoutMenuEntry; |
47 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.PropertyLayoutMenuEntry; |
48 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.RefreshLayoutMenuEntry; |
49 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.SelectAllLayoutMenuEntry; |
50 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.SimplifyLayoutMenuEntry; |
51 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.TerminateLayoutMenuEntry; |
52 |
import org.gvsig.app.project.documents.layout.fframes.FFrame; |
53 |
import org.gvsig.app.project.documents.layout.fframes.FFrameBasicFactory; |
54 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphics; |
55 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphicsFactory; |
56 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid; |
57 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGridFactory; |
58 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup; |
59 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGroupFactory; |
60 |
import org.gvsig.app.project.documents.layout.fframes.FFrameLegend; |
61 |
import org.gvsig.app.project.documents.layout.fframes.FFrameLegendFactory; |
62 |
import org.gvsig.app.project.documents.layout.fframes.FFrameNorth; |
63 |
import org.gvsig.app.project.documents.layout.fframes.FFrameNorthFactory; |
64 |
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView; |
65 |
import org.gvsig.app.project.documents.layout.fframes.FFrameOverViewFactory; |
66 |
import org.gvsig.app.project.documents.layout.fframes.FFramePicture; |
67 |
import org.gvsig.app.project.documents.layout.fframes.FFramePictureFactory; |
68 |
import org.gvsig.app.project.documents.layout.fframes.FFrameScaleBar; |
69 |
import org.gvsig.app.project.documents.layout.fframes.FFrameScaleBarFactory; |
70 |
import org.gvsig.app.project.documents.layout.fframes.FFrameSymbol; |
71 |
import org.gvsig.app.project.documents.layout.fframes.FFrameSymbolFactory; |
72 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTable; |
73 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTableFactory; |
74 |
import org.gvsig.app.project.documents.layout.fframes.FFrameText; |
75 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTextFactory; |
76 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
77 |
import org.gvsig.app.project.documents.layout.fframes.FFrameViewFactory; |
78 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameBoxDialog; |
79 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGraphicsDialog; |
80 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGridDialog; |
81 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGroupDialog; |
82 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog; |
83 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameNorthDialog; |
84 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameOverViewDialog; |
85 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFramePictureDialog; |
86 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog; |
87 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameTextDialog; |
88 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameViewDialog; |
89 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
90 |
import org.gvsig.gui.beans.swing.JFileChooser; |
91 |
import org.gvsig.tools.ToolsLocator; |
92 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
93 |
import org.gvsig.tools.persistence.PersistenceManager; |
94 |
import org.gvsig.tools.persistence.PersistentState; |
95 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
96 |
import org.gvsig.utils.GenericFileFilter; |
97 |
|
98 |
/**
|
99 |
* Extension que proporciona controles para crear proyectos nuevos, abrirlos y
|
100 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos
|
101 |
* en esta clase.
|
102 |
*
|
103 |
* @author Fernando Gonz?lez Cort?s
|
104 |
*/
|
105 |
public class LayoutMainExtension extends Extension { |
106 |
|
107 |
private String templatesPath; |
108 |
public static final String LAYOUT_TEMPLATE_FILECHOOSER_ID = |
109 |
"LAYOUT_TEMPLATE_FILECHOOSER_ID";
|
110 |
|
111 |
private void registerIcons() { |
112 |
PluginServices.getIconTheme().registerDefault( |
113 |
"layout-template-open",
|
114 |
this.getClass().getClassLoader()
|
115 |
.getResource("images/opentemplate.png"));
|
116 |
} |
117 |
|
118 |
public void initialize() { |
119 |
// Nothing to do
|
120 |
} |
121 |
|
122 |
public void postInitialize() { |
123 |
super.postInitialize();
|
124 |
initializeDocumentActionsExtensionPoint(); |
125 |
registerIcons(); |
126 |
registerDocuments(); |
127 |
registerFFrames(); |
128 |
registerContextMenuOptions(); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
133 |
*/
|
134 |
public void execute(String actionCommand) { |
135 |
if ("OPENTEMPLATE".equals(actionCommand)) { |
136 |
openLayout(); |
137 |
} |
138 |
} |
139 |
|
140 |
private void openLayout() { |
141 |
// Project project = ((ProjectExtension)
|
142 |
// PluginServices.getExtension(ProjectExtension.class)).getProject();
|
143 |
LayoutPanel layout = null;
|
144 |
|
145 |
if (templatesPath == null) { |
146 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
147 |
templatesPath = prefs.get("TemplatesFolder", null); |
148 |
} |
149 |
|
150 |
JFileChooser jfc =
|
151 |
new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID, templatesPath); |
152 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
153 |
LayoutManager.TEMPLATE_FILE_EXTENSION, PluginServices.getText(this, |
154 |
"_Layout_template")));
|
155 |
|
156 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
157 |
File file = jfc.getSelectedFile();
|
158 |
if (!file.getPath().toLowerCase()
|
159 |
.endsWith(LayoutManager.TEMPLATE_FILE_EXTENSION.toLowerCase())) {
|
160 |
file = |
161 |
new File(file.getPath() |
162 |
+ LayoutManager.TEMPLATE_FILE_EXTENSION);
|
163 |
} |
164 |
try {
|
165 |
File xmlFile = new File(file.getAbsolutePath()); |
166 |
FileInputStream is = new FileInputStream(xmlFile); |
167 |
|
168 |
PersistenceManager persistenceManager = |
169 |
ToolsLocator.getPersistenceManager(); |
170 |
PersistentState persistentState = |
171 |
persistenceManager.loadState(is); |
172 |
layout = |
173 |
(LayoutPanel) persistenceManager.create(persistentState); |
174 |
|
175 |
} catch (FileNotFoundException e) { |
176 |
NotificationManager.addError(MessageFormat.format(
|
177 |
PluginServices.getText(this,
|
178 |
"_Cant_load_layout_template_{0}"), file.getPath()), e);
|
179 |
} catch (PersistenceException e) {
|
180 |
NotificationManager.addError(MessageFormat.format(
|
181 |
PluginServices.getText(this,
|
182 |
"_Cant_load_layout_template_{0}"), file.getPath()), e);
|
183 |
} |
184 |
|
185 |
LayoutDocument layoutDocument = |
186 |
(LayoutDocument) ProjectManager.getInstance().createDocument( |
187 |
DefaultLayoutManager.TYPENAME, file.getName()); |
188 |
Project p = |
189 |
ApplicationLocator.getManager().getProjectManager() |
190 |
.getCurrentProject(); |
191 |
p.add(layoutDocument); |
192 |
PluginServices.getMDIManager().addWindow(layout); |
193 |
|
194 |
} |
195 |
} |
196 |
|
197 |
private void registerDocuments() { |
198 |
DefaultLayoutManager.register(); |
199 |
} |
200 |
|
201 |
private void registerFFrames() { |
202 |
DefaultLayoutManager layoutManager = |
203 |
(DefaultLayoutManager) ProjectManager.getInstance() |
204 |
.getDocumentManager(DefaultLayoutManager.TYPENAME); |
205 |
|
206 |
// Register Frames
|
207 |
layoutManager.registerFrameFactory(new FFrameBasicFactory());
|
208 |
layoutManager.registerFrameFactory(new FFrameGraphicsFactory());
|
209 |
layoutManager.registerFrameFactory(new FFrameGroupFactory());
|
210 |
layoutManager.registerFrameFactory(new FFrameLegendFactory());
|
211 |
layoutManager.registerFrameFactory(new FFrameNorthFactory());
|
212 |
layoutManager.registerFrameFactory(new FFrameOverViewFactory());
|
213 |
layoutManager.registerFrameFactory(new FFramePictureFactory());
|
214 |
layoutManager.registerFrameFactory(new FFrameScaleBarFactory());
|
215 |
layoutManager.registerFrameFactory(new FFrameSymbolFactory());
|
216 |
layoutManager.registerFrameFactory(new FFrameTableFactory());
|
217 |
layoutManager.registerFrameFactory(new FFrameTextFactory());
|
218 |
layoutManager.registerFrameFactory(new FFrameViewFactory());
|
219 |
layoutManager.registerFrameFactory(new FFrameGridFactory());
|
220 |
|
221 |
// Register FFrameDialogs forms
|
222 |
layoutManager.registerFFrameDialog( |
223 |
FFrameGraphics.PERSISTENCE_DEFINITION_NAME, FFrameGraphicsDialog.class); |
224 |
layoutManager.registerFFrameDialog( |
225 |
FFrameSymbol.PERSISTENCE_DEFINITION_NAME, FFrameGraphicsDialog.class); |
226 |
layoutManager.registerFFrameDialog( |
227 |
FFrameGroup.PERSISTENCE_DEFINITION_NAME, FFrameGroupDialog.class); |
228 |
layoutManager.registerFFrameDialog( |
229 |
FFrameTable.PERSISTENCE_DEFINITION_NAME, FFrameBoxDialog.class); |
230 |
layoutManager.registerFFrameDialog( |
231 |
FFrameLegend.PERSISTENCE_DEFINITION_NAME, FFrameLegendDialog.class); |
232 |
layoutManager.registerFFrameDialog( |
233 |
FFramePicture.PERSISTENCE_DEFINITION_NAME, FFramePictureDialog.class); |
234 |
layoutManager.registerFFrameDialog( |
235 |
FFrameNorth.PERSISTENCE_DEFINITION_NAME, FFrameNorthDialog.class); |
236 |
layoutManager.registerFFrameDialog( |
237 |
FFrameScaleBar.PERSISTENCE_DEFINITION_NAME, FFrameScaleBarDialog.class); |
238 |
layoutManager.registerFFrameDialog( |
239 |
FFrameText.PERSISTENCE_DEFINITION_NAME, FFrameTextDialog.class); |
240 |
layoutManager.registerFFrameDialog( |
241 |
FFrameView.PERSISTENCE_DEFINITION_NAME, FFrameViewDialog.class); |
242 |
layoutManager.registerFFrameDialog( |
243 |
FFrameOverView.PERSISTENCE_DEFINITION_NAME, FFrameOverViewDialog.class); |
244 |
layoutManager.registerFFrameDialog( |
245 |
FFrameGrid.PERSISTENCE_DEFINITION_NAME, FFrameGridDialog.class); |
246 |
|
247 |
FFrame.initializeIcons(); |
248 |
FFrameTable.initializeIcons(); |
249 |
} |
250 |
|
251 |
private void registerContextMenuOptions() { |
252 |
LayoutManager layoutManager =
|
253 |
(LayoutManager) ProjectManager.getInstance()
|
254 |
.getDocumentManager("project.document.layout");
|
255 |
|
256 |
layoutManager.registerLayoutMenuAction("Terminate", TerminateLayoutMenuEntry.class);
|
257 |
layoutManager.registerLayoutMenuAction("Cancel", CancelLayoutMenuEntry.class);
|
258 |
layoutManager.registerLayoutMenuAction("Copy", CopyLayoutMenuEntry.class);
|
259 |
layoutManager.registerLayoutMenuAction("Cut", CutLayoutMenuEntry.class);
|
260 |
layoutManager.registerLayoutMenuAction("Paste", PasteLayoutMenuEntry.class);
|
261 |
layoutManager.registerLayoutMenuAction("Simplify", SimplifyLayoutMenuEntry.class);
|
262 |
layoutManager.registerLayoutMenuAction("Property",PropertyLayoutMenuEntry.class);
|
263 |
layoutManager.registerLayoutMenuAction("SelectAll", SelectAllLayoutMenuEntry.class);
|
264 |
layoutManager.registerLayoutMenuAction("Behind", BehindLayoutMenuEntry.class);
|
265 |
layoutManager.registerLayoutMenuAction("Before", BeforeLayoutMenuEntry.class);
|
266 |
layoutManager.registerLayoutMenuAction("Position", PositionLayoutMenuEntry.class);
|
267 |
layoutManager.registerLayoutMenuAction("Refresh", RefreshLayoutMenuEntry.class);
|
268 |
|
269 |
} |
270 |
|
271 |
private void initializeDocumentActionsExtensionPoint() { |
272 |
ExtensionPointManager epMan = ToolsLocator.getExtensionPointManager(); |
273 |
epMan.add("DocumentActions_Map",
|
274 |
"Context menu options of the map document list"
|
275 |
+ " in the project window " + "(register instances of " |
276 |
+ "org.gvsig.app.project.AbstractDocumentContextMenuAction)");
|
277 |
} |
278 |
|
279 |
public boolean isEnabled() { |
280 |
return true; |
281 |
} |
282 |
|
283 |
public boolean isVisible() { |
284 |
return true; |
285 |
} |
286 |
} |