Revision 5818

View differences:

trunk/extensions/extGeoreferencing/config/text.properties
39 39
gcps_exist=La capa ya tiene un fichero .rmf. Si este ya contiene GCP's ser?n sobreescritos.\n ?Desea continuar?
40 40
grado_polinomio= Grado del Polinomio
41 41
guardar=Salvar
42
import_from_ascii=Importar la tabla de puntos a fichero .csv.
42 43
latitud=Latitud
43 44
load_from_xml=Cargar puntos de control desde .rmf
44 45
longitud=Longitud
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/utils/GeoLayerFactory.java
23 23

  
24 24
import org.cresques.cts.IProjection;
25 25
import org.gvsig.georeferencing.GeoreferencingToolsModule;
26
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
26
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
27 27

  
28 28
import com.iver.andami.PluginServices;
29 29
import com.iver.cit.gvsig.fmap.DriverException;
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/utils/PointManager.java
30 30

  
31 31
import org.gvsig.georeferencing.GeoOperations;
32 32
import org.gvsig.georeferencing.GeoreferencingToolsModule;
33
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
33
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
34 34
import org.gvsig.georeferencing.gui.listeners.GeoRasterFrameListener;
35 35
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener;
36 36
import org.gvsig.georeferencing.gui.panels.AdjustGeorefPanel;
......
73 73
	
74 74
	private TablePointsPanel 			tablePointsPanel = null;
75 75
	private TableControlerPanel 		tableControlerPanel2 = null;
76
	private TablePanelButtons	buttonsExportImportPanel = null;
76
	private TablePanelButtons			buttonsExportImportPanel = null;
77 77
	
78 78
	private OptionsPanel				optionsPanel = null;
79 79
	private ZoomControlPanel			zoomControlPanelLeft = null;
......
155 155
		//Actualizamos los textBox
156 156
		if(pixel != null)
157 157
			dialog.setPixelText(GeoUtils.tailDecimals(pixel.getX(), 2), GeoUtils.tailDecimals(pixel.getY(), 2));
158
			//dialog.getSelectPointsPanel().lastTx = String.valueOf(pixel.getX());
159
			//dialog.getSelectPointsPanel().lastTy = String.valueOf(pixel.getY());
160 158
		
161 159
		if(map != null)
162 160
			dialog.setMapCoordText(map.getX(), map.getY());
163
			//dialog.getSelectPointsPanel().lastLong = String.valueOf(map.getX());
164
			//dialog.getSelectPointsPanel().lastLat = String.valueOf(map.getY());
165 161
		
166
		
167 162
		//El Checkbox de activaci?n
168 163
		GeoPoint gp = ((GeoPoint)lyrPoints.getPoint(nPunto - 1));
169 164
		if(gp != null){
......
568 563
		agp.getZoomRight().clear();
569 564
		dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(false);
570 565
		
566
		//Desactivamos los controles de salvar puntos
567
		if(lyrPoints.getCountPoints() == 0)
568
			dialog.setEnableSaveButtons(false);
569
		
571 570
		//Actualizamos la vista
572 571
		View theView = null;
573 572
		try{
......
671 670
		
672 671
		//Volvemos a dejar los controles con su valor habitual
673 672
		dialog.getPointManager().restoreControlsValue();
673
		dialog.setEnableSaveButtons(true);
674 674
		
675 675
		//Obtenemos del dialogo el n? de pto seleccionado y lo actualizamos en la capa de ptos
676 676
		int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/utils/GeoPointPersistence.java
44 44
import org.cresques.cts.ProjectionPool;
45 45
import org.cresques.io.RasterMetaFileTags;
46 46
import org.gvsig.georeferencing.GeoreferencingToolsModule;
47
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
47
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
48
import org.gvsig.georeferencing.gui.panels.ZoomControlPanel;
48 49
import org.w3c.dom.Document;
49 50
import org.w3c.dom.Element;
50 51
import org.w3c.dom.Node;
......
124 125
	        		}
125 126
	        	}
126 127
	        }
127

  
128
	       
128 129
	    } catch (ParserConfigurationException e) {
129 130
	            return;
130 131
	    } catch (SAXException e1) {
......
160 161
	} 
161 162
	
162 163
	/**
164
	 * Crea la lista de puntos a partir de un fichero CSV
165
	 * @param file
166
	 */
167
	public void loadCSVPointList(String file){
168
		try{
169
			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
170
			String line = in.readLine();
171
			int nPoint = 0;
172
			while(line != null){
173
				if(nPoint == 0){
174
					if(!line.equals("\"Pt\",\"X\",\"Y\",\"X'\",\"Y'\",\"ErrX\",\"ErrY\",\"RMS\""))
175
						return;
176
				}else{
177
					double x = 0D, y = 0D, xx = 0D, yy = 0D;
178
					String[] tokens = line.split(",");
179
				    for(int tok=0; tok<tokens.length;tok++){
180
				    	try{
181
					    	if(tok == 1)
182
					    		x = Double.parseDouble(tokens[tok]); 
183
					    	if(tok == 2)
184
					    		y = Double.parseDouble(tokens[tok]);
185
					    	if(tok == 3)
186
					    		xx = Double.parseDouble(tokens[tok]);
187
					    	if(tok == 4)
188
					    		yy = Double.parseDouble(tokens[tok]);
189
				    	}catch(NumberFormatException ex){
190
				    		return;
191
				    	}
192
				    }
193
					int pos = nPoint - 1;
194
					
195
					if(x == 0 && y == 0 && xx == 0 && yy == 0){
196
						line = in.readLine();
197
						continue;
198
					}
199
					
200
					lyrPoints.getPointManager().newEmptyPoint();
201
				    Point2D p = new Point2D.Double();
202
					p.setLocation(x, y);
203
					Point2D m = new Point2D.Double();
204
					m.setLocation(xx, yy);
205
					
206
					Point2D leftCenter = new Point2D.Double();
207
					leftCenter.setLocation(lyrPoints.getLyrGeoRaster().img2World(p));
208
					Point2D rightCenter = new Point2D.Double();
209
					rightCenter.setLocation(m);
210
					
211
					View theView = null;
212
					ViewPort viewPort = null;
213
		        	try{
214
		        		theView = (View) PluginServices.getMDIManager().getActiveView();
215
		        		viewPort = theView.getMapControl().getMapContext().getViewPort();
216
		        	}catch(ClassCastException exc){
217
		        		return ;
218
		        	}
219
					ViewPort leftViewPort = viewPort.cloneViewPort();
220
					leftViewPort.setImageSize(new java.awt.Dimension(ZoomControlPanel.WIDTH_MINIMG, ZoomControlPanel.HEIGHT_MINIMG));
221
					ViewPort rightViewPort = viewPort.cloneViewPort();
222
					rightViewPort.setImageSize(new java.awt.Dimension(ZoomControlPanel.WIDTH_MINIMG, ZoomControlPanel.HEIGHT_MINIMG));
223
					leftViewPort = lyrPoints.getPointManager().getDialog().getZoomControlLeft().getCanvas().initViewPort(viewPort, leftCenter, leftViewPort, 1);
224
					rightViewPort = lyrPoints.getPointManager().getDialog().getZoomControlLeft().getCanvas().initViewPort(viewPort, rightCenter, rightViewPort, 1);
225
					
226
					GeoreferencingToolsModule.setEnabled(true);
227
					
228
					lyrPoints.setPointActive(pos, true);
229
					lyrPoints.setLeftCenterPoint(pos,leftCenter);
230
					lyrPoints.setRightCenterPoint(pos, rightCenter);
231
					lyrPoints.setMiniExtent(pos, lyrPoints.getLyrGeoRaster().img2World(p), leftViewPort, false);
232
					lyrPoints.setMiniExtent(pos, m, rightViewPort, true);
233
					lyrPoints.getPointManager().updateData(pos + 1, p, m, lyrPoints.getPointManager().getDialog(), null);
234
					lyrPoints.setZoomLeft(pos, 1);
235
					lyrPoints.setZoomRight(pos, 1);
236
					if(lyrPoints.getCountPoints() > 0){
237
						GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog();
238
						grd.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
239
						grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
240
						lyrPoints.getPointManager().selectPoint(0, grd);
241
					}
242
				}
243
				nPoint++;
244
				line = in.readLine();
245
			}
246
			in.close();
247
		}catch(FileNotFoundException ex){
248
			//No salvamos el csv
249
		}catch(IOException ex){
250
			//No salvamos el csv
251
		}
252
	}
253
	
254
	/**
163 255
	 * Crea el fichero Ascii con la lista de puntos y la salva a disco
164 256
	 * @param file
165 257
	 */
166
	public void saveAsciiPointList(String file){
258
	public void saveCSVPointList(String file){
167 259
		this.geoPointList = lyrPoints.getListPoint();
168 260
		try{
169 261
			BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/wizards/GeoRasterWizard.java
37 37
import org.cresques.cts.IProjection;
38 38
import org.cresques.io.GeoRasterFile;
39 39
import org.cresques.px.Extent;
40
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
40
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
41 41
import org.gvsig.georeferencing.utils.GeoLayerFactory;
42 42
import org.gvsig.georeferencing.utils.GeoUtils;
43 43
import org.gvsig.georeferencing.utils.PointManager;
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/wizards/SelectFilePanel.java
37 37
import org.cresques.cts.IProjection;
38 38
import org.cresques.io.GeoRasterFile;
39 39
import org.cresques.px.Extent;
40
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
40
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
41 41
import org.gvsig.georeferencing.utils.GeoPointPersistence;
42 42
import org.gvsig.georeferencing.utils.StackZoom;
43 43

  
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/listeners/GeorefPointSelectorListener.java
24 24
import javax.swing.JOptionPane;
25 25

  
26 26
import org.gvsig.georeferencing.GeoreferencingToolsModule;
27
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
27
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
28 28

  
29 29
import com.iver.andami.PluginServices;
30 30
import com.iver.cit.gvsig.fmap.ViewPort;
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/listeners/GeorefMovePointListener.java
23 23

  
24 24
import javax.swing.JOptionPane;
25 25

  
26
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
26
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
27 27

  
28 28
import com.iver.andami.PluginServices;
29 29
import com.iver.cit.gvsig.fmap.ViewPort;
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/options/GeorefTableOptionsPanel.java
27 27
import javax.swing.JPanel;
28 28
import javax.swing.JTable;
29 29

  
30
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
30
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
31 31
import org.gvsig.georeferencing.gui.options.TableOptions.TableModelPoint;
32 32

  
33 33
import com.iver.andami.PluginServices;
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/selectPoints/SelectPointsPanel.java
37 37
import javax.swing.JPanel;
38 38

  
39 39
import org.gvsig.georeferencing.GeoreferencingToolsModule;
40
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
40
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
41 41
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener;
42 42
import org.gvsig.georeferencing.gui.pointsTable.TableControlerPanel;
43 43

  
......
223 223
			bInsertPoint.setText("");
224 224
			bInsertPoint.setPreferredSize(new java.awt.Dimension(22,22));
225 225
			bInsertPoint.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "selectfromview.png")));
226
			bInsertPoint.setToolTipText(PluginServices.getText(this, "selectfromview"));
226 227
			bInsertPoint.setEnabled(false);
227 228
			bInsertPoint.setSelected(true);
228
			bInsertPoint.setToolTipText(PluginServices.getText(this, "selectfromview"));
229 229
			bInsertPoint.addActionListener(this);
230 230
		}
231 231
		return bInsertPoint;
......
830 830
				tableControlerPanel.setLayout(flowLayout1);
831 831
				flowLayout1.setVgap(1);
832 832
				flowLayout1.setHgap(0);
833
				//jLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
834
				//tableControlerPanel.setLNumberOfPoints(jLabel);
833
				
835 834
				tableControlerPanel.getBFirst().addActionListener(this);
836 835
				tableControlerPanel.getBLast().addActionListener(this);
837 836
				tableControlerPanel.getBNext().addActionListener(this);
......
841 840
				tableControlerPanel.getBClear().addActionListener(this);
842 841
				tableControlerPanel.getBDelPoint().addActionListener(this);
843 842
			}
844
			//pPointSelection.add(getPTableControl(), null);
843

  
845 844
			pPointSelection.add(tableControlerPanel, null);
846 845
			pPointSelection.add(getPExtend(), null);
847 846
		}
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/dialog/DialogButtons.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.georeferencing.gui.dialog;
20

  
21
import java.awt.FlowLayout;
22

  
23
import javax.swing.ImageIcon;
24
import javax.swing.JButton;
25
import javax.swing.JPanel;
26

  
27
import com.iver.andami.PluginServices;
28
import com.iver.andami.ui.mdiFrame.JToggleButton;
29
import com.iver.cit.gvsig.gui.View;
30

  
31
/**
32
 * Control para el manejo de tablas. No contiene eventos, estos deben 
33
 * ser manejados desde la clase que lo llame.
34
 * 
35
 * @author Nacho Brodin (brodin_ign@gva.es)
36
 *
37
 */
38
public class DialogButtons extends JPanel{
39
	
40
	//**********************Vars**********************************		
41
	private JButton 		bSave = null;
42
	private JButton 		bLoad = null;
43
	private JButton 		bExportToCSV = null;
44
	private JButton 		bImportFromCSV = null;
45
	private String			pathToImages = "images/";//"/com/iver/cit/gvsig/gui/panels/images/";
46
	//**********************End Vars******************************
47
	
48
	//**********************Methods*******************************
49
	/**
50
	 * This is the default constructor
51
	 */
52
	public DialogButtons() {
53
		super();
54
		initialize();
55
	}
56

  
57
	/**
58
	 * This method initializes this
59
	 * 
60
	 * @return void
61
	 */
62
	private void initialize() {                
63
		this.setSize(new java.awt.Dimension(91,22));
64
		FlowLayout flowLayout5 = new FlowLayout();
65
		flowLayout5.setHgap(0);
66
		flowLayout5.setVgap(0);
67
        
68
		this.setLayout(flowLayout5);
69

  
70
		this.add(getBSave(), null);
71
		this.add(getBLoad(), null);
72
		this.add(getBExportToCSV(), null);
73
		this.add(getBImportFromCSV(), null);
74
	}
75
	//**********************End Methods***************************	
76
	
77
	//**********************Getters & Setters*********************
78
	/**
79
	 * This method initializes jButton	
80
	 * 	
81
	 * @return javax.swing.JButton	
82
	 */    
83
	public JButton getBImportFromCSV() {
84
		if (bImportFromCSV == null) {
85
			bImportFromCSV = new JButton();
86
			bImportFromCSV.setText("");
87
			bImportFromCSV.setPreferredSize(new java.awt.Dimension(22,22));
88
			bImportFromCSV.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "importFromCSV.png")));
89
			bImportFromCSV.setEnabled(true);
90
			bImportFromCSV.setSelected(true);
91
			bImportFromCSV.setToolTipText(PluginServices.getText(this, "import_from_ascii"));
92
		}
93
		return bImportFromCSV;
94
	}
95
	
96
	/**
97
	 * This method initializes jButton	
98
	 * 	
99
	 * @return javax.swing.JButton	
100
	 */    
101
	public JButton getBLoad() {
102
		if (bLoad == null) {
103
			bLoad = new JButton();
104
			bLoad.setPreferredSize(new java.awt.Dimension(22,22));
105
			bLoad.setEnabled(true);
106
			bLoad.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "load.png")));
107
			bLoad.setToolTipText(PluginServices.getText(this, "load_from_xml"));
108
		}
109
		return bLoad;
110
	}
111
	
112
	/**
113
	 * This method initializes bSave	
114
	 * 	
115
	 * @return javax.swing.JButton	
116
	 */
117
	public JButton getBSave() {
118
		if (bSave == null) {
119
			bSave = new JButton();
120
			bSave.setText("");
121
			bSave.setEnabled(false);
122
			bSave.setPreferredSize(new java.awt.Dimension(22,22));
123
			bSave.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "save.png")));
124
			bSave.setActionCommand("");
125
			bSave.setToolTipText(PluginServices.getText(this, "save_to_xml"));
126
		}
127
		return bSave;
128
	}
129
	
130
	/**
131
	 * This method initializes jButton	
132
	 * 	
133
	 * @return javax.swing.JButton	
134
	 */    
135
	public JButton getBExportToCSV() { 
136
		if (bExportToCSV == null) {
137
			bExportToCSV = new JButton();
138
			bExportToCSV.setPreferredSize(new java.awt.Dimension(22,22));
139
			bExportToCSV.setEnabled(false);
140
			bExportToCSV.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "exportToCSV.png")));
141
			bExportToCSV.setToolTipText(PluginServices.getText(this, "save_to_ascii"));
142
		}
143
		return bExportToCSV;
144
	}
145
	
146
	/**
147
	 * Activa o desactiva los botones de exportar capa de puntos y salvar
148
	 * la tabla a Ascii.
149
	 *@param isPossible Si vale true activa los controles de salvar y exportaci?n
150
	 *y si vale false los desactiva
151
	 */
152
	public void setSaveToDisk(boolean isPossible){
153
		this.getBSave().setEnabled(isPossible);
154
		this.getBExportToCSV().setEnabled(isPossible);
155
	}
156
	//**********************End Getters & Setters*****************
157
 }
0 158

  
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/dialog/GeoreferencingDialog.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.georeferencing.gui.dialog;
20

  
21
import java.awt.BorderLayout;
22
import java.awt.Component;
23
import java.awt.Dimension;
24
import java.awt.FlowLayout;
25
import java.awt.event.ActionListener;
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.ComponentListener;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30
import java.beans.PropertyVetoException;
31
import java.io.File;
32

  
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JFileChooser;
36
import javax.swing.JInternalFrame;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39
import javax.swing.filechooser.FileFilter;
40
import javax.swing.table.DefaultTableModel;
41

  
42
import org.cresques.cts.IProjection;
43
import org.cresques.px.Extent;
44
import org.gvsig.georeferencing.GeoOperations;
45
import org.gvsig.georeferencing.gui.listeners.GeoRasterFrameListener;
46
import org.gvsig.georeferencing.gui.listeners.GeorefMovePointListener;
47
import org.gvsig.georeferencing.gui.listeners.GeorefPanListener;
48
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener;
49
import org.gvsig.georeferencing.gui.listeners.ZoomGeorefListener;
50
import org.gvsig.georeferencing.gui.panels.ConectorPanel;
51
import org.gvsig.georeferencing.gui.panels.OptionsPanel;
52
import org.gvsig.georeferencing.gui.panels.ZoomControlPanel;
53
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel;
54
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel.PointTable;
55
import org.gvsig.georeferencing.gui.selectPoints.SelectPointsPanel;
56
import org.gvsig.georeferencing.toc.GeoRasterTocMenuEntry;
57
import org.gvsig.georeferencing.utils.GeoLayerFactory;
58
import org.gvsig.georeferencing.utils.GeoPointPersistence;
59
import org.gvsig.georeferencing.utils.GeoUtils;
60
import org.gvsig.georeferencing.utils.PointManager;
61
import org.gvsig.georeferencing.utils.StackZoom;
62

  
63
import com.iver.andami.PluginServices;
64
import com.iver.andami.ui.mdiFrame.JToggleButton;
65
import com.iver.cit.gvsig.fmap.DriverException;
66
import com.iver.cit.gvsig.fmap.MapControl;
67
import com.iver.cit.gvsig.fmap.ViewPort;
68
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
69
import com.iver.cit.gvsig.fmap.layers.FLayers;
70
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
71
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
72
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
73
import com.iver.cit.gvsig.fmap.layers.IGeoUi;
74
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter;
75
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
76
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
77
import com.iver.cit.gvsig.fmap.tools.Behavior.DraggedBehavior;
78
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior;
79
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior;
80
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
81
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
82
import com.iver.cit.gvsig.gui.View;
83
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
84
import com.iver.cit.gvsig.gui.wizards.WizardListener;
85
import com.iver.cit.gvsig.project.Project;
86

  
87
/**
88
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
89
 * interiores
90
 *
91
 * @author Nacho Brodin (brodin_ign@gva.es)
92
 */
93
public class GeoreferencingDialog extends JPanel implements IGeoUi, ActionListener, ComponentListener {
94
	
95
	//**********************Vars**********************************
96
	static private IProjection 			proj = Project.getProjection();
97
	private JPanel 						pBotones = null;  //  @jve:decl-index=0:
98
	private JButton 					bProcesar = null;  //  @jve:decl-index=0:
99
	private JButton 					bCancelar = null;  //  @jve:decl-index=0:
100
	private WizardListener 				wizardListener = new DialogWizardListener();
101
	private GeoRedimBehavior 			rb = null;
102
	private GeoMoveBehavior 			mb = null;
103
	private boolean 					loadTools = false;
104
	private JInternalFrame 				frame = null;
105
	/**
106
	 * Lista de formatos soportados
107
	 */
108
	private String[] 					fileFilters = {"csv"};
109
	/**
110
	 * Recuerda la ?ltima ruta seleccionada por el usuario
111
	 */
112
	private String 						lastPathLoad = "./";
113
	private String 						lastPathSave = "./";
114
	private ConectorPanel				conectorPanel = null;
115
	
116
	private boolean 					enlarge = false;
117
	private int 						normalWidth = 400;
118
	private int 						normalHeight = 273;
119
	private int 						enlargeHeight = 438;
120
	private int 						tmpWidth = normalWidth;
121
	
122
	private JButton 					bAceptar = null;
123
	
124
	private FLyrGeoRaster 				lyrGeoRaster = null;
125
	private TablePointsPanel 			tablePointsPanel = null;
126
	private	PointManager				pointManager = null;
127
	/**
128
	 * True si ha de crearse un fichero de georreferenciaci?n
129
	 */
130
	private boolean 					createWorldFile = false;
131
	/**
132
	 * True si los errores han de incluirse en el fichero csv
133
	 */
134
	private boolean 					errorCSV = true;
135
	/**
136
	 * Estado de los botones cuando se ejecuta disableAllControls
137
	 */
138
	private boolean[] 					buttonsState = new boolean[7];
139
	/**
140
	 * DisableAllControls ha sido ejecutada si est? a true esta variabled
141
	 */
142
	private boolean 					disableAllControls = false;
143
	/**
144
	 * Variable que controla si la capa de georreferenciaci?n se ha de desactivar
145
	 * despu?s del primer punto.
146
	 */
147
	private boolean 					offLayer = true;
148
	/**
149
	 * Variable que controla si la vista ha de centrarse sobre el punto seleccionado
150
	 * o no
151
	 */
152
	private boolean 					centerPoint = true;
153
	/**
154
	 * Variable que controla si la capa de puntos se ha de desactivar
155
	 * despu?s del primer punto.
156
	 */
157
	private boolean 					offPoints = true;
158
	/**
159
	 * Panel que contiene los botones de la barra inferior
160
	 */
161
	private DialogButtons				dialogButtons = null;
162
	//**********************End Vars******************************	
163
	
164
	//**********************Classes*******************************
165
	/**
166
	 * Filtro para selecci?n de ficheros.
167
	 * @author Nacho Brodin (brodin_ign@gva.es)
168
	 */
169
	class SelectFileFilter extends javax.swing.filechooser.FileFilter {
170
		
171
		private JFileChooser chooser = null;
172
		private String file = null;
173
		
174
		public SelectFileFilter(JFileChooser ch, String file){
175
			this.chooser = ch;
176
			this.file = file;
177
		}
178
		
179
	    public boolean accept(File f) {
180

  
181
	    	return f.isDirectory() || f.getName().toLowerCase().endsWith("."+file);
182
	    }
183
	    
184
	    public String getDescription() {
185
	    	return file;
186
	    }
187
	    
188
	}
189
	
190
	/**
191
	 * @author Nacho Brodin (brodin_ign@gva.es)
192
	 */
193
	public class DialogWizardListener implements WizardListener {
194

  
195
		/**
196
		 * @see org.gvsig.georeferencing.gui.wms.WizardListener#error(java.lang.Exception)
197
		 */
198
		public void error(Exception e) {
199
		}
200

  
201
		/**
202
		 * @see org.gvsig.georeferencing.gui.wms.WizardListener#wizardStateChanged(boolean)
203
		 */
204
		public void wizardStateChanged(boolean finishable) {
205
			getBProcess().setEnabled(finishable);
206
		}
207
		
208
	}
209
	//**********************End Classes***************************
210
	
211
	//**********************Methods*******************************
212
    /**
213
     * Constructor.
214
     */
215
    public GeoreferencingDialog(JInternalFrame f, FLyrGeoRaster lyr) {
216
    	frame = f;
217
    	lyrGeoRaster = lyr;
218
    	
219
    	frame.addComponentListener(this);
220
    	initialize();
221
    	
222
    	//Creamos el pointManager y lo asignamos a la capa de puntos
223
    	pointManager = new PointManager(this, lyrGeoRaster.getFLyrPoints());
224
    	this.lyrGeoRaster.getFLyrPoints().setPointManager(pointManager);
225
    	
226
    	//En estos casos entra cuando la capa se crea al abrir un proyecto
227
    	if(lyrGeoRaster.getPersistence() == null){
228
    		lyrGeoRaster.setPersistence(new GeoPointPersistence(lyrGeoRaster.getFLyrPoints()));
229
    		f.addInternalFrameListener(new GeoRasterFrameListener());
230
    		GeoRasterTocMenuEntry.isOpen = true;
231
    	}
232
    	if(lyrGeoRaster.getStackZoom() == null)
233
    		lyrGeoRaster.setZoom(new StackZoom());
234
    		
235
    }
236
      
237
    /**
238
     * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos 
239
     * ls herramientas para manejar las imagenes a georeferenciar.
240
     */
241
    private void initialize() {
242
    	//Cargamos las herramientas la primera vez que abrimos la ventana
243
        if(!loadTools){
244
        	com.iver.cit.gvsig.gui.View  vista = null;
245
			try{
246
				vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
247
			}catch(ClassCastException exc){
248
				return;
249
			}
250
			
251
			MapControl mapCtrl = null;
252
			if(vista != null)
253
				mapCtrl = vista.getMapControl();
254

  
255
	        if(mapCtrl != null){
256
	        	loadTools = true;
257
				StatusBarListener sbl = new StatusBarListener(mapCtrl);
258
				
259
				ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
260
				ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
261
				rb = new GeoRedimBehavior(zigl);
262
				mapCtrl.addMapTool("geoZoom", new Behavior[]{rb,
263
		        				new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
264
								
265
				GeorefPanListener pl = new GeorefPanListener(mapCtrl);
266
				mb = new GeoMoveBehavior(pl);
267
				mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
268
				
269
				//Seleccion de un punto sobre la vista
270
		        GeorefPointSelectorListener psl = new GeorefPointSelectorListener(this);
271
		        mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
272
		        
273
		        GeorefMovePointListener mpl = new GeorefMovePointListener(this);
274
		        mapCtrl.addMapTool("geoMovePoint", new Behavior[]{new DraggedBehavior(mpl), new MouseMovementBehavior(sbl)});
275
	        }
276
        }
277
        
278
        this.setLayout(new BorderLayout());
279
        if(!enlarge){
280
        	this.setPreferredSize(new java.awt.Dimension(normalWidth, normalHeight));
281
        	this.setSize(new java.awt.Dimension(400,273));
282
        	this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(false);
283
        	this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(false);
284
        }else{
285
        	this.setPreferredSize(new java.awt.Dimension(normalWidth, enlargeHeight));
286
        	this.setSize(new java.awt.Dimension(normalWidth, enlargeHeight));
287
        	this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(true);
288
        	this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(true);
289
        }
290
        this.setLocation(new java.awt.Point(0,0));
291
        
292
        this.add(this.getPBotones(), BorderLayout.SOUTH);
293
        this.add(this.getConectorPanel(), BorderLayout.NORTH);    
294
        
295
        //A?adimos los listener de los botones de la tabla
296
        //Los botones de borrado los gestiona SelectPointsPanel
297
        //Los botones de cargar y exportar los gestiona GeoreferencigDialog
298
        tablePointsPanel = getConectorPanel().getDataPointsTabPanel().getTablePointsPanel(); 
299
        tablePointsPanel.getTableControlerPanel().getBClear().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
300
        tablePointsPanel.getTableControlerPanel().getBDelPoint().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
301
        
302
        getDialogButtons().getBExportToCSV().addActionListener(this);
303
        getDialogButtons().getBImportFromCSV().addActionListener(this);
304
        getDialogButtons().getBLoad().addActionListener(this);
305
        getDialogButtons().getBSave().addActionListener(this);
306
                
307
        conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive().addActionListener(this);
308
		getBInsertPointOfTablePoints().addActionListener(conectorPanel.getDataPointsTabPanel().getSelectPointsPanel());
309
		getBNewPointOfTablePoints().addActionListener(conectorPanel.getDataPointsTabPanel().getSelectPointsPanel());
310
    }
311
    		
312
	/**
313
	 * Comprueba si existe el fichero pasado por par?metro existe solicitando confirmaci?n
314
	 * de sobreescritura. Si el usuario acepta devolver? true y si no acepta devuelve false.
315
	 * Si se acepta la sobreescritura el fichero es borrado. 
316
	 * @param file Cadena con el nombre del fichero a comprobar su existencia.
317
	 * @return Devuelve true si el fichero existe y va a ser sobreescrito
318
	 */
319
	public boolean checkFileExists(String file, boolean delete){
320
		File f = new File(file);
321
		if(f.exists()){
322
			if (messageBoxYesOrNot("file_exists")){ 
323
				if(delete)
324
					f.delete();
325
				return true;
326
			}else
327
				return false;
328
		}
329
		return true;
330
	}
331
	
332
	/**
333
	 * MessageBox con dos botones (OK y Cancel) que mostrar? el mensaje pasado por
334
	 * par?metro 
335
	 * @param msg Mensaje a mostrar
336
	 * @return true si el usuario pulsa Ok y false si pulsa Cancel
337
	 */
338
	public boolean messageBoxYesOrNot(String msg){
339
		String string1 = PluginServices.getText(this, "yes");
340
		String string2 = PluginServices.getText(this, "no");
341
		Object[] options = {string1, string2};
342
		int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
343
					PluginServices.getText(this, msg),
344
					PluginServices.getText(this, "confirmacion"),
345
					JOptionPane.YES_NO_OPTION,
346
					JOptionPane.QUESTION_MESSAGE,
347
					null,     
348
					options,  
349
					string1); 
350
		if (n == JOptionPane.YES_OPTION) 
351
			return true;
352
		else
353
			return false;
354
	}
355
	
356
	/**
357
	 * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
358
	 * <UL>
359
	 * <LI>Cambiamos el nombre a la capa georraster</LI>
360
	 * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
361
	 * <LI>Cerramos la ventana</LI>
362
	 * </UL>
363
	 */
364
	public void actionPerformed(java.awt.event.ActionEvent e) {
365
		com.iver.cit.gvsig.gui.View  theView = null;
366
		try{
367
			theView = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
368
		}catch(ClassCastException exc){
369
			return;
370
		}
371

  
372
		try{
373
			//ACEPTAR 
374
			if(e.getSource() == bAceptar)
375
				accept(theView);	
376
						
377
			//CANCELAR
378
			if(e.getSource() == bCancelar)
379
				cancel(theView);
380
						
381
			//CARGAR PUNTOS
382
			if(e.getSource() == getDialogButtons().getBLoad())
383
				loadPoints(theView);
384
						
385
			//SALVAR PUNTOS
386
			if(e.getSource() == getDialogButtons().getBSave())
387
				savePoints();				
388
			
389
			//EXPORTAR A CSV
390
			if(e.getSource() == getDialogButtons().getBExportToCSV())
391
				exportToCSV(theView);	
392
						
393
			//IMPORTAR DESDE CSV
394
			if(e.getSource() == getDialogButtons().getBImportFromCSV())
395
				importFromCSV(theView);
396
			
397
			//DESACTIVAR PANELES
398
			JCheckBox cb = this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive();
399
			if(e.getSource() == cb)
400
				deactivatePanel(theView, cb);
401
						
402
			//PROCESAR
403
			if(e.getSource() == this.getBProcess())
404
				process(theView);
405
		}catch(Exception exc){
406
			exc.printStackTrace();
407
			return; 
408
		}		
409
	}
410
	
411
	/**
412
	 * Cierra el dialogo
413
	 */
414
	public void close(){
415
		try{
416
			frame.setClosed(true);
417
		}catch(PropertyVetoException exc){}
418
	}
419
    
420
	/**
421
	 * Funci?n que se ejecuta al pulsar el bot?n procesar. Este procesamiento calcula a partir de
422
	 * los puntos de control la georreferenciaci?n de la imagen y la asigna como extent temporal de
423
	 * la capa FLyrGeoRaster. Cuando termina actualiza la visualizaci?n.
424
	 * @param theView
425
	 */
426
	private void process(View theView)throws Exception{
427
		if(getLyrPoints() == null)
428
			throw new Exception("LyrPoints not loaded.");
429
		
430
		if(this.getLyrPoints().getCountPoints() > 0){
431
			
432
			//Salvamos los centros
433
			Point2D[] oldCenter = new Point2D.Double[lyrGeoRaster.getFLyrPoints().getCountPoints()];
434
			for(int i=0; i<lyrGeoRaster.getFLyrPoints().getCountPoints(); i++)
435
				oldCenter[i] = lyrGeoRaster.img2World(lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint);
436
						
437
			//Calculamos las coordenadas de georreferenciaci?n
438
			GeoOperations go = new GeoOperations(getLyrPoints());
439
			double[] begin = go.transformPoint(0, 0, go.getAffine());
440
			double[] end = go.transformPoint((int)lyrGeoRaster.getImageWidth(), (int)lyrGeoRaster.getImageHeight(), go.getAffine());
441
			Extent ext = new Extent(begin[0], begin[1], end[0], end[1]);
442
			
443
			//Asignamos el extent temporal a la capa de georreferenciaci?n
444
			ViewPort vp = theView.getMapControl().getMapContext().getViewPort();
445
			((FLyrGeoRaster)theView.getMapControl().getMapContext().getLayers().getLayer(lyrGeoRaster.getName())).setAssignExtent(ext);
446
			
447
			//Si la capa tiene puntos de control hacemos un update de estos 
448
			//a su posici?n para que se actualicen los controles
449
			
450
			for(int i=0; i<lyrGeoRaster.getFLyrPoints().getCountPoints(); i++){
451
				Point2D center = lyrGeoRaster.img2World(lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint);
452
				lyrGeoRaster.getFLyrPoints().setMiniExtent(	i,
453
															center,
454
															GeoUtils.shiftExtent(oldCenter[i], center, getLyrPoints().getMiniExtent(i, false)),
455
															false);
456
				if(i == getSelectedPoint())
457
					updateData(i + 1, lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint, null, null);
458
			}
459
			theView.getMapControl().getMapContext().invalidate();
460
		}
461
	}
462
	
463
	/**
464
	 * Funci?n que se ejecuta al pulsar el bot?n aceptar. Este procesamiento calcula a partir de
465
	 * los puntos de control la georreferenciaci?n de la imagen, crear el fichero .rmf de georreferenciaci?n
466
	 * y descarga la capa del TOC. A continuaci?n vuelve a cargar la capa como FLyrRaster dando
467
	 * por finalizada la georreferenciaci?n. 
468
	 * @param theView
469
	 */
470
	private void accept(View theView)throws Exception{
471
		if(getLyrPoints() == null)
472
			throw new Exception("LyrPoints not loaded.");
473
		
474
		if(this.getLyrPoints().getCountPoints() > 0){
475
			savePoints();
476
			
477
			//Creamos el fichero de georreferenciaci?n
478
			GeoOperations go = new GeoOperations(getLyrPoints());
479
			go.setCreateWorldFile(this.createWorldFile);
480
			go.createGeorefFile( (int)getLyrGeoRaster().getImageWidth(), 
481
								(int)getLyrGeoRaster().getImageHeight(),
482
								getLyrGeoRaster().getSource().getFiles()[0].getName());
483
			
484
			FLayers lyrs = this.getLyrGeoRaster().getParentLayer(); 
485
			
486
			for(int i = 0; i < lyrs.getLayersCount();i++){
487
				if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
488
					
489
					//Eliminamos la capa
490
					lyrs.removeLayer(i);
491
					File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
492
					try{
493
						//Creamos la nueva capa GeoRaster y la a?adimos al TOC. 						
494
						FLyrRaster lyrRaster = GeoLayerFactory.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()),
495
																			(RasterDriver)getLyrGeoRaster().getSource().getDriver(), 
496
																			fich,
497
																			getLyrGeoRaster().getProjection());
498
						lyrs.addLayer(lyrRaster);
499
						theView.getMapControl().getMapContext().invalidate();
500
					}catch(DriverException exc){
501
						
502
					}
503
					break;
504
				}
505
			}
506
		}
507
		//Cerramos la ventana
508
		try{
509
			frame.setClosed(true);
510
		}catch(PropertyVetoException exc){}
511
			
512
	}
513
		
514
	/**
515
	 * Funci?n que se ejecuta al pulsar el bot?n cancelar
516
	 * @param theView
517
	 */
518
	private void cancel(View theView)throws Exception{
519
		if(getLyrPoints() == null)
520
			throw new Exception("LyrPoints not loaded.");
521
					
522
		//Cerramos la ventana 
523
		//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
524
		try{
525
			frame.setClosed(true);
526
			theView.getMapControl().getMapContext().invalidate();
527
		}catch(PropertyVetoException exc){}
528
	}
529
	
530
	/**
531
	 * Funci?n que se ejecuta al pulsar el bot?n de cargar puntos 
532
	 * @param theView
533
	 */
534
	private void loadPoints(View theView)throws Exception{		
535
		if(getLyrPoints() == null)
536
			throw new Exception("LyrPoints not loaded.");
537
		
538
		if(messageBoxYesOrNot("cargar_puntos")){
539
			String name = lyrGeoRaster.getName().substring(lyrGeoRaster.getName().indexOf("*") + 1, lyrGeoRaster.getName().lastIndexOf("."));
540
			String path = ((RasterFileAdapter)lyrGeoRaster.getSource()).getFile().getAbsolutePath();
541
			String nameRmf = path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".rmf";
542
			
543
			//Antes de cargar puntos plegamos el cuadro 
544
		 	getSelectPointsPanel().setEnlarge(true);
545
		 	
546
			getLyrPoints().saveState();
547
			getLyrPoints().XML2PointList(nameRmf);
548
						
549
			//Esto es por si el panel ha sido estirado cuando cargamos los puntos			
550
			frame.pack();
551
			frame.show();
552
			
553
			//Por problemas con repaint e hilos concurrentes tenemos que poner esto explicitamente
554
			//ya que es posible que se haga un paint de las miniimagenes antes de que cleanCanvas vuelva a valer false
555
			this.getZoomControlLeft().getCanvas().setCleanCanvas(false);
556
			this.getZoomControlRight().getCanvas().setCleanCanvas(false);
557
			
558
			if(getLyrPoints().getCountPoints() > 0)
559
				setEnableSaveButtons(true);
560
		}
561
	}
562
	
563
	/**
564
	 * Funci?n usada para salvar puntos
565
	 * @param theView
566
	 */
567
	public void savePoints()throws Exception{
568
		if(getLyrPoints() == null)
569
			throw new Exception("LyrPoints not loaded.");
570
		String name = lyrGeoRaster.getName().substring(lyrGeoRaster.getName().indexOf("*") + 1, lyrGeoRaster.getName().lastIndexOf("."));
571
		String path = ((RasterFileAdapter)lyrGeoRaster.getSource()).getFile().getAbsolutePath();
572
		String nameRmf = path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".rmf";
573
			
574
		File f = new File(nameRmf);
575
		if(f.exists()){
576
			if (messageBoxYesOrNot("gcps_exist")){ 
577
				if(getLyrPoints() != null)
578
			 		getLyrPoints().PointList2XML( path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".grf");
579
			}
580
		}else
581
			getLyrPoints().PointList2XML( path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".grf");		
582
	}
583
	
584
	/**
585
	 * Funci?n que se ejecuta al pulsar el bot?n de export a ascii
586
	 * @param theView
587
	 */
588
	private void exportToCSV(View theView)throws Exception{
589
		if(getLyrPoints() == null)
590
			throw new Exception("LyrPoints not loaded.");
591
		
592
		JFileChooser chooser = new JFileChooser(lastPathSave);
593
		chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
594
		
595
		FileFilter f = null;
596
		for(int i=0; i<this.fileFilters.length;i++){
597
			f = new SelectFileFilter(chooser, this.fileFilters[i]);
598
			chooser.addChoosableFileFilter(f);
599
		}
600
		int returnVal = chooser.showOpenDialog(this);
601
		if(returnVal == JFileChooser.APPROVE_OPTION){
602
		 	String fName = chooser.getSelectedFile().toString();
603
		 	lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
604
		 	if(checkFileExists(fName, true)){
605
		 		if(getLyrPoints() != null)
606
		 			getLyrPoints().PointList2CSV(fName);
607
		 	}
608
		}			
609
	}
610
	
611
	/**
612
	 * Funci?n que se ejecuta al pulsar el bot?n de importar desde CSV
613
	 * @param theView
614
	 */
615
	private void importFromCSV(View theView)throws Exception{
616
		if(getLyrPoints() == null)
617
			throw new Exception("LyrPoints not loaded.");
618
		
619
		JFileChooser chooser = new JFileChooser(lastPathSave);
620
		chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
621
		
622
		FileFilter f = null;
623
		for(int i=0; i<this.fileFilters.length;i++){
624
			f = new SelectFileFilter(chooser, this.fileFilters[i]);
625
			chooser.addChoosableFileFilter(f);
626
		}
627
		int returnVal = chooser.showOpenDialog(this);
628
		if(returnVal == JFileChooser.APPROVE_OPTION){
629
		 	String fName = chooser.getSelectedFile().toString();
630
		 	lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
631
		 	getLyrPoints().PointListFromCSV(fName);
632
		
633
			//Antes de cargar puntos plegamos el cuadro 
634
		 	getSelectPointsPanel().setEnlarge(true);
635
		 	
636
			//Por problemas con repaint e hilos concurrentes tenemos que poner esto explicitamente
637
			//ya que es posible que se haga un paint de las miniimagenes antes de que cleanCanvas vuelva a valer false
638
			this.getZoomControlLeft().getCanvas().setCleanCanvas(false);
639
			this.getZoomControlRight().getCanvas().setCleanCanvas(false);
640
			
641
		 	//Si se han cargado puntos desde el CSV se activan los controles 
642
			if(getLyrPoints().getCountPoints() > 0)
643
				setEnableSaveButtons(true);
644
		}			
645
	}
646
	
647
	/**
648
	 * Funci?n que se ejecuta al pulsar el bot?n desactivar panel
649
	 * @param theView
650
	 */
651
	public void deactivatePanel(View theView, JCheckBox cb)throws Exception{
652
		if(getLyrPoints() == null)
653
			throw new Exception("LyrPoints not loaded.");
654
		
655
		//Sincronizamos con el checkBox de la tabla
656
		tablePointsPanel.getJTable().getTableModel().setValueAt(new Boolean(cb.isSelected()), 
657
																			tablePointsPanel.getJTable().getTable().getSelectedRow(),
658
																			0);
659
		
660
		if(cb.isSelected()){
661
			this.setEnabled(true);
662
			getLyrPoints().setPointActive(getSelectedPoint(), true);
663
		}else{
664
			this.setEnabled(false);
665
			getLyrPoints().setPointActive(getSelectedPoint(), false);
666
		}
667
		
668
		//Al activar y desactivar tenemos que recalcular errores
669
		this.getPointManager().setErrors(getSelectedPoint());
670
		
671
		theView.getMapControl().getMapContext().invalidate();
672
		getZoomControlLeft().draw();
673
		getZoomControlRight().draw();		
674
	}
675
		 
676
	/**
677
	 * Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas
678
	 * pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre
679
	 * el nuevo centro y el viejo desplaza el extent completo de la mini-imagen.
680
	 * @param theView
681
	 */
682
	private void calcNewMiniExtent(View theView){
683

  
684
		ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
685
		for(int j = 0; j < getLyrPoints().getCountPoints(); j++){
686
			//Calculamos el nuevo centro
687
			Point2D oldCenter = getLyrPoints().getPoint(j).leftCenterPoint;
688
			Point2D newCenter = new Point2D.Double();
689
			newCenter.setLocation(	lyrGeoRaster.img2World(getLyrPoints().getPoint(j).pixelPoint));
690
			
691
			double diffX = oldCenter.getX() - newCenter.getX();
692
			double diffY = oldCenter.getY() - newCenter.getY();
693
			
694
			getLyrPoints().getPoint(j).leftCenterPoint = newCenter;	
695
						
696
			ViewPort vpOld = getLyrPoints().getPoint(j).leftViewPort;			
697
			Rectangle2D newExtent = new Rectangle2D.Double(	vpOld.getExtent().getMinX() - diffX, 
698
															vpOld.getExtent().getMinY() - diffY, 
699
															vpOld.getExtent().getWidth(), 
700
															vpOld.getExtent().getHeight() );
701
			ViewPort vpNew = new ViewPort(vpOld.getProjection());
702
			vpNew.setExtent(newExtent);
703
			vpNew.setImageSize(vpOld.getImageSize());
704
			vpNew.setScale();
705
			getLyrPoints().getPoint(j).leftViewPort = vpNew;
706
		}
707
	}
708
	
709
	/**
710
	 * This method initializes jButton	
711
	 * 	
712
	 * @return javax.swing.JButton	
713
	 */    
714
	public JButton getBAccept() {
715
		if (bAceptar == null) {
716
			bAceptar = new JButton();
717
			bAceptar.setText(PluginServices.getText(this,"aceptar"));
718
			bAceptar.setToolTipText(PluginServices.getText(this,"accept_tip"));
719
			bAceptar.addActionListener(this);
720
		}
721
		return bAceptar;
722
	}
723
	
724
	/**
725
	 * This method initializes bProcesar	
726
	 * 	
727
	 * @return javax.swing.JButton	
728
	 */    
729
	public JButton getBProcess() {
730
		if (bProcesar == null) {
731
			bProcesar = new JButton();
732
			bProcesar.setText(PluginServices.getText(this,"procesar"));
733
			bProcesar.setToolTipText(PluginServices.getText(this,"process_tip"));
734
			bProcesar.setEnabled(true);
735
			bProcesar.addActionListener(this);
736
		}
737
		return bProcesar;
738
	}
739
	
740
	/**
741
	 * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
742
	 * y cierra la ventana. 	
743
	 * 	
744
	 * @return javax.swing.JButton	
745
	 */    
746
	public JButton getBCancel() {
747
		if (bCancelar == null) {
748
			bCancelar = new JButton();
749
			bCancelar.setText(PluginServices.getText(this,"cancelar"));
750
			bCancelar.setToolTipText(PluginServices.getText(this,"cancel_tip"));
751
			bCancelar.addActionListener(this);
752
		}
753
		return bCancelar;
754
	}
755
		
756
	/**
757
	 * Asigna a las textbox el valor de pixel pasado
758
	 * @param x	valor x
759
	 * @param y	valor y
760
	 */
761
	public void setPixelText(double x, double y){
762
		getSelectPointsPanel().getDataPointPanel().getTX().setText(String.valueOf(x));
763
		getSelectPointsPanel().getDataPointPanel().getTY().setText(String.valueOf(y));
764
	}
765
	
766
	/**
767
	 * Asigna a las textbox el valor de coordenadas pasado
768
	 * @param x	valor x
769
	 * @param y	valor y
770
	 */
771
	public void setMapCoordText(double x, double y){
772
		getSelectPointsPanel().getDataPointPanel().getLongitud().setText(GeoUtils.tailDecimals(String.valueOf(x), 5));
773
		getSelectPointsPanel().getDataPointPanel().getLatitud().setText(GeoUtils.tailDecimals(String.valueOf(y), 5));
774
	}
775
	
776
	/**
777
	 * Esta funci?n resetea los controles del panel de info de un punto.
778
	 */
779
	public void resetControls(boolean active){
780
		getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().setSaveToDisk(active);
781
		getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().resetControls(active);		
782
		getConectorPanel().getAdjustGeorefPanel().getZoomLeft().clear();
783
		getConectorPanel().getAdjustGeorefPanel().getZoomRight().clear();
784
		setEnabled(active);
785
	}
786
	
787
	/* (non-Javadoc)
788
	 * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
789
	 */
790
	public void componentHidden(ComponentEvent arg0) {
791
		// TODO Auto-generated method stub
792

  
793
	}
794
	/* (non-Javadoc)
795
	 * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
796
	 */
797
	public void componentMoved(ComponentEvent arg0) {
798
		// TODO Auto-generated method stub
799

  
800
	}
801
	/* (non-Javadoc)
802
	 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
803
	 */
804
	public void componentResized(ComponentEvent ev) {
805
		
806
		if(frame.getWidth() <= this.normalWidth + 10)
807
			frame.setSize(this.normalWidth, frame.getHeight());
808
		
809
		if(this.getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 1){
810
			tmpWidth = frame.getWidth();
811
			this.newFrameSize(frame.getWidth(), frame.getHeight() - 10);
812
		}
813
	}
814
	/* (non-Javadoc)
815
	 * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
816
	 */
817
	public void componentShown(ComponentEvent arg0) {
818
		// TODO Auto-generated method stub
819

  
820
	}
821
	
822
    /**
823
     *Inicializa el tama?o del dialogo
824
     */
825
    public void resetSize(){
826
    	if(!enlarge){
827
    		frame.setSize(this.normalWidth + 12, this.normalHeight + 10);
828
    	}else{
829
    		frame.setSize(this.normalWidth + 12, this.enlargeHeight + 10);
830
    	}
831
    	newFrameSize((int)Math.round(this.normalWidth / 0.98), this.normalHeight);
832
    }
833
	
834
	/**
835
	 * Calculo del nuevo tama?o a partir de un frame redimensionado
836
	 * @param w Ancho del frame
837
	 * @param h Alto del frame
838
	 */
839
	public void newFrameSize(int w, int h){
840
		int newWidth = (int)Math.round(w * 0.98);
841
				
842
        this.setSize(new java.awt.Dimension(newWidth, normalHeight ));
843
        this.setPreferredSize(new java.awt.Dimension(newWidth, normalHeight ));
844
        this.getConectorPanel().newFrameSize(newWidth, h);    
845
	}
846
	
847
	/**
848
	 * Elimina un punto de la tabla de puntos
849
	 * @param pos Posici?n del punto a eliminar
850
	 */
851
	public void removeTableValueAt(int pos) throws ArrayIndexOutOfBoundsException{
852
		((DefaultTableModel)getTable().getTable().getModel()).removeRow(pos);
853
	}
854
	
855
	/**
856
	 * A partir de nuevas coordenadas actualiza la vista, minimagen, capa de puntos el
857
	 * dialogo y la tabla.
858
	 *
859
	 */
860
	public void updateData(int nPunto, Point2D pixel, Point2D map, View view){
861
		getPointManager().updateData(nPunto, pixel, map, this, view);
862
	} 
863
	
864
	/**
865
	 * Esta funci?n deshabilita todos los controles y guarda sus valores
866
	 * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
867
	 * se vuelvan a quedar como estaba
868
	 */
869
	public void disableAllControls(){
870
		if(!disableAllControls){
871
			disableAllControls = true;
872
			
873
			//Salvamos los estados
874
			buttonsState[0] = getBProcess().isEnabled();
875
			buttonsState[1] = getBAccept().isEnabled();
876
			buttonsState[2] = getBCancel().isEnabled();
877
			buttonsState[3] = getDialogButtons().getBExportToCSV().isEnabled();
878
			buttonsState[4] = getDialogButtons().getBImportFromCSV().isEnabled();
879
			buttonsState[5] = getDialogButtons().getBLoad().isEnabled();
880
			buttonsState[6] = getDialogButtons().getBSave().isEnabled();
881
			
882
			//Desactivamos controles
883
			getBProcess().setEnabled(false);
884
			getBAccept().setEnabled(false);
885
			getBCancel().setEnabled(false);
886
			
887
			getDialogButtons().getBExportToCSV().setEnabled(false);
888
			getDialogButtons().getBImportFromCSV().setEnabled(false);
889
			getDialogButtons().getBLoad().setEnabled(false);
890
			getDialogButtons().getBSave().setEnabled(false);
891
		}
892
	}
893
	
894
	/**
895
	 * Esta funci?n deja los controles como estaban al ejecutar la funci?n 
896
	 * disableAllControls
897
	 */
898
	public void restoreControlsValue(){
899
		if(disableAllControls){
900
			disableAllControls = false;
901
			getBProcess().setEnabled(buttonsState[0]);
902
			getBAccept().setEnabled(buttonsState[1]);
903
			getBCancel().setEnabled(buttonsState[2]);
904
			getDialogButtons().getBExportToCSV().setEnabled(buttonsState[3]);
905
			getDialogButtons().getBImportFromCSV().setEnabled(buttonsState[4]);
906
			getDialogButtons().getBLoad().setEnabled(buttonsState[5]);
907
			getDialogButtons().getBSave().setEnabled(buttonsState[6]);
908
		}
909
	}
910
	//**********************End Methods***************************
911
	
912
	//**********************Setters & Getters*********************
913
	/**
914
	 * Obtiene la tabla de puntos
915
	 */
916
	public PointTable getTable(){
917
		return this.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getJTable();
918
	}
919
		
920
	/**
921
	 * Asigna un valor a una posici?n de la tabla
922
	 * @param value Valor a asignar
923
	 * @param row	Fila en la que se asigna
924
	 * @param col	Columna en la que se asigna
925
	 */
926
	public void setTableValueAt(String value, int row, int col)throws ArrayIndexOutOfBoundsException{
927
		((DefaultTableModel)getTable().getTable().getModel()).setValueAt(value, row, col);
928
	}
929
	
930
	/**
931
	 * Asigna un valor del checkBox para una fila de la tabla
932
	 * @param row Fila en la que se asigna
933
	 */
934
	public void setCheckValueAt(Boolean value, int row)throws ArrayIndexOutOfBoundsException{
935
		((DefaultTableModel)getTable().getTable().getModel()).setValueAt(value, row, 0);
936
	}
937
	
938
	/**
939
	 * Obtiene el n?mero de filas de la tabla
940
	 * @return N?mero de filas de la tabla
941
	 */
942
	public int getTableRowCount(){
943
		return getTable().getTable().getRowCount();
944
	}
945
	
946
	/**
947
	 * A?ade una nueva fila a la tabla de puntos
948
	 */
949
	public void addTableNew(){
950
		getTable().getTableModel().addNew();
951
	}
952
	/**
953
	 * @return Returns the tmpWidth.
954
	 */
955
	public int getTmpWidth() {
956
		return tmpWidth;
957
	}
958
	/**
959
	 * @param tmpWidth The tmpWidth to set.
960
	 */
961
	public void setTmpWidth(int tmpWidth) {
962
		this.tmpWidth = tmpWidth;
963
	}
964
	/**
965
	 * @return Returns the enlargeHeight.
966
	 */
967
	public int getEnlargeHeight() {
968
		return enlargeHeight;
969
	}
970
	/**
971
	 * @return Returns the normalHeight.
972
	 */
973
	public int getNormalHeight() {
974
		return normalHeight;
975
	}
976

  
977
	/**
978
	 * @return Returns the normalWidth.
979
	 */
980
	public int getNormalWidth() {
981
		return normalWidth;
982
	}
983
	
984
	/**
985
	 * Asigna el valor del campo RMS
986
	 * @param rms Cadena que representa el RMS
987
	 */
988
	public void setRMS(String rms){
989
		this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTRMS().setText(rms);
990
	}
991
	
992
	/**
993
	 * Asigna el valor del campo de residuo en X
994
	 * @param rms Cadena que representa el RMS
995
	 */
996
	public void setResX(String resX){
997
		this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResX().setText(resX);
998
	}
999
	
1000
	/**
1001
	 * Asigna el valor del campo de residuo en Y
1002
	 * @param rms Cadena que representa el RMS
1003
	 */
1004
	public void setResY(String resY){
1005
		this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResY().setText(resY);
1006
	}
1007
	
1008
	/**
1009
	 * Asigna el valor del campo RMS
1010
	 * @param rms Cadena que representa el RMS
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff