Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 24759

History | View | Annotate | Download (4.59 KB)

1
package com.iver.cit.gvsig.project.documents.view.toc.actions;
2

    
3
import org.gvsig.fmap.dal.exception.ReadException;
4
import org.gvsig.fmap.geom.primitive.DefaultEnvelope;
5
import org.gvsig.fmap.geom.primitive.Envelope;
6
import org.gvsig.fmap.mapcontext.layers.FLayer;
7

    
8
import com.iver.andami.PluginServices;
9
import com.iver.cit.gvsig.ProjectExtension;
10
import com.iver.cit.gvsig.project.Project;
11
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
12
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
13

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

    
86
        public int getGroupOrder() {
87
                return 20;
88
        }
89

    
90
        public int getOrder() {
91
                return 1;
92
        }
93

    
94
        public String getText() {
95
                return PluginServices.getText(this, "Zoom_a_la_capa");
96
        }
97

    
98
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
99
                return true;
100
        }
101

    
102
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
103
                if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) {
104
                        return true;
105
                }
106
                return false;
107

    
108
        }
109

    
110

    
111
        public void execute(ITocItem item, FLayer[] selectedItems) {
112

    
113

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

    
116
                if (selectedItems.length==1) {
117
                try {
118
                        if (!selectedItems[0].isAvailable()) {
119
                                        return;
120
                                }
121
                        getMapContext().zoomToEnvelope(selectedItems[0].getFullEnvelope());
122
                        } catch (ReadException e1) {
123
                                e1.printStackTrace();
124
                        }
125
                } else {
126
                        try {
127
                                Envelope maxExtent = setMaxExtent(selectedItems);
128
                                getMapContext().zoomToEnvelope(maxExtent);
129
                        } catch (ReadException e1) {
130
                                e1.printStackTrace();
131
                        }
132
                }
133
                Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
134
                project.setModified(true);
135
        }
136

    
137
        private Envelope setMaxExtent(FLayer[] actives)
138
                        throws ReadException {
139
                Envelope extRef = null;
140
                        extRef = actives[0].getFullEnvelope();
141

    
142
                        double minXRef = extRef.getMinimum(0);
143
                        double maxYRef = extRef.getMaximum(1);
144
                        double maxXRef = extRef.getMaximum(0);
145
                        double minYRef = extRef.getMinimum(1);
146
                        for (int i = 0; i < actives.length; i++) {
147
                                if (actives[i].isAvailable()) {
148
                                        Envelope extVar = actives[i].getFullEnvelope();
149
                                        double minXVar = extVar.getMinimum(0);
150
                                        double maxYVar = extVar.getMaximum(1);
151
                                        double maxXVar = extVar.getMaximum(0);
152
                                        double minYVar = extVar.getMinimum(1);
153
                                        if (minXVar <= minXRef) {
154
                                                minXRef = minXVar;
155
                                        }
156
                                        if (maxYVar >= maxYRef) {
157
                                                maxYRef = maxYVar;
158
                                        }
159
                                        if (maxXVar >= maxXRef) {
160
                                                maxXRef = maxXVar;
161
                                        }
162
                                        if (minYVar <= minYRef) {
163
                                                minYRef = minYVar;
164
                                        }
165
                                        extRef=new DefaultEnvelope(2,new double[]{minXRef, minYRef},new double[]{ maxXRef, maxYRef});
166
                                }
167
                        }
168
                return extRef;
169
        }
170
}