Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutControls.java @ 5005

History | View | Annotate | Download (4.79 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.ui.mdiManager.View;
62
import com.iver.cit.gvsig.gui.layout.FLayoutZooms;
63
import com.iver.cit.gvsig.gui.layout.Layout;
64
import com.iver.utiles.GenericFileFilter;
65

    
66

    
67
/**
68
 * Extensi?n para controlar las operaciones basicas sobre el Layout.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class LayoutControls extends Extension {
73
        private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
74
        private Layout layout = null;
75

    
76
        /**
77
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
78
         */
79
        public void execute(String s) {
80
                layout = (Layout) PluginServices.getMDIManager().getActiveView();
81

    
82
                FLayoutZooms zooms = new FLayoutZooms(layout);
83
                logger.debug("Comand : " + s);
84

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

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

    
139
                if (f == null) {
140
                        return false;
141
                }
142

    
143
                if (f.getClass() == Layout.class) {
144
                //        Layout layout = (Layout) f;
145

    
146
                        return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0;
147
                } else {
148
                        return false;
149
                }
150
        }
151

    
152
        /**
153
         * @see com.iver.andami.plugins.IExtension#initialize()
154
         */
155
        public void initialize() {
156
        }
157

    
158
        /**
159
         * @see com.iver.andami.plugins.IExtension#isEnabled()
160
         */
161
        public boolean isEnabled() {
162
                return true;
163
        }
164

    
165
        /**
166
         * Devuelve el Layout sobre el que se opera.
167
         *
168
         * @return Layout.
169
         */
170
        public Layout getLayout() {
171
                return layout;
172
        }
173
}