Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 7738

History | View | Annotate | Download (3.88 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.fmap.DriverException;
7
import com.iver.cit.gvsig.fmap.layers.FLayer;
8
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
9
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
10

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

    
71
        public int getGroupOrder() {
72
                return 20;
73
        }
74

    
75
        public int getOrder() {
76
                return 1;
77
        }
78

    
79
        public String getText() {
80
                return PluginServices.getText(this, "Zoom_a_la_capa");
81
        }
82

    
83
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
84
                return true;
85
        }
86

    
87
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
88
                if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) {
89
                        return true;
90
                }
91
                return false;
92

    
93
        }
94

    
95

    
96
        public void execute(ITocItem item, FLayer[] selectedItems) {
97

    
98

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

    
101
                if (selectedItems.length==1) {
102
                try {
103
                        if (!selectedItems[0].isAvailable()) return;
104
                        getMapContext().getViewPort().setExtent(selectedItems[0].getFullExtent());
105
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
106
                                e1.printStackTrace();
107
                        }
108
                } else {
109
                        try {
110
                                Rectangle2D maxExtent = setMaxExtent(selectedItems);
111
                                getMapContext().getViewPort().setExtent(maxExtent);
112
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
113
                                e1.printStackTrace();
114
                        }
115
                }
116
        }
117

    
118
        private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException {
119
                Rectangle2D extRef = actives[0].getFullExtent();
120
                double minXRef = extRef.getMinX();
121
                double maxYRef = extRef.getMaxY();
122
                double maxXRef = extRef.getMaxX();
123
                double minYRef = extRef.getMinY();
124
                for (int i=0;i<actives.length;i++) {
125
                        if (actives[i].isAvailable()) {
126
                                Rectangle2D extVar = actives[i].getFullExtent();
127
                                double minXVar = extVar.getMinX();
128
                                double maxYVar = extVar.getMaxY();
129
                                double maxXVar = extVar.getMaxX();
130
                                double minYVar = extVar.getMinY();
131
                                if (minXVar<=minXRef) minXRef=minXVar;
132
                                if (maxYVar>=maxYRef) maxYRef=maxYVar;
133
                                if (maxXVar>=maxXRef) maxXRef=maxXVar;
134
                                if (minYVar<=minYRef) minYRef=minYVar;
135
                                extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef);
136
                        }
137
                }
138
                return extRef;
139
        }
140
}