Statistics
| Revision:

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

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 com.iver.andami.PluginServices;
56
import com.iver.andami.messages.NotificationManager;
57
import com.iver.andami.plugins.Extension;
58
import com.iver.andami.ui.mdiManager.View;
59

    
60
import com.iver.cit.gvsig.gui.layout.FLayoutZooms;
61
import com.iver.cit.gvsig.gui.layout.Layout;
62
import com.iver.utiles.GenericFileFilter;
63

    
64
import org.apache.log4j.Logger;
65
import org.exolab.castor.xml.Marshaller;
66

    
67

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

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

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

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

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

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

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

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

    
153
        /**
154
         * @see com.iver.andami.plugins.Extension#inicializar()
155
         */
156
        public void inicializar() {
157
        }
158

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

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