svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 21501
History | View | Annotate | Download (4.43 KB)
1 |
package com.iver.cit.gvsig.project.documents.view.toc.actions; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
|
5 |
import org.gvsig.data.ReadException; |
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 21501 2008-06-11 14:33:20Z vcaballero $
|
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()) return; |
119 |
getMapContext().zoomToEnvelope(selectedItems[0].getFullEnvelope());
|
120 |
} catch (ReadException e1) {
|
121 |
e1.printStackTrace(); |
122 |
} |
123 |
} else {
|
124 |
try {
|
125 |
Rectangle2D maxExtent = setMaxExtent(selectedItems);
|
126 |
getMapContext().zoomToEnvelope(maxExtent); |
127 |
} catch (ReadException e1) {
|
128 |
e1.printStackTrace(); |
129 |
} |
130 |
} |
131 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
132 |
project.setModified(true);
|
133 |
} |
134 |
|
135 |
private Rectangle2D setMaxExtent(FLayer[] actives) |
136 |
throws ReadException {
|
137 |
Rectangle2D extRef = null; |
138 |
extRef = actives[0].getFullEnvelope();
|
139 |
|
140 |
double minXRef = extRef.getMinX();
|
141 |
double maxYRef = extRef.getMaxY();
|
142 |
double maxXRef = extRef.getMaxX();
|
143 |
double minYRef = extRef.getMinY();
|
144 |
for (int i = 0; i < actives.length; i++) { |
145 |
if (actives[i].isAvailable()) {
|
146 |
Rectangle2D extVar = actives[i].getFullEnvelope();
|
147 |
double minXVar = extVar.getMinX();
|
148 |
double maxYVar = extVar.getMaxY();
|
149 |
double maxXVar = extVar.getMaxX();
|
150 |
double minYVar = extVar.getMinY();
|
151 |
if (minXVar <= minXRef)
|
152 |
minXRef = minXVar; |
153 |
if (maxYVar >= maxYRef)
|
154 |
maxYRef = maxYVar; |
155 |
if (maxXVar >= maxXRef)
|
156 |
maxXRef = maxXVar; |
157 |
if (minYVar <= minYRef)
|
158 |
minYRef = minYVar; |
159 |
extRef.setRect(minXRef, minYRef, maxXRef - minXRef, maxYRef |
160 |
- minYRef); |
161 |
} |
162 |
} |
163 |
return extRef;
|
164 |
} |
165 |
} |