svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 8163
History | View | Annotate | Download (3.95 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 8163 2006-10-18 16:02:30Z sbayarri $
|
54 |
* $Log$
|
55 |
* Revision 1.3 2006-10-18 16:01:13 sbayarri
|
56 |
* Added zoomToExtent method to MapContext.
|
57 |
*
|
58 |
* Revision 1.2 2006/10/02 13:52:34 jaume
|
59 |
* organize impots
|
60 |
*
|
61 |
* Revision 1.1 2006/09/15 10:41:30 caballero
|
62 |
* extensibilidad de documentos
|
63 |
*
|
64 |
* Revision 1.1 2006/09/12 15:58:14 jorpiell
|
65 |
* "Sacadas" las opcines del men? de FPopupMenu
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
public class ZoomAlTemaTocMenuEntry extends AbstractTocContextMenuAction { |
70 |
public String getGroup() { |
71 |
return "group2"; //FIXME |
72 |
} |
73 |
|
74 |
public int getGroupOrder() { |
75 |
return 20; |
76 |
} |
77 |
|
78 |
public int getOrder() { |
79 |
return 1; |
80 |
} |
81 |
|
82 |
public String getText() { |
83 |
return PluginServices.getText(this, "Zoom_a_la_capa"); |
84 |
} |
85 |
|
86 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
87 |
return true; |
88 |
} |
89 |
|
90 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
91 |
if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) { |
92 |
return true; |
93 |
} |
94 |
return false; |
95 |
|
96 |
} |
97 |
|
98 |
|
99 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
100 |
|
101 |
|
102 |
// 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
|
103 |
|
104 |
if (selectedItems.length==1) { |
105 |
try {
|
106 |
if (!selectedItems[0].isAvailable()) return; |
107 |
getMapContext().zoomToExtent(selectedItems[0].getFullExtent());
|
108 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
109 |
e1.printStackTrace(); |
110 |
} |
111 |
} else {
|
112 |
try {
|
113 |
Rectangle2D maxExtent = setMaxExtent(selectedItems);
|
114 |
getMapContext().zoomToExtent(maxExtent); |
115 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
116 |
e1.printStackTrace(); |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException { |
122 |
Rectangle2D extRef = actives[0].getFullExtent(); |
123 |
double minXRef = extRef.getMinX();
|
124 |
double maxYRef = extRef.getMaxY();
|
125 |
double maxXRef = extRef.getMaxX();
|
126 |
double minYRef = extRef.getMinY();
|
127 |
for (int i=0;i<actives.length;i++) { |
128 |
if (actives[i].isAvailable()) {
|
129 |
Rectangle2D extVar = actives[i].getFullExtent();
|
130 |
double minXVar = extVar.getMinX();
|
131 |
double maxYVar = extVar.getMaxY();
|
132 |
double maxXVar = extVar.getMaxX();
|
133 |
double minYVar = extVar.getMinY();
|
134 |
if (minXVar<=minXRef) minXRef=minXVar;
|
135 |
if (maxYVar>=maxYRef) maxYRef=maxYVar;
|
136 |
if (maxXVar>=maxXRef) maxXRef=maxXVar;
|
137 |
if (minYVar<=minYRef) minYRef=minYVar;
|
138 |
extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef); |
139 |
} |
140 |
} |
141 |
return extRef;
|
142 |
} |
143 |
} |