Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 1219

History | View | Annotate | Download (4.88 KB)

1
/*
2
 * Created on 31-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 com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51

    
52
import com.iver.cit.gvsig.fmap.FMap;
53
import com.iver.cit.gvsig.fmap.NewMapControl;
54
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
57
import com.iver.cit.gvsig.gui.View;
58
import com.iver.cit.gvsig.project.castor.ProjectView;
59

    
60
import com.iver.utiles.GenericFileFilter;
61

    
62
import org.apache.log4j.Logger;
63

    
64
import java.awt.Component;
65
import java.awt.geom.Rectangle2D;
66
import java.io.File;
67

    
68
import java.util.BitSet;
69

    
70
import javax.swing.JFileChooser;
71

    
72

    
73
/**
74
 * Extensi?n de operaciones sobre el tema.
75
 *
76
 * @author Vicente Caballero Navarro
77
 */
78
public class ThemeControls implements Extension {
79
        private static Logger logger = Logger.getLogger(ThemeControls.class.getName());
80

    
81
        /**
82
         * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
83
         */
84
        public void execute(String s) {
85
                View vista = (View) PluginServices.getMDIManager().getActiveView();
86
                ProjectView model = vista.getModel();
87
                FMap mapa = model.getMapContext();
88
                NewMapControl mapCtrl = vista.getMapControl();
89
                logger.debug("Comand : " + s);
90

    
91
                if (s.compareTo("PROPERTIES") == 0) {
92
                        vista.openThemeProperties();
93
                } else if (s.compareTo("SHAPE_SELECTED") == 0) {
94
                        createShape(mapa);
95
                } else if (s.compareTo("DEL_SELECTION") == 0) {
96
                        boolean refresh = false;
97

    
98
                        for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
99
                                if (mapa.getLayers().getLayer(i) instanceof Selectable) {
100
                                        if (mapa.getLayers().getLayer(i).isActive()) {
101
                                                BitSet bitset = ((Selectable) mapa.getLayers().getLayer(i)).getSelection();
102

    
103
                                                if (bitset.cardinality() != 0) {
104
                                                        refresh = true;
105
                                                }
106

    
107
                                                bitset.clear();
108
                                        }
109
                                }
110
                        }
111

    
112
                        if (refresh) {
113
                                mapCtrl.drawMap(false);
114
                        }
115
                } else if (s.compareTo("ZOOM_SELECT") == 0) {
116
                        Rectangle2D selectedExtent = mapa.getSelectionBounds();
117

    
118
                        if (selectedExtent != null) {
119
                                mapa.getViewPort().setExtent(selectedExtent);
120
                        }
121
                }
122
        }
123

    
124
        /**
125
         * Crea un nuevo shape.
126
         *
127
         * @param map FMap de donde coger las capas a copiar.
128
         */
129
        private void createShape(FMap map) {
130
                if (map.getSelectionBounds() != null) {
131
                        JFileChooser jfc = new JFileChooser();
132
                        jfc.addChoosableFileFilter(new GenericFileFilter("shp",
133
                                        PluginServices.getText(this, "ShapeFile")));
134

    
135
                        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
136
                                File file=jfc.getSelectedFile();
137
                                if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){
138
                                        file=new File(file.getPath()+".shp");
139
                                }
140
                                SHP.SHPFileFromSelected(map, file);
141
                        }
142
                } // else {
143

    
144
                //}
145
        }
146

    
147
        /**
148
         * @see com.iver.mdiApp.plugins.Extension#isVisible()
149
         */
150
        public boolean isVisible() {
151
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
152
                                                                                                                         .getActiveView();
153

    
154
                if (f == null) {
155
                        return false;
156
                }
157

    
158
                if (f.getClass() == View.class) {
159
                        FMap mapa = ((View) f).getModel().getMapContext();
160

    
161
                        View v = (View) f;
162

    
163
                        return mapa.getLayers().getLayersCount() > 0;
164
                } else {
165
                        return false;
166
                }
167
        }
168

    
169
        /**
170
         * @see com.iver.andami.plugins.Extension#isEnabled()
171
         */
172
        public boolean isEnabled() {
173
                View f = (View) PluginServices.getMDIManager().getActiveView();
174

    
175
                if (f == null) {
176
                        return false;
177
                }
178

    
179
                FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
180

    
181
                return selected.length > 0;
182
        }
183

    
184
        /**
185
         * @see com.iver.andami.plugins.Extension#inicializar()
186
         */
187
        public void inicializar() {
188
        }
189
}