Statistics
| Revision:

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

History | View | Annotate | Download (4.59 KB)

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

    
3
import java.awt.geom.Rectangle2D;
4

    
5
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
6
import com.iver.andami.PluginServices;
7
import com.iver.cit.gvsig.ProjectExtension;
8
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
9
import com.iver.cit.gvsig.fmap.layers.FLayer;
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 10626 2007-03-06 16:55:54Z caballero $
57
 * $Log$
58
 * Revision 1.5  2007-03-06 16:37:08  caballero
59
 * Exceptions
60
 *
61
 * Revision 1.4  2007/01/04 07:24:31  caballero
62
 * isModified
63
 *
64
 * Revision 1.3  2006/10/18 16:01:13  sbayarri
65
 * Added zoomToExtent method to MapContext.
66
 *
67
 * Revision 1.2  2006/10/02 13:52:34  jaume
68
 * organize impots
69
 *
70
 * Revision 1.1  2006/09/15 10:41:30  caballero
71
 * extensibilidad de documentos
72
 *
73
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
74
 * "Sacadas" las opcines del men? de FPopupMenu
75
 *
76
 *
77
 */
78
public class ZoomAlTemaTocMenuEntry extends AbstractTocContextMenuAction {
79
        public String getGroup() {
80
                return "group2"; //FIXME
81
        }
82

    
83
        public int getGroupOrder() {
84
                return 20;
85
        }
86

    
87
        public int getOrder() {
88
                return 1;
89
        }
90

    
91
        public String getText() {
92
                return PluginServices.getText(this, "Zoom_a_la_capa");
93
        }
94

    
95
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
96
                return true;
97
        }
98

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

    
105
        }
106

    
107

    
108
        public void execute(ITocItem item, FLayer[] selectedItems) {
109

    
110

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

    
113
                if (selectedItems.length==1) {
114
                try {
115
                        if (!selectedItems[0].isAvailable()) return;
116
                        getMapContext().zoomToExtent(selectedItems[0].getFullExtent());
117
                        } catch (ReadDriverException e1) {
118
                                e1.printStackTrace();
119
                        } catch (ExpansionFileReadException e) {
120
                                e.printStackTrace();
121
                        }
122
                } else {
123
                        try {
124
                                Rectangle2D maxExtent = setMaxExtent(selectedItems);
125
                                getMapContext().zoomToExtent(maxExtent);
126
                        } catch (ReadDriverException e1) {
127
                                e1.printStackTrace();
128
                        }
129
                }
130
                Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
131
                project.setModified(true);
132
        }
133

    
134
        private Rectangle2D setMaxExtent(FLayer[] actives)
135
                        throws ReadDriverException {
136
                Rectangle2D extRef = null;
137
                try {
138

    
139
                        extRef = actives[0].getFullExtent();
140

    
141
                        double minXRef = extRef.getMinX();
142
                        double maxYRef = extRef.getMaxY();
143
                        double maxXRef = extRef.getMaxX();
144
                        double minYRef = extRef.getMinY();
145
                        for (int i = 0; i < actives.length; i++) {
146
                                if (actives[i].isAvailable()) {
147
                                        Rectangle2D extVar = actives[i].getFullExtent();
148
                                        double minXVar = extVar.getMinX();
149
                                        double maxYVar = extVar.getMaxY();
150
                                        double maxXVar = extVar.getMaxX();
151
                                        double minYVar = extVar.getMinY();
152
                                        if (minXVar <= minXRef)
153
                                                minXRef = minXVar;
154
                                        if (maxYVar >= maxYRef)
155
                                                maxYRef = maxYVar;
156
                                        if (maxXVar >= maxXRef)
157
                                                maxXRef = maxXVar;
158
                                        if (minYVar <= minYRef)
159
                                                minYRef = minYVar;
160
                                        extRef.setRect(minXRef, minYRef, maxXRef - minXRef, maxYRef
161
                                                        - minYRef);
162
                                }
163
                        }
164
                } catch (ExpansionFileReadException e) {
165
                        e.printStackTrace();
166
                }
167
                return extRef;
168
        }
169
}