Revision 17727

View differences:

trunk/extensions/extRasterTools-SE/config/config.xml
31 31
					action-command="PIXELINCREASE"  
32 32
					tooltip="pixel_increase"/>	
33 33
			</tool-bar>
34
			<tool-bar name="com.iver.cit.gvsig.raster">
35
				<action-tool 
36
					icon="geolocalization-icon" 
37
					action-command="GEOREFERENCING"  
38
					tooltip="georeferencing"/>	
39
			</tool-bar>
34 40
		</extension>
35 41
	</extensions>
36 42
</plugin-config>
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/view/ViewPanel.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.view;
20

  
21
import javax.swing.JPanel;
22

  
23
import com.iver.andami.PluginServices;
24
import com.iver.andami.ui.mdiManager.IWindow;
25
import com.iver.andami.ui.mdiManager.WindowInfo;
26

  
27
/**
28
 * Panel que contiene la tabla de puntos de control
29
 * 
30
 * 22/12/2007
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public class ViewPanel extends JPanel implements IWindow {
34
	private static final long         serialVersionUID = 1L;
35
	
36
	private int                       w = 640;
37
	private int                       h = 100;
38
	private int                       posX = 0;
39
	private int                       posY = 0;
40
	
41
	/**
42
	 * Constructor.
43
	 * Crea la composici?n de controles de zoom.
44
	 */
45
	public ViewPanel(int posX, int posY, int w, int h) {
46
		setPosition(posX, posY);
47
		setWindowsSize(w, h);
48
		init();
49
	}
50
	
51
	/**
52
	 * Asigna la posici?n de la ventana
53
	 * @param posX Posici?n en X
54
	 * @param posY Posici?n en Y
55
	 */
56
	public void setPosition(int posX, int posY) {
57
		this.posX = posX;
58
		this.posY = posY;
59
	}
60
	
61
	/**
62
	 * Asigna la posici?n de la ventana
63
	 * @param posX Posici?n en X
64
	 * @param posY Posici?n en Y
65
	 */
66
	public void setWindowsSize(int w, int h) {
67
		this.w = w;
68
		this.h = h;
69
	}
70
	
71
	/**
72
	 * Inicializaci?n de los componentes gr?ficos
73
	 */
74
	private void init() {
75
	
76
	}
77
	
78
	/*
79
	 * (non-Javadoc)
80
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
81
	 */
82
	public WindowInfo getWindowInfo() {
83
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
84
		//if (getClippingPanel().getFLayer() != null)
85
			//m_viewinfo.setAdditionalInfo(getClippingPanel().getFLayer().getName());
86
		m_viewinfo.setTitle(PluginServices.getText(this, "points_panel"));
87
		m_viewinfo.setX(posX);
88
		m_viewinfo.setY(posY);
89
		m_viewinfo.setHeight(h);
90
		m_viewinfo.setWidth(w);
91
		return m_viewinfo;
92
	}
93
}
94

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/GeoPointsPersistence.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;
20

  
21

  
22
/**
23
 * Operaciones de lectura y escritura en disco de puntos de control.
24
 * 
25
 * 26/12/2007
26
 * @author Nacho Brodin nachobrodin@gmail.com
27
 */
28
public class GeoPointsPersistence {
29
	/**
30
	 * Funci?n que se ejecuta al pulsar el bot?n de export a ascii
31
	 */
32
	public static void exportToCSV()throws Exception{
33
		
34
	}
35

  
36
	/**
37
	 * Funci?n que se ejecuta al pulsar el bot?n de importar desde CSV
38
	 */
39
	public static void importFromCSV()throws Exception{
40
		
41
	}
42
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/CanvasZone.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.Graphics2D;
24
import java.awt.event.MouseEvent;
25
import java.awt.event.MouseListener;
26
import java.awt.event.MouseMotionListener;
27
import java.awt.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
29
import java.awt.image.BufferedImage;
30
import java.util.ArrayList;
31

  
32
import javax.swing.JPanel;
33

  
34
/**
35
 * Zona de dibujado del raster
36
 * 21/12/2007
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class CanvasZone extends JPanel implements MouseListener, MouseMotionListener {
40
	private static final long      serialVersionUID = 1308683333757367640L;
41
	
42
	private BufferedImage          image = null;
43
	private double                 scale = 1;
44
	private Rectangle2D            extent = null;
45
	private double                 pixelSize = 1;
46
	private Point2D                center = null;
47
	private ArrayList              graphicLayers = new ArrayList();
48
	/**
49
	 * ?ltimo extent aplicado. Si no ha variado el siguiente a aplicar no hace falta que releamos de nuevo
50
	 */
51
	private Rectangle2D            lastExtent = null;
52
	private BufferedImage          lastImage = null;
53
    
54
    private boolean                clear = false;
55
    private Color                  background = Color.WHITE;
56
		
57
    /**
58
	 * Asigna los par?metros de dibujado
59
	 * @param img Buffer con un ?rea de datos
60
	 * @param ext Rectangle2D del ?rea de datos dada 
61
	 * @param pixelSize Tama?o de pixel
62
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
63
	 */
64
	public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
65
		this.image = img;
66
		this.extent = ext;
67
		this.pixelSize = pixelSize;
68
		this.center = center;
69
		this.addMouseListener(this);
70
		this.addMouseMotionListener(this);
71
		repaint();
72
	}
73
	
74
	/**
75
	 * Asigna un nuevo centro de visualizaci?n
76
	 * @param center
77
	 */
78
	public void setCenter(Point2D center) {
79
		this.center = center;
80
		repaint();
81
	}
82
	
83
	/**
84
	 * Asigna un nuevo centro de visualizaci?n en coordenadas pixel
85
	 * del ?rea de dibujado (canvas). El nuevo centro ser? calculado en coordenadas
86
	 * del mapa.
87
	 * @param center
88
	 */
89
	public void setPixelCenter(Point2D c) {
90
		int w = getVisibleRect().width;
91
		int h = getVisibleRect().height;
92
		
93
		//Calculamos el extent del canvas 
94
		Rectangle2D ext = getCanvasExtent(w, h, scale);
95
		
96
		//Calculamos el nuevo centro en coordenadas reales
97
		double wWC = (c.getX() / scale) * pixelSize;
98
		double hWC = (c.getY() / scale) * pixelSize;
99
		this.center = new Point2D.Double(ext.getMinX() + wWC,
100
										 ext.getMinY() - hWC);
101
		repaint();
102
	}
103
	
104
	/**
105
	 * Asigna un nuevo centro de visualizaci?n en coordenadas pixel. Esta llamada tiene
106
	 * en cuenta solo p?xeles completos. No centra sobre porciones de pixel cuando el zoom es
107
	 * mayor de 1:1. El nuevo centro es en coordenadas del mapa pero siempre centrar?
108
	 * en la esquina inferior izquierda del pixel.
109
	 * @param center
110
	 */
111
	public void setPixelCenter(int x, int y) {
112
		int w = getVisibleRect().width;
113
		int h = getVisibleRect().height;
114
		
115
		//Calculamos el extent del canvas 
116
		Rectangle2D ext = getCanvasExtent(w, h, scale);
117
		
118
		//Calculamos el nuevo centro en coordenadas reales
119
		double wWC = (x / scale) * pixelSize;
120
		double hWC = (y / scale) * pixelSize;
121
		Point2D center = new Point2D.Double(ext.getMinX() + wWC,
122
				 						 	ext.getMinY() - hWC);
123
		
124
		//Calculamos la coordena pixel a la que pertenece esa coordenada real
125
		int pxX = (int)((center.getX() * (w / scale)) / ext.getWidth());
126
		int pxY = (int)((center.getY() * (h / scale)) / ext.getHeight());
127
		
128
		//Despu?s de haber convertido a pixel y redondeado la coordenada a entero volvemos a convertirla en real
129
		double wcX = (pxX * ext.getWidth()) / (w / scale);
130
		double wcY = (pxY * ext.getHeight()) / (h / scale);
131

  
132
		this.center = new Point2D.Double(wcX, wcY);
133
		repaint();
134
	}
135
	
136
	/**
137
	 * Asigna una capa gr?fica
138
	 * @param layer IGraphicLayer
139
	 */
140
	public void setGraphicLayer(IGraphicLayer layer) {
141
		graphicLayers.add(layer);
142
	}
143
	
144
	/**
145
	 * Asigna la escala para el nuevo zoom
146
	 * @param scale
147
	 */
148
	public void setZoom(double scale) {
149
		this.scale = scale;
150
		repaint();
151
	}
152
	
153
	/**
154
	 * Obtiene la escala aplicada en el dibujado
155
	 * @return double
156
	 */
157
	public double getZoom() {
158
		return scale;
159
	}
160
	
161
	/**
162
	 * Obtiene el buffer de la vista activa y lo dibuja sobre el panel
163
	 * con los datos de escala y desplazamiento seleccionados.
164
	 */
165
	protected void paintComponent(Graphics g) {
166
		if(image == null)
167
			return;
168
		int w = getVisibleRect().width;
169
		int h = getVisibleRect().height;
170
		Rectangle2D ext = getCanvasExtent(w, h, scale);
171
		
172
		if(lastImage == null || !equal(lastExtent, ext)) 
173
			lastImage = new BufferedImage((int)w, (int)h, BufferedImage.TYPE_INT_RGB);
174
		
175
		if(clear) {
176
			g.setColor(Color.WHITE);
177
			g.fillRect(0, 0, w, h);
178
			return;
179
		}
180

  
181
		//Dibujamos el buffer sobre el grafics
182
		draw((Graphics2D)g, ext, w, h);	
183
		
184
		//Dibujamos todas las capas registradas
185
		for (int i = 0; i < graphicLayers.size(); i++) 
186
			((IGraphicLayer)graphicLayers.get(i)).draw((Graphics2D)g, ext, w, h);
187
		
188
		lastExtent = ext;
189
		g.dispose();
190
	}
191
	
192
	/**
193
	 * Compara dos extents y devuelve true si son iguales y false si son distintos
194
	 * @param e1 Extent 1
195
	 * @param e2 Extent 2
196
	 * @return true si son iguales y false si son diferentes
197
	 */
198
	private boolean equal(Rectangle2D e1, Rectangle2D e2) {
199
		return (e1 != null && e2 != null && e1.getMinX() == e2.getMinX() && e1.getMinY() == e2.getMinY() 
200
				&& e1.getMaxX() == e2.getMaxX() && e1.getMaxY() == e2.getMaxY());
201
	}
202
	
203
	/**
204
	 * Obtiene el Extent del canvas. Este canvas tiene un ancho en pixeles
205
	 * de w y un alto de h. Tiene en cuenta la escala a la que se quiere dibujar
206
	 * para devolver el extent cuando el zoom ya est? aplicado.
207
	 * @param w Ancho del canvas en p?xeles
208
	 * @param h Alto del canvas en p?xeles
209
	 * @return Rectangle2D
210
	 */
211
	private Rectangle2D getCanvasExtent(double w, double h, double scale) {
212
		double tW = ((w / scale) / 2) * pixelSize;
213
		double tH = ((h / scale) / 2) * pixelSize;
214
		double minX = center.getX() - tW;
215
		double maxY = center.getY() + tH;
216
		double width = Math.abs((center.getX() + tW) - minX);
217
		double height = Math.abs(maxY - (center.getY() - tH));
218
		return new Rectangle2D.Double(minX, maxY, width, height);
219
	}
220
	
221
	/**
222
	 * <P>
223
	 * Dibujado del buffer de datos sobre el Graphics. 
224
	 * </P><P>
225
	 * No podemos aplicar un escalado al
226
	 * Graphics y dibujar porque cuando el zoom es mayor a 1 los pixeles no empiezan a dibujarse
227
	 * siempre en la esquina superior izquierda y al Graphics solo podemos ordenarle el dibujado
228
	 * en coordenadas enteras. Para solucionarlo debemos copiar el trozo de buffer a dibujar teniendo
229
	 * en cuenta el desplazamiento de la esquina superior izquierda de un pixel.
230
	 * </P> 
231
	 * @param g
232
	 * @param ext
233
	 * @param w
234
	 * @param h
235
	 */
236
	private void draw(Graphics2D g, Rectangle2D ext, double w, double h) {
237
		if(!equal(lastExtent, ext)) {
238
			//Hallamos la coordenada pixel del buffer de la esquina superior izquierda del extent
239
			double pxX = ((ext.getMinX() - extent.getMinX()) * (w/scale)) / ext.getWidth();
240
			double pxY = ((extent.getMaxY() - ext.getMinY()) * (h/scale)) / ext.getHeight();
241

  
242
			//Creamos el buffer y lo cargamos teniendo en cuenta el desplazamiento inicial
243
			double step = 1 / scale;
244

  
245
			double xValue = pxX;
246
			double yValue = pxY;
247

  
248
			for (int i = 0; i < w; i++) {
249
				yValue = pxY;
250
				for (int j = 0; j < h; j++) {
251
					if((int)xValue >= 0 && (int)yValue >= 0 && (int)xValue < image.getWidth() && (int)yValue < image.getHeight())
252
						lastImage.setRGB(i, j, image.getRGB((int)xValue, (int)yValue));
253
					else
254
						lastImage.setRGB(i, j, 0xffffffff);
255
					yValue += step;
256
				}
257
				xValue += step;
258
			}
259
		}
260
		//Ahora ya podemos ordenar el dibujado con coordenadas enteras
261
		g.setColor(background);
262
		g.fillRect(0, 0, (int)w, (int)h);
263
		g.drawImage(lastImage, 0, 0, this);
264
	}
265

  
266
	/*
267
	 * (non-Javadoc)
268
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
269
	 */
270
	public void mouseClicked(MouseEvent e) {
271
		for (int i = 0; i < graphicLayers.size(); i++) 
272
			((IGraphicLayer)graphicLayers.get(i)).mouseClicked(e);
273
		repaint();
274
	}
275

  
276
	/*
277
	 * (non-Javadoc)
278
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
279
	 */
280
	public void mouseEntered(MouseEvent e) {
281
		for (int i = 0; i < graphicLayers.size(); i++) 
282
			((IGraphicLayer)graphicLayers.get(i)).mouseEntered(e);
283
		repaint();
284
	}
285

  
286
	/*
287
	 * (non-Javadoc)
288
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
289
	 */
290
	public void mouseExited(MouseEvent e) {
291
		for (int i = 0; i < graphicLayers.size(); i++) 
292
			((IGraphicLayer)graphicLayers.get(i)).mouseExited(e);
293
		repaint();
294
	}
295

  
296
	/*
297
	 * (non-Javadoc)
298
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
299
	 */
300
	public void mousePressed(MouseEvent e) {
301
		for (int i = 0; i < graphicLayers.size(); i++) 
302
			((IGraphicLayer)graphicLayers.get(i)).mousePressed(e);
303
		repaint();
304
	}
305

  
306
	/*
307
	 * (non-Javadoc)
308
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
309
	 */
310
	public void mouseReleased(MouseEvent e) {
311
		for (int i = 0; i < graphicLayers.size(); i++) 
312
			((IGraphicLayer)graphicLayers.get(i)).mouseReleased(e);
313
		repaint();
314
	}
315

  
316
	/*
317
	 * (non-Javadoc)
318
	 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
319
	 */
320
	public void mouseDragged(MouseEvent e) {
321
		for (int i = 0; i < graphicLayers.size(); i++) 
322
			((IGraphicLayer)graphicLayers.get(i)).mouseDragged(e);
323
		repaint();
324
	}
325

  
326
	/*
327
	 * (non-Javadoc)
328
	 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
329
	 */
330
	public void mouseMoved(MouseEvent e) {
331
		for (int i = 0; i < graphicLayers.size(); i++) 
332
			((IGraphicLayer)graphicLayers.get(i)).mouseMoved(e);
333
		repaint();
334
	}
335
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ControlsPanel.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.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.awt.geom.Point2D;
24
import java.awt.geom.Rectangle2D;
25
import java.awt.image.BufferedImage;
26

  
27
import javax.swing.JPanel;
28

  
29
import com.iver.andami.PluginServices;
30
import com.iver.andami.ui.mdiManager.IWindow;
31
import com.iver.andami.ui.mdiManager.WindowInfo;
32

  
33
/**
34
 * Panel que contiene los controles de zoom para el mapa
35
 * y para el raster a georreferenciar.
36
 * 
37
 * 22/12/2007
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class ControlsPanel extends JPanel implements IWindow {
41
	private static final long         serialVersionUID = 1L;
42
	private ZoomControl               zoomMapControl = null;
43
	private ZoomControl               zoomPixelControl = null;
44
	private CenterPointGraphicLayer   mapGraphicLayer = null;
45
	private CenterPointGraphicLayer   pixelGraphicLayer = null;
46
	
47
	private int                       w = 640;
48
	private int                       h = 100; 
49
	private int                       posX = 0;
50
	private int                       posY = 0;
51
	
52
	/**
53
	 * Constructor.
54
	 * Crea la composici?n de controles de zoom.
55
	 */
56
	public ControlsPanel(int posX, int posY, int w, int h) {
57
		setPosition(posX, posY);
58
		setWindowsSize(w, h);
59
		init();
60
	}
61
	
62
	/**
63
	 * Asigna la posici?n de la ventana
64
	 * @param posX Posici?n en X
65
	 * @param posY Posici?n en Y
66
	 */
67
	public void setPosition(int posX, int posY) {
68
		this.posX = posX;
69
		this.posY = posY;
70
	}
71
	
72
	/**
73
	 * Asigna la posici?n de la ventana
74
	 * @param posX Posici?n en X
75
	 * @param posY Posici?n en Y
76
	 */
77
	public void setWindowsSize(int w, int h) {
78
		this.w = w;
79
		this.h = h;
80
	}
81
	
82
	/**
83
	 * Inicializaci?n de los componentes gr?ficos
84
	 */
85
	private void init() {
86
		setLayout(new GridBagLayout());
87
		setPreferredSize(new java.awt.Dimension(w, h)); 
88
		
89
		GridBagConstraints gb = new GridBagConstraints();
90
		gb.insets = new java.awt.Insets(0, 0, 0, 0);
91
		gb.gridy = 0;
92
		gb.gridx = 0;
93
		gb.weightx = 1D; //El espacio sobrante se distribuye horizontalmente
94
		gb.weighty = 1D; //El espacio sobrante se distribuye verticalmente
95
		gb.fill = GridBagConstraints.BOTH; //El componente se hace tan ancho como espacio disponible tiene
96
		gb.anchor = GridBagConstraints.NORTH; //Alineamos las cajas arriba
97
		add(getZoomMapControl(), gb);
98
		
99
		gb.gridx = 1;
100
		add(getZoomPixelControl(), gb);
101
	}
102
	
103
	/**
104
	 * Obtiene el panel de control de zoom de coordenadas de mapa
105
	 * @return
106
	 */
107
	public ZoomControl getZoomMapControl() {
108
		if(zoomMapControl == null)
109
			zoomMapControl = new ZoomControl(ZoomControl.RIGHT_CONTROL);
110
		return zoomMapControl;
111
	}
112

  
113
	/**
114
	 * Obtiene el panel de control de zoom de coordenadas pixel
115
	 * @return
116
	 */
117
	public ZoomControl getZoomPixelControl() {
118
		if(zoomPixelControl == null)
119
			zoomPixelControl = new ZoomControl(ZoomControl.LEFT_CONTROL);
120
		return zoomPixelControl;
121
	}
122
	
123
	/**
124
	 * Obtiene el panel de control de zoom de coordenadas de mapa
125
	 * @return
126
	 */
127
	public CenterPointGraphicLayer getMapGraphicLayer() {
128
		if(mapGraphicLayer == null) {
129
			mapGraphicLayer = new CenterPointGraphicLayer(GPGraphic.MAP, getZoomMapControl());
130
			mapGraphicLayer.setShowNumber(false);
131
			mapGraphicLayer.setShowLabel(false);
132
			getZoomMapControl().setGraphicLayer(mapGraphicLayer);
133
		}
134
		return mapGraphicLayer;
135
	}
136

  
137
	/**
138
	 * Obtiene el panel de control de zoom de coordenadas pixel
139
	 * @return
140
	 */
141
	public CenterPointGraphicLayer getPixelGraphicLayer() {
142
		if(pixelGraphicLayer == null)
143
			pixelGraphicLayer = new CenterPointGraphicLayer(GPGraphic.PIXEL, getZoomPixelControl());
144
		return pixelGraphicLayer;
145
	}
146
	
147
	/**
148
	 * Asigna los par?metros de dibujado para el mapa
149
	 * @param img Buffer con un ?rea de datos
150
	 * @param ext Rectangle2D del ?rea de datos dada 
151
	 * @param pixelSize Tama?o de pixel
152
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
153
	 */
154
	public void setMapDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
155
		getZoomMapControl().setDrawParams(img, ext, pixelSize, center) ;
156
	}
157
	
158
	/**
159
	 * Asigna los par?metros de dibujado para el raster
160
	 * @param img Buffer con un ?rea de datos
161
	 * @param ext Rectangle2D del ?rea de datos dada 
162
	 * @param pixelSize Tama?o de pixel
163
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
164
	 */
165
	public void setPixelDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
166
		getZoomPixelControl().setDrawParams(img, ext, pixelSize, center) ;
167
	}
168

  
169
	/*
170
	 * (non-Javadoc)
171
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
172
	 */
173
	public WindowInfo getWindowInfo() {
174
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
175
		//if (getClippingPanel().getFLayer() != null)
176
			//m_viewinfo.setAdditionalInfo(getClippingPanel().getFLayer().getName());
177
		m_viewinfo.setTitle(PluginServices.getText(this, "zooms_control"));
178
		m_viewinfo.setX(posX);
179
		m_viewinfo.setY(posY);
180
		m_viewinfo.setHeight(h);
181
		m_viewinfo.setWidth(w);
182
		return m_viewinfo;
183
	}
184
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/IGraphicLayer.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.Graphics2D;
22
import java.awt.event.MouseListener;
23
import java.awt.event.MouseMotionListener;
24
import java.awt.geom.Rectangle2D;
25

  
26
/**
27
 * Interfaz  de dibujado de capas sobre ZoomControl
28
 * 22/12/2007
29
 * @author Nacho Brodin nachobrodin@gmail.com
30
 */
31
public interface IGraphicLayer extends MouseListener, MouseMotionListener {
32

  
33
	/**
34
	 * Dibujado del gr?fico
35
	 * @param g Graphics2D
36
	 * @param ext Rectangle2D del ?rea de dibujado
37
	 * @param w Ancho en p?xeles del ?rea de dibujado
38
	 * @param h Alto en p?xeles del ?rea de dibujado
39
	 */
40
	public void draw(Graphics2D g, Rectangle2D ext, int w, int h);
41
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/GPGraphic.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.Graphics2D;
23
import java.awt.geom.Point2D;
24

  
25
/**
26
 * Punto de control gr?fico.
27
 * 22/12/2007
28
 * @author Nacho Brodin nachobrodin@gmail.com
29
 */
30
public class GPGraphic {
31
	public static final int         PIXEL = 0;
32
	public static final int         MAP = 1;
33
	/**
34
	 * Diametro del centro de la cruz
35
	 */
36
	private final int               DIAM_CIRCLE = 18;
37
	private boolean                 showNumber = true;
38
	private boolean                 showLabel = true;
39
	private int                     type = PIXEL;
40
	
41
	/**
42
	 * Tipo de gr?fico en el punto
43
	 * @param type El valor de "type" viene definido por las constantes en esta clase
44
	 */
45
	public GPGraphic(int type) {
46
		this.type = type;
47
	}
48
	
49
	/**
50
	 * Dibuja sobre el graphics pasado la cruz del punto que marca
51
	 * el pixel de la imagen.
52
	 * @param g Graphics sobre el que se pinta
53
	 * @param p Punto del graphics que coincide con el centro del GP
54
	 * @param pointNumber Numero de punto a mostrar
55
	 * @param label Etiqueta del punto
56
	 */
57
	public void draw(Graphics2D g, Point2D p, int pointNumber, String label) {
58
		switch (type) {
59
		case PIXEL:
60
			drawPixelCrux(g, p, pointNumber, label);
61
			break;
62
		case MAP:
63
			drawMapCrux(g, p, pointNumber, label);
64
			break;
65
		}
66
	}
67
	
68
	/**
69
	 * Dibuja sobre el graphics pasado la cruz del punto que marca
70
	 * el pixel de la imagen.
71
	 * @param g Graphics sobre el que se pinta
72
	 * @param p Punto del graphics que coincide con el centro del GP
73
	 * @param pointNumber Numero de punto a mostrar
74
	 * @param label Etiqueta del punto
75
	 */
76
	private void drawPixelCrux(Graphics2D g, Point2D p, int pointNumber, String label) {
77
		int dpto = (DIAM_CIRCLE >> 1);
78
		int incr = 5;
79
		g.setColor(Color.WHITE);
80
		g.drawOval(	(int)p.getX() - dpto + 1,
81
					(int)p.getY() - dpto + 1,
82
					DIAM_CIRCLE - 2,
83
					DIAM_CIRCLE - 2);
84
		g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1);
85
		g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1);
86

  
87
		g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1);
88
		g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1);
89

  
90
		g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1);
91
		g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1);
92

  
93
		g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1);
94
		g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1);
95

  
96
		g.setColor(Color.red);
97
		g.drawOval(	(int)p.getX() - dpto,
98
					(int)p.getY() - dpto,
99
					DIAM_CIRCLE,
100
					DIAM_CIRCLE);
101
		g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
102
		g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
103

  
104
		if(showNumber) {
105
			String pt = String.valueOf(pointNumber );
106
			int ptX = (int)(p.getX() + dpto + 1);
107
			int ptY = (int)(p.getY() + dpto - 1);
108
			g.setColor(Color.WHITE);
109
			for (int i= -1; i<2; i++)
110
				for (int j= -1; j<2; j++)
111
					g.drawString(pt, ptX + i, ptY + j );
112
			g.setColor(Color.red);
113
			g.drawString(pt, ptX, ptY );
114
		}
115
		if(showLabel) {
116
			//TODO: FUNCIONALIDAD mostrar etiqueta
117
		}
118
	}
119

  
120
	/**
121
	 * Dibuja sobre el graphics pasado la cruz del punto que marca
122
	 * el pixel de la imagen.
123
	 * @param g Graphics sobre el que se pinta
124
	 * @param p Punto del graphics que coincide con el centro del GP
125
	 * @param pointNumber Numero de punto a mostrar
126
	 * @param label Etiqueta del punto
127
	 */
128
	private void drawMapCrux(Graphics2D g, Point2D p, int pointNumber, String label){
129
		int dpto = (DIAM_CIRCLE >> 1);
130
		int incr = 5;
131
		g.setColor(Color.WHITE);
132
		g.drawRect(	(int)p.getX() - dpto + 1,
133
					(int)p.getY() - dpto + 1,
134
					DIAM_CIRCLE - 2,
135
					DIAM_CIRCLE - 2);
136
		g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1);
137
		g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1);
138

  
139
		g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1);
140
		g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1);
141

  
142
		g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1);
143
		g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1);
144

  
145
		g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1);
146
		g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1);
147

  
148
		g.setColor(new Color(45, 8 , 165));
149
		g.drawRect(	(int)p.getX() - dpto,
150
					(int)p.getY() - dpto,
151
					DIAM_CIRCLE,
152
					DIAM_CIRCLE);
153
		g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
154
		g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
155
		if(showNumber){
156
			String pt = String.valueOf(pointNumber);
157
			int ptX = (int)(p.getX() + dpto + 1);
158
			int ptY = (int)(p.getY() - dpto - 1);
159
			g.setColor(Color.WHITE);
160
			for (int i= -1; i<2; i++)
161
				for (int j= -1; j<2; j++)
162
					g.drawString(pt, ptX + i, ptY + j );
163
			g.setColor(new Color(45, 8 , 165));
164
			g.drawString(String.valueOf(pointNumber), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) );
165
		}
166
		if(showLabel) {
167
			//TODO: FUNCIONALIDAD mostrar etiqueta
168
		}
169
	}
170

  
171
	/**
172
	 * Asigna el flag que muestra u oculta la etiqueta del punto
173
	 * @param showLabel true para mostrar la etiqueta y false para ocultarla
174
	 */
175
	public void setShowLabel(boolean showLabel) {
176
		this.showLabel = showLabel;
177
	}
178

  
179
	/**
180
	 * Asigna el flag que muestra u oculta el n?mero del punto
181
	 * @param showLabel true para mostrar el punto y false para ocultarlo
182
	 */
183
	public void setShowNumber(boolean showNumber) {
184
		this.showNumber = showNumber;
185
	}
186

  
187
	/**
188
	 * Asigna el tipo de gr?fico para el punto
189
	 * @param type Tipo de punto definido en las constantes de clase
190
	 */
191
	public void setType(int type) {
192
		this.type = type;
193
	}
194
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/CenterPointGraphicLayer.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.Graphics2D;
22
import java.awt.event.MouseEvent;
23
import java.awt.geom.Point2D;
24
import java.awt.geom.Rectangle2D;
25

  
26
/**
27
 * Capa gr?fica que se dibuja sobre un ZoomControl y que dibuja 
28
 * un GPGraphic en el centro del control.
29
 * 22/12/2007
30
 * @author Nacho Brodin nachobrodin@gmail.com
31
 */
32
public class CenterPointGraphicLayer implements IGraphicLayer {
33
	
34
	private GPGraphic               gPoint = null;
35
	private String                  label = "";
36
	private int                     number = 0;
37
	private ZoomControl             control = null;
38
	private int                     type = GPGraphic.MAP;
39
	
40
	private boolean                 move = false;
41
	private int                     x = 0;
42
	private int                     y = 0;
43

  
44
	/**
45
	 * Constructor. Asigna el tipo de punto a dibujar en la 
46
	 * capa gr?fica.
47
	 * @param type El valor de type viene definido por las constantes de GPGraphic
48
	 * @param control
49
	 */
50
	public CenterPointGraphicLayer(int type, ZoomControl control) {
51
		this.type = type;
52
		gPoint = new GPGraphic(type);
53
		this.control = control;
54
	}
55
	
56
	/*
57
	 * (non-Javadoc)
58
	 * @see org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer#draw(java.awt.Graphics2D, org.gvsig.raster.datastruct.Extent, int, int)
59
	 */
60
	public void draw(Graphics2D g, Rectangle2D ext, int w, int h) {
61
		if(move) {
62
			gPoint.draw(g, new Point2D.Double(x, y), number, label);
63
			return;
64
		}
65
		gPoint.draw(g, new Point2D.Double(w >> 1, h >> 1), number, label);
66
	}
67
	
68
	/**
69
	 * Asigna el flag que muestra u oculta la etiqueta del punto
70
	 * @param showLabel true para mostrar la etiqueta y false para ocultarla
71
	 */
72
	public void setShowLabel(boolean showLabel) {
73
		gPoint.setShowLabel(showLabel);
74
	}
75

  
76
	/**
77
	 * Asigna el flag que muestra u oculta el n?mero del punto
78
	 * @param showLabel true para mostrar el punto y false para ocultarlo
79
	 */
80
	public void setShowNumber(boolean showNumber) {
81
		gPoint.setShowNumber(showNumber);
82
	}
83
	
84
	/**
85
	 * Asigna la etiqueta del punto
86
	 * @param label
87
	 */
88
	public void setLabel(String label) {
89
		this.label = label;
90
	}
91

  
92
	/**
93
	 * Asigna el n?mero de punto
94
	 * @param number
95
	 */
96
	public void setNumber(int number) {
97
		this.number = number;
98
	}
99

  
100
	/*
101
	 * (non-Javadoc)
102
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
103
	 */
104
	public void mouseClicked(MouseEvent e) {
105
	}
106

  
107
	/*
108
	 * (non-Javadoc)
109
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
110
	 */
111
	public void mouseEntered(MouseEvent e) {
112
	}
113

  
114
	/*
115
	 * (non-Javadoc)
116
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
117
	 */
118
	public void mouseExited(MouseEvent e) {
119
	}
120

  
121
	/*
122
	 * (non-Javadoc)
123
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
124
	 */
125
	public void mousePressed(MouseEvent e) {
126
		move = true;
127
		x = e.getX();
128
		y = e.getY();
129
	}
130

  
131
	/*
132
	 * (non-Javadoc)
133
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
134
	 */
135
	public void mouseReleased(MouseEvent e) {
136
		switch(type) {
137
		case GPGraphic.MAP: control.setPixelCenter(e.getPoint()); break;
138
		case GPGraphic.PIXEL: control.setPixelCenter(e.getX(), e.getY()); break;
139
		}
140
		move = false;
141
	}
142

  
143
	/*
144
	 * (non-Javadoc)
145
	 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
146
	 */
147
	public void mouseDragged(MouseEvent e) {
148
		x = e.getX();
149
		y = e.getY();
150
	}
151

  
152
	/*
153
	 * (non-Javadoc)
154
	 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
155
	 */
156
	public void mouseMoved(MouseEvent e) {
157

  
158
	}
159
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/zoom/ZoomControl.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.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.awt.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
29
import java.awt.image.BufferedImage;
30

  
31
import javax.swing.JButton;
32
import javax.swing.JPanel;
33

  
34
import org.gvsig.raster.util.RasterToolsUtil;
35

  
36
/**
37
 * <P>
38
 * Control de zoom. Muestra una imagen contenida en un buffer con controles de aumento
39
 * y disminuci?n del zoom de la misma. 
40
 * </P><P>
41
 * El visualizador mostrar? el buffer de datos pasado en <code>setDrawParams</code>. 
42
 * En esta llamada asignamos tambi?n el Extent del ?rea de datos, tama?o de pixel y punto
43
 * del buffer que coincidir? con el centro del control de zoom. De esta forma la imagen 
44
 * visualizada se centra sobre este punto. En caso de no tener informaci?n geogr?fica del
45
 * buffer de datos a visualizar el Extent coincidir? con su tama?o en p?xeles y el tama?o
46
 * de pixel ser? de 1. El punto donde queramos centrar en este caso se dar? tambi?n en 
47
 * coordenadas pixel.
48
 * </P>
49
 * <P>
50
 * En la inicializaci?n podemos solicitar que los controles de zoom est?n a la izquierda, 
51
 * a la derecha o no esten.
52
 * </p>
53
 * 		
54
 * 21/12/2007
55
 * @author Nacho Brodin nachobrodin@gmail.com
56
 */
57
public class ZoomControl extends JPanel  implements ActionListener {
58
	private static final long        serialVersionUID = 1L;
59
	
60
	public static final int          RIGHT_CONTROL = 1;
61
	public static final int          LEFT_CONTROL = 2;
62
	public static final int          NOCONTROL = 0;
63
	
64
	private int                      control;
65
	private CanvasZone               canvas = null;
66
	private JPanel                   buttons = null;
67
	private JButton 				 bZoomMas = null;
68
	private JButton 				 bZoomMenos = null;
69
	private double                   stepScale = 2;
70
			
71
	/**
72
	 * Constructor. Crea el panel y asigna el lado donde se crear?n los botones
73
	 * @param right true para los botones a derecha y false para la izquierda
74
	 */
75
	public ZoomControl(int control) {
76
		this.control = control;
77
		init();
78
	}
79
	
80
	/**
81
	 * Inicializaci?n de los componetes
82
	 */
83
	private void init() {
84
		BorderLayout layout = new BorderLayout();
85
		setLayout(layout); 
86
		
87
		if(control == LEFT_CONTROL)
88
			add(getButtonsPanel(), BorderLayout.WEST);
89
		if(control == RIGHT_CONTROL)
90
			add(getButtonsPanel(), BorderLayout.EAST);
91
		
92
		add(getCanvas(), BorderLayout.CENTER);
93
	}
94
	
95
	/**
96
	 * Asigna una capa gr?fica
97
	 * @param layer IGraphicLayer
98
	 */
99
	public void setGraphicLayer(IGraphicLayer layer) {
100
		canvas.setGraphicLayer(layer);
101
	}
102
	
103
	/**
104
	 * Obtiene el panel de dibujado del zoom
105
	 * @return Canvas Zone
106
	 */
107
	public CanvasZone getCanvas() {
108
		if(canvas == null) {
109
			canvas = new CanvasZone();
110
			canvas.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
111
		}
112
		return canvas;
113
	}
114
	
115
	/**
116
	 * Obtiene el panel con los botones de zoom
117
	 * @return
118
	 */
119
	public JPanel getButtonsPanel() {
120
		if(buttons == null) {
121
			buttons = new JPanel();
122
			GridBagLayout l = new GridBagLayout();
123
			GridBagConstraints gbc = new GridBagConstraints();
124
			gbc.insets = new Insets(5, 0, 3, 3);
125
			buttons.setLayout(l);
126
			
127
			buttons.add(getBZoomMas(), gbc);
128
			gbc.gridy = 1;
129
			buttons.add(getBZoomMenos(), gbc);
130
		}
131
		return buttons;
132
	}
133
	
134
	/**
135
	 * Crea el bot?n de zoom m?s
136
	 * @return
137
	 */
138
	public JButton getBZoomMas() {
139
		if (bZoomMas == null) {
140
			bZoomMas = new JButton();
141
			bZoomMas.setPreferredSize(new java.awt.Dimension(25,25));
142
			try{
143
				bZoomMas.setIcon(RasterToolsUtil.getIcon("increase-icon"));
144
			}catch(NullPointerException e){
145
				//Sin icono
146
			}
147
			bZoomMas.addActionListener(this);
148
		}
149
		return bZoomMas;
150
	}
151

  
152
	/**
153
	 * Crea el bot?n de zoom menos
154
	 * @return
155
	 */
156
	public JButton getBZoomMenos() {
157
		if (bZoomMenos == null) {
158
			bZoomMenos = new JButton();
159
			bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25));
160
			try{
161
				bZoomMenos.setIcon(RasterToolsUtil.getIcon("decrease-icon"));
162
			}catch(NullPointerException e){
163
				//Sin icono
164
			}
165
			bZoomMenos.addActionListener(this);
166
		}
167
		return bZoomMenos;
168
	}
169
	
170
	/**
171
	 * Asigna los par?metros de dibujado
172
	 * @param img Buffer con un ?rea de datos
173
	 * @param ext Rectangle2D del ?rea de datos dada 
174
	 * @param pixelSize Tama?o de pixel
175
	 * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
176
	 */
177
	public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
178
		canvas.setDrawParams(img, ext, pixelSize, center) ;
179
	}
180
	
181
	/**
182
	 * Asigna un nuevo centro de visualizaci?n
183
	 * @param center
184
	 */
185
	public void setCenter(Point2D center) {
186
		canvas.setCenter(center);
187
	}
188
	
189
	/**
190
	 * Asigna un nuevo centro de visualizaci?n en coordenadas pixel
191
	 * del ?rea de dibujado (canvas)
192
	 * @param center
193
	 */
194
	public void setPixelCenter(Point2D center) {
195
		canvas.setPixelCenter(center);
196
	}
197
	
198
	/**
199
	 * Asigna un nuevo centro de visualizaci?n en coordenadas pixel. Esta llamada tiene
200
	 * en cuenta solo p?xeles completos. No centra sobre porciones de pixel cuando el zoom es
201
	 * mayor de 1:1.
202
	 * @param center
203
	 */
204
	public void setPixelCenter(int x, int y) {
205
		canvas.setPixelCenter(x, y);
206
	}
207

  
208
	/**
209
	 * Eventos de los botones zoom m?s y zoom menos
210
	 */
211
	public void actionPerformed(ActionEvent e) {
212
		if(e.getSource() == bZoomMas)
213
			canvas.setZoom(canvas.getZoom() * stepScale );
214

  
215
		if(e.getSource() == bZoomMenos)
216
			canvas.setZoom(canvas.getZoom() / stepScale);
217
	}
218

  
219
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/georeferencing/ui/table/GCPTablePanel.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.table;
20

  
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25

  
26
import javax.swing.JButton;
27
import javax.swing.JPanel;
28

  
29
import org.gvsig.gui.beans.table.TableContainer;
30
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
31
import org.gvsig.raster.util.RasterToolsUtil;
32

  
33
import com.iver.andami.PluginServices;
34
import com.iver.andami.ui.mdiManager.IWindow;
35
import com.iver.andami.ui.mdiManager.WindowInfo;
36

  
37
/**
38
 * Panel que contiene la tabla de puntos de control
39
 * 
40
 * 22/12/2007
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class GCPTablePanel extends JPanel implements IWindow {
44
	private static final long         serialVersionUID = 1L;
45
	private String[]                  columnNames = {"-", "N?", "X", "Y", "X'", "Y'", "Error X", "Error Y", "RMS"};
46
	private int[]                     columnWidths = {25, 25, 90, 90, 90, 90, 50, 50, 50};
47
	private TableContainer            table = null;
48
	
49
	private JPanel                    buttonsPanel = null;
50
	private JButton                   saveToXml = null;
51
	private JButton                   loadFromXml = null;
52
	private JButton                   saveToAscii = null;
53
	private JButton                   loadFromAscii = null;
54
	private JButton                   viewTable = null;
55
	private JButton                   process = null;
56
	
57
	private int                       w = 640;
58
	private int                       h = 100;
59
	private int                       posX = 0;
60
	private int                       posY = 0;
61
	
62
	/**
63
	 * Constructor.
64
	 * Crea la composici?n de controles de zoom.
65
	 */
66
	public GCPTablePanel(int posX, int posY, int w, int h) {
67
		setPosition(posX, posY);
68
		setWindowsSize(w, h);
69
		try {
70
			init();
71
		} catch (NotInitializeException e) {
72
			RasterToolsUtil.messageBoxError(RasterToolsUtil.getText(this, "table_not_initialize"), this);
73
		}
74
	}
75
	
76
	/**
77
	 * Asigna la posici?n de la ventana
78
	 * @param posX Posici?n en X
79
	 * @param posY Posici?n en Y
80
	 */
81
	public void setPosition(int posX, int posY) {
82
		this.posX = posX;
83
		this.posY = posY;
84
	}
85
	
86
	/**
87
	 * Asigna la posici?n de la ventana
88
	 * @param posX Posici?n en X
89
	 * @param posY Posici?n en Y
90
	 */
91
	public void setWindowsSize(int w, int h) {
92
		this.w = w;
93
		this.h = h;
94
	}
95
	
96
	/**
97
	 * Inicializaci?n de los componentes gr?ficos
98
	 */
99
	private void init() throws NotInitializeException  {
100
		setLayout(new BorderLayout());
101
		setSize(new java.awt.Dimension(w, h)); 
102
		
103
		GridBagConstraints gb = new GridBagConstraints();
104
		gb.insets = new java.awt.Insets(0, 0, 0, 0);
105
		gb.gridy = 0;
106
		gb.gridx = 0;
107
		gb.weightx = 1D; //El espacio sobrante se distribuye horizontalmente
108
		gb.weighty = 1D; //El espacio sobrante se distribuye verticalmente
109
		gb.fill = GridBagConstraints.BOTH; //El componente se hace tan ancho como espacio disponible tiene
110
		gb.anchor = GridBagConstraints.NORTH; //Alineamos las cajas arriba
111
		add(getTable(), BorderLayout.CENTER);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff