Revision 16326

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/RasterModule.java
265 265
				"reset-icon",
266 266
				this.getClass().getClassLoader().getResource("images/reset.png")
267 267
			);
268
		PluginServices.getIconTheme().registerDefault(
269
				"tfwload-icon",
270
				this.getClass().getClassLoader().getResource("images/load.png")
271
			);
272
		PluginServices.getIconTheme().registerDefault(
273
				"centerraster-icon",
274
				this.getClass().getClassLoader().getResource("images/center_image.png")
275
			);
268 276
	}
269 277
	/*
270 278
	 * (non-Javadoc)
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/geolocation/listener/GeoLocationPanelListener.java
21 21
import java.awt.event.ActionEvent;
22 22
import java.awt.event.ActionListener;
23 23
import java.awt.geom.AffineTransform;
24
import java.awt.geom.Rectangle2D;
25
import java.io.BufferedReader;
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.FileNotFoundException;
24 29
import java.io.IOException;
30
import java.io.InputStreamReader;
25 31
import java.util.EventObject;
26 32

  
33
import javax.swing.JFileChooser;
34

  
35
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
27 36
import org.gvsig.gui.beans.datainput.DataInputContainerListener;
37
import org.gvsig.raster.datastruct.Extent;
28 38
import org.gvsig.raster.util.Historical;
29 39
import org.gvsig.raster.util.RasterToolsUtil;
30 40
import org.gvsig.rastertools.geolocation.ui.GeoLocationPanel;
31 41

  
32 42
import com.iver.andami.PluginServices;
43
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard;
44
import com.iver.cit.gvsig.fmap.ViewPort;
33 45

  
34 46
/**
35 47
 * Listener para el panel de geolocalizaci?n.
......
108 120
		if(e.getSource() == panel.getResetButton())
109 121
			at = panel.getLayer().getDataSource().getOwnAffineTransform();
110 122
		
123
		//Cargar la georreferenciaci?n desde tfw
124
		if(e.getSource() == panel.getTfwLoad()) {
125
			JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath());
126
			chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
127
			chooser.addChoosableFileFilter(new GeorreferencingFileFilter("tfw"));
128
			chooser.addChoosableFileFilter(new GeorreferencingFileFilter("wld"));
129
			int returnVal = chooser.showOpenDialog(panel);
130
			if (returnVal == JFileChooser.APPROVE_OPTION) {
131
				String fName = chooser.getSelectedFile().toString();
132
				at = readTfw(fName);
133
			}
134
		}
111 135
		
136
		//Centrar el raster en la vista
137
		if(e.getSource() == panel.getCenterToView()) {
138
			Extent extentView = calcCenterExtent(panel.getViewPort());
139
			double x = extentView.minX();
140
			double y = extentView.maxY();
141
			double psX = extentView.width() / ((FLyrRasterSE)panel.getLayer()).getPxWidth();
142
			double psY = -(extentView.height() / ((FLyrRasterSE)panel.getLayer()).getPxHeight());
143
			at = new AffineTransform(psX, 0, 0, psY, x, y);
144
			panel.setModify(true);
145
		}
146
		
112 147
		//Entrar? en el caso de que se haya seleccionado alguna transformaci?n
113 148
		if(at != null) {
114 149
			panel.getLayer().setAT(at);
......
147 182
	public void setEnableValueChangeEvent(boolean enableValueChangeEvent) {
148 183
		this.enableValueChangeEvent = enableValueChangeEvent;
149 184
	}
185
	
186
	/**
187
	 * Centra el raster asociado a la capa en al extent del viewport pasado 
188
	 * por par?metro. 
189
	 * @param vp ViewPort
190
	 * @return	Extent para la imagen
191
	 */
192
	private Extent calcCenterExtent(ViewPort vp) {
193
		Extent tempExtent = null;
194
		double widthPxImg, heightPxImg;
195
		
196
		widthPxImg = ((FLyrRasterSE)panel.getLayer()).getPxWidth();
197
		heightPxImg = ((FLyrRasterSE)panel.getLayer()).getPxHeight();
198
		
199
		if(vp == null || vp.getAdjustedExtent() == null) {
200
			vp = new ViewPort(null);
201
			Rectangle2D r2d = new Rectangle2D.Double(0, 0, widthPxImg, heightPxImg);
202
			vp.setExtent(r2d);
203
			tempExtent = new Extent(0, 0, widthPxImg, heightPxImg);
204
		} else
205
			tempExtent = new Extent(vp.getAdjustedExtent());
206

  
207
		double ulX = 0D, ulY = 0D, lrX = 0D, lrY = 0D;
208
		if(widthPxImg > heightPxImg) {
209
			double widthView = tempExtent.maxX() - tempExtent.minX();
210
			ulX = tempExtent.minX() + (widthView / 4);
211
			lrX = ulX + (widthView / 2);
212
			double newAlto = ((heightPxImg * (widthView / 2)) / widthPxImg);
213
			double centroY = tempExtent.minY()+((tempExtent.maxY() - tempExtent.minY())/2);
214
			ulY = centroY - (newAlto / 2);
215
			lrY = centroY + (newAlto / 2);
216
		} else {
217
			double heightView = tempExtent.maxY() - tempExtent.minY();
218
			ulY = tempExtent.minY() + (heightView / 4);
219
			lrY = ulY + (heightView / 2);
220
			double newAncho = ((widthPxImg * (heightView / 2)) / heightPxImg);
221
			double centroX = tempExtent.minX()+((tempExtent.maxX() - tempExtent.minX())/2);
222
			ulX = centroX - (newAncho / 2);
223
			lrX = centroX + (newAncho / 2);
224
		}
225
		return new Extent(ulX, ulY, lrX, lrY);
226
	}
227
	
228
	/**
229
	 * Lee las coordenadas de un fichero de tfw con una transformaci?n y 
230
	 * devuelve la clase AffineTransform con dicha transformaci?n. Esta llamada gestiona los
231
	 * errores producidos actuando en consecuencia. Muestra los mensajes al usuario y retorna
232
	 * null en caso de tener problemas.
233
	 * @param fName Nombre del fichero tfw
234
	 * @return AffineTransform
235
	 */
236
	private AffineTransform readTfw(String fName) {
237
		BufferedReader inGrf = null;
238
		double[] result = new double[6];
239
		try {
240
			inGrf = new BufferedReader(new InputStreamReader(new FileInputStream(fName)));
241
			String str = inGrf.readLine();
242
			int count = 0;
243
			while(str != null && count < 6) {
244
				try {
245
					Double value =  new Double(str);
246
					result[count] = value.doubleValue();
247
				} catch (NumberFormatException ex) {
248
					RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_file_not_valid"), panel, ex);
249
					return null;
250
				}
251
				str = inGrf.readLine();
252
				count ++;
253
			}
254
		} catch (FileNotFoundException e) {
255
			RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_file_not_found"), panel, e);
256
			return null;
257
		} catch (IOException ex) {
258
			RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_lectura"), panel, ex);
259
			return null;
260
		}
261
		return new AffineTransform(result[0], result[1], result[2], result[3], result[4], result[5]);
262
	}
263
	
264
	/**
265
	 * Filtro para el selector de formatos de georreferenciaci?n
266
	 * @author Nacho Brodin (nachobrodin@gmail.com)
267
	 */
268
	class GeorreferencingFileFilter extends javax.swing.filechooser.FileFilter {
269
		private String				filter;
270

  
271
		public GeorreferencingFileFilter(String fil) {
272
			this.filter = fil;
273
		}
274

  
275
		public boolean accept(File f) {
276
			return f.isDirectory() || f.getName().toLowerCase().endsWith("." + filter);
277
		}
278

  
279
		public String getDescription() {
280
			return "." + filter;
281
		}
282
	}
150 283
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/geolocation/ui/GeoLocationDialog.java
33 33
import com.iver.andami.ui.mdiManager.IWindowListener;
34 34
import com.iver.andami.ui.mdiManager.WindowInfo;
35 35
import com.iver.cit.gvsig.fmap.MapControl;
36
import com.iver.cit.gvsig.fmap.ViewPort;
36 37
import com.iver.cit.gvsig.fmap.layers.FLayer;
37 38
import com.iver.cit.gvsig.fmap.layers.FLayers;
38 39
import com.iver.cit.gvsig.project.documents.view.gui.IView;
......
55 56
	private int               posWindowY       = 0;
56 57

  
57 58
	private int               widthWindow      = 260;
58
	private int               heightWindow     = 145;
59
	private int               heightWindow     = 155;
59 60

  
60 61
	private String            lastTool         = null;
61 62

  
62
	//private FLyrRasterSE      lyr              = null;
63
	    
64
		
65 63
	/**
66 64
	 * Constructor
67 65
	 */
......
76 74
	 * Constructor. Asigna la capa raster.
77 75
	 *
78 76
	 */
79
	public GeoLocationDialog(FLyrRasterSE lyr) {
77
	public GeoLocationDialog(FLyrRasterSE lyr, ViewPort vp) {
80 78
		BorderLayout bl = new BorderLayout(5, 5);
81 79
		this.setLayout(bl);
82 80

  
83 81
		this.add(getGeoLocationPanel());
84
		getGeoLocationPanel().setLayer(lyr);
82
		getGeoLocationPanel().setParams(lyr, vp);
85 83
	}
86 84

  
87 85
	/**
......
102 100
	 * Referencia la capa que est? seleccionada
103 101
	 *
104 102
	 */
105
	private void loadLayer() {
103
	private void loadLayer(ViewPort vp) {
106 104
		if(getGeoLocationPanel().getLayer() != null)
107 105
			return;
108 106
		//Este c?digo es para poder lanzar la funcionalidad desde la barra de herramientas y no desde el TOC
......
110 108
		FLayer[] actives = flyrs.getActives();
111 109
		for (int i = 0; i < actives.length; i++) {
112 110
			if(actives[i] instanceof FLyrRasterSE) {
113
				getGeoLocationPanel().setLayer(((FLyrRasterSE)actives[i]));
111
				getGeoLocationPanel().setParams(((FLyrRasterSE)actives[i]), vp);
114 112
				break;
115 113
			}
116 114
		}
......
123 121
	public void init(MapControl mapCtrl) {
124 122
		geolocationPanel.setMapCtrl(mapCtrl);
125 123
		lastTool = mapCtrl.getCurrentTool();
126
		loadLayer();
124
		loadLayer(mapCtrl.getViewPort());
127 125
		FLyrRasterSE lyr = getGeoLocationPanel().getLayer();
128 126
		if(lyr != null) {
129 127
			lyr.getAffineTransformHistorical().clear();
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/geolocation/ui/GeoLocationPanel.java
36 36

  
37 37
import com.iver.andami.PluginServices;
38 38
import com.iver.cit.gvsig.fmap.MapControl;
39
import com.iver.cit.gvsig.fmap.ViewPort;
39 40

  
40 41
/**
41 42
 * Panel de geolocalizaci?n. Este muestra los par?metros de la matriz de transformaci?n
......
60 61
	private JButton                    next = null;
61 62
	private JButton                    apply = null;
62 63
	private JButton                    reset = null;
64
	private JButton                    tfwload = null;
65
	private JButton                    center = null;
63 66
	
64 67
	private JPanel			           coordsPanel = null;
65 68
	private JPanel			           paramsPanel = null;
66 69
	private JPanel			           buttonsPanel = null;
67 70
	private GeoLocationPanelListener   listener = null;
68 71
	private FLyrRasterSE               lyr = null;
72
	private ViewPort                   vp = null;
73
	
69 74
	/**
70 75
     * N?mero de decimales a mostrar
71 76
     */
......
82 87
		ImageIcon saveIcon = null;
83 88
		ImageIcon firstIcon = null;
84 89
		ImageIcon resetIcon = null;
90
		ImageIcon tfwLoadIcon = null;
91
		ImageIcon centerRasterIcon = null;
85 92
		try {
86 93
			backIcon = PluginServices.getIconTheme().get("back-icon");
87 94
			nextIcon = PluginServices.getIconTheme().get("next-icon");
88 95
			saveIcon = PluginServices.getIconTheme().get("save-icon"); 
89 96
			firstIcon = PluginServices.getIconTheme().get("undo-icon");
90 97
			resetIcon = PluginServices.getIconTheme().get("reset-icon");
98
			centerRasterIcon = PluginServices.getIconTheme().get("centerraster-icon");
99
			tfwLoadIcon = PluginServices.getIconTheme().get("tfwload-icon");
91 100
		} catch(NullPointerException e) {
92 101
			
93 102
		}
......
127 136
		next = new JButton(nextIcon);
128 137
		apply = new JButton(PluginServices.getText(this,"apply"));
129 138
		reset = new JButton(resetIcon);
139
		tfwload = new JButton(tfwLoadIcon);
140
		center = new JButton(centerRasterIcon);
130 141
		
131 142
		save.setToolTipText(PluginServices.getText(this,"salvar_transf"));
132 143
		back.setToolTipText(PluginServices.getText(this,"back_transf"));
......
134 145
		apply.setToolTipText(PluginServices.getText(this,"aplicar_transf"));
135 146
		first.setToolTipText(PluginServices.getText(this,"first_transf"));
136 147
		reset.setToolTipText(PluginServices.getText(this,"reset_transf"));
148
		center.setToolTipText(PluginServices.getText(this,"center_raster"));
149
		tfwload.setToolTipText(PluginServices.getText(this,"tfw_load"));
137 150
		
138 151
		save.setPreferredSize(new Dimension(28, 24));
139 152
		first.setPreferredSize(new Dimension(28, 24));
......
141 154
		next.setPreferredSize(new Dimension(28, 24));
142 155
		apply.setPreferredSize(new Dimension(64,24));
143 156
		reset.setPreferredSize(new Dimension(28,24));
157
		center.setPreferredSize(new Dimension(28,24));
158
		tfwload.setPreferredSize(new Dimension(28,24));
144 159
		
145 160
		first.addActionListener(listener);
146 161
		save.addActionListener(listener);
......
148 163
		next.addActionListener(listener);
149 164
		apply.addActionListener(listener);
150 165
		reset.addActionListener(listener);
166
		tfwload.addActionListener(listener);
167
		center.addActionListener(listener);
151 168
		
152 169
		save.setEnabled(false);
153 170
		back.setEnabled(false);
154 171
		next.setEnabled(false);
155 172
		first.setEnabled(false);
156 173
		reset.setEnabled(true);
174
		center.setEnabled(true);
175
		tfwload.setEnabled(true);
157 176
		
158 177
		coordsPanel = new JPanel();
159 178
		GridLayout l = new GridLayout(2, 1);
......
178 197
		paramsPanel.add(rotx);
179 198
		paramsPanel.add(roty);
180 199
		
200
		JPanel smallButtons = new JPanel();
201
		smallButtons.setLayout(new GridBagLayout());
202
		JPanel applyButton = new JPanel();
203
		applyButton.setLayout(new GridBagLayout());
204
		
181 205
		GridBagConstraints gbc = new GridBagConstraints();
182
		gbc.insets = new java.awt.Insets(0, 0, 0, 2);
183
		buttonsPanel.add(reset, gbc);
184
		buttonsPanel.add(back, gbc);
185
		buttonsPanel.add(next, gbc);
186
		buttonsPanel.add(first, gbc);
187
		buttonsPanel.add(save, gbc);
188
		buttonsPanel.add(apply, gbc);
206
				
207
		gbc.gridx = 0;
208
		gbc.gridy = 0;
209
		gbc.insets = new java.awt.Insets(1, 0, 0, 2);
210
		smallButtons.add(center, gbc);
211
		gbc.gridx = 1;
212
		smallButtons.add(reset, gbc);
213
		gbc.gridx = 2;
214
		smallButtons.add(first, gbc);
215
		gbc.gridx = 3;
216
		smallButtons.add(back, gbc);
217
		gbc.gridx = 4;
218
		smallButtons.add(next, gbc);
219
		gbc.gridx = 5;
220
		smallButtons.add(tfwload, gbc);
221
		gbc.gridx = 6;
222
		smallButtons.add(save, gbc);
189 223
		
190 224
		gbc.gridx = 0;
191 225
		gbc.gridy = 0;
226
		gbc.anchor = GridBagConstraints.EAST;
227
		applyButton.add(apply, gbc);
228
		
229
		buttonsPanel.add(smallButtons, gbc);
230
		gbc.gridy = 1;
231
		gbc.weightx = 1.0;
232
		buttonsPanel.add(applyButton, gbc);
233
		
192 234
		gbc.fill = GridBagConstraints.HORIZONTAL;
193
		gbc.weightx = 1.0;
235
		gbc.gridx = 0;
236
		gbc.gridy = 0;
194 237
		gbc.insets = new java.awt.Insets(1, 1, 1, 1);
195 238
		this.add(coordsPanel, gbc);
196 239
		
197 240
		gbc.gridy = 1;
198 241
		this.add(paramsPanel, gbc);
199
		
242
		gbc.weightx = 1.0;
200 243
		gbc.gridy = 2;
201 244
		this.add(buttonsPanel, gbc);
202 245
	}
......
209 252
		if(buttonsPanel == null) {
210 253
			buttonsPanel = new JPanel();
211 254
			buttonsPanel.setLayout(new GridBagLayout());
255
			//buttonsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
212 256
		}
213 257
		return buttonsPanel;
214 258
	}
......
267 311
	 * al cual se asigna la georreferenciaci?n al dialogo.
268 312
	 * @param lyr
269 313
	 */
270
	public void setLayer(FLyrRasterSE lyr) {
314
	public void setParams(FLyrRasterSE lyr, ViewPort vp) {
271 315
		this.lyr = lyr;
316
		this.vp = vp;
272 317
		loadTransform(lyr.getAffineTransform());
273 318
	}
319
	
320
	/**
321
	 * Obtiene el viewport de la vista en el momento de lanzar el interfaz
322
	 * @return
323
	 */
324
	public ViewPort getViewPort() {
325
		return this.vp;
326
	}
274 327

  
275 328
	/**
276 329
	 * Carga los par?metros en el dialogo a partir de la capa
......
382 435
	public JButton getNextButton() {
383 436
		return next;
384 437
	}
438
	
439
	/**
440
	 * Obtiene el bot?n de carga de georreferenciaci?n desde tfw
441
	 * @return JButton
442
	 */
443
	public JButton getTfwLoad() {
444
		return tfwload;
445
	}
385 446

  
386 447
	/**
448
	 * Obtiene el bot?n de centrado de raster en la vista
449
	 * @return JButton
450
	 */
451
	public JButton getCenterToView() {
452
		return center;
453
	}
454
	
455
	/**
387 456
	 * Obtiene el tama?o de pixel en X
388 457
	 * @return
389 458
	 */
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/geolocation/GeoLocationTocMenuEntry.java
138 138
			return;
139 139
		
140 140
		FLyrRasterSE lyr = (FLyrRasterSE)selectedItems[0];
141
		GeoLocationDialog gld = new GeoLocationDialog(lyr);
141
		GeoLocationDialog gld = new GeoLocationDialog(lyr, mapCtrl.getViewPort());
142 142
		if(!isOpen) {
143 143
			gld.calcPosition();
144 144
			PluginServices.getMDIManager().addWindow(gld);
trunk/extensions/extRasterTools-SE/config/text.properties
11 11
de=de
12 12
cancelando=Cancelando
13 13
cargar_toc=\u00bfDesea cargar la capa en el TOC?
14
center_raster=Centrar la capa raster en la vista
15
tfw_load=Cargar georreferenciaci?n desde fichero tfw
14 16
closeanalysisview=Cerrar vista de analisis
15 17
compress=Compresi\u00f3n
16 18
confirmacion=Confirmaci\u00f3n
......
21 23
error_aplicando_filtro=Error aplicando Filtro
22 24
error_carga_capa=Error en la carga de la capa.
23 25
error_escritura=No se puede escribir en la ruta especificada.
26
error_lectura=No se puede leer en la ruta especificada.
24 27
error_props_show=La capa est? en un estado inconsistente. Es posible que deba esperar a que acabe la operaci?n en curso.
25 28
error_props_tabs=El panel de propiedades se cerr? por falta de pesta?as.
26 29
error_extensiones_soportadas=Error al obtener la lista de extensiones soportadas. No se puede exportar la capa.
27 30
error_file_exists=El fichero ya existe.\u00bfDesea sobreescribirlo?.
31
error_file_not_found=Fichero no encontrado.
32
error_file_not_valid=El fichero seleccionado no parece ser valido.
28 33
error_file_not_writable=No es posible crear el fichero de salida.
29 34
error_load_layer=No se ha podido cargar la capa en el TOC. Intentelo manualmente.
30 35
error_salvando_rmf=Error escribiendo el fichero rmf
trunk/extensions/extRasterTools-SE/src-test-ui/org/gvsig/rastertools/geolocation/TestGeoLocationDialog.java
36 36
		initialize();
37 37
	}
38 38

  
39
	public static void main(String[] args){
39
	public static void main(String[] args) {
40 40
		try {
41 41
			UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
42 42
		} catch( Exception e ) {

Also available in: Unified diff