Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutControls.java @ 8516

History | View | Annotate | Download (5.04 KB)

1
/*
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
import java.io.FileWriter;
52

    
53
import javax.swing.JFileChooser;
54

    
55
import org.apache.log4j.Logger;
56
import org.exolab.castor.xml.Marshaller;
57

    
58
import com.iver.andami.PluginServices;
59
import com.iver.andami.messages.NotificationManager;
60
import com.iver.andami.plugins.Extension;
61
import com.iver.andami.preferences.IPreference;
62
import com.iver.andami.preferences.IPreferenceExtension;
63
import com.iver.andami.ui.mdiManager.IWindow;
64
import com.iver.cit.gvsig.gui.layout.Layout;
65
import com.iver.cit.gvsig.gui.preferencespage.LayoutPage;
66
import com.iver.cit.gvsig.project.documents.layout.FLayoutZooms;
67
import com.iver.utiles.GenericFileFilter;
68

    
69

    
70
/**
71
 * Extensi?n para controlar las operaciones basicas sobre el Layout.
72
 *
73
 * @author Vicente Caballero Navarro
74
 */
75
public class LayoutControls extends Extension implements IPreferenceExtension {
76
        private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
77
        private Layout layout = null;
78
        private static LayoutPage layoutPropertiesPage=new LayoutPage();
79

    
80
        /**
81
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
82
         */
83
        public void execute(String s) {
84
                layout = (Layout) PluginServices.getMDIManager().getActiveWindow();
85

    
86
                FLayoutZooms zooms = new FLayoutZooms(layout);
87
                logger.debug("Comand : " + s);
88

    
89
                if (s.equals("PAN")) {
90
                        layout.setTool(Layout.PAN);
91
                } else if (s.equals("ZOOM_IN")) {
92
                        layout.setTool(Layout.ZOOM_MAS);
93
                } else if (s.equals("ZOOM_OUT")) {
94
                        layout.setTool(Layout.ZOOM_MENOS);
95
                } else if (s.equals("CONFIG")) {
96
                        layout.showFConfig();
97
                        layout.fullRect();
98
                } else if (s.equals("FULL")) {
99
                        layout.fullRect();
100
                } else if (s.equals("REALZOOM")) {
101
                        zooms.realZoom();
102
                } else if (s.equals("ZOOMOUT")) {
103
                        zooms.zoomOut();
104
                } else if (s.equals("ZOOMIN")) {
105
                        zooms.zoomIn();
106
                } else if (s.equals("ZOOMSELECT")) {
107
                        zooms.zoomSelect();
108
                } else if (s.equals("PDF")){
109
                        layout.layoutToPDF();
110
                } else if (s.equals("PS")){
111
                        layout.layoutToPS();
112
                } else if (s.equals("SAVETEMPLATE")){
113
                        saveLayout();
114
                }
115
        }
116
        private void saveLayout() {
117
            layout = (Layout) PluginServices.getMDIManager().getActiveWindow();
118
                JFileChooser jfc = new JFileChooser();
119
                jfc.addChoosableFileFilter(new GenericFileFilter("gvt",
120
                                PluginServices.getText(this, "plantilla")));
121

    
122
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
123
                        File file=jfc.getSelectedFile();
124
                        if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){
125
                                file=new File(file.getPath()+".gvt");
126
                        }
127
                        try {
128
                                FileWriter writer = new FileWriter(file.getAbsolutePath());
129
                                Marshaller m = new Marshaller(writer);
130
                                m.setEncoding("ISO-8859-1");
131
                                m.marshal(layout.getXMLEntity().getXmlTag());
132
                        } catch (Exception e) {
133
                                NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_plantilla"), e);
134
                        }
135
                }
136
        }
137
        /**
138
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
139
         */
140
        public boolean isVisible() {
141
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
142

    
143
                if (f == null) {
144
                        return false;
145
                }
146

    
147
                if (f instanceof Layout) {
148
                //        Layout layout = (Layout) f;
149

    
150
                        return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0;
151
                } else {
152
                        return false;
153
                }
154
        }
155

    
156
        /**
157
         * @see com.iver.andami.plugins.IExtension#initialize()
158
         */
159
        public void initialize() {
160
        }
161

    
162
        /**
163
         * @see com.iver.andami.plugins.IExtension#isEnabled()
164
         */
165
        public boolean isEnabled() {
166
                return true;
167
        }
168

    
169
        /**
170
         * Devuelve el Layout sobre el que se opera.
171
         *
172
         * @return Layout.
173
         */
174
        public Layout getLayout() {
175
                return layout;
176
        }
177

    
178
        public IPreference getPreferencesPage() {
179
                return layoutPropertiesPage;
180
        }
181
}