root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / LayoutExtension.java @ 29596
History | View | Annotate | Download (8.51 KB)
1 |
/*
|
---|---|
2 |
* Created on 05-may-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.gvsig.app.extension; |
48 |
|
49 |
import java.awt.Component; |
50 |
import java.io.File; |
51 |
import java.io.FileOutputStream; |
52 |
import java.io.OutputStreamWriter; |
53 |
|
54 |
import javax.swing.JFileChooser; |
55 |
import javax.swing.JOptionPane; |
56 |
|
57 |
import org.slf4j.Logger; |
58 |
import org.slf4j.LoggerFactory; |
59 |
import org.exolab.castor.xml.Marshaller; |
60 |
import org.gvsig.andami.PluginServices; |
61 |
import org.gvsig.andami.messages.NotificationManager; |
62 |
import org.gvsig.andami.plugins.Extension; |
63 |
import org.gvsig.andami.preferences.IPreference; |
64 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
65 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
66 |
import org.gvsig.app.gui.preferencespage.LayoutPage; |
67 |
import org.gvsig.app.project.documents.layout.FLayoutZooms; |
68 |
import org.gvsig.app.project.documents.layout.fframes.FFrameBasicFactory; |
69 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphicsFactory; |
70 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGridFactory; |
71 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGroupFactory; |
72 |
import org.gvsig.app.project.documents.layout.fframes.FFrameLegendFactory; |
73 |
import org.gvsig.app.project.documents.layout.fframes.FFrameNorthFactory; |
74 |
import org.gvsig.app.project.documents.layout.fframes.FFrameOverViewFactory; |
75 |
import org.gvsig.app.project.documents.layout.fframes.FFramePictureFactory; |
76 |
import org.gvsig.app.project.documents.layout.fframes.FFrameScaleBarFactory; |
77 |
import org.gvsig.app.project.documents.layout.fframes.FFrameSymbolFactory; |
78 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTableFactory; |
79 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTextFactory; |
80 |
import org.gvsig.app.project.documents.layout.fframes.FFrameViewFactory; |
81 |
import org.gvsig.app.project.documents.layout.gui.Layout; |
82 |
import org.gvsig.utils.GenericFileFilter; |
83 |
import org.gvsig.utils.XMLEntity; |
84 |
|
85 |
|
86 |
|
87 |
/**
|
88 |
* Extensi?n para controlar las operaciones basicas sobre el Layout.
|
89 |
*
|
90 |
* @author Vicente Caballero Navarro
|
91 |
*/
|
92 |
public class LayoutExtension extends Extension implements IPreferenceExtension { |
93 |
private static final Logger logger = LoggerFactory |
94 |
.getLogger(LayoutExtension.class); |
95 |
|
96 |
private Layout layout = null; |
97 |
private static LayoutPage layoutPropertiesPage=new LayoutPage(); |
98 |
|
99 |
/**
|
100 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
101 |
*/
|
102 |
public void execute(String s) { |
103 |
layout = (Layout) PluginServices.getMDIManager().getActiveWindow(); |
104 |
|
105 |
FLayoutZooms zooms = new FLayoutZooms(layout);
|
106 |
logger.debug("Comand : " + s);
|
107 |
|
108 |
if (s.equals("LAYOUT_PAN")) { |
109 |
layout.getLayoutControl().setTool("layoutpan");
|
110 |
} else if (s.equals("LAYOUT_ZOOM_IN")) { |
111 |
layout.getLayoutControl().setTool("layoutzoomin");
|
112 |
} else if (s.equals("LAYOUT_ZOOM_OUT")) { |
113 |
layout.getLayoutControl().setTool("layoutzoomout");
|
114 |
} else if (s.equals("LAYOUT_FULL")) { |
115 |
layout.getLayoutControl().fullRect(); |
116 |
} else if (s.equals("REALZOOM")) { |
117 |
zooms.realZoom(); |
118 |
} else if (s.equals("LAYOUT_ZOOMOUT")) { |
119 |
zooms.zoomOut(); |
120 |
} else if (s.equals("LAYOUT_ZOOMIN")) { |
121 |
zooms.zoomIn(); |
122 |
} else if (s.equals("ZOOMSELECT")) { |
123 |
zooms.zoomSelect(); |
124 |
} else if (s.equals("SAVETEMPLATE")){ |
125 |
saveLayout(); |
126 |
} |
127 |
} |
128 |
private void saveLayout() { |
129 |
layout = (Layout) PluginServices.getMDIManager().getActiveWindow(); |
130 |
JFileChooser jfc = new JFileChooser(); |
131 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvt", |
132 |
PluginServices.getText(this, "plantilla"))); |
133 |
|
134 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
135 |
File file=jfc.getSelectedFile();
|
136 |
if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){ |
137 |
file=new File(file.getPath()+".gvt"); |
138 |
} |
139 |
if (file.exists()) {
|
140 |
int resp = JOptionPane.showConfirmDialog( |
141 |
(Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"), |
142 |
PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
143 |
if (resp != JOptionPane.YES_OPTION) { |
144 |
return;
|
145 |
} |
146 |
} |
147 |
|
148 |
try {
|
149 |
FileOutputStream fos = new FileOutputStream(file.getAbsolutePath()); |
150 |
OutputStreamWriter writer = new OutputStreamWriter(fos, ProjectExtension.PROJECTENCODING); |
151 |
Marshaller m = new Marshaller(writer);
|
152 |
m.setEncoding(ProjectExtension.PROJECTENCODING); |
153 |
XMLEntity xml=layout.getXMLEntity(); |
154 |
xml.putProperty("followHeaderEncoding", true); |
155 |
m.marshal(xml.getXmlTag()); |
156 |
} catch (Exception e) { |
157 |
NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_plantilla"), e); |
158 |
} |
159 |
} |
160 |
} |
161 |
/**
|
162 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
163 |
*/
|
164 |
public boolean isVisible() { |
165 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
166 |
|
167 |
if (f == null) { |
168 |
return false; |
169 |
} |
170 |
|
171 |
if (f instanceof Layout) { |
172 |
return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0; |
173 |
} |
174 |
return false; |
175 |
} |
176 |
|
177 |
/**
|
178 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
179 |
*/
|
180 |
public void initialize() { |
181 |
registerFFrames(); |
182 |
registerIcons(); |
183 |
} |
184 |
private void registerFFrames() { |
185 |
FFrameBasicFactory.register(); |
186 |
FFrameGraphicsFactory.register(); |
187 |
FFrameGroupFactory.register(); |
188 |
FFrameLegendFactory.register(); |
189 |
FFrameNorthFactory.register(); |
190 |
FFrameOverViewFactory.register(); |
191 |
FFramePictureFactory.register(); |
192 |
FFrameScaleBarFactory.register(); |
193 |
FFrameSymbolFactory.register(); |
194 |
FFrameTableFactory.register(); |
195 |
FFrameTextFactory.register(); |
196 |
FFrameViewFactory.register(); |
197 |
FFrameGridFactory.register(); |
198 |
} |
199 |
|
200 |
private void registerIcons(){ |
201 |
PluginServices.getIconTheme().registerDefault( |
202 |
"layout-zoom-in",
|
203 |
this.getClass().getClassLoader().getResource("images/LayoutZoomIn.png") |
204 |
); |
205 |
|
206 |
PluginServices.getIconTheme().registerDefault( |
207 |
"layout-zoom-out",
|
208 |
this.getClass().getClassLoader().getResource("images/LayoutZoomOut.png") |
209 |
); |
210 |
|
211 |
PluginServices.getIconTheme().registerDefault( |
212 |
"view-zoom-center-in",
|
213 |
this.getClass().getClassLoader().getResource("images/zoommas.png") |
214 |
); |
215 |
|
216 |
PluginServices.getIconTheme().registerDefault( |
217 |
"view-zoom-center-out",
|
218 |
this.getClass().getClassLoader().getResource("images/zoommenos.png") |
219 |
); |
220 |
|
221 |
PluginServices.getIconTheme().registerDefault( |
222 |
"layout-zoom-fit",
|
223 |
this.getClass().getClassLoader().getResource("images/mundo.gif") |
224 |
); |
225 |
|
226 |
PluginServices.getIconTheme().registerDefault( |
227 |
"layout-zoom-real",
|
228 |
this.getClass().getClassLoader().getResource("images/zoomreal.png") |
229 |
); |
230 |
|
231 |
PluginServices.getIconTheme().registerDefault( |
232 |
"layout-zoom-selected",
|
233 |
this.getClass().getClassLoader().getResource("images/zoomselect.png") |
234 |
); |
235 |
|
236 |
PluginServices.getIconTheme().registerDefault( |
237 |
"layout-pan",
|
238 |
this.getClass().getClassLoader().getResource("images/LayoutPan.png") |
239 |
); |
240 |
|
241 |
PluginServices.getIconTheme().registerDefault( |
242 |
"save-icon",
|
243 |
this.getClass().getClassLoader().getResource("images/save.png") |
244 |
); |
245 |
} |
246 |
/**
|
247 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
248 |
*/
|
249 |
public boolean isEnabled() { |
250 |
return true; |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Devuelve el Layout sobre el que se opera.
|
255 |
*
|
256 |
* @return Layout.
|
257 |
*/
|
258 |
public Layout getLayout() {
|
259 |
return layout;
|
260 |
} |
261 |
|
262 |
public IPreference[] getPreferencesPages() { |
263 |
IPreference[] preferences=new IPreference[1]; |
264 |
preferences[0]=layoutPropertiesPage;
|
265 |
return preferences;
|
266 |
} |
267 |
} |