Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 9532

History | View | Annotate | Download (4.22 KB)

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

    
3
import java.awt.geom.Rectangle2D;
4

    
5
import com.iver.andami.PluginServices;
6
import com.iver.cit.gvsig.ProjectExtension;
7
import com.iver.cit.gvsig.fmap.DriverException;
8
import com.iver.cit.gvsig.fmap.layers.FLayer;
9
import com.iver.cit.gvsig.project.Project;
10
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
11
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
12

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

    
79
        public int getGroupOrder() {
80
                return 20;
81
        }
82

    
83
        public int getOrder() {
84
                return 1;
85
        }
86

    
87
        public String getText() {
88
                return PluginServices.getText(this, "Zoom_a_la_capa");
89
        }
90

    
91
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
92
                return true;
93
        }
94

    
95
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
96
                if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) {
97
                        return true;
98
                }
99
                return false;
100

    
101
        }
102

    
103

    
104
        public void execute(ITocItem item, FLayer[] selectedItems) {
105

    
106

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

    
109
                if (selectedItems.length==1) {
110
                try {
111
                        if (!selectedItems[0].isAvailable()) return;
112
                        getMapContext().zoomToExtent(selectedItems[0].getFullExtent());
113
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
114
                                e1.printStackTrace();
115
                        }
116
                } else {
117
                        try {
118
                                Rectangle2D maxExtent = setMaxExtent(selectedItems);
119
                                getMapContext().zoomToExtent(maxExtent);
120
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
121
                                e1.printStackTrace();
122
                        }
123
                }
124
                Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
125
                project.setModified(true);
126
        }
127

    
128
        private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException {
129
                Rectangle2D extRef = actives[0].getFullExtent();
130
                double minXRef = extRef.getMinX();
131
                double maxYRef = extRef.getMaxY();
132
                double maxXRef = extRef.getMaxX();
133
                double minYRef = extRef.getMinY();
134
                for (int i=0;i<actives.length;i++) {
135
                        if (actives[i].isAvailable()) {
136
                                Rectangle2D extVar = actives[i].getFullExtent();
137
                                double minXVar = extVar.getMinX();
138
                                double maxYVar = extVar.getMaxY();
139
                                double maxXVar = extVar.getMaxX();
140
                                double minYVar = extVar.getMinY();
141
                                if (minXVar<=minXRef) minXRef=minXVar;
142
                                if (maxYVar>=maxYRef) maxYRef=maxYVar;
143
                                if (maxXVar>=maxXRef) maxXRef=maxXVar;
144
                                if (minYVar<=minYRef) minYRef=minYVar;
145
                                extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef);
146
                        }
147
                }
148
                return extRef;
149
        }
150
}