Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutExtension.java @ 25350

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