Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_903+3D / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutControls.java @ 10722

History | View | Annotate | Download (4.89 KB)

1 312 fernando
/*
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 1103 fjp
/* 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 312 fernando
package com.iver.cit.gvsig;
48
49 3122 caballero
import java.awt.Component;
50
import java.io.File;
51
import java.io.FileWriter;
52
53
import javax.swing.JFileChooser;
54
55 5005 jorpiell
import org.apache.log4j.Logger;
56
import org.exolab.castor.xml.Marshaller;
57
58 596 fernando
import com.iver.andami.PluginServices;
59 3122 caballero
import com.iver.andami.messages.NotificationManager;
60 596 fernando
import com.iver.andami.plugins.Extension;
61 8765 jjdelcerro
import com.iver.andami.preferences.IPreference;
62
import com.iver.andami.preferences.IPreferenceExtension;
63 6877 cesar
import com.iver.andami.ui.mdiManager.IWindow;
64 312 fernando
import com.iver.cit.gvsig.gui.layout.Layout;
65 8765 jjdelcerro
import com.iver.cit.gvsig.gui.preferencespage.LayoutPage;
66
import com.iver.cit.gvsig.project.documents.layout.FLayoutZooms;
67 3122 caballero
import com.iver.utiles.GenericFileFilter;
68 312 fernando
69
70
/**
71 1219 vcaballero
 * Extensi?n para controlar las operaciones basicas sobre el Layout.
72 312 fernando
 *
73
 * @author Vicente Caballero Navarro
74
 */
75 8765 jjdelcerro
public class LayoutControls extends Extension implements IPreferenceExtension {
76 1219 vcaballero
        private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
77
        private Layout layout = null;
78 8765 jjdelcerro
        private static LayoutPage layoutPropertiesPage=new LayoutPage();
79 1219 vcaballero
80
        /**
81 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
82 1219 vcaballero
         */
83
        public void execute(String s) {
84 6880 cesar
                layout = (Layout) PluginServices.getMDIManager().getActiveWindow();
85 1219 vcaballero
86
                FLayoutZooms zooms = new FLayoutZooms(layout);
87
                logger.debug("Comand : " + s);
88
89 10635 caballero
                if (s.equals("LAYOUT_PAN")) {
90 1219 vcaballero
                        layout.setTool(Layout.PAN);
91 10635 caballero
                } else if (s.equals("LAYOUT_ZOOM_IN")) {
92 1219 vcaballero
                        layout.setTool(Layout.ZOOM_MAS);
93 10635 caballero
                } else if (s.equals("LAYOUT_ZOOM_OUT")) {
94 1219 vcaballero
                        layout.setTool(Layout.ZOOM_MENOS);
95 10635 caballero
                } else if (s.equals("LAYOUT_FULL")) {
96 1219 vcaballero
                        layout.fullRect();
97 6239 caballero
                } else if (s.equals("REALZOOM")) {
98 1219 vcaballero
                        zooms.realZoom();
99 10635 caballero
                } else if (s.equals("LAYOUT_ZOOMOUT")) {
100 1219 vcaballero
                        zooms.zoomOut();
101 10635 caballero
                } else if (s.equals("LAYOUT_ZOOMIN")) {
102 1219 vcaballero
                        zooms.zoomIn();
103 6239 caballero
                } else if (s.equals("ZOOMSELECT")) {
104 1219 vcaballero
                        zooms.zoomSelect();
105 6239 caballero
                } else if (s.equals("SAVETEMPLATE")){
106 3122 caballero
                        saveLayout();
107 6239 caballero
                }
108 1219 vcaballero
        }
109 3122 caballero
        private void saveLayout() {
110 6880 cesar
            layout = (Layout) PluginServices.getMDIManager().getActiveWindow();
111 3122 caballero
                JFileChooser jfc = new JFileChooser();
112
                jfc.addChoosableFileFilter(new GenericFileFilter("gvt",
113
                                PluginServices.getText(this, "plantilla")));
114 312 fernando
115 3122 caballero
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
116
                        File file=jfc.getSelectedFile();
117
                        if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){
118
                                file=new File(file.getPath()+".gvt");
119
                        }
120
                        try {
121
                                FileWriter writer = new FileWriter(file.getAbsolutePath());
122
                                Marshaller m = new Marshaller(writer);
123
                                m.setEncoding("ISO-8859-1");
124
                                m.marshal(layout.getXMLEntity().getXmlTag());
125
                        } catch (Exception e) {
126
                                NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_plantilla"), e);
127
                        }
128
                }
129
        }
130 1219 vcaballero
        /**
131 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
132 1219 vcaballero
         */
133
        public boolean isVisible() {
134 6880 cesar
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
135 312 fernando
136 1219 vcaballero
                if (f == null) {
137
                        return false;
138
                }
139 312 fernando
140 5900 jorpiell
                if (f instanceof Layout) {
141 2429 caballero
                //        Layout layout = (Layout) f;
142 312 fernando
143 1219 vcaballero
                        return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0;
144
                } else {
145
                        return false;
146
                }
147
        }
148 596 fernando
149
        /**
150 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#initialize()
151 596 fernando
         */
152 5005 jorpiell
        public void initialize() {
153 596 fernando
        }
154 6393 caballero
155 596 fernando
        /**
156 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isEnabled()
157 596 fernando
         */
158
        public boolean isEnabled() {
159 644 fernando
                return true;
160 596 fernando
        }
161 1219 vcaballero
162
        /**
163
         * Devuelve el Layout sobre el que se opera.
164
         *
165
         * @return Layout.
166
         */
167
        public Layout getLayout() {
168 677 vcaballero
                return layout;
169
        }
170 8765 jjdelcerro
171
        public IPreference getPreferencesPage() {
172
                return layoutPropertiesPage;
173
        }
174 312 fernando
}