svn-document-layout / trunk / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / extension / LayoutExtension.java @ 23
History | View | Annotate | Download (16.8 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.FileOutputStream; |
27 |
|
28 |
import javax.swing.JFileChooser; |
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.andami.IconThemeHelper; |
35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.andami.messages.NotificationManager; |
37 |
import org.gvsig.andami.plugins.Extension; |
38 |
import org.gvsig.andami.preferences.IPreference; |
39 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
40 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
41 |
import org.gvsig.app.gui.preferencespage.LayoutPage; |
42 |
import org.gvsig.app.project.documents.layout.FLayoutZooms; |
43 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.persistence.PersistenceManager; |
46 |
import org.gvsig.tools.persistence.PersistentState; |
47 |
import org.gvsig.utils.GenericFileFilter; |
48 |
|
49 |
/**
|
50 |
* Extensi?n para controlar las operaciones basicas sobre el Layout.
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class LayoutExtension extends Extension implements IPreferenceExtension { |
55 |
|
56 |
private static final Logger logger = LoggerFactory |
57 |
.getLogger(LayoutExtension.class); |
58 |
|
59 |
private LayoutPanel layout = null; |
60 |
|
61 |
/**
|
62 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
63 |
*/
|
64 |
public void execute(String s) { |
65 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
66 |
|
67 |
FLayoutZooms zooms = new FLayoutZooms(layout);
|
68 |
logger.debug("Comand : " + s);
|
69 |
|
70 |
if (s.equals("LAYOUT_PAN")) { |
71 |
layout.getLayoutControl().setTool("layoutpan");
|
72 |
} else
|
73 |
if (s.equals("LAYOUT_ZOOM_IN")) { |
74 |
layout.getLayoutControl().setTool("layoutzoomin");
|
75 |
} else
|
76 |
if (s.equals("LAYOUT_ZOOM_OUT")) { |
77 |
layout.getLayoutControl().setTool("layoutzoomout");
|
78 |
} else
|
79 |
if (s.equals("LAYOUT_FULL")) { |
80 |
layout.getLayoutControl().fullRect(); |
81 |
} else
|
82 |
if (s.equals("REALZOOM")) { |
83 |
zooms.realZoom(); |
84 |
} else
|
85 |
if (s.equals("LAYOUT_ZOOMOUT")) { |
86 |
zooms.zoomOut(); |
87 |
} else
|
88 |
if (s.equals("LAYOUT_ZOOMIN")) { |
89 |
zooms.zoomIn(); |
90 |
} else
|
91 |
if (s.equals("ZOOMSELECT")) { |
92 |
zooms.zoomSelect(); |
93 |
} else
|
94 |
if (s.equals("SAVETEMPLATE")) { |
95 |
saveLayout(); |
96 |
} |
97 |
} |
98 |
|
99 |
private void saveLayout() { |
100 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
101 |
JFileChooser jfc = new JFileChooser(); |
102 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvt", PluginServices |
103 |
.getText(this, "plantilla"))); |
104 |
|
105 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
106 |
File file = jfc.getSelectedFile();
|
107 |
if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith( |
108 |
".GVT"))) {
|
109 |
file = new File(file.getPath() + ".gvt"); |
110 |
} |
111 |
if (file.exists()) {
|
112 |
int resp =
|
113 |
JOptionPane.showConfirmDialog((Component) PluginServices |
114 |
.getMainFrame(), PluginServices.getText(this,
|
115 |
"fichero_ya_existe_seguro_desea_guardarlo"),
|
116 |
PluginServices.getText(this, "guardar"), |
117 |
JOptionPane.YES_NO_OPTION);
|
118 |
if (resp != JOptionPane.YES_OPTION) { |
119 |
return;
|
120 |
} |
121 |
} |
122 |
|
123 |
try {
|
124 |
FileOutputStream fos =
|
125 |
new FileOutputStream(file.getAbsolutePath()); |
126 |
// OutputStreamWriter writer = new OutputStreamWriter(fos,
|
127 |
// ProjectExtension.PROJECTENCODING);
|
128 |
// Marshaller m = new Marshaller(writer);
|
129 |
// m.setEncoding(ProjectExtension.PROJECTENCODING);
|
130 |
// XMLEntity xml=layout.getXMLEntity();
|
131 |
// xml.putProperty("followHeaderEncoding", true);
|
132 |
// m.marshal(xml.getXmlTag());
|
133 |
|
134 |
PersistenceManager persistenceManager = |
135 |
ToolsLocator.getPersistenceManager(); |
136 |
PersistentState persistentState = |
137 |
persistenceManager.getState(layout); |
138 |
persistenceManager.saveState(persistentState, fos); |
139 |
} catch (Exception e) { |
140 |
NotificationManager.addError(PluginServices.getText(this,
|
141 |
"Error_guardando_la_plantilla"), e);
|
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
/**
|
147 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
148 |
*/
|
149 |
public boolean isVisible() { |
150 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
151 |
|
152 |
if (f == null) { |
153 |
return false; |
154 |
} |
155 |
|
156 |
if (f instanceof LayoutPanel) { |
157 |
return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() |
158 |
// > 0;
|
159 |
} |
160 |
return false; |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
165 |
*/
|
166 |
public void initialize() { |
167 |
registerIcons(); |
168 |
} |
169 |
|
170 |
private void registerIcons() { |
171 |
PluginServices.getIconTheme().registerDefault( |
172 |
"layout-zoom-in",
|
173 |
this.getClass().getClassLoader()
|
174 |
.getResource("images/LayoutZoomIn.png"));
|
175 |
|
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"layout-zoom-out",
|
178 |
this.getClass().getClassLoader()
|
179 |
.getResource("images/LayoutZoomOut.png"));
|
180 |
|
181 |
PluginServices.getIconTheme().registerDefault("layout-zoom-fit",
|
182 |
this.getClass().getClassLoader().getResource("images/layout-zoom-fit.gif")); |
183 |
|
184 |
PluginServices.getIconTheme() |
185 |
.registerDefault( |
186 |
"layout-zoom-real",
|
187 |
this.getClass().getClassLoader()
|
188 |
.getResource("images/zoomreal.png"));
|
189 |
|
190 |
PluginServices.getIconTheme().registerDefault( |
191 |
"layout-zoom-selected",
|
192 |
this.getClass().getClassLoader()
|
193 |
.getResource("images/zoomselect.png"));
|
194 |
|
195 |
PluginServices.getIconTheme().registerDefault( |
196 |
"layout-pan",
|
197 |
this.getClass().getClassLoader()
|
198 |
.getResource("images/layout-pan.png"));
|
199 |
|
200 |
PluginServices.getIconTheme().registerDefault("layout-template-save",
|
201 |
this.getClass().getClassLoader().getResource("images/layout-template-save.png")); |
202 |
|
203 |
PluginServices.getIconTheme().registerDefault( |
204 |
"layout-zoom-in-cursor",
|
205 |
this.getClass().getClassLoader().getResource(
|
206 |
"images/LayoutZoomInCursor.gif"));
|
207 |
PluginServices.getIconTheme().registerDefault( |
208 |
"layout-zoom-out-cursor",
|
209 |
this.getClass().getClassLoader().getResource(
|
210 |
"images/LayoutZoomOutCursor.gif"));
|
211 |
|
212 |
PluginServices.getIconTheme().registerDefault("document-map-icon",
|
213 |
this.getClass().getClassLoader().getResource("images/mapas.png")); |
214 |
PluginServices.getIconTheme() |
215 |
.registerDefault( |
216 |
"document-map-icon-sel",
|
217 |
this.getClass().getClassLoader().getResource(
|
218 |
"images/mapas_sel.png"));
|
219 |
PluginServices.getIconTheme().registerDefault("neresize-icon",
|
220 |
this.getClass().getClassLoader().getResource("images/NEResize.png")); |
221 |
PluginServices.getIconTheme().registerDefault("eresize-icon",
|
222 |
this.getClass().getClassLoader().getResource("images/EResize.png")); |
223 |
PluginServices.getIconTheme().registerDefault("nresize-icon",
|
224 |
this.getClass().getClassLoader().getResource("images/NResize.png")); |
225 |
PluginServices.getIconTheme().registerDefault("move-icon",
|
226 |
this.getClass().getClassLoader().getResource("images/Move.png")); |
227 |
PluginServices.getIconTheme().registerDefault("sereresize-icon",
|
228 |
this.getClass().getClassLoader().getResource("images/SEResize.png")); |
229 |
PluginServices.getIconTheme() |
230 |
.registerDefault( |
231 |
"symboltag-icon",
|
232 |
this.getClass().getClassLoader().getResource(
|
233 |
"images/symbolTag.gif"));
|
234 |
PluginServices.getIconTheme().registerDefault("move-icon",
|
235 |
this.getClass().getClassLoader().getResource("images/Move.png")); |
236 |
PluginServices.getIconTheme().registerDefault("numero-icon",
|
237 |
this.getClass().getClassLoader().getResource("images/numero.png")); |
238 |
PluginServices.getIconTheme().registerDefault("barra1-icon",
|
239 |
this.getClass().getClassLoader().getResource("images/barra1.png")); |
240 |
PluginServices.getIconTheme().registerDefault("barra2-icon",
|
241 |
this.getClass().getClassLoader().getResource("images/barra2.png")); |
242 |
PluginServices.getIconTheme().registerDefault("barra3-icon",
|
243 |
this.getClass().getClassLoader().getResource("images/barra3.png")); |
244 |
PluginServices.getIconTheme().registerDefault("text-left-icon",
|
245 |
this.getClass().getClassLoader().getResource("images/left.PNG")); |
246 |
PluginServices.getIconTheme().registerDefault("text-center-v-icon",
|
247 |
this.getClass().getClassLoader().getResource("images/centerV.PNG")); |
248 |
PluginServices.getIconTheme().registerDefault("text-right-icon",
|
249 |
this.getClass().getClassLoader().getResource("images/right.PNG")); |
250 |
PluginServices.getIconTheme().registerDefault( |
251 |
"left-rotation-icon",
|
252 |
this.getClass().getClassLoader().getResource(
|
253 |
"images/leftrotation.png"));
|
254 |
PluginServices.getIconTheme().registerDefault("text-up-icon",
|
255 |
this.getClass().getClassLoader().getResource("images/up.PNG")); |
256 |
PluginServices.getIconTheme().registerDefault("text-center-h-icon",
|
257 |
this.getClass().getClassLoader().getResource("images/centerH.PNG")); |
258 |
PluginServices.getIconTheme().registerDefault("text-down-icon",
|
259 |
this.getClass().getClassLoader().getResource("images/down.PNG")); |
260 |
PluginServices.getIconTheme().registerDefault("text-distup-icon",
|
261 |
this.getClass().getClassLoader().getResource("images/distUp.PNG")); |
262 |
PluginServices.getIconTheme().registerDefault( |
263 |
"text-distcenterh-icon",
|
264 |
this.getClass().getClassLoader().getResource(
|
265 |
"images/distCenterH.PNG"));
|
266 |
PluginServices.getIconTheme().registerDefault("text-distdown-icon",
|
267 |
this.getClass().getClassLoader().getResource("images/distDown.PNG")); |
268 |
PluginServices.getIconTheme().registerDefault("text-distleft-icon",
|
269 |
this.getClass().getClassLoader().getResource("images/distLeft.PNG")); |
270 |
PluginServices.getIconTheme().registerDefault( |
271 |
"text-distcenterv-icon",
|
272 |
this.getClass().getClassLoader().getResource(
|
273 |
"images/distCenterV.PNG"));
|
274 |
PluginServices.getIconTheme() |
275 |
.registerDefault( |
276 |
"text-distright-icon",
|
277 |
this.getClass().getClassLoader().getResource(
|
278 |
"images/distRight.PNG"));
|
279 |
PluginServices.getIconTheme() |
280 |
.registerDefault( |
281 |
"text-size-width-icon",
|
282 |
this.getClass().getClassLoader().getResource(
|
283 |
"images/sizeWidth.PNG"));
|
284 |
PluginServices.getIconTheme().registerDefault( |
285 |
"text-size-height-icon",
|
286 |
this.getClass().getClassLoader()
|
287 |
.getResource("images/sizeHeight.PNG"));
|
288 |
PluginServices.getIconTheme() |
289 |
.registerDefault( |
290 |
"text-size-other-icon",
|
291 |
this.getClass().getClassLoader().getResource(
|
292 |
"images/sizeOther.PNG"));
|
293 |
PluginServices.getIconTheme().registerDefault( |
294 |
"text-space-right-icon",
|
295 |
this.getClass().getClassLoader()
|
296 |
.getResource("images/spaceRight.PNG"));
|
297 |
PluginServices.getIconTheme().registerDefault("text-inlayout-icon",
|
298 |
this.getClass().getClassLoader().getResource("images/inLayout.PNG")); |
299 |
|
300 |
// Tools
|
301 |
PluginServices.getIconTheme().registerDefault("rect-select-cursor",
|
302 |
this.getClass().getClassLoader().getResource("images/rect-select-cursor.png")); |
303 |
|
304 |
PluginServices.getIconTheme().registerDefault( |
305 |
"circle-cursor",
|
306 |
this.getClass().getClassLoader().getResource(
|
307 |
"images/CircleCursor.png"));
|
308 |
PluginServices.getIconTheme().registerDefault( |
309 |
"line-cursor",
|
310 |
this.getClass().getClassLoader()
|
311 |
.getResource("images/LineCursor.png"));
|
312 |
PluginServices.getIconTheme().registerDefault( |
313 |
"point-cursor",
|
314 |
this.getClass().getClassLoader().getResource(
|
315 |
"images/point-cursor.png"));
|
316 |
PluginServices.getIconTheme().registerDefault( |
317 |
"poligon-cursor",
|
318 |
this.getClass().getClassLoader().getResource(
|
319 |
"images/PoligonCursor.png"));
|
320 |
PluginServices.getIconTheme().registerDefault( |
321 |
"rectangle-cursor",
|
322 |
this.getClass().getClassLoader().getResource(
|
323 |
"images/rectangle-cursor.png"));
|
324 |
PluginServices.getIconTheme().registerDefault( |
325 |
"crux-cursor",
|
326 |
this.getClass().getClassLoader()
|
327 |
.getResource("images/CruxCursor.png"));
|
328 |
PluginServices.getIconTheme().registerDefault( |
329 |
"layout-pan-icon",
|
330 |
this.getClass().getClassLoader()
|
331 |
.getResource("images/layout-pan-icon.png"));
|
332 |
PluginServices.getIconTheme().registerDefault("view-pan-icon",
|
333 |
this.getClass().getClassLoader().getResource("images/view-pan-icon.png")); |
334 |
|
335 |
|
336 |
PluginServices.getIconTheme().registerDefault("view-zoom-map-contents",
|
337 |
this.getClass().getClassLoader().getResource("images/view-zoom-map-contents.png")); |
338 |
PluginServices.getIconTheme().registerDefault("view-zoom-in",
|
339 |
this.getClass().getClassLoader().getResource("images/view-zoom-in.png")); |
340 |
PluginServices.getIconTheme().registerDefault("view-zoom-out",
|
341 |
this.getClass().getClassLoader().getResource("images/view-zoom-out.png")); |
342 |
|
343 |
|
344 |
PluginServices.getIconTheme().registerDefault( |
345 |
"view-pan",
|
346 |
this.getClass().getClassLoader()
|
347 |
.getResource("images/view-pan.png"));
|
348 |
|
349 |
PluginServices.getIconTheme().registerDefault("zoom-in-cursor",
|
350 |
this.getClass().getClassLoader().getResource("images/zoom-in-cursor.png")); |
351 |
PluginServices.getIconTheme().registerDefault("zoom-out-cursor",
|
352 |
this.getClass().getClassLoader().getResource("images/zoom-out-cursor.png")); |
353 |
|
354 |
|
355 |
PluginServices.getIconTheme().registerDefault( |
356 |
"right-rotation-icon",
|
357 |
this.getClass().getClassLoader().getResource(
|
358 |
"images/rightrotation.png"));
|
359 |
PluginServices.getIconTheme().registerDefault("point-select-cursor",
|
360 |
this.getClass().getClassLoader().getResource("images/point-select-cursor.png")); |
361 |
|
362 |
IconThemeHelper.registerIcon(null, "layout-zoom-center-in", this); |
363 |
IconThemeHelper.registerIcon(null, "layout-zoom-center-out", this); |
364 |
} |
365 |
|
366 |
/**
|
367 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
368 |
*/
|
369 |
public boolean isEnabled() { |
370 |
return true; |
371 |
} |
372 |
|
373 |
/**
|
374 |
* Devuelve el Layout sobre el que se opera.
|
375 |
*
|
376 |
* @return Layout.
|
377 |
*/
|
378 |
public LayoutPanel getLayout() {
|
379 |
return layout;
|
380 |
} |
381 |
|
382 |
public IPreference[] getPreferencesPages() { |
383 |
return new IPreference[] { new LayoutPage() }; |
384 |
} |
385 |
} |