Statistics
| Revision:

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

History | View | Annotate | Download (4.88 KB)

1 312 fernando
/*
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 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 596 fernando
import com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51 1219 vcaballero
52 312 fernando
import com.iver.cit.gvsig.fmap.FMap;
53 1169 vcaballero
import com.iver.cit.gvsig.fmap.NewMapControl;
54
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
55 312 fernando
import com.iver.cit.gvsig.fmap.layers.FLayer;
56 1169 vcaballero
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
57 312 fernando
import com.iver.cit.gvsig.gui.View;
58 1169 vcaballero
import com.iver.cit.gvsig.project.castor.ProjectView;
59 1219 vcaballero
60 1169 vcaballero
import com.iver.utiles.GenericFileFilter;
61 312 fernando
62 1219 vcaballero
import org.apache.log4j.Logger;
63 312 fernando
64 1219 vcaballero
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 312 fernando
/**
74 1219 vcaballero
 * Extensi?n de operaciones sobre el tema.
75 312 fernando
 *
76
 * @author Vicente Caballero Navarro
77
 */
78 596 fernando
public class ThemeControls implements Extension {
79 1219 vcaballero
        private static Logger logger = Logger.getLogger(ThemeControls.class.getName());
80 312 fernando
81 1219 vcaballero
        /**
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 1169 vcaballero
                FMap mapa = model.getMapContext();
88
                NewMapControl mapCtrl = vista.getMapControl();
89
                logger.debug("Comand : " + s);
90 1219 vcaballero
91
                if (s.compareTo("PROPERTIES") == 0) {
92
                        vista.openThemeProperties();
93
                } else if (s.compareTo("SHAPE_SELECTED") == 0) {
94 1169 vcaballero
                        createShape(mapa);
95 1219 vcaballero
                } 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 1169 vcaballero
                                }
110
                        }
111 1219 vcaballero
112
                        if (refresh) {
113
                                mapCtrl.drawMap(false);
114 1169 vcaballero
                        }
115 1219 vcaballero
                } else if (s.compareTo("ZOOM_SELECT") == 0) {
116 1169 vcaballero
                        Rectangle2D selectedExtent = mapa.getSelectionBounds();
117
118
                        if (selectedExtent != null) {
119
                                mapa.getViewPort().setExtent(selectedExtent);
120
                        }
121
                }
122 1219 vcaballero
        }
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 1169 vcaballero
                if (map.getSelectionBounds() != null) {
131
                        JFileChooser jfc = new JFileChooser();
132 1219 vcaballero
                        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 1169 vcaballero
                        }
142 1219 vcaballero
                } // else {
143
144 1169 vcaballero
                //}
145 1219 vcaballero
        }
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 1169 vcaballero
                }
157 312 fernando
158 1219 vcaballero
                if (f.getClass() == View.class) {
159
                        FMap mapa = ((View) f).getModel().getMapContext();
160 312 fernando
161 1219 vcaballero
                        View v = (View) f;
162 312 fernando
163 1219 vcaballero
                        return mapa.getLayers().getLayersCount() > 0;
164
                } else {
165
                        return false;
166
                }
167
        }
168 312 fernando
169 1219 vcaballero
        /**
170
         * @see com.iver.andami.plugins.Extension#isEnabled()
171
         */
172
        public boolean isEnabled() {
173
                View f = (View) PluginServices.getMDIManager().getActiveView();
174 312 fernando
175 1219 vcaballero
                if (f == null) {
176
                        return false;
177
                }
178 312 fernando
179 1219 vcaballero
                FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
180 312 fernando
181 1219 vcaballero
                return selected.length > 0;
182
        }
183 596 fernando
184
        /**
185
         * @see com.iver.andami.plugins.Extension#inicializar()
186
         */
187
        public void inicializar() {
188
        }
189 312 fernando
}