Revision 2903 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/Behavior/GeoMoveBehavior.java

View differences:

GeoMoveBehavior.java
48 48
import java.awt.event.MouseEvent;
49 49
import java.awt.event.MouseWheelEvent;
50 50
import java.awt.geom.Point2D;
51
import java.io.File;
51 52

  
52 53
import javax.swing.ImageIcon;
53 54

  
55
import org.cresques.io.GeoRasterFile;
56
import org.cresques.px.Extent;
57

  
58
import com.hardcode.driverManager.DriverLoadException;
59
import com.iver.andami.messages.NotificationManager;
54 60
import com.iver.cit.gvsig.fmap.MapControl;
55 61
import com.iver.cit.gvsig.fmap.ViewPort;
62
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56 63
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
64
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
65
import com.iver.cit.gvsig.fmap.layers.RasterAdapter;
66
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter;
57 67
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
58 68
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener;
59 69
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
70
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog;
60 71

  
61 72

  
62 73
/**
......
68 79
	
69 80
	private PanListener listener;
70 81
	private Cursor cur = null;
71
	
82
		
72 83
	private final Image defaultCursor = new ImageIcon(MapControl.class.getResource(
73 84
	"images/CruxCursor.png")).getImage();
74 85
	private final Image handCursor = new ImageIcon(MapControl.class.getResource(
......
79 90
	private boolean isMoveable = false;
80 91
	
81 92
	/**
93
	 * Variable booleana que est? a true si el cursor por defecto est? 
94
	 * activo y a false si hay otro.
95
	 */
96
	private boolean defaultCursorActive = true;
97
	
98
	/**
99
	 * Puntos de inicio y final para el arrastre de la imagen.
100
	 */
101
	private Point2D ptoIni = null;
102
	private Point2D ptoFin = null;
103
	
104
	private GeoreferencingDialog parent = null;
105
	/**
82 106
	 * Crea un nuevo RectangleBehavior.
83 107
	 *
84 108
	 * @param zili listener.
85 109
	 */
86
	public GeoMoveBehavior(PanListener zili) {
110
	public GeoMoveBehavior(PanListener zili, GeoreferencingDialog p) {
87 111
		listener = zili;
112
		parent = p;
88 113
		cur = zili.getCursor();
89 114
	}
90 115
	
......
95 120
	public void mouseMoved(MouseEvent e) throws BehaviorException {
96 121
		ViewPort vp = getMapControl().getMapContext().getViewPort();
97 122
		Point2D pto = vp.toMapPoint(e.getX(), e.getY());
98
		//System.out.println(pto);
99 123
		
124
		if(	pto.getX() > lyrRaster.getMinX() &&
125
			pto.getX() < lyrRaster.getMaxX() &&
126
			pto.getY() > lyrRaster.getMinY() &&
127
			pto.getY() < lyrRaster.getMaxY()){
128
			if(defaultCursorActive){
129
				getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(handCursor,
130
					new Point(16, 16), ""));
131
				defaultCursorActive = false;
132
			}
133
		}else{
134
			if(!defaultCursorActive){
135
				getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(defaultCursor,
136
					new Point(16, 16), ""));
137
				defaultCursorActive = true;
138
			}
139
		}
100 140
	}
101 141
	
102 142
	/**
......
105 145
	public Cursor getCursor() {
106 146
		return this.cur;
107 147
	}
148
	
149
	/**
150
	 * Si no est? activo el cursor por defecto capturamos el punto 
151
	 * seleccionado en coordenadas del mundo real.
152
	 */
153
	public void mousePressed(MouseEvent e) throws BehaviorException {
154
		if(!defaultCursorActive){
155
			ViewPort vp = getMapControl().getMapContext().getViewPort();
156
			ptoIni = vp.toMapPoint(e.getPoint());
157
			isMoveable = true;
158
		}		
159
	}
160
	
161
	/**
162
	 *  
163
	 */
164
	public void mouseReleased(MouseEvent e) throws BehaviorException {
165
		if(isMoveable){
166
			ViewPort vp = getMapControl().getMapContext().getViewPort();
167
			ptoFin = vp.toMapPoint(e.getPoint());
168
			double distX = ptoFin.getX() - ptoIni.getX();
169
			double distY = ptoFin.getY() - ptoIni.getY();
170
			Extent ext = new Extent(lyrRaster.getMinX() + distX, 
171
									lyrRaster.getMinY() + distY,
172
									lyrRaster.getMaxX() + distX, 
173
									lyrRaster.getMaxY() + distY);
174
			if(this.pathToFile != null && this.lyrRaster != null){
175
				File fich = new File(this.pathToFile);
176
				RasterAdapter adapter = new RasterFileAdapter(fich);
177
				try{
178
					adapter.setDriver(LayerFactory.getDM().getDriver("gvSIG Image Driver"));
179
				}catch(DriverLoadException exc){
180
					NotificationManager.addError("No se pudo acceder a los drivers", exc);
181
				}
182
				FLyrRaster capa = new FLyrRaster();
183
				if (capa != null) {
184
					capa.setName(lyrRaster.getName());
185
					capa.setSource(adapter);
186
					capa.setProjection(lyrRaster.getProjection());
187
					capa.setTempExtent(ext);
188
					capa.setExtentFlag(GeoRasterFile.ASSIGNED_EXTENT);
189
					try {
190
						capa.load();
191
					} catch (DriverIOException exc) {
192
				
193
					}
194
			        capa.setVisible(true);
195
				}
196
				
197
				getMapControl().getMapContext().getLayers().removeLayer(lyrRaster.getName());
198
				lyrRaster = null;
199
				getMapControl().getMapContext().getLayers().addLayer(capa);
200
				this.setLyrRaster(capa);
201
				this.parent.getGeoRedimBehavior().setLyrRaster(capa);
202
				getMapControl().repaint();
203
			}
204
			isMoveable = false;
205
		}
206
	}
207
	
108 208
	/* (non-Javadoc)
109 209
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
110 210
	 */
......
149 249
	}
150 250

  
151 251
	/* (non-Javadoc)
152
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
153
	 */
154
	public void mousePressed(MouseEvent e) throws BehaviorException {
155
		// TODO Auto-generated method stub
156
		super.mousePressed(e);
157
	}
158
	/* (non-Javadoc)
159
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
160
	 */
161
	public void mouseReleased(MouseEvent e) throws BehaviorException {
162
		// TODO Auto-generated method stub
163
		super.mouseReleased(e);
164
	}
165
	/* (non-Javadoc)
166 252
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
167 253
	 */
168 254
	public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException {

Also available in: Unified diff