root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / GeoreferencingToolsModule.java @ 9632
History | View | Annotate | Download (4.83 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 |
import com.iver.andami.PluginServices; |
24 |
import com.iver.andami.plugins.Extension; |
25 |
import com.iver.cit.gvsig.fmap.MapControl; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
27 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
28 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
29 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
30 |
|
31 |
|
32 |
/**
|
33 |
* Extensi?n encargada de cargar la herramientas de redimensi?n, movimiento
|
34 |
* de imagen, movimiento de puntos y cargar extent anterior.
|
35 |
*
|
36 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
37 |
*/
|
38 |
public class GeoreferencingToolsModule extends Extension { |
39 |
|
40 |
//**********************Vars****************************************
|
41 |
private static Logger logger = Logger.getLogger(GeoreferencingToolsModule.class.getName()); |
42 |
private Layout layout = null; |
43 |
public static boolean enabled = true; |
44 |
//**********************End Vars************************************
|
45 |
|
46 |
//**********************Methods*************************************
|
47 |
/**
|
48 |
* El control est? activo siempre que haya una vista abierta
|
49 |
*/
|
50 |
public boolean isEnabled() { |
51 |
if(enabled)
|
52 |
return true; |
53 |
else
|
54 |
return false; |
55 |
} |
56 |
|
57 |
/**
|
58 |
* El control es visible siempre que haya una vista abierta
|
59 |
*/
|
60 |
public boolean isVisible() { |
61 |
com.iver.andami.ui.mdiManager.IWindow f = null;
|
62 |
try{
|
63 |
f = PluginServices.getMDIManager().getActiveWindow(); |
64 |
}catch(ClassCastException exc){ |
65 |
return false; |
66 |
} |
67 |
|
68 |
if (f == null) { |
69 |
return false; |
70 |
} |
71 |
|
72 |
try{
|
73 |
for(int i=0;i<((View)f).getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
74 |
FLayer lyr = ((View)f).getMapControl().getMapContext().getLayers().getLayer(i);
|
75 |
if( lyr instanceof FLyrGeoRaster && |
76 |
lyr.getName().startsWith("*") &&
|
77 |
lyr.isActive()) |
78 |
return true; |
79 |
} |
80 |
}catch(ClassCastException ex){ |
81 |
return false; |
82 |
} |
83 |
|
84 |
return false; |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Obtiene la capa de georreferenciaci?n
|
89 |
* @param theView Vista de gvSIG
|
90 |
* @return capa de georreferenciaci?n
|
91 |
*/
|
92 |
private FLyrGeoRaster getLayer(View theView){ |
93 |
FLyrGeoRaster lyrGeoRaster = null;
|
94 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
95 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
96 |
if(lyr instanceof FLyrGeoRaster && lyr.getName().startsWith("*")) |
97 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
98 |
} |
99 |
return lyrGeoRaster;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Cuando ejecutamos alguna herramienta de georeferenciaci?n seleccionamos
|
104 |
* la que ha sido activada.
|
105 |
*/
|
106 |
public void execute(String s) { |
107 |
View theView = null; |
108 |
try{
|
109 |
theView = (View) PluginServices.getMDIManager().getActiveWindow();
|
110 |
}catch(ClassCastException exc){ |
111 |
return;
|
112 |
} |
113 |
MapControl mapCtrl = theView.getMapControl(); |
114 |
|
115 |
if (s.compareTo("GEO_PAN") == 0) { |
116 |
mapCtrl.setTool("geoPan");
|
117 |
} else if (s.compareTo("GEO_ZOOM") == 0) { |
118 |
mapCtrl.setTool("geoZoom");
|
119 |
} else if (s.compareTo("GEO_ZOOM_PREV") == 0) { |
120 |
//Obtenemos la capa
|
121 |
FLyrGeoRaster lyrGeoRaster = getLayer(theView); |
122 |
|
123 |
//Asignamos el ?ltimo extent
|
124 |
if(lyrGeoRaster != null){ |
125 |
lyrGeoRaster.setLastExtent(); |
126 |
mapCtrl.getMapContext().invalidate(); |
127 |
} |
128 |
} else if (s.compareTo("GEO_MOVE_POINT") == 0){ |
129 |
mapCtrl.setTool("geoMovePoint");
|
130 |
} else if (s.compareTo("GEO_ZOOM_NEXT") == 0) { |
131 |
//Obtenemos la capa
|
132 |
FLyrGeoRaster lyrGeoRaster = getLayer(theView); |
133 |
|
134 |
//Asignamos el extent anterior
|
135 |
if(lyrGeoRaster != null){ |
136 |
lyrGeoRaster.setNextExtent(); |
137 |
mapCtrl.getMapContext().invalidate(); |
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
/**
|
143 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
144 |
*/
|
145 |
public void initialize() { |
146 |
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Activa o desactiva la barra de herramientas de georreferenciaci?n
|
151 |
* @param enabled true para activar y false para desactivar
|
152 |
*/
|
153 |
public static void setEnabled(boolean enabled){ |
154 |
if(PluginServices.getExtension(GeoreferencingToolsModule.class) != null){ |
155 |
GeoreferencingToolsModule.enabled = enabled; |
156 |
PluginServices.getMainFrame().enableControls(); |
157 |
} |
158 |
} |
159 |
//**********************End Methods**********************************
|
160 |
} |