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 @ 101
History | View | Annotate | Download (12.1 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.LayoutManager; |
44 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.persistence.PersistenceManager; |
47 |
import org.gvsig.tools.persistence.PersistentState; |
48 |
import org.gvsig.utils.GenericFileFilter; |
49 |
|
50 |
/**
|
51 |
* Extensi?n para controlar las operaciones basicas sobre el Layout.
|
52 |
*
|
53 |
* @author Vicente Caballero Navarro
|
54 |
*/
|
55 |
public class LayoutExtension extends Extension implements IPreferenceExtension { |
56 |
|
57 |
private static final Logger logger = LoggerFactory |
58 |
.getLogger(LayoutExtension.class); |
59 |
|
60 |
private LayoutPanel layout = null; |
61 |
|
62 |
/**
|
63 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
64 |
*/
|
65 |
public void execute(String s) { |
66 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
67 |
|
68 |
FLayoutZooms zooms = new FLayoutZooms(layout);
|
69 |
logger.debug("Comand : " + s);
|
70 |
|
71 |
if (s.equals("layout-navigation-pan")) { |
72 |
layout.getLayoutControl().setTool("layoutpan");
|
73 |
} else
|
74 |
if (s.equals("layout-navigation-zoom-in-topoint")) { |
75 |
layout.getLayoutControl().setTool("layoutzoomin");
|
76 |
} else
|
77 |
if (s.equals("layout-navigation-zoom-out-topoint")) { |
78 |
layout.getLayoutControl().setTool("layoutzoomout");
|
79 |
} else
|
80 |
if (s.equals("layout-navigation-zoom-all")) { |
81 |
layout.getLayoutControl().fullRect(); |
82 |
} else
|
83 |
if (s.equals("layout-navigation-zoom-real")) { |
84 |
zooms.realZoom(); |
85 |
} else
|
86 |
if (s.equals("layout-navigation-zoom-out-center")) { |
87 |
zooms.zoomOut(); |
88 |
} else
|
89 |
if (s.equals("layout-navigation-zoom-in-center")) { |
90 |
zooms.zoomIn(); |
91 |
} else
|
92 |
if (s.equals("layout-navigation-zoom-selected")) { |
93 |
zooms.zoomSelect(); |
94 |
} else
|
95 |
if (s.equals("application-layout-template-save")) { |
96 |
saveLayout(); |
97 |
} |
98 |
} |
99 |
|
100 |
private void saveLayout() { |
101 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
102 |
JFileChooser jfc = new JFileChooser(); |
103 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
104 |
LayoutManager.TEMPLATE_FILE_POINTEXT,
|
105 |
PluginServices.getText(this, "plantilla"))); |
106 |
|
107 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
108 |
File file = jfc.getSelectedFile();
|
109 |
if (!(file.getPath().endsWith(
|
110 |
LayoutManager.TEMPLATE_FILE_POINTEXT.toLowerCase())
|
111 |
|| file.getPath().endsWith( |
112 |
LayoutManager.TEMPLATE_FILE_POINTEXT))) {
|
113 |
file = new File(file.getPath() + |
114 |
LayoutManager.TEMPLATE_FILE_POINTEXT);
|
115 |
} |
116 |
if (file.exists()) {
|
117 |
int resp =
|
118 |
JOptionPane.showConfirmDialog((Component) PluginServices |
119 |
.getMainFrame(), PluginServices.getText(this,
|
120 |
"fichero_ya_existe_seguro_desea_guardarlo"),
|
121 |
PluginServices.getText(this, "guardar"), |
122 |
JOptionPane.YES_NO_OPTION);
|
123 |
if (resp != JOptionPane.YES_OPTION) { |
124 |
return;
|
125 |
} |
126 |
} |
127 |
|
128 |
try {
|
129 |
FileOutputStream fos =
|
130 |
new FileOutputStream(file.getAbsolutePath()); |
131 |
// OutputStreamWriter writer = new OutputStreamWriter(fos,
|
132 |
// ProjectExtension.PROJECTENCODING);
|
133 |
// Marshaller m = new Marshaller(writer);
|
134 |
// m.setEncoding(ProjectExtension.PROJECTENCODING);
|
135 |
// XMLEntity xml=layout.getXMLEntity();
|
136 |
// xml.putProperty("followHeaderEncoding", true);
|
137 |
// m.marshal(xml.getXmlTag());
|
138 |
|
139 |
PersistenceManager persistenceManager = |
140 |
ToolsLocator.getPersistenceManager(); |
141 |
PersistentState persistentState = |
142 |
persistenceManager.getState(layout); |
143 |
persistenceManager.saveState(persistentState, fos); |
144 |
} catch (Exception e) { |
145 |
NotificationManager.addError(PluginServices.getText(this,
|
146 |
"Error_guardando_la_plantilla"), e);
|
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
153 |
*/
|
154 |
public boolean isVisible() { |
155 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
156 |
|
157 |
if (f == null) { |
158 |
return false; |
159 |
} |
160 |
|
161 |
if (f instanceof LayoutPanel) { |
162 |
return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() |
163 |
// > 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 |
|
177 |
IconThemeHelper.registerIcon("action", "application-layout-template-save", this); |
178 |
|
179 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-in-center", this); |
180 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-out-center", this); |
181 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-in-topoint", this); |
182 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-out-topoint", this); |
183 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-all", this); |
184 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-real", this); |
185 |
IconThemeHelper.registerIcon("action", "layout-navigation-zoom-selected", this); |
186 |
IconThemeHelper.registerIcon("action", "layout-navigation-pan", this); |
187 |
|
188 |
IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-in-topoint", this); |
189 |
IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-out-topoint", this); |
190 |
IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-all", this); |
191 |
IconThemeHelper.registerIcon("action", "layout-view-navigation-pan", this); |
192 |
// ================================================
|
193 |
// Cursors
|
194 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-navigation-zoom-in-topoint", this); |
195 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-navigation-zoom-out-topoint", this); |
196 |
IconThemeHelper.registerIcon("cursor", "cursor-selection-by-rectangle", this); |
197 |
IconThemeHelper.registerIcon("cursor", "cursor-selection-simple", this); |
198 |
IconThemeHelper.registerIcon("cursor", "cursor-selection-complex", this); |
199 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-graphic-edit-vertex", this); |
200 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-circle", this); |
201 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polyline", this); |
202 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-point", this); |
203 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polygon", this); |
204 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-rectangle", this); |
205 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-view-navigation-zoom-in-topoint", this); |
206 |
IconThemeHelper.registerIcon("cursor", "cursor-layout-view-navigation-zoom-out-topoint", this); |
207 |
// End cursors
|
208 |
// ================================================
|
209 |
|
210 |
IconThemeHelper.registerIcon("document", "document-map-icon", this); |
211 |
IconThemeHelper.registerIcon("document", "document-map-icon-sel", this); |
212 |
|
213 |
IconThemeHelper.registerIcon("layout", "neresize-icon", this); |
214 |
IconThemeHelper.registerIcon("layout", "eresize-icon", this); |
215 |
IconThemeHelper.registerIcon("layout", "nresize-icon", this); |
216 |
IconThemeHelper.registerIcon("layout", "move-icon", this); |
217 |
|
218 |
IconThemeHelper.registerIcon("layout", "sereresize-icon", this); |
219 |
IconThemeHelper.registerIcon("layout", "symboltag-icon", this); |
220 |
IconThemeHelper.registerIcon("layout", "numero-icon", this); |
221 |
IconThemeHelper.registerIcon("layout", "barra1-icon", this); |
222 |
IconThemeHelper.registerIcon("layout", "barra2-icon", this); |
223 |
IconThemeHelper.registerIcon("layout", "barra3-icon", this); |
224 |
|
225 |
IconThemeHelper.registerIcon("layout", "text-left-icon", this); |
226 |
IconThemeHelper.registerIcon("layout", "text-center-v-icon", this); |
227 |
IconThemeHelper.registerIcon("layout", "text-right-icon", this); |
228 |
IconThemeHelper.registerIcon("layout", "left-rotation-icon", this); |
229 |
IconThemeHelper.registerIcon("layout", "text-up-icon", this); |
230 |
IconThemeHelper.registerIcon("layout", "text-center-h-icon", this); |
231 |
IconThemeHelper.registerIcon("layout", "text-down-icon", this); |
232 |
IconThemeHelper.registerIcon("layout", "text-distup-icon", this); |
233 |
IconThemeHelper.registerIcon("layout", "text-distcenterh-icon", this); |
234 |
IconThemeHelper.registerIcon("layout", "text-distdown-icon", this); |
235 |
IconThemeHelper.registerIcon("layout", "text-distleft-icon", this); |
236 |
|
237 |
IconThemeHelper.registerIcon("layout", "text-distcenterv-icon", this); |
238 |
IconThemeHelper.registerIcon("layout", "text-distright-icon", this); |
239 |
IconThemeHelper.registerIcon("layout", "text-size-width-icon", this); |
240 |
IconThemeHelper.registerIcon("layout", "text-size-height-icon", this); |
241 |
IconThemeHelper.registerIcon("layout", "text-size-other-icon", this); |
242 |
IconThemeHelper.registerIcon("layout", "text-space-right-icon", this); |
243 |
IconThemeHelper.registerIcon("layout", "text-inlayout-icon", this); |
244 |
IconThemeHelper.registerIcon("layout", "layout-pan-icon", this); |
245 |
IconThemeHelper.registerIcon("layout", "view-pan-icon", this); |
246 |
IconThemeHelper.registerIcon("layout", "right-rotation-icon", this); |
247 |
} |
248 |
|
249 |
/**
|
250 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
251 |
*/
|
252 |
public boolean isEnabled() { |
253 |
return true; |
254 |
} |
255 |
|
256 |
/**
|
257 |
* Devuelve el Layout sobre el que se opera.
|
258 |
*
|
259 |
* @return Layout.
|
260 |
*/
|
261 |
public LayoutPanel getLayout() {
|
262 |
return layout;
|
263 |
} |
264 |
|
265 |
public IPreference[] getPreferencesPages() { |
266 |
return new IPreference[] { new LayoutPage() }; |
267 |
} |
268 |
} |