Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutExtension.java @ 28546

History | View | Annotate | Download (8.57 KB)

1 9634 caballero
/*
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 com.iver.cit.gvsig;
48
49
import java.awt.Component;
50
import java.io.File;
51 18780 vcaballero
import java.io.FileOutputStream;
52
import java.io.OutputStreamWriter;
53 9634 caballero
54
import javax.swing.JFileChooser;
55 12029 jmvivo
import javax.swing.JOptionPane;
56 9634 caballero
57 28033 cordinyana
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59 9634 caballero
import org.exolab.castor.xml.Marshaller;
60
61
import com.iver.andami.PluginServices;
62
import com.iver.andami.messages.NotificationManager;
63
import com.iver.andami.plugins.Extension;
64
import com.iver.andami.preferences.IPreference;
65
import com.iver.andami.preferences.IPreferenceExtension;
66
import com.iver.andami.ui.mdiManager.IWindow;
67
import com.iver.cit.gvsig.gui.preferencespage.LayoutPage;
68
import com.iver.cit.gvsig.project.documents.layout.FLayoutZooms;
69
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameBasicFactory;
70
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGraphicsFactory;
71 27972 vcaballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGridFactory;
72 9634 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroupFactory;
73
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameLegendFactory;
74
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameNorthFactory;
75
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameOverViewFactory;
76
import com.iver.cit.gvsig.project.documents.layout.fframes.FFramePictureFactory;
77
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameScaleBarFactory;
78
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameSymbolFactory;
79
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameTableFactory;
80
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameTextFactory;
81
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameViewFactory;
82
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
83
import com.iver.utiles.GenericFileFilter;
84 18780 vcaballero
import com.iver.utiles.XMLEntity;
85 9634 caballero
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 28033 cordinyana
    private static final Logger logger = LoggerFactory
94
            .getLogger(LayoutExtension.class);
95
96 9634 caballero
        private Layout layout = null;
97
        private static LayoutPage layoutPropertiesPage=new LayoutPage();
98
99
        /**
100
         * @see com.iver.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 10636 caballero
                if (s.equals("LAYOUT_PAN")) {
109 9634 caballero
                        layout.getLayoutControl().setTool("layoutpan");
110 10636 caballero
                } else if (s.equals("LAYOUT_ZOOM_IN")) {
111 9634 caballero
                        layout.getLayoutControl().setTool("layoutzoomin");
112 10636 caballero
                } else if (s.equals("LAYOUT_ZOOM_OUT")) {
113 9634 caballero
                        layout.getLayoutControl().setTool("layoutzoomout");
114 10636 caballero
                } else if (s.equals("LAYOUT_FULL")) {
115 9634 caballero
                        layout.getLayoutControl().fullRect();
116
                } else if (s.equals("REALZOOM")) {
117
                        zooms.realZoom();
118 10636 caballero
                } else if (s.equals("LAYOUT_ZOOMOUT")) {
119 9634 caballero
                        zooms.zoomOut();
120 10636 caballero
                } else if (s.equals("LAYOUT_ZOOMIN")) {
121 9634 caballero
                        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 12029 jmvivo
                        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 14821 jmvivo
148 9634 caballero
                        try {
149 18780 vcaballero
                                FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
150
                    OutputStreamWriter writer = new OutputStreamWriter(fos, ProjectExtension.PROJECTENCODING);
151 9634 caballero
                                Marshaller m = new Marshaller(writer);
152 18780 vcaballero
                                m.setEncoding(ProjectExtension.PROJECTENCODING);
153
                                XMLEntity xml=layout.getXMLEntity();
154
                                xml.putProperty("followHeaderEncoding", true);
155
                                m.marshal(xml.getXmlTag());
156 9634 caballero
                        } 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 com.iver.andami.plugins.IExtension#initialize()
179
         */
180
        public void initialize() {
181
                registerFFrames();
182 14821 jmvivo
                registerIcons();
183 9634 caballero
        }
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 27972 vcaballero
                FFrameGridFactory.register();
198 9634 caballero
        }
199 14821 jmvivo
200
        private void registerIcons(){
201 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
202 14821 jmvivo
                                "layout-zoom-in",
203
                                this.getClass().getClassLoader().getResource("images/LayoutZoomIn.png")
204
                        );
205
206 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
207 14821 jmvivo
                                "layout-zoom-out",
208
                                this.getClass().getClassLoader().getResource("images/LayoutZoomOut.png")
209
                        );
210
211 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
212 14821 jmvivo
                                "view-zoom-center-in",
213
                                this.getClass().getClassLoader().getResource("images/zoommas.png")
214
                        );
215
216 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
217 14821 jmvivo
                                "view-zoom-center-out",
218
                                this.getClass().getClassLoader().getResource("images/zoommenos.png")
219
                        );
220
221 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
222 14821 jmvivo
                                "layout-zoom-fit",
223
                                this.getClass().getClassLoader().getResource("images/mundo.gif")
224
                        );
225
226 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
227 14821 jmvivo
                                "layout-zoom-real",
228
                                this.getClass().getClassLoader().getResource("images/zoomreal.png")
229
                        );
230
231 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
232 14821 jmvivo
                                "layout-zoom-selected",
233
                                this.getClass().getClassLoader().getResource("images/zoomselect.png")
234
                        );
235
236 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
237 14821 jmvivo
                                "layout-pan",
238
                                this.getClass().getClassLoader().getResource("images/LayoutPan.png")
239
                        );
240 18780 vcaballero
241 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
242
                                "save-icon",
243
                                this.getClass().getClassLoader().getResource("images/save.png")
244
                        );
245 14821 jmvivo
        }
246 9634 caballero
        /**
247
         * @see com.iver.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
}