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