Revision 18251

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/view/ZoomRasterDialog.java
24 24
import java.awt.geom.Rectangle2D;
25 25
import java.awt.image.BufferedImage;
26 26

  
27
import org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest;
27 28
import org.gvsig.rastertools.georeferencing.ui.zoom.ViewControl;
28 29
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.CenterPointGraphicLayer;
29 30
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.GPGraphic;
......
96 97
	}
97 98
	
98 99
	/**
100
	 * Registra un objeto IExtensionRequest para que no se aplique un escalado sobre
101
	 * el buffer pasado por par?metro. Alternativamente a la aplicaci?n de este escalado
102
	 * se ejecutar? el m?todo request del interfaz para que el cliente pueda pasar un 
103
	 * nuevo buffer con escala 1:1 y con la extensi?n correspondiente al zoom.
104
	 * @param er
105
	 */
106
	public void setExtensionRequest(IExtensionRequest er) {
107
		zoomPixelControl.setExtensionRequest(er);
108
	}
109
	
110
	/**
99 111
	 * Obtiene el panel de control de zoom de coordenadas pixel
100 112
	 * @return
101 113
	 */
......
105 117
			zoomPixelControl.hideButton(ViewControl.PREV_ZOOM);
106 118
			zoomPixelControl.hideButton(ViewControl.FULL_VIEW);
107 119
			zoomPixelControl.hideButton(ViewControl.SELECT_ZOOM_AREA);
120
			zoomPixelControl.hideButton(ViewControl.ZOOM_INCREASE);
121
			zoomPixelControl.hideButton(ViewControl.ZOOM_DECREASE);
108 122
		}
109 123
		return zoomPixelControl;
110 124
	}
......
130 144
	 * @param pixelSize Tama?o de pixel
131 145
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
132 146
	 */
133
	public void setPixelDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
147
	public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
134 148
		getZoomPixelControl().setDrawParams(img, ext, pixelSize, center) ;
135 149
	}
136 150

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/view/BaseZoomView.java
19 19
package org.gvsig.rastertools.georeferencing.view;
20 20

  
21 21
import java.awt.Graphics2D;
22
import java.awt.geom.Point2D;
23
import java.awt.geom.Rectangle2D;
24
import java.awt.image.BufferedImage;
22 25

  
23 26
import javax.swing.JPanel;
24 27

  
28
import org.gvsig.rastertools.georeferencing.ui.zoom.CanvasZone;
25 29
import org.gvsig.rastertools.georeferencing.ui.zoom.ViewControl;
26 30

  
27 31
/**
......
58 62
	public int getCanvasHeight() {
59 63
		return zoomPixelControl.getCanvasHeight();
60 64
	}
65
	
66
	/**
67
	 * Asigna los par?metros de dibujado para el raster
68
	 * @param img Buffer con un ?rea de datos
69
	 * @param ext Rectangle2D del ?rea de datos dada 
70
	 * @param pixelSize Tama?o de pixel
71
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
72
	 */
73
	public abstract void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center);
74
	
75
	/**
76
	 * Obtiene el canvas asociado
77
	 * @return CanvasZone
78
	 */
79
	public CanvasZone getCanvas() {
80
		return zoomPixelControl.getCanvas();
81
	}
61 82
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/view/ViewDialog.java
28 28
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.GCPsGraphicLayer;
29 29
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.GPGraphic;
30 30
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer;
31
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
31 32

  
32 33
import com.iver.andami.PluginServices;
33 34
import com.iver.andami.ui.mdiManager.IWindow;
......
43 44
	private static final long         serialVersionUID = 1L;
44 45
	private GCPsGraphicLayer          graphicLayer = null;
45 46
	private ZoomCursorGraphicLayer    zoomCursorGraphic = null;
47
	private ToolListener              zoomCursorGraphicListener = null;
46 48
	private int                       w = 640;
47 49
	private int                       h = 100;
48 50
	private int                       posX = 0;
......
56 58
	 * @param w Tama?o en pixeles de ancho
57 59
	 * @param h Tama?o en pixeles de alto
58 60
	 */
59
	public ViewDialog(int posX, int posY, int w, int h) {
61
	public ViewDialog(int posX, int posY, int w, int h, ToolListener zoomCursorGraphicListener) {
60 62
		setPosition(posX, posY);
61 63
		setWindowsSize(w, h);
64
		this.zoomCursorGraphicListener = zoomCursorGraphicListener;
62 65
		init();
63 66
	}
64 67
	
......
99 102
	 * @param pixelSize Tama?o de pixel
100 103
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
101 104
	 */
102
	public void setPixelDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
105
	public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
103 106
		getZoomPixelControl().setDrawParams(img, ext, pixelSize, center) ;
104 107
	}
105 108
	
......
144 147
	 */
145 148
	public ZoomCursorGraphicLayer getZoomCursorGraphicLayer() {
146 149
		if(zoomCursorGraphic == null) {
147
			zoomCursorGraphic = new ZoomCursorGraphicLayer(w / 2, h / 2, 40, 20);
150
			zoomCursorGraphic = new ZoomCursorGraphicLayer(w / 2, h / 2, 20, 10, zoomCursorGraphicListener);
151
			zoomCursorGraphic.setCanvas(getZoomPixelControl().getCanvas());
148 152
			getZoomPixelControl().setGraphicLayer(zoomCursorGraphic);
149 153
		}
150 154
		return zoomCursorGraphic;
......
167 171
		getZoomCursorGraphicLayer().setCursorSize(w, h);
168 172
	}
169 173
	
174
	/**
175
	 * Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
176
	 * en referencia a las coordenadas del mundo. 
177
	 * @return
178
	 */
179
	public Rectangle2D getCursorWorldCoordinates() {
180
		Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
181
		Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY()));
182
		Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight()));
183
		return new Rectangle2D.Double(	Math.min(p1.getX(), p2.getX()), 
184
										Math.max(p1.getY(), p2.getY()), 
185
										Math.abs(p2.getX() - p1.getX()), 
186
										Math.abs(p2.getY() - p1.getY()));
187
	}
188
	
189
	/**
190
	 * Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
191
	 * en referencia a las coordenadas del mundo. Esta llamada ajusta el tama?o de la ventana a la 
192
	 * proporci?n pasada por par?metro. Es decir, si pasamos una proporci?n en la que el ancho es 3 veces 
193
	 * mayor que el alto se ajustar? el zoom a esta proporci?n ya que presupone que la ventana de
194
	 * destino del zoom va a tener esas proporciones.
195
	 * @return
196
	 */
197
	public Rectangle2D getCursorAdjustedWorldCoordinates(int wWindow, int hWindow) {
198
		Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
199

  
200
		double x = r.getX(), y = r.getY(), w = r.getWidth(), h = r.getHeight();
201
		if(r.getWidth() >= r.getHeight()) { //La X y la W no varian
202
			h = (hWindow * r.getWidth()) / wWindow;
203
			y = r.getCenterY() - (h / 2);
204
		} else { //La Y y la H no varian
205
			w = (wWindow * r.getHeight()) / hWindow;
206
			x = r.getCenterX() - (r.getWidth() / 2);
207
		}
208
		r = new Rectangle2D.Double(x, y, w, h);
209
		Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY()));
210
		Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight()));
211
		return new Rectangle2D.Double(	Math.min(p1.getX(), p2.getX()), 
212
										Math.max(p1.getY(), p2.getY()), 
213
										Math.abs(p2.getX() - p1.getX()), 
214
										Math.abs(p2.getY() - p1.getY()));
215
	}
216
	
170 217
	/*
171 218
	 * (non-Javadoc)
172 219
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/view/ZoomMapDialog.java
130 130
	 * @param pixelSize Tama?o de pixel
131 131
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
132 132
	 */
133
	public void setMapDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
133
	public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
134 134
		getZoomMapControl().setDrawParams(img, ext, pixelSize, center) ;
135 135
	}
136 136
	
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ToolEvent.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom;
20

  
21
import java.util.EventObject;
22

  
23
/**
24
 * Evento lanzado por las herramientas de la vista
25
 * 17/01/2008
26
 * @author Nacho Brodin nachobrodin@gmail.com
27
 */
28
public class ToolEvent  extends EventObject {
29
	private static final long serialVersionUID = 1L;
30
	
31
	/**
32
	 * Constructor
33
	 * @param source
34
	 */
35
	public ToolEvent(Object source) {
36
		super(source);
37
	}
38
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/BaseViewTool.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom;
20

  
21
import java.awt.Graphics;
22
import java.util.ArrayList;
23

  
24
/**
25
 * Clase base de la que deben extender las herramientas para la vista del 
26
 * zoom.
27
 * 
28
 * 17/01/2008
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public abstract class BaseViewTool {
32
	
33
	protected ArrayList        listeners   = new ArrayList();
34
	protected boolean          selectArea  = false;
35
	protected ToolListener     listener    = null;
36
	protected CanvasZone       canvas      = null;
37
	
38
	/**
39
	 * Constructor. Asigna el canvas y el listener para la tool.
40
	 * @param canvas
41
	 * @param listener
42
	 */
43
	public BaseViewTool(CanvasZone canvas, ToolListener listener) {
44
		this.canvas = canvas;
45
		this.listener = listener;
46
	}
47
	
48
	/**
49
	 * A?ade un listener para eventos de la tool
50
	 * @param listener
51
	 */
52
	public void addToolListener(ToolListener listener) {
53
		listeners.add(listener);
54
	}
55
			
56
	/**
57
	 * Asigna o desasigna como seleccionada la herramienta.
58
	 * @param selected
59
	 */
60
	public void setSelected(boolean selected) {
61
		this.selectArea = selected;
62
	}
63

  
64
	/**
65
	 * Parte gr?fica de una tool. Una tool puede dibujar sobre una vista
66
	 * @param img BufferedImage
67
	 * @param ext Rectangle2D
68
	 */
69
	public abstract void draw(Graphics g);
70
	
71
	/**
72
	 * Obtiene el resultado de la aplicaci?n de la herramienta
73
	 * @return Object
74
	 */
75
	public abstract Object getResult();
76
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ToolListener.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom;
20

  
21

  
22
/**
23
 * Listener para las herramientas de la vista
24
 * 
25
 * 17/01/2008
26
 * @author Nacho Brodin (nachobrodin@gmail.com)
27
 */
28
public interface ToolListener {
29
	/**
30
	 * Evento de finalizaci?n de las acciones de la tool
31
	 * @param ev ToolEvent
32
	 */
33
	public void endAction(ToolEvent ev);
34
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ZoomRectangleTool.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom;
20

  
21
import java.awt.Color;
22
import java.awt.Graphics;
23
import java.awt.event.MouseEvent;
24
import java.awt.event.MouseListener;
25
import java.awt.event.MouseMotionListener;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

  
29
/**
30
 * Herramienta de selecci?n de zoom sobre la vista.
31
 * 
32
 * 17/01/2008
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class ZoomRectangleTool extends BaseViewTool implements MouseListener, MouseMotionListener {
36
    private Point2D                  initPoint = null;
37
    private double                   x = 0, y = 0, w = 0, h = 0;
38
    private Rectangle2D              result = null;
39

  
40
	/**
41
	 * Constructor. Asigna el canvas e inicializa los listeners.
42
	 * @param canvas
43
	 */
44
	public ZoomRectangleTool(CanvasZone canvas, ToolListener listener) {
45
		super(canvas, listener);
46
		canvas.addMouseListener(this);
47
		canvas.addMouseMotionListener(this);
48
	}
49
	
50
	/*
51
	 * (non-Javadoc)
52
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#draw(java.awt.image.BufferedImage, java.awt.geom.Rectangle2D)
53
	 */
54
	public void draw(Graphics g) {
55
		if(initPoint == null || w == 0 || h == 0)
56
			return;
57
		g.setColor(Color.RED);
58
		g.drawRect((int)x, (int)y, (int)w, (int)h);
59
	}
60

  
61
	/*
62
	 * (non-Javadoc)
63
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#getResult()
64
	 */
65
	public Object getResult() {
66
		return result;
67
	}
68

  
69
	/**
70
	 * Selecciona el punto inicial del cuadro del que se quiere el zoom
71
	 */
72
	public void mousePressed(MouseEvent e) {
73
		if(selectArea) {
74
			initPoint = e.getPoint();
75
			result = null;
76
		}
77
	}
78
	
79
	/**
80
	 * Dibujado del cuadro con el ?rea a hacer zoom.
81
	 */
82
	public void mouseDragged(MouseEvent e) {
83
		if(selectArea) {
84
			x = initPoint.getX();
85
			y = initPoint.getY();
86
			w = Math.abs(e.getX() - x);
87
			h = Math.abs(e.getY() - y);
88
			if(e.getX() < x) 
89
				x = e.getX();
90
			if(e.getY() < y) 
91
				y = e.getY();
92
			Graphics g1 = canvas.getGraphics();
93
			g1.setColor(Color.RED);
94
			g1.drawRect((int)x,(int)y, (int)w, (int)h);
95
		}
96
	}
97

  
98
	/*
99
	 * (non-Javadoc)
100
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
101
	 */
102
	public void mouseReleased(MouseEvent e) {
103
		if(selectArea) {
104
			
105
			//Ajuste de la petici?n a la proporci?n del canvas. Esto se hace porque la relaci?n entre
106
			//el ancho y alto del canvas es distinta a la del cuadro que hemos pintado en pantalla.
107
			double centerX = x + (w / 2);
108
			double centerY = y + (h / 2);
109
			if(w >= h) { //La X y la W no varian
110
				h = (canvas.getHeight() * w) / canvas.getWidth();
111
				y = centerY - (h / 2);
112
			} else { //La Y y la H no varian
113
				w = (canvas.getWidth() * h) / canvas.getHeight();
114
				x = centerX - (w / 2);
115
			}
116
			
117
			Point2D pInit = canvas.viewCoordsToWorld(new Point2D.Double(x, y));
118
			Point2D pEnd = canvas.viewCoordsToWorld(new Point2D.Double(x + w, y + h));
119
			result = new Rectangle2D.Double(pInit.getX(), pEnd.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY()));
120
			initPoint = null;
121
			x = y = w = h = 0;
122
			listener.endAction(new ToolEvent(this));
123
		}
124
	}
125

  
126
	public void mouseClicked(MouseEvent e) {
127
	}
128

  
129
	public void mouseEntered(MouseEvent e) {
130
	}
131

  
132
	public void mouseExited(MouseEvent e) {
133
	}
134

  
135
	public void mouseMoved(MouseEvent e) {
136
	}
137
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/CanvasZone.java
32 32
import javax.swing.JPanel;
33 33

  
34 34
import org.gvsig.raster.util.MathUtils;
35
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.BaseViewTool;
35 36

  
36 37
/**
37 38
 * Zona de dibujado del raster
......
58 59
    private BaseViewTool           selectedTool = null;
59 60
    
60 61
    private Point2D                realCoord = new Point2D.Double(0, 0);
62
    private Point2D                viewCoord = new Point2D.Double(0, 0);
61 63
    private boolean                showInfo = false;
62 64
    		
63 65
    /**
......
213 215
	}
214 216
	
215 217
	/**
218
	 * Asigna el extent del canvas
219
	 * @param r
220
	 */
221
	public void setCanvasExtent(Rectangle2D r) {
222
		this.lastExtent = r;
223
	}
224
	
225
	/**
216 226
	 * Obtiene el tama?o de pixel
217 227
	 * @return double
218 228
	 */
......
273 283
	 */
274 284
	private void showInfo(Graphics g) {
275 285
		g.setColor(Color.RED);
276
		g.drawString("X: " + MathUtils.tailDecimals(realCoord.getX(), 3), 12, 10);
277
		g.drawString("Y: " + MathUtils.tailDecimals(realCoord.getY(), 3), 12, 24);
286
		g.drawString("X: " + MathUtils.tailDecimals(viewCoord.getX(), 3), 12, 10);
287
		g.drawString("Y: " + MathUtils.tailDecimals(viewCoord.getY(), 3), 12, 24);
288
		g.drawString("X': " + MathUtils.tailDecimals(realCoord.getX(), 3), 12, 38);
289
		g.drawString("Y': " + MathUtils.tailDecimals(realCoord.getY(), 3), 12, 52);
278 290
	}
279 291
	
280 292
	/**
......
417 429
	 */
418 430
	public void mouseMoved(MouseEvent e) {
419 431
		realCoord = viewCoordsToWorld((Point2D)e.getPoint());
432
		viewCoord = e.getPoint();
420 433
		for (int i = 0; i < graphicLayers.size(); i++) 
421 434
			((IGraphicLayer)graphicLayers.get(i)).mouseMoved(e);
422 435
		repaint();
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ViewControl.java
33 33
import javax.swing.JPanel;
34 34

  
35 35
import org.gvsig.raster.util.RasterToolsUtil;
36
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.BaseViewTool;
37
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolEvent;
38
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
39
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ZoomRectangleTool;
36 40

  
37 41
/**
38 42
 * <P>
......
446 450
			double width = 0, height = 0;
447 451
			canvas.setZoom(1);
448 452
			if(e.getSource() == bFullView) {
449
				extReq.fullExtent();
453
				try {
454
					extReq.fullExtent();
455
				} catch (InvalidRequestException e1) {
456
					RasterToolsUtil.messageBoxError("error_setview_preview", this);
457
				}
450 458
				return;
451 459
			}
452 460
			if(e.getSource() == bPrevZoom) {
453 461
				Object request = getZoomRecord().getRequest();
454 462
				if(request != null) {
455
					if(request instanceof Rectangle2D)
456
						extReq.request((Rectangle2D)request);
457
					if(request instanceof Integer && ((Integer)request).intValue() == FULL_VIEW)
458
						extReq.fullExtent();
463
					if(request instanceof Rectangle2D) {
464
						try {
465
							extReq.request((Rectangle2D)request);
466
						} catch (InvalidRequestException e1) {
467
							RasterToolsUtil.messageBoxError("error_setview_preview", this);
468
						}
469
					}
470
					if(request instanceof Integer && ((Integer)request).intValue() == FULL_VIEW) {
471
						try {
472
							extReq.fullExtent();
473
						} catch (InvalidRequestException e1) {
474
							RasterToolsUtil.messageBoxError("error_setview_preview", this);
475
						}
476
					}
459 477
					getZoomRecord().getRequest(); //El que hemos metido al hacer zoom previo no sirve por lo que hay que sacarlo
460 478
				}
461 479
				return;
......
476 494
			double x = canvas.getCenter().getX() - (width / 2);
477 495
			double y = canvas.getCenter().getY() - (height / 2);
478 496
			Rectangle2D request = new Rectangle2D.Double(x, y, width, height);
479
			extReq.request(request);
497
			try {
498
				extReq.request(request);
499
			} catch (InvalidRequestException e1) {
500
				RasterToolsUtil.messageBoxError("error_setview_preview", this);
501
			}
480 502
		}
481 503
	}
482 504
	
......
497 519
	}
498 520

  
499 521
	/**
500
	 * Evento de finalizaci?n de la tool que maneja el viewControl
522
	 * Evento de finalizaci?n de la tool que maneja el viewControl y de la capa con el 
523
	 * cursor gr?fico que controla el ?rea de la miniimagen asociada
501 524
	 */
502 525
	public void endAction(ToolEvent ev) {
503 526
		if(ev.getSource() instanceof ZoomRectangleTool) {
504 527
			Rectangle2D extent = (Rectangle2D)canvas.getSelectedTool().getResult();
505
			extReq.request(extent);
528
			try {
529
				extReq.request(extent);
530
			} catch (InvalidRequestException e1) {
531
				RasterToolsUtil.messageBoxError("error_setview_preview", this);
532
			}
506 533
			this.selectTool(null);
507 534
		}
508 535
	}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/IExtensionRequest.java
38 38
	 * @param Rectangle2D extent
39 39
	 * @return Extent aplicado
40 40
	 */
41
	public Rectangle2D request(Rectangle2D extent);
41
	public Rectangle2D request(Rectangle2D extent)throws InvalidRequestException;
42 42
	
43 43
	/**
44 44
	 * Extensi?n completa de la capa.
45 45
	 */
46
	public void fullExtent();
46
	public void fullExtent() throws InvalidRequestException ;
47 47
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/InvalidRequestException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom;
20

  
21
/**
22
 * Excepci?n que lanzan las peticiones de zoom que no pueden ser
23
 * satisfechas.
24
 * 
25
 * 21/01/2008
26
 * @author Nacho Brodin (nachobrodin@gmail.com)
27
 */
28
public class InvalidRequestException extends Exception {
29
	private static final long serialVersionUID = 337663732071639106L;
30

  
31
	public InvalidRequestException(String msg){
32
		super(msg);
33
	}
34
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ViewRasterRequestManager.java
30 30
import org.gvsig.raster.datastruct.Extent;
31 31
import org.gvsig.raster.datastruct.ViewPortData;
32 32
import org.gvsig.raster.util.RasterUtilities;
33
import org.gvsig.rastertools.georeferencing.view.ViewDialog;
33
import org.gvsig.rastertools.georeferencing.view.BaseZoomView;
34 34

  
35 35
/**
36 36
 * Gestor de peticiones de zoom sobre el panel con el raster a georreferenciar.
......
42 42
 */
43 43
public class ViewRasterRequestManager implements IExtensionRequest {
44 44
	private FLyrRasterSE     lyr = null;
45
	private ViewDialog        view = null;
45
	private BaseZoomView     view = null;
46 46
	
47 47
	/**
48 48
	 * Asigna la capa a georreferenciar de donde se obtienen los datos.
49 49
	 * @param lyr
50 50
	 */
51
	public ViewRasterRequestManager(ViewDialog view, FLyrRasterSE lyr) {
51
	public ViewRasterRequestManager(BaseZoomView view, FLyrRasterSE lyr) {
52 52
		this.lyr = lyr;
53 53
		this.view = view;
54 54
	}
......
59 59
	 * entre vista y petici?n
60 60
	 * @param Rectangle2D
61 61
	 */
62
	public Rectangle2D initRequest(Rectangle2D extent) {
62
	public Rectangle2D initRequest(Rectangle2D extent) throws InvalidRequestException {
63 63
		double x, y, w, h;
64 64
		//Calculamos la extensi?n de la vista para el extent m?ximo que va a contener
65 65
		//teniendo en cuenta las proporciones de ambos.
......
75 75
			y = extent.getCenterY() - (h / 2);
76 76
		}
77 77
		Rectangle2D r = new Rectangle2D.Double(x, y, w, h);
78
		view.getCanvas().setCanvasExtent(new Rectangle2D.Double(x, y + h, w, h));
78 79
		request(r);
79 80
		return r;
80 81
	}
......
83 84
	 * (non-Javadoc)
84 85
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#request(java.awt.geom.Rectangle2D)
85 86
	 */
86
	public Rectangle2D request(Rectangle2D extent) {
87
	public Rectangle2D request(Rectangle2D extent) throws InvalidRequestException {
87 88
		if(extent == null)
88 89
			return lyr.getFullExtent();
89 90
							
......
111 112
			else
112 113
				throw new InvalidSetViewException("Buffer de dibujado vacio");
113 114
		} catch (RasterDriverException e) {
115
			throw new InvalidRequestException("Error en al acceso al fichero");
114 116
		} catch (InvalidSetViewException e) {
117
			throw new InvalidRequestException("Error asignando el ?rea de la petici?n");
115 118
		} catch (InterruptedException e) {
116 119
		}
117 120
		return extent;
......
121 124
	 * (non-Javadoc)
122 125
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#fullExtent(java.awt.Dimension)
123 126
	 */
124
	public void fullExtent() {
127
	public void fullExtent() throws InvalidRequestException  {
125 128
		this.initRequest(lyr.getFullRasterExtent().toRectangle2D());
126 129
	}
127 130
			
......
133 136
	public void setDrawParams(BufferedImage img, Rectangle2D extBuf) {
134 137
		if(view != null && lyr != null) {
135 138
			if(img != null)
136
				view.setPixelDrawParams(img, extBuf, extBuf.getWidth()/img.getWidth(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY()));
139
				view.setDrawParams(img, extBuf, extBuf.getWidth()/img.getWidth(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY()));
137 140
		}
138 141
	}
139 142

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/layers/ZoomCursorGraphicLayer.java
19 19
package org.gvsig.rastertools.georeferencing.ui.zoom.layers;
20 20

  
21 21
import java.awt.Color;
22
import java.awt.Cursor;
22 23
import java.awt.Graphics2D;
24
import java.awt.Image;
25
import java.awt.Point;
26
import java.awt.Toolkit;
23 27
import java.awt.event.MouseEvent;
24 28
import java.awt.geom.Rectangle2D;
25 29

  
30
import javax.swing.ImageIcon;
31

  
32
import org.gvsig.rastertools.georeferencing.ui.zoom.CanvasZone;
26 33
import org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer;
34
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolEvent;
35
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
27 36

  
28 37
/**
29 38
 * Capa gr?fica que se dibuja sobre una vista de zoom un cursor
......
32 41
 * @author Nacho Brodin (nachobrodin@gmail.com)
33 42
 */
34 43
public class ZoomCursorGraphicLayer implements IGraphicLayer {
35
	private Color       color = Color.RED;
36
	private int         wCursor = 0;
37
	private int         hCursor = 0;
38
	private int         posX = 0;
39
	private int         posY = 0;
44
	//Operaciones sobre el cursor gr?fico
45
	private static final int    NONE = -1;
46
	private static final int    REDIM_LEFT = 0;
47
	private static final int    REDIM_RIGHT = 1;
48
	private static final int    REDIM_UP = 2;
49
	private static final int    REDIM_DOWN = 3;
50
	private static final int    MOVE_UR = 4;
51
	private static final int    MOVE_UL = 5;
52
	private static final int    MOVE_LR = 6;
53
	private static final int    MOVE_LL = 7;
54
	private int                 operation = NONE; 
40 55
	
56
	private Color               color = Color.RED;
57
	private int                 wCursor = 0;
58
	private int                 hCursor = 0;
59
	private int                 posX = 0;
60
	private int                 posY = 0;
61
	private Image               iconHoriz = null;
62
	private Image               iconVert = null;
63
	private Image               iconMove = null;
64
	private CanvasZone          canvas = null;
65
	//Memoria temporal de las posiciones en X y en Y previas a una operaci?n
66
	private int                 prevX, prevY;
67
	private ToolListener        listener = null;
68
	
41 69
	/**
42 70
	 * Constructor. Asigna el ancho y alto del rectangulo del cursor y la
43 71
	 * posici?n en la inicializaci?n.
44 72
	 */
45
	public ZoomCursorGraphicLayer(int pX, int pY, int w, int h) {
73
	public ZoomCursorGraphicLayer(int pX, int pY, int w, int h, ToolListener listener) {
46 74
		wCursor = w;
47 75
		hCursor = h;
48 76
		posX = pX;
49 77
		posY = pY;
78
		this.listener = listener;
79
		try {
80
			iconHoriz = new ImageIcon(getClass().getClassLoader().getResource("images/FlechaHorizCursor.gif")).getImage(); 
81
			iconVert = new ImageIcon(getClass().getClassLoader().getResource("images/FlechaVertCursor.gif")).getImage();
82
			iconMove = new ImageIcon(getClass().getClassLoader().getResource("images/FlechaMoveCursor.gif")).getImage();
83
		} catch (NullPointerException e) {
84
			
85
		}
50 86
	}
51 87
	
52 88
	/**
89
	 * Asigna el canvas
90
	 * @param canvas
91
	 */
92
	public void setCanvas(CanvasZone canvas) {
93
		this.canvas = canvas;
94
		canvas.addMouseMotionListener(this);
95
		canvas.addMouseListener(this);
96
	}
97
	
98
	/**
53 99
	 * Asigna la posici?n del cursor en el canvas
54 100
	 * @param x Posici?n en X
55 101
	 * @param y Posici?n en Y
......
69 115
		this.hCursor = h;
70 116
	}
71 117
	
118
	/**
119
	 * Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
120
	 * en referencia a la vista. 
121
	 * @return
122
	 */
123
	public Rectangle2D getCursorViewCoordinates() {
124
		return new Rectangle2D.Double(posX - (wCursor >> 1), posY - (hCursor >> 1), wCursor, hCursor);
125
	}
126
	 
72 127
	/*
73 128
	 * (non-Javadoc)
74 129
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer#draw(java.awt.Graphics2D, org.gvsig.raster.datastruct.Extent, int, int)
......
108 163
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
109 164
	 */
110 165
	public void mousePressed(MouseEvent e) {
111
	
166
		prevX = e.getX();
167
		prevY = e.getY();
112 168
	}
113 169

  
114 170
	/*
......
116 172
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
117 173
	 */
118 174
	public void mouseReleased(MouseEvent e) {
119
		
175
		if(getOperation() != NONE) {
176
			setOperation(NONE);
177
			if(listener != null)
178
				listener.endAction(new ToolEvent(this));
179
		}
120 180
	}
181
	
121 182

  
122
	/*
123
	 * (non-Javadoc)
124
	 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
183
	/**
184
	 * Cuando se pincha y se arrastra en los contornos se redimensiona el marco.
125 185
	 */
126 186
	public void mouseDragged(MouseEvent e) {
127
	
187
		if(getOperation() == MOVE_UR) {
188
			posX += (e.getX() - (wCursor >> 1)) - posX;
189
			posY += (e.getY() + (hCursor >> 1)) - posY;
190
			return;
191
		}
192
		if(getOperation() == MOVE_UL) {
193
			posX += (e.getX() + (wCursor >> 1)) - posX;
194
			posY += (e.getY() + (hCursor >> 1)) - posY;
195
			return;
196
		}
197
		if(getOperation() == MOVE_LR) {
198
			posX += (e.getX() - (wCursor >> 1)) - posX;
199
			posY += (e.getY() - (hCursor >> 1)) - posY;
200
			return;
201
		}
202
		if(getOperation() == MOVE_LL) {
203
			posX += (e.getX() + (wCursor >> 1)) - posX;
204
			posY += (e.getY() - (hCursor >> 1)) - posY;
205
			return;
206
		}
207
		if(getOperation() == REDIM_LEFT) {
208
			wCursor += prevX - e.getX();
209
			posX = e.getX() + (wCursor >> 1);
210
			prevX = e.getX();
211
			return;
212
		}
213
		if(getOperation() == REDIM_RIGHT) {
214
			int prevULX = posX - (wCursor >> 1);
215
			wCursor += e.getX() - prevX;
216
			posX = prevULX + (wCursor >> 1);
217
			prevX = e.getX();
218
			return;
219
		}
220
		if(getOperation() == REDIM_UP) {
221
			hCursor += prevY - e.getY();
222
			posY = e.getY() + (hCursor >> 1);
223
			prevY = e.getY();
224
			return;
225
		}
226
		if(getOperation() == REDIM_DOWN) {
227
			int prevULY = posY - (hCursor >> 1);
228
			hCursor += e.getY() - prevY;
229
			posY = prevULY + (hCursor >> 1);
230
			prevY = e.getY();
231
			return;
232
		}
128 233
	}
129 234

  
130 235
	/*
......
132 237
	 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
133 238
	 */
134 239
	public void mouseMoved(MouseEvent e) {
135

  
240
		int pxLeft = posX - (wCursor >> 1);
241
		int pxRight = posX + (wCursor >> 1);
242
		int pyUp = posY - (hCursor >> 1);
243
		int pyDown = posY + (hCursor >> 1);
244
		if(e.getX() >= (pxRight - 2) && e.getX() <= (pxRight + 2) && e.getY() >= (pyUp - 2) && e.getY() <= (pyUp + 2)) {
245
			if(iconMove != null)
246
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
247
			setOperation(MOVE_UR);
248
			return;
249
		}
250
		if(e.getX() >= (pxLeft - 2) && e.getX() <= (pxLeft + 2) && e.getY() >= (pyUp - 2) && e.getY() <= (pyUp + 2)) {
251
			if(iconMove != null)
252
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
253
			setOperation(MOVE_UL);
254
			return;
255
		}
256
		if(e.getX() >= (pxLeft - 2) && e.getX() <= (pxLeft + 2) && e.getY() >= (pyDown - 2) && e.getY() <= (pyDown + 2)) {
257
			if(iconMove != null)
258
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
259
			setOperation(MOVE_LL);
260
			return;
261
		}
262
		if(e.getX() >= (pxRight - 2) && e.getX() <= (pxRight + 2) && e.getY() >= (pyDown - 2) && e.getY() <= (pyDown + 2)) {
263
			if(iconMove != null)
264
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
265
			setOperation(MOVE_LR);
266
			return;
267
		}
268
		if(e.getX() >= (pxLeft - 1) && e.getX() <= (pxLeft + 1)) {
269
			if(iconHoriz != null)
270
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, new Point(16, 16), ""));
271
			setOperation(REDIM_LEFT);
272
			return;
273
		}
274
		if(e.getX() >= (pxRight - 1) && e.getX() <= (pxRight + 1)) {
275
			if(iconHoriz != null)
276
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, new Point(16, 16), ""));
277
			setOperation(REDIM_RIGHT);
278
			return;
279
		}
280
		if(e.getY() >= (pyUp - 1) && e.getY() <= (pyUp + 1)) {
281
			if(iconVert != null)
282
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconVert, new Point(16, 16), ""));
283
			setOperation(REDIM_UP);
284
			return;
285
		}
286
		if(e.getY() >= (pyDown - 1) && e.getY() <= (pyDown + 1)) {
287
			if(iconVert != null)
288
				canvas.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconVert, new Point(16, 16), ""));
289
			setOperation(REDIM_DOWN);
290
			return;
291
		}
292
		canvas.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
136 293
	}
294
	
295
	/**
296
	 * Obtiene la operaci?n sobre el cursor que hay seleccionada
297
	 * @return Entero que representa a la operaci?n
298
	 */
299
	private int getOperation() {
300
		return operation;
301
	}
302
	
303
	/**
304
	 * Asigna la operaci?n sobre el cursor que hay seleccionada
305
	 * @param op
306
	 */
307
	private void setOperation(int op) {
308
		operation = op;
309
	}
137 310

  
138 311
	/**
139 312
	 * Obtiene el color del cursor
......
151 324
		this.color = color;
152 325
	}
153 326
}
327

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/tools/ToolEvent.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom.tools;
20

  
21
import java.util.EventObject;
22

  
23
/**
24
 * Evento lanzado por las herramientas de la vista
25
 * 17/01/2008
26
 * @author Nacho Brodin nachobrodin@gmail.com
27
 */
28
public class ToolEvent  extends EventObject {
29
	private static final long serialVersionUID = 1L;
30
	
31
	/**
32
	 * Constructor
33
	 * @param source
34
	 */
35
	public ToolEvent(Object source) {
36
		super(source);
37
	}
38
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/tools/BaseViewTool.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom.tools;
20

  
21
import java.awt.Graphics;
22
import java.util.ArrayList;
23

  
24
import org.gvsig.rastertools.georeferencing.ui.zoom.CanvasZone;
25

  
26
/**
27
 * Clase base de la que deben extender las herramientas para la vista del 
28
 * zoom.
29
 * 
30
 * 17/01/2008
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public abstract class BaseViewTool {
34
	
35
	protected ArrayList        listeners   = new ArrayList();
36
	protected boolean          selectArea  = false;
37
	protected ToolListener     listener    = null;
38
	protected CanvasZone       canvas      = null;
39
	
40
	/**
41
	 * Constructor. Asigna el canvas y el listener para la tool.
42
	 * @param canvas
43
	 * @param listener
44
	 */
45
	public BaseViewTool(CanvasZone canvas, ToolListener listener) {
46
		this.canvas = canvas;
47
		this.listener = listener;
48
	}
49
	
50
	/**
51
	 * A?ade un listener para eventos de la tool
52
	 * @param listener
53
	 */
54
	public void addToolListener(ToolListener listener) {
55
		listeners.add(listener);
56
	}
57
			
58
	/**
59
	 * Asigna o desasigna como seleccionada la herramienta.
60
	 * @param selected
61
	 */
62
	public void setSelected(boolean selected) {
63
		this.selectArea = selected;
64
	}
65

  
66
	/**
67
	 * Parte gr?fica de una tool. Una tool puede dibujar sobre una vista
68
	 * @param img BufferedImage
69
	 * @param ext Rectangle2D
70
	 */
71
	public abstract void draw(Graphics g);
72
	
73
	/**
74
	 * Obtiene el resultado de la aplicaci?n de la herramienta
75
	 * @return Object
76
	 */
77
	public abstract Object getResult();
78
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/tools/ToolListener.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom.tools;
20

  
21

  
22
/**
23
 * Listener para las herramientas de la vista
24
 * 
25
 * 17/01/2008
26
 * @author Nacho Brodin (nachobrodin@gmail.com)
27
 */
28
public interface ToolListener {
29
	/**
30
	 * Evento de finalizaci?n de las acciones de la tool
31
	 * @param ev ToolEvent
32
	 */
33
	public void endAction(ToolEvent ev);
34
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/tools/ZoomRectangleTool.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.rastertools.georeferencing.ui.zoom.tools;
20

  
21
import java.awt.Color;
22
import java.awt.Graphics;
23
import java.awt.event.MouseEvent;
24
import java.awt.event.MouseListener;
25
import java.awt.event.MouseMotionListener;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

  
29
import org.gvsig.rastertools.georeferencing.ui.zoom.CanvasZone;
30

  
31
/**
32
 * Herramienta de selecci?n de zoom sobre la vista.
33
 * 
34
 * 17/01/2008
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 */
37
public class ZoomRectangleTool extends BaseViewTool implements MouseListener, MouseMotionListener {
38
    private Point2D                  initPoint = null;
39
    private double                   x = 0, y = 0, w = 0, h = 0;
40
    private Rectangle2D              result = null;
41

  
42

  
43
	/**
44
	 * Constructor. Asigna el canvas e inicializa los listeners.
45
	 * @param canvas
46
	 */
47
	public ZoomRectangleTool(CanvasZone canvas, ToolListener listener) {
48
		super(canvas, listener);
49
		canvas.addMouseListener(this);
50
		canvas.addMouseMotionListener(this);
51
	}
52
	
53
	/*
54
	 * (non-Javadoc)
55
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#draw(java.awt.image.BufferedImage, java.awt.geom.Rectangle2D)
56
	 */
57
	public void draw(Graphics g) {
58
		if(initPoint == null || w == 0 || h == 0)
59
			return;
60
		g.setColor(Color.RED);
61
		g.drawRect((int)x, (int)y, (int)w, (int)h);
62
	}
63

  
64
	/*
65
	 * (non-Javadoc)
66
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#getResult()
67
	 */
68
	public Object getResult() {
69
		return result;
70
	}
71

  
72
	/**
73
	 * Selecciona el punto inicial del cuadro del que se quiere el zoom
74
	 */
75
	public void mousePressed(MouseEvent e) {
76
		if(selectArea) {
77
			initPoint = e.getPoint();
78
			result = null;
79
		}
80
	}
81
	
82
	/**
83
	 * Dibujado del cuadro con el ?rea a hacer zoom.
84
	 */
85
	public void mouseDragged(MouseEvent e) {
86
		if(selectArea) {
87
			x = initPoint.getX();
88
			y = initPoint.getY();
89
			w = Math.abs(e.getX() - x);
90
			h = Math.abs(e.getY() - y);
91
			if(e.getX() < x) 
92
				x = e.getX();
93
			if(e.getY() < y) 
94
				y = e.getY();
95
			Graphics g1 = canvas.getGraphics();
96
			g1.setColor(Color.RED);
97
			g1.drawRect((int)x,(int)y, (int)w, (int)h);
98
		}
99
	}
100

  
101
	/*
102
	 * (non-Javadoc)
103
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
104
	 */
105
	public void mouseReleased(MouseEvent e) {
106
		if(selectArea) {
107
			
108
			//Ajuste de la petici?n a la proporci?n del canvas. Esto se hace porque la relaci?n entre
109
			//el ancho y alto del canvas es distinta a la del cuadro que hemos pintado en pantalla.
110
			double centerX = x + (w / 2);
111
			double centerY = y + (h / 2);
112
			if(w >= h) { //La X y la W no varian
113
				h = (canvas.getHeight() * w) / canvas.getWidth();
114
				y = centerY - (h / 2);
115
			} else { //La Y y la H no varian
116
				w = (canvas.getWidth() * h) / canvas.getHeight();
117
				x = centerX - (w / 2);
118
			}
119
			
120
			Point2D pInit = canvas.viewCoordsToWorld(new Point2D.Double(x, y));
121
			Point2D pEnd = canvas.viewCoordsToWorld(new Point2D.Double(x + w, y + h));
122
			result = new Rectangle2D.Double(pInit.getX(), pEnd.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY()));
123
			initPoint = null;
124
			x = y = w = h = 0;
125
			listener.endAction(new ToolEvent(this));
126
		}
127
	}
128

  
129
	public void mouseClicked(MouseEvent e) {
130
	}
131

  
132
	public void mouseEntered(MouseEvent e) {
133
	}
134

  
135
	public void mouseExited(MouseEvent e) {
136
	}
137

  
138
	public void mouseMoved(MouseEvent e) {			
139
	}
140
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/Georeferencing.java
30 30
import org.gvsig.raster.util.RasterToolsUtil;
31 31
import org.gvsig.rastertools.georeferencing.ui.launcher.GeorefLauncherDialog;
32 32
import org.gvsig.rastertools.georeferencing.ui.table.GCPTablePanel;
33
import org.gvsig.rastertools.georeferencing.ui.zoom.InvalidRequestException;
33 34
import org.gvsig.rastertools.georeferencing.ui.zoom.ViewRasterRequestManager;
35
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer;
36
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolEvent;
37
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
34 38
import org.gvsig.rastertools.georeferencing.view.ViewDialog;
35 39
import org.gvsig.rastertools.georeferencing.view.ZoomMapDialog;
36 40
import org.gvsig.rastertools.georeferencing.view.ZoomRasterDialog;
......
58 62
 * 26/12/2007
59 63
 * @author Nacho Brodin (nachobrodin@gmail.com)
60 64
 */
61
public class Georeferencing implements ButtonsPanelListener {
62
	public static final int               UNDEFINED = -1;
65
public class Georeferencing implements ButtonsPanelListener, ToolListener {
66
	public static final int               UNDEFINED                      = -1;
63 67
	//Algoritmo
64
	public static final int               POLYNOMIAL = 0;
65
	public static final int               AFFINE = 1;
68
	public static final int               POLYNOMIAL                     = 0;
69
	public static final int               AFFINE                         = 1;
66 70
	
67 71
	//Tipo de georreferenciacion
68
	public static final int               WITH_MAP = 0;
69
	public static final int               WITHOUT_MAP = 1;
72
	public static final int               WITH_MAP                       = 0;
73
	public static final int               WITHOUT_MAP                    = 1;
70 74
	
71
	private static int                    DEFAULT_DEGREE = 3;
75
	private static int                    DEFAULT_DEGREE                 = 3;
72 76
	
73
	private GeorefLauncherDialog          initDialog = null;
74
	private FLyrRasterSE                  lyrToGeoref = null;
75
	private static GCPTablePanel          table = null;
76
	private static ZoomMapDialog          zoomMap = null;
77
	private static ZoomRasterDialog       zoomPixel = null;
78
	private static ViewDialog              view = null;
79
	private static final int              smallWindowsHeight = 100;
80
	private static final double           smallWindowsWidthPercent = 0.5;
81
	private ViewRasterRequestManager      viewRequestManager = null;
77
	private GeorefLauncherDialog          initDialog                     = null;
78
	private FLyrRasterSE                  lyrToGeoref                    = null;
79
	private static GCPTablePanel          table                          = null;
80
	private static ZoomMapDialog          zoomMap                        = null;
81
	private static ZoomRasterDialog       zoomPixel                      = null;
82
	private static ViewDialog             view                           = null;
83
	private static final int              smallWindowsHeight             = 100;
84
	private static final double           smallWindowsWidthPercent       = 0.5;
85
	private ViewRasterRequestManager      viewRequestManager             = null;
86
	private ViewRasterRequestManager      viewRequestManagerZoomPixel    = null;
82 87
	
83 88
	public Georeferencing() {
84 89
		
......
123 128
		if(table != null)
124 129
			PluginServices.getMDIManager().closeWindow(table);
125 130
		
126
		zoomMap = new ZoomMapDialog(0, posYViews, smallWindowsWidth, smallWindowsHeight);
127 131
		table = new GCPTablePanel(smallWindowsWidth, posYViews, tableWidth, smallWindowsHeight);
128
		zoomPixel = new ZoomRasterDialog(smallWindowsWidth + tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
129 132
		
130
		view = new ViewDialog(wViews, 0, wViews, hViews);
133
		//Inicializaci?n de la vista raster
134
		view = new ViewDialog(wViews, 0, wViews, hViews, this);
131 135
		view.setShowInfo(true);
132
		//Gestor de peticiones a la capa (IExtensionRequest)
133
		ViewRasterRequestManager viewRequestManager = new ViewRasterRequestManager(view, lyrToGeoref);
134
		//Asignamos al componente cual ser? su gestor de peticiones. Cada vez que se pulse un zoom el componente har? 
135
		//una llamada request a su gestor de peticiones
136
		viewRequestManager = new ViewRasterRequestManager(view, lyrToGeoref);
136 137
		view.setExtensionRequest(viewRequestManager);
137 138
		
139
		//Inicializaci?n del zoom de la vista raster
140
		zoomPixel = new ZoomRasterDialog(smallWindowsWidth + tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
141
		viewRequestManagerZoomPixel = new ViewRasterRequestManager(zoomPixel, lyrToGeoref);
142
		zoomPixel.setExtensionRequest(viewRequestManagerZoomPixel);
143
		
144
		//Inicializaci?n del zoom de la vista de referencia
145
		zoomMap = new ZoomMapDialog(0, posYViews, smallWindowsWidth, smallWindowsHeight);
146
		
138 147
		/*GeoPoint gp = new GeoPoint(new Point2D.Double(100, 100), null);
139 148
		GPGraphic gpg = new GPGraphic(GPGraphic.PIXEL, gp);
140 149
		view.getPixelGraphicLayer().addGeoPoint(gpg);*/
......
145 154
		if(imgRasterToGeoref != null)
146 155
			setPixelParams(imgRasterToGeoref, lyrToGeoref);
147 156
		*/
157
		//A?adimos las ventanas a gvSIG
148 158
		PluginServices.getMDIManager().addWindow(view);
149 159
		PluginServices.getMDIManager().addWindow(table);
150 160
		PluginServices.getMDIManager().addWindow(zoomMap);
151 161
		PluginServices.getMDIManager().addWindow(zoomPixel);
152 162
		
153 163
		//Inicializamos la extensi?n del componente y dibujamos
154
		viewRequestManager.initRequest(lyrToGeoref.getFullExtent());
155
		view.setZoomCursorSize(zoomPixel.getCanvasWidth(), zoomPixel.getCanvasHeight());
164
		try {
165
			viewRequestManager.initRequest(lyrToGeoref.getFullExtent());
166
			view.setZoomCursorSize(zoomPixel.getCanvasWidth() / 3, zoomPixel.getCanvasHeight() / 3);
167
			
168
			Rectangle2D ext = view.getCursorWorldCoordinates();
169
			viewRequestManagerZoomPixel.request(ext);
170
		} catch (InvalidRequestException e1) {
171
			RasterToolsUtil.messageBoxError("error_setview_preview", this);
172
		}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff