root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / GeoreferencingToolsModule.java @ 6877
History | View | Annotate | Download (4.85 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.georeferencing; |
20 |
|
21 |
import java.util.logging.Logger; |
22 |
|
23 |
|
24 |
import com.iver.andami.PluginServices; |
25 |
import com.iver.andami.plugins.Extension; |
26 |
import com.iver.cit.gvsig.LayoutControls; |
27 |
import com.iver.cit.gvsig.fmap.MapControl; |
28 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
29 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
30 |
import com.iver.cit.gvsig.gui.View; |
31 |
import com.iver.cit.gvsig.gui.layout.Layout; |
32 |
|
33 |
|
34 |
/**
|
35 |
* Extensi?n encargada de cargar la herramientas de redimensi?n, movimiento
|
36 |
* de imagen, movimiento de puntos y cargar extent anterior.
|
37 |
*
|
38 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
39 |
*/
|
40 |
public class GeoreferencingToolsModule extends Extension { |
41 |
|
42 |
//**********************Vars****************************************
|
43 |
private static Logger logger = Logger.getLogger(LayoutControls.class.getName()); |
44 |
private Layout layout = null; |
45 |
public static boolean enabled = true; |
46 |
//**********************End Vars************************************
|
47 |
|
48 |
//**********************Methods*************************************
|
49 |
/**
|
50 |
* El control est? activo siempre que haya una vista abierta
|
51 |
*/
|
52 |
public boolean isEnabled() { |
53 |
if(enabled)
|
54 |
return true; |
55 |
else
|
56 |
return false; |
57 |
} |
58 |
|
59 |
/**
|
60 |
* El control es visible siempre que haya una vista abierta
|
61 |
*/
|
62 |
public boolean isVisible() { |
63 |
com.iver.andami.ui.mdiManager.IWindow f = null;
|
64 |
try{
|
65 |
f = PluginServices.getMDIManager().getActiveView(); |
66 |
}catch(ClassCastException exc){ |
67 |
return false; |
68 |
} |
69 |
|
70 |
if (f == null) { |
71 |
return false; |
72 |
} |
73 |
|
74 |
try{
|
75 |
for(int i=0;i<((View)f).getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
76 |
FLayer lyr = ((View)f).getMapControl().getMapContext().getLayers().getLayer(i);
|
77 |
if( lyr instanceof FLyrGeoRaster && |
78 |
lyr.getName().startsWith("*") &&
|
79 |
lyr.isActive()) |
80 |
return true; |
81 |
} |
82 |
}catch(ClassCastException ex){ |
83 |
return false; |
84 |
} |
85 |
|
86 |
return false; |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Obtiene la capa de georreferenciaci?n
|
91 |
* @param theView Vista de gvSIG
|
92 |
* @return capa de georreferenciaci?n
|
93 |
*/
|
94 |
private FLyrGeoRaster getLayer(View theView){ |
95 |
FLyrGeoRaster lyrGeoRaster = null;
|
96 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
97 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
98 |
if(lyr instanceof FLyrGeoRaster && lyr.getName().startsWith("*")) |
99 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
100 |
} |
101 |
return lyrGeoRaster;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Cuando ejecutamos alguna herramienta de georeferenciaci?n seleccionamos
|
106 |
* la que ha sido activada.
|
107 |
*/
|
108 |
public void execute(String s) { |
109 |
View theView = null; |
110 |
try{
|
111 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
112 |
}catch(ClassCastException exc){ |
113 |
return;
|
114 |
} |
115 |
MapControl mapCtrl = theView.getMapControl(); |
116 |
|
117 |
if (s.compareTo("GEO_PAN") == 0) { |
118 |
mapCtrl.setTool("geoPan");
|
119 |
} else if (s.compareTo("GEO_ZOOM") == 0) { |
120 |
mapCtrl.setTool("geoZoom");
|
121 |
} else if (s.compareTo("GEO_ZOOM_PREV") == 0) { |
122 |
//Obtenemos la capa
|
123 |
FLyrGeoRaster lyrGeoRaster = getLayer(theView); |
124 |
|
125 |
//Asignamos el ?ltimo extent
|
126 |
if(lyrGeoRaster != null){ |
127 |
lyrGeoRaster.setLastExtent(); |
128 |
mapCtrl.getMapContext().invalidate(); |
129 |
} |
130 |
} else if (s.compareTo("GEO_MOVE_POINT") == 0){ |
131 |
mapCtrl.setTool("geoMovePoint");
|
132 |
} else if (s.compareTo("GEO_ZOOM_NEXT") == 0) { |
133 |
//Obtenemos la capa
|
134 |
FLyrGeoRaster lyrGeoRaster = getLayer(theView); |
135 |
|
136 |
//Asignamos el extent anterior
|
137 |
if(lyrGeoRaster != null){ |
138 |
lyrGeoRaster.setNextExtent(); |
139 |
mapCtrl.getMapContext().invalidate(); |
140 |
} |
141 |
} |
142 |
} |
143 |
|
144 |
/**
|
145 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
146 |
*/
|
147 |
public void initialize() { |
148 |
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Activa o desactiva la barra de herramientas de georreferenciaci?n
|
153 |
* @param enabled true para activar y false para desactivar
|
154 |
*/
|
155 |
public static void setEnabled(boolean enabled){ |
156 |
if(PluginServices.getExtension(GeoreferencingToolsModule.class) != null){ |
157 |
GeoreferencingToolsModule.enabled = enabled; |
158 |
PluginServices.getMainFrame().enableControls(); |
159 |
} |
160 |
} |
161 |
//**********************End Methods**********************************
|
162 |
} |