Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 40558

History | View | Annotate | Download (6.07 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.view.toc.actions;
25

    
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.app.extension.ProjectExtension;
28
import org.gvsig.app.project.Project;
29
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
30
import org.gvsig.app.project.documents.view.toc.ITocItem;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

    
41

    
42
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
43
 *
44
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
45
 *
46
 * This program is free software; you can redistribute it and/or
47
 * modify it under the terms of the GNU General Public License
48
 * as published by the Free Software Foundation; either version 2
49
 * of the License, or (at your option) any later version.
50
 *
51
 * This program is distributed in the hope that it will be useful,
52
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54
 * GNU General Public License for more details.
55
 *
56
 * You should have received a copy of the GNU General Public License
57
 * along with this program; if not, write to the Free Software
58
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
59
 *
60
 * For more information, contact:
61
 *
62
 *  Generalitat Valenciana
63
 *   Conselleria d'Infraestructures i Transport
64
 *   Av. Blasco Ib??ez, 50
65
 *   46010 VALENCIA
66
 *   SPAIN
67
 *
68
 *      +34 963862235
69
 *   gvsig@gva.es
70
 *      www.gvsig.gva.es
71
 *
72
 *    or
73
 *
74
 *   IVER T.I. S.A
75
 *   Salamanca 50
76
 *   46005 Valencia
77
 *   Spain
78
 *
79
 *   +34 963163400
80
 *   dac@iver.es
81
 */
82
/* CVS MESSAGES:
83
 *
84
 * $Id: ZoomAlTemaTocMenuEntry.java 31496 2009-11-04 12:53:20Z jjdelcerro $
85
 * $Log$
86
 * Revision 1.6  2007-09-19 15:52:16  jaume
87
 * ReadExpansionFileException removed from this context
88
 *
89
 * Revision 1.5  2007/03/06 16:37:08  caballero
90
 * Exceptions
91
 *
92
 * Revision 1.4  2007/01/04 07:24:31  caballero
93
 * isModified
94
 *
95
 * Revision 1.3  2006/10/18 16:01:13  sbayarri
96
 * Added zoomToExtent method to MapContext.
97
 *
98
 * Revision 1.2  2006/10/02 13:52:34  jaume
99
 * organize impots
100
 *
101
 * Revision 1.1  2006/09/15 10:41:30  caballero
102
 * extensibilidad de documentos
103
 *
104
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
105
 * "Sacadas" las opcines del men? de FPopupMenu
106
 *
107
 *
108
 */
109
public class ZoomAlTemaTocMenuEntry extends AbstractTocContextMenuAction {
110
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
111
        private static final Logger logger = LoggerFactory.getLogger(ZoomAlTemaTocMenuEntry.class);
112
        
113
        public String getGroup() {
114
                return "group2"; //FIXME
115
        }
116

    
117
        public int getGroupOrder() {
118
                return 20;
119
        }
120

    
121
        public int getOrder() {
122
                return 1;
123
        }
124

    
125
        public String getText() {
126
                return PluginServices.getText(this, "Zoom_a_la_capa");
127
        }
128

    
129
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
130
                return true;
131
        }
132

    
133
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
134
                if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) {
135
                        return true;
136
                }
137
                return false;
138

    
139
        }
140

    
141

    
142
        public void execute(ITocItem item, FLayer[] selectedItems) {
143

    
144

    
145
                // 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
146

    
147
                if (selectedItems.length==1) {
148
                try {
149
                        if (!selectedItems[0].isAvailable()) {
150
                                        return;
151
                                }
152
                        getMapContext().zoomToEnvelope(selectedItems[0].getFullEnvelope());
153
                        } catch (ReadException e1) {
154
                                e1.printStackTrace();
155
                        }
156
                } else {
157
                        try {
158
                                Envelope maxExtent = setMaxExtent(selectedItems);
159
                                getMapContext().zoomToEnvelope(maxExtent);
160
                        } catch (ReadException e1) {
161
                                e1.printStackTrace();
162
                        }
163
                }
164
                Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
165
                project.setModified(true);
166
        }
167

    
168
        private Envelope setMaxExtent(FLayer[] actives)
169
                        throws ReadException {
170
                Envelope extRef = null;
171
                        extRef = actives[0].getFullEnvelope();
172

    
173
                        double minXRef = extRef.getMinimum(0);
174
                        double maxYRef = extRef.getMaximum(1);
175
                        double maxXRef = extRef.getMaximum(0);
176
                        double minYRef = extRef.getMinimum(1);
177
                        for (int i = 0; i < actives.length; i++) {
178
                                if (actives[i].isAvailable()) {
179
                                        Envelope extVar = actives[i].getFullEnvelope();
180
                                        double minXVar = extVar.getMinimum(0);
181
                                        double maxYVar = extVar.getMaximum(1);
182
                                        double maxXVar = extVar.getMaximum(0);
183
                                        double minYVar = extVar.getMinimum(1);
184
                                        if (minXVar <= minXRef) {
185
                                                minXRef = minXVar;
186
                                        }
187
                                        if (maxYVar >= maxYRef) {
188
                                                maxYRef = maxYVar;
189
                                        }
190
                                        if (maxXVar >= maxXRef) {
191
                                                maxXRef = maxXVar;
192
                                        }
193
                                        if (minYVar <= minYRef) {
194
                                                minYRef = minYVar;
195
                                        }
196
                                        try {
197
                                                extRef = geomManager.createEnvelope(minXRef, minYRef, maxXRef, maxYRef, SUBTYPES.GEOM2D);
198
                                        } catch (CreateEnvelopeException e) {
199
                                                logger.error("Error creating the envelope", e);
200
                                        }
201
                                }
202
                        }
203
                return extRef;
204
        }
205
}