svn-gvsig-desktop / tags / v2_0_0_Build_2020 / applications / appgvSIG / src / org / gvsig / app / extension / LayoutExtension.java @ 33920
History | View | Annotate | Download (7.28 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 |
|
53 |
import javax.swing.JFileChooser; |
54 |
import javax.swing.JOptionPane; |
55 |
|
56 |
import org.slf4j.Logger; |
57 |
import org.slf4j.LoggerFactory; |
58 |
|
59 |
import org.gvsig.andami.PluginServices; |
60 |
import org.gvsig.andami.messages.NotificationManager; |
61 |
import org.gvsig.andami.plugins.Extension; |
62 |
import org.gvsig.andami.preferences.IPreference; |
63 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
64 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
65 |
import org.gvsig.app.gui.preferencespage.LayoutPage; |
66 |
import org.gvsig.app.project.documents.layout.FLayoutZooms; |
67 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
68 |
import org.gvsig.tools.ToolsLocator; |
69 |
import org.gvsig.tools.persistence.PersistenceManager; |
70 |
import org.gvsig.tools.persistence.PersistentState; |
71 |
import org.gvsig.utils.GenericFileFilter; |
72 |
|
73 |
|
74 |
|
75 |
/**
|
76 |
* Extensi?n para controlar las operaciones basicas sobre el Layout.
|
77 |
*
|
78 |
* @author Vicente Caballero Navarro
|
79 |
*/
|
80 |
public class LayoutExtension extends Extension implements IPreferenceExtension { |
81 |
private static final Logger logger = LoggerFactory |
82 |
.getLogger(LayoutExtension.class); |
83 |
|
84 |
private LayoutPanel layout = null; |
85 |
|
86 |
/**
|
87 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
88 |
*/
|
89 |
public void execute(String s) { |
90 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
91 |
|
92 |
FLayoutZooms zooms = new FLayoutZooms(layout);
|
93 |
logger.debug("Comand : " + s);
|
94 |
|
95 |
if (s.equals("LAYOUT_PAN")) { |
96 |
layout.getLayoutControl().setTool("layoutpan");
|
97 |
} else if (s.equals("LAYOUT_ZOOM_IN")) { |
98 |
layout.getLayoutControl().setTool("layoutzoomin");
|
99 |
} else if (s.equals("LAYOUT_ZOOM_OUT")) { |
100 |
layout.getLayoutControl().setTool("layoutzoomout");
|
101 |
} else if (s.equals("LAYOUT_FULL")) { |
102 |
layout.getLayoutControl().fullRect(); |
103 |
} else if (s.equals("REALZOOM")) { |
104 |
zooms.realZoom(); |
105 |
} else if (s.equals("LAYOUT_ZOOMOUT")) { |
106 |
zooms.zoomOut(); |
107 |
} else if (s.equals("LAYOUT_ZOOMIN")) { |
108 |
zooms.zoomIn(); |
109 |
} else if (s.equals("ZOOMSELECT")) { |
110 |
zooms.zoomSelect(); |
111 |
} else if (s.equals("SAVETEMPLATE")){ |
112 |
saveLayout(); |
113 |
} |
114 |
} |
115 |
private void saveLayout() { |
116 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
117 |
JFileChooser jfc = new JFileChooser(); |
118 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvt", |
119 |
PluginServices.getText(this, "plantilla"))); |
120 |
|
121 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
122 |
File file=jfc.getSelectedFile();
|
123 |
if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){ |
124 |
file=new File(file.getPath()+".gvt"); |
125 |
} |
126 |
if (file.exists()) {
|
127 |
int resp = JOptionPane.showConfirmDialog( |
128 |
(Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"), |
129 |
PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
130 |
if (resp != JOptionPane.YES_OPTION) { |
131 |
return;
|
132 |
} |
133 |
} |
134 |
|
135 |
try {
|
136 |
FileOutputStream fos = new FileOutputStream(file.getAbsolutePath()); |
137 |
// OutputStreamWriter writer = new OutputStreamWriter(fos, ProjectExtension.PROJECTENCODING);
|
138 |
// Marshaller m = new Marshaller(writer);
|
139 |
// m.setEncoding(ProjectExtension.PROJECTENCODING);
|
140 |
// XMLEntity xml=layout.getXMLEntity();
|
141 |
// xml.putProperty("followHeaderEncoding", true);
|
142 |
// m.marshal(xml.getXmlTag());
|
143 |
|
144 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
145 |
PersistentState persistentState = persistenceManager.getState(layout); |
146 |
persistenceManager.saveState(persistentState, fos); |
147 |
} catch (Exception e) { |
148 |
NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_plantilla"), e); |
149 |
} |
150 |
} |
151 |
} |
152 |
/**
|
153 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
154 |
*/
|
155 |
public boolean isVisible() { |
156 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
157 |
|
158 |
if (f == null) { |
159 |
return false; |
160 |
} |
161 |
|
162 |
if (f instanceof LayoutPanel) { |
163 |
return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0; |
164 |
} |
165 |
return false; |
166 |
} |
167 |
|
168 |
/**
|
169 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
170 |
*/
|
171 |
public void initialize() { |
172 |
registerIcons(); |
173 |
} |
174 |
|
175 |
private void registerIcons(){ |
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"layout-zoom-in",
|
178 |
this.getClass().getClassLoader().getResource("images/LayoutZoomIn.png") |
179 |
); |
180 |
|
181 |
PluginServices.getIconTheme().registerDefault( |
182 |
"layout-zoom-out",
|
183 |
this.getClass().getClassLoader().getResource("images/LayoutZoomOut.png") |
184 |
); |
185 |
|
186 |
PluginServices.getIconTheme().registerDefault( |
187 |
"view-zoom-center-in",
|
188 |
this.getClass().getClassLoader().getResource("images/zoommas.png") |
189 |
); |
190 |
|
191 |
PluginServices.getIconTheme().registerDefault( |
192 |
"view-zoom-center-out",
|
193 |
this.getClass().getClassLoader().getResource("images/zoommenos.png") |
194 |
); |
195 |
|
196 |
PluginServices.getIconTheme().registerDefault( |
197 |
"layout-zoom-fit",
|
198 |
this.getClass().getClassLoader().getResource("images/mundo.gif") |
199 |
); |
200 |
|
201 |
PluginServices.getIconTheme().registerDefault( |
202 |
"layout-zoom-real",
|
203 |
this.getClass().getClassLoader().getResource("images/zoomreal.png") |
204 |
); |
205 |
|
206 |
PluginServices.getIconTheme().registerDefault( |
207 |
"layout-zoom-selected",
|
208 |
this.getClass().getClassLoader().getResource("images/zoomselect.png") |
209 |
); |
210 |
|
211 |
PluginServices.getIconTheme().registerDefault( |
212 |
"layout-pan",
|
213 |
this.getClass().getClassLoader().getResource("images/LayoutPan.png") |
214 |
); |
215 |
|
216 |
PluginServices.getIconTheme().registerDefault( |
217 |
"save-icon",
|
218 |
this.getClass().getClassLoader().getResource("images/save.png") |
219 |
); |
220 |
} |
221 |
/**
|
222 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
223 |
*/
|
224 |
public boolean isEnabled() { |
225 |
return true; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* Devuelve el Layout sobre el que se opera.
|
230 |
*
|
231 |
* @return Layout.
|
232 |
*/
|
233 |
public LayoutPanel getLayout() {
|
234 |
return layout;
|
235 |
} |
236 |
|
237 |
public IPreference[] getPreferencesPages() { |
238 |
return new IPreference[] { new LayoutPage() }; |
239 |
} |
240 |
} |