svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / extension / LayoutExtension.java @ 1737
History | View | Annotate | Download (14.9 KB)
1 | 5 | jldominguez | /* 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 | 1701 | fdiaz | import java.awt.BorderLayout; |
25 | 5 | jldominguez | import java.awt.Component; |
26 | 1701 | fdiaz | import java.awt.event.ActionEvent; |
27 | 5 | jldominguez | import java.io.File; |
28 | import java.io.FileOutputStream; |
||
29 | 1701 | fdiaz | import javax.swing.ImageIcon; |
30 | import javax.swing.JButton; |
||
31 | 5 | jldominguez | import javax.swing.JFileChooser; |
32 | import javax.swing.JOptionPane; |
||
33 | 1701 | fdiaz | import javax.swing.JPanel; |
34 | import org.apache.commons.lang3.StringUtils; |
||
35 | 23 | jldominguez | import org.gvsig.andami.IconThemeHelper; |
36 | 5 | jldominguez | import org.gvsig.andami.PluginServices; |
37 | import org.gvsig.andami.messages.NotificationManager; |
||
38 | import org.gvsig.andami.plugins.Extension; |
||
39 | import org.gvsig.andami.preferences.IPreference; |
||
40 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
41 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
42 | 1701 | fdiaz | import org.gvsig.app.ApplicationLocator; |
43 | import org.gvsig.app.ApplicationManager; |
||
44 | import org.gvsig.app.PreferencesNode; |
||
45 | import static org.gvsig.app.extension.InitializeApplicationExtension.TEMPLATES_FOLDER_PROPERTY_NAME; |
||
46 | 5 | jldominguez | import org.gvsig.app.gui.preferencespage.LayoutPage; |
47 | import org.gvsig.app.project.documents.layout.FLayoutZooms; |
||
48 | 33 | jldominguez | import org.gvsig.app.project.documents.layout.LayoutManager; |
49 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
50 | 1531 | jjdelcerro | import org.gvsig.app.project.documents.layout.report.LayoutReportActionFactory; |
51 | 1701 | fdiaz | import org.gvsig.filedialogchooser.FileDialogChooser; |
52 | import org.gvsig.filedialogchooser.FileDialogChooserManager; |
||
53 | 5 | jldominguez | import org.gvsig.tools.ToolsLocator; |
54 | 1701 | fdiaz | import org.gvsig.tools.i18n.I18nManager; |
55 | 5 | jldominguez | import org.gvsig.tools.persistence.PersistenceManager; |
56 | import org.gvsig.tools.persistence.PersistentState; |
||
57 | 274 | cmartinez | import org.gvsig.tools.persistence.text.JavaTextFactory; |
58 | 1701 | fdiaz | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
59 | import org.gvsig.tools.util.ToolsUtilLocator; |
||
60 | 5 | jldominguez | import org.gvsig.utils.GenericFileFilter; |
61 | 1737 | fdiaz | import org.slf4j.Logger; |
62 | import org.slf4j.LoggerFactory; |
||
63 | 5 | jldominguez | |
64 | /**
|
||
65 | * Extensi?n para controlar las operaciones basicas sobre el Layout.
|
||
66 | *
|
||
67 | * @author Vicente Caballero Navarro
|
||
68 | */
|
||
69 | public class LayoutExtension extends Extension implements IPreferenceExtension { |
||
70 | |||
71 | private static final Logger logger = LoggerFactory |
||
72 | 402 | mcompany | .getLogger(LayoutExtension.class); |
73 | 5 | jldominguez | |
74 | private LayoutPanel layout = null; |
||
75 | |||
76 | /**
|
||
77 | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
||
78 | */
|
||
79 | 1737 | fdiaz | @Override
|
80 | 5 | jldominguez | public void execute(String s) { |
81 | layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
||
82 | |||
83 | FLayoutZooms zooms = new FLayoutZooms(layout);
|
||
84 | logger.debug("Comand : " + s);
|
||
85 | |||
86 | 1737 | fdiaz | switch (s) {
|
87 | case "layout-navigation-pan": |
||
88 | layout.getLayoutControl().setTool("layoutpan");
|
||
89 | break;
|
||
90 | case "layout-navigation-zoom-in-topoint": |
||
91 | layout.getLayoutControl().setTool("layoutzoomin");
|
||
92 | break;
|
||
93 | case "layout-navigation-zoom-out-topoint": |
||
94 | layout.getLayoutControl().setTool("layoutzoomout");
|
||
95 | break;
|
||
96 | case "layout-navigation-zoom-all": |
||
97 | layout.getLayoutControl().fullRect(); |
||
98 | break;
|
||
99 | case "layout-navigation-zoom-real": |
||
100 | zooms.realZoom(); |
||
101 | break;
|
||
102 | case "layout-navigation-zoom-out-center": |
||
103 | zooms.zoomOut(); |
||
104 | break;
|
||
105 | case "layout-navigation-zoom-in-center": |
||
106 | zooms.zoomIn(); |
||
107 | break;
|
||
108 | case "layout-navigation-zoom-selected": |
||
109 | zooms.zoomSelect(); |
||
110 | break;
|
||
111 | case "application-layout-template-save": |
||
112 | saveLayout(); |
||
113 | break;
|
||
114 | default:
|
||
115 | break;
|
||
116 | 402 | mcompany | } |
117 | 5 | jldominguez | } |
118 | 1701 | fdiaz | |
119 | 5 | jldominguez | private void saveLayout() { |
120 | 1701 | fdiaz | I18nManager i18n = ToolsLocator.getI18nManager(); |
121 | 5 | jldominguez | layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
122 | 1701 | fdiaz | FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager(); |
123 | FileDialogChooser fc = manager.create("_Last_layout_template_folder");
|
||
124 | 402 | mcompany | GenericFileFilter layoutMainFilter = new GenericFileFilter(
|
125 | 1701 | fdiaz | LayoutManager.TEMPLATE_FILE_POINTEXT,
|
126 | i18n.getTranslation("_Layout_template") + " (*" |
||
127 | + LayoutManager.TEMPLATE_FILE_POINTEXT + ")"); |
||
128 | 5 | jldominguez | |
129 | 1701 | fdiaz | fc.addChoosableFileFilter(layoutMainFilter); |
130 | fc.setFileFilter(layoutMainFilter); |
||
131 | ApplicationManager application = ApplicationLocator.getApplicationManager(); |
||
132 | PreferencesNode prefs = application.getPreferences("gvsig.foldering");
|
||
133 | |||
134 | File projectfile = application.getCurrentProject().getFile();
|
||
135 | if(projectfile != null) { |
||
136 | JPanel accesory = new JPanel(); |
||
137 | accesory.setLayout(new BorderLayout(0, 0)); |
||
138 | ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-project-gotofolder"); |
||
139 | JButton goToProjectButton = new JButton(icon); |
||
140 | |||
141 | goToProjectButton.setToolTipText(i18n.getTranslation("_Go_to_folder_project"));
|
||
142 | accesory.add(goToProjectButton, BorderLayout.NORTH);
|
||
143 | 1737 | fdiaz | goToProjectButton.addActionListener((ActionEvent e) -> {
|
144 | fc.setCurrentDirectory(projectfile.getParentFile()); |
||
145 | 1701 | fdiaz | }); |
146 | fc.setAccessory(accesory); |
||
147 | } |
||
148 | 1737 | fdiaz | |
149 | File folder = null; |
||
150 | folder = manager.getLastPath("_Last_layout_template_folder", null); |
||
151 | if(folder == null) { |
||
152 | if(projectfile != null){ |
||
153 | folder = projectfile.getParentFile(); |
||
154 | 5 | jldominguez | } |
155 | 1737 | fdiaz | if (folder == null) { |
156 | folder = ToolsLocator.getFoldersManager().getHome(); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if (folder == null) { |
||
161 | String path = prefs.get(TEMPLATES_FOLDER_PROPERTY_NAME, null); |
||
162 | if (StringUtils.isNotBlank(path)) {
|
||
163 | folder = new File(path); |
||
164 | } |
||
165 | } |
||
166 | 1701 | fdiaz | |
167 | |||
168 | if (fc.showSaveDialog((Component) PluginServices.getMainFrame(), folder) != JFileChooser.APPROVE_OPTION) { |
||
169 | return;
|
||
170 | } |
||
171 | File file = fc.getSelectedFile();
|
||
172 | if (!(file.getPath().endsWith(
|
||
173 | LayoutManager.TEMPLATE_FILE_POINTEXT.toLowerCase()) || file
|
||
174 | .getPath().endsWith(LayoutManager.TEMPLATE_FILE_POINTEXT))) {
|
||
175 | file = new File(file.getPath() |
||
176 | + LayoutManager.TEMPLATE_FILE_POINTEXT);
|
||
177 | } |
||
178 | if (file.exists()) {
|
||
179 | int resp = JOptionPane.showConfirmDialog( |
||
180 | (Component) PluginServices.getMainFrame(),
|
||
181 | PluginServices.getText(this,
|
||
182 | "fichero_ya_existe_seguro_desea_guardarlo"),
|
||
183 | PluginServices.getText(this, "guardar"), |
||
184 | JOptionPane.YES_NO_OPTION);
|
||
185 | if (resp != JOptionPane.YES_OPTION) { |
||
186 | return;
|
||
187 | 402 | mcompany | } |
188 | 5 | jldominguez | } |
189 | 1701 | fdiaz | |
190 | try {
|
||
191 | FileOutputStream fos = new FileOutputStream( |
||
192 | file.getAbsolutePath()); |
||
193 | PersistenceManager persistenceManager = ToolsLocator |
||
194 | .getPersistenceManager(); |
||
195 | PersistentState persistentState = persistenceManager |
||
196 | .getState(layout); |
||
197 | persistenceManager.saveState(persistentState, fos); |
||
198 | } catch (Exception e) { |
||
199 | NotificationManager.addError(PluginServices.getText(this,
|
||
200 | "Error_guardando_la_plantilla"), e);
|
||
201 | } |
||
202 | |||
203 | // manager.setLastPath("_Last_layout_template_folder", file.getParentFile());
|
||
204 | |||
205 | 5 | jldominguez | } |
206 | 1701 | fdiaz | |
207 | 5 | jldominguez | /**
|
208 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
209 | */
|
||
210 | 1737 | fdiaz | @Override
|
211 | 5 | jldominguez | public boolean isVisible() { |
212 | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
||
213 | |||
214 | if (f == null) { |
||
215 | return false; |
||
216 | } |
||
217 | |||
218 | if (f instanceof LayoutPanel) { |
||
219 | 200 | cmartinez | return true; |
220 | 5 | jldominguez | } |
221 | return false; |
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
||
226 | */
|
||
227 | 1737 | fdiaz | @Override
|
228 | 5 | jldominguez | public void initialize() { |
229 | 402 | mcompany | registerPersistence(); |
230 | 5 | jldominguez | registerIcons(); |
231 | } |
||
232 | |||
233 | 1531 | jjdelcerro | @Override
|
234 | public void postInitialize() { |
||
235 | LayoutReportActionFactory.selfRegister(); |
||
236 | } |
||
237 | |||
238 | 274 | cmartinez | private void registerPersistence() { |
239 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
240 | JavaTextFactory factory = new JavaTextFactory();
|
||
241 | manager.registerFactory(factory); |
||
242 | } |
||
243 | 402 | mcompany | |
244 | 5 | jldominguez | private void registerIcons() { |
245 | 402 | mcompany | |
246 | IconThemeHelper.registerIcon("action",
|
||
247 | "application-layout-template-save", this); |
||
248 | |||
249 | IconThemeHelper.registerIcon("action",
|
||
250 | 1701 | fdiaz | "application-project-gotofolder", this); |
251 | |||
252 | IconThemeHelper.registerIcon("action",
|
||
253 | 402 | mcompany | "layout-navigation-zoom-in-center", this); |
254 | IconThemeHelper.registerIcon("action",
|
||
255 | "layout-navigation-zoom-out-center", this); |
||
256 | IconThemeHelper.registerIcon("action",
|
||
257 | "layout-navigation-zoom-in-topoint", this); |
||
258 | IconThemeHelper.registerIcon("action",
|
||
259 | "layout-navigation-zoom-out-topoint", this); |
||
260 | IconThemeHelper.registerIcon("action", "layout-navigation-zoom-all", |
||
261 | this);
|
||
262 | IconThemeHelper.registerIcon("action", "layout-navigation-zoom-real", |
||
263 | this);
|
||
264 | IconThemeHelper.registerIcon("action",
|
||
265 | "layout-navigation-zoom-selected", this); |
||
266 | 24 | jldominguez | IconThemeHelper.registerIcon("action", "layout-navigation-pan", this); |
267 | 5 | jldominguez | |
268 | 402 | mcompany | IconThemeHelper.registerIcon("action",
|
269 | "layout-view-navigation-zoom-in-topoint", this); |
||
270 | IconThemeHelper.registerIcon("action",
|
||
271 | "layout-view-navigation-zoom-out-topoint", this); |
||
272 | IconThemeHelper.registerIcon("action",
|
||
273 | "layout-view-navigation-zoom-all", this); |
||
274 | IconThemeHelper.registerIcon("action", "layout-view-navigation-pan", |
||
275 | this);
|
||
276 | 24 | jldominguez | // ================================================
|
277 | // Cursors
|
||
278 | 402 | mcompany | IconThemeHelper.registerIcon("cursor",
|
279 | "cursor-layout-navigation-zoom-in-topoint", this); |
||
280 | IconThemeHelper.registerIcon("cursor",
|
||
281 | "cursor-layout-navigation-zoom-out-topoint", this); |
||
282 | IconThemeHelper.registerIcon("cursor", "cursor-selection-by-rectangle", |
||
283 | this);
|
||
284 | 24 | jldominguez | IconThemeHelper.registerIcon("cursor", "cursor-selection-simple", this); |
285 | 402 | mcompany | IconThemeHelper |
286 | .registerIcon("cursor", "cursor-selection-complex", this); |
||
287 | IconThemeHelper.registerIcon("cursor",
|
||
288 | "cursor-layout-graphic-edit-vertex", this); |
||
289 | IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-circle", |
||
290 | this);
|
||
291 | IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polyline", |
||
292 | this);
|
||
293 | IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-point", |
||
294 | this);
|
||
295 | IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polygon", |
||
296 | this);
|
||
297 | IconThemeHelper.registerIcon("cursor",
|
||
298 | "cursor-layout-insert-rectangle", this); |
||
299 | IconThemeHelper.registerIcon("cursor",
|
||
300 | "cursor-layout-view-navigation-zoom-in-topoint", this); |
||
301 | IconThemeHelper.registerIcon("cursor",
|
||
302 | "cursor-layout-view-navigation-zoom-out-topoint", this); |
||
303 | 24 | jldominguez | // End cursors
|
304 | // ================================================
|
||
305 | 5 | jldominguez | |
306 | 24 | jldominguez | IconThemeHelper.registerIcon("document", "document-map-icon", this); |
307 | IconThemeHelper.registerIcon("document", "document-map-icon-sel", this); |
||
308 | 402 | mcompany | |
309 | 24 | jldominguez | IconThemeHelper.registerIcon("layout", "neresize-icon", this); |
310 | IconThemeHelper.registerIcon("layout", "eresize-icon", this); |
||
311 | IconThemeHelper.registerIcon("layout", "nresize-icon", this); |
||
312 | 125 | jldominguez | IconThemeHelper.registerIcon("layout", "graphic-move-icon", this); |
313 | 402 | mcompany | |
314 | 24 | jldominguez | IconThemeHelper.registerIcon("layout", "sereresize-icon", this); |
315 | IconThemeHelper.registerIcon("layout", "symboltag-icon", this); |
||
316 | IconThemeHelper.registerIcon("layout", "numero-icon", this); |
||
317 | IconThemeHelper.registerIcon("layout", "barra1-icon", this); |
||
318 | IconThemeHelper.registerIcon("layout", "barra2-icon", this); |
||
319 | IconThemeHelper.registerIcon("layout", "barra3-icon", this); |
||
320 | 12 | jldominguez | |
321 | 24 | jldominguez | IconThemeHelper.registerIcon("layout", "text-left-icon", this); |
322 | IconThemeHelper.registerIcon("layout", "text-center-v-icon", this); |
||
323 | IconThemeHelper.registerIcon("layout", "text-right-icon", this); |
||
324 | IconThemeHelper.registerIcon("layout", "left-rotation-icon", this); |
||
325 | IconThemeHelper.registerIcon("layout", "text-up-icon", this); |
||
326 | IconThemeHelper.registerIcon("layout", "text-center-h-icon", this); |
||
327 | IconThemeHelper.registerIcon("layout", "text-down-icon", this); |
||
328 | IconThemeHelper.registerIcon("layout", "text-distup-icon", this); |
||
329 | IconThemeHelper.registerIcon("layout", "text-distcenterh-icon", this); |
||
330 | IconThemeHelper.registerIcon("layout", "text-distdown-icon", this); |
||
331 | IconThemeHelper.registerIcon("layout", "text-distleft-icon", this); |
||
332 | 14 | jldominguez | |
333 | 24 | jldominguez | IconThemeHelper.registerIcon("layout", "text-distcenterv-icon", this); |
334 | IconThemeHelper.registerIcon("layout", "text-distright-icon", this); |
||
335 | IconThemeHelper.registerIcon("layout", "text-size-width-icon", this); |
||
336 | IconThemeHelper.registerIcon("layout", "text-size-height-icon", this); |
||
337 | IconThemeHelper.registerIcon("layout", "text-size-other-icon", this); |
||
338 | IconThemeHelper.registerIcon("layout", "text-space-right-icon", this); |
||
339 | 107 | jldominguez | IconThemeHelper.registerIcon("layout", "text-space-down-icon", this); |
340 | 24 | jldominguez | IconThemeHelper.registerIcon("layout", "text-inlayout-icon", this); |
341 | IconThemeHelper.registerIcon("layout", "layout-pan-icon", this); |
||
342 | IconThemeHelper.registerIcon("layout", "view-pan-icon", this); |
||
343 | IconThemeHelper.registerIcon("layout", "right-rotation-icon", this); |
||
344 | 5 | jldominguez | } |
345 | |||
346 | /**
|
||
347 | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
||
348 | */
|
||
349 | 1737 | fdiaz | @Override
|
350 | 5 | jldominguez | public boolean isEnabled() { |
351 | return true; |
||
352 | } |
||
353 | |||
354 | /**
|
||
355 | * Devuelve el Layout sobre el que se opera.
|
||
356 | *
|
||
357 | * @return Layout.
|
||
358 | */
|
||
359 | public LayoutPanel getLayout() {
|
||
360 | return layout;
|
||
361 | } |
||
362 | |||
363 | 1737 | fdiaz | @Override
|
364 | 5 | jldominguez | public IPreference[] getPreferencesPages() { |
365 | return new IPreference[] { new LayoutPage() }; |
||
366 | } |
||
367 | } |