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