Revision 8711

View differences:

trunk/libraries/libJCRS/src/org/gvsig/crs/gui/CRSMainTrPanel.java
172 172
		if (jComboOptions == null){
173 173
			String[] selection = {PluginServices.getText(this, "sin_transformacion"),
174 174
					PluginServices.getText(this, "transformacion_manual"), 
175
					"+"+PluginServices.getText(this, "nadgrids"), 
175
					PluginServices.getText(this, "nadgrids"), 
176 176
					PluginServices.getText(this, "transformacion_epsg")}; 
177 177
			jComboOptions = new JComboBox(selection);
178 178
			jComboOptions.setPreferredSize(new Dimension(150,25));	
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/TreePanel.java
159 159
			}
160 160
		}
161 161
	}
162
	
163
	public void setRoot(String name){
164
		DefaultTreeModel model =(DefaultTreeModel)tree.getModel();
165
		//for (int index = 0; index<model.getChildCount(model.getRoot());index++)
166
		//	model.removeNodeFromParent((DefaultMutableTreeNode)model.getChild(raiz, index));
167
		rootName=name;
168
		raiz =  new DefaultMutableTreeNode(rootName);
169
		model.setRoot(raiz);
170
		map.clear();
171
		
172
	}
162 173
}
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/TransformationNadgridsPanel.java
34 34
import org.gvsig.crs.CrsFactory;
35 35
import org.gvsig.crs.CrsWkt;
36 36
import org.gvsig.crs.ICrs;
37
import org.gvsig.crs.persistence.RecentCRSsPersistence;
37 38

  
38 39
import au.com.objectix.jgridshift.GridShiftFile;
39 40
import au.com.objectix.jgridshift.SubGrid;
......
41 42
import com.iver.andami.PluginServices;
42 43
import com.iver.andami.ui.mdiManager.IWindow;
43 44
import com.iver.andami.ui.mdiManager.WindowInfo;
45
import com.iver.utiles.XMLEntity;
44 46

  
45 47
public class TransformationNadgridsPanel extends DefaultDialogPanel implements IWindow, ActionListener, ItemListener {
46 48
	
......
52 54
	private JRadioButton jRadioButtonTarget = null;
53 55
	
54 56
	private IProjection firstProj;
55
	private String nad = null;
57
	private String nadFile = null;
56 58
	String[] targetAuthority;
57 59
	String targetAbrev = "";
58 60
	String sourceAbrev = "";
......
70 72
	private JComboBox jComboNadFile = null;
71 73
	private JLabel jLabelSelectNad = null;
72 74
	
73
	
74 75
	private JPanel jPanel;	
75
	private JTextArea jTextAreaInfo;	
76
	private JTextArea jTextAreaInfo;
76 77
	
78
	private PluginServices ps = null;
79
	private XMLEntity xml = null;
80
	
77 81
	boolean targetNad = false;
78 82

  
79 83
	public TransformationNadgridsPanel() {
80
		//nad = "+nadgrids=sped2et.gsb";
84
		ps = PluginServices.getPluginServices(RecentCRSsPersistence.pluginClassInstance); 
85
		xml = ps.getPersistentXML();
81 86
	}
82 87
		
83 88
	public JPanel getJPanel(){
......
93 98
									BorderFactory.createEmptyBorder(2,2,2,2)),
94 99
									jPanel.getBorder()));
95 100
			jPanel.add(getJPanelOpen());
101
			nadFile = restoreNadFileName();
96 102
			jPanel.add(getJPanelSelectNad());
97 103
			jPanel.add(getJLabelChooser());
98 104
			jPanel.add(getGroupRadioButton());
99
			initializeTreeList();
105
			initializeTree();
100 106
			jPanel.add(getTreePanel());
101 107
		}
102 108
		return jPanel;
......
202 208
				setNad(false);
203 209
				crs = new CrsFactory().getCRS(getCode(),
204 210
						getWKT());
205
				crs.setNadGrid(nad);
211
				crs.setNadGrid("+nadgrids="+nadFile);
206 212
				return crs;
207 213
			} catch (org.gvsig.crs.CrsException e) {
208 214
				e.printStackTrace();
......
214 220
			try {
215 221
				crs = new CrsFactory().getCRS(getCode(),
216 222
						getWKT());
217
				crs.setNadGrid(nad);
223
				crs.setNadGrid("+nadgrids="+nadFile);
218 224
				crs.setNadInTarget(true);
219 225
				
220 226
				return crs;
......
309 315
	            File inFile = openFileChooser.getSelectedFile();
310 316
	            //jTextOpen.setText(file.getAbsolutePath());
311 317

  
318
	            String fileName = inFile.getName();
319
	            
320
	            //Comprobar que el fichero existe y tiene formato valido
321
	    		RandomAccessFile raFile = null;
322
	    		try {
323
	    			raFile = new RandomAccessFile(inFile.getAbsolutePath(),"r");
324
	    		} catch (FileNotFoundException ex) {
325
	    			ex.printStackTrace();
326
	    			getJComboNadFile().setSelectedIndex(0);
327
	    			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_not_found"));
328
	    			nadFile = null;
329
	    			return;
330
	    		}
331
	    		GridShiftFile gsf = new GridShiftFile();
332
	    		try {
333
	    			gsf.loadGridShiftFile(raFile);
334
	    		} catch (IOException ex) {
335
	    			ex.printStackTrace();
336
	    			getJComboNadFile().setSelectedIndex(0);
337
	    			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_bad_format"));
338
	    			nadFile = null;
339
	    			return;
340
	    		}catch (java.lang.Exception ex) {
341
	    			ex.printStackTrace();
342
	    			getJComboNadFile().setSelectedIndex(0);
343
	    			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_bad_format"));
344
	    			nadFile = null;
345
	    			return;
346
	    		}
347
	            
312 348
	            //Copiar el fichero seleccionado al directorio data de la extensi?n:
313 349
	            
314
	            String fileName = inFile.getName();
315 350
	    		File outFile = new File(dataPath+fileName);
316 351
	    		InputStream in = null;
317 352
	    		OutputStream out = null;
......
341 376
	    		if(!exists)
342 377
		    		getJComboNadFile().addItem(fileName);
343 378
	    		getJComboNadFile().setSelectedItem(fileName);
344
	    		nad = "+nadgrids="+fileName;
379
	    		nadFile = fileName;
345 380
	        }
346 381
		}
347 382
	}
348 383

  
349 384
	public TreePanel getTreePanel() {
350 385
		if (treePanel == null){
351
			treePanel = new TreePanel(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb");
386
			treePanel = new TreePanel(PluginServices.getText(this,"grids_en")+": "+nadFile);
352 387
			treePanel.getTree().expandRow(0);
353 388
			treePanel.setPanelSize(530,200);
354 389
		}
355 390
		return treePanel;
356 391
	}
357 392
	
358
	private void initializeTreeList(){
393
	private void initializeTree(){
359 394
		// leer el fichero nadgrids
360 395
		RandomAccessFile raFile = null;
361 396
		try {
362
			raFile = new RandomAccessFile("./gvSIG/extensiones/org.gvsig.crs/data/sped2et.gsb","r");
397
			raFile = new RandomAccessFile("./gvSIG/extensiones/org.gvsig.crs/data/"+nadFile,"r");
363 398
		} catch (FileNotFoundException e) {
364
			// TODO Auto-generated catch block
365 399
			e.printStackTrace();
400
			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_not_found"));
401
			return;
366 402
		}
367 403
		GridShiftFile gsf = new GridShiftFile();
368 404
		try {
369 405
			gsf.loadGridShiftFile(raFile);
370 406
		} catch (IOException e) {
371
			// TODO Auto-generated catch block
372 407
			e.printStackTrace();
408
			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_bad_format"));
409
			return;
410
		}catch (java.lang.Exception e) {
411
			e.printStackTrace();
412
			getTreePanel().setRoot(PluginServices.getText(this,"nadfile_bad_format"));
413
			return;
373 414
		}
374 415
		
375 416
		SubGrid subGrid[] = gsf.getSubGridTree(); 
376 417
		
377 418
		for (int i=0;i<subGrid.length;i++){
378 419
			getTreePanel().addClass(subGrid[i].getSubGridName(),i);
379
			getTreePanel().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMinLon()),subGrid[i].getSubGridName(), "");
380
			getTreePanel().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()),subGrid[i].getSubGridName(), "");
381
			getTreePanel().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMaxLon()),subGrid[i].getSubGridName(), "");
382
			getTreePanel().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()),subGrid[i].getSubGridName(), "");
420
			getTreePanel().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMaxLon()/-3600)+"?",subGrid[i].getSubGridName(), "");
421
			getTreePanel().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()/3600)+"?",subGrid[i].getSubGridName(), "");
422
			getTreePanel().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMinLon()/-3600+"?"),subGrid[i].getSubGridName(), "");
423
			getTreePanel().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()/3600+"?"),subGrid[i].getSubGridName(), "");
383 424
			getTreePanel().addEntry(PluginServices.getText(this,"node_count")+": "+String.valueOf(subGrid[i].getNodeCount()),subGrid[i].getSubGridName(), "");
384 425
			getTreePanel().addEntry(PluginServices.getText(this,"detalles")+": "+String.valueOf(subGrid[i].getDetails()),subGrid[i].getSubGridName(), "");
385 426
		}
......
399 440
				if (dataDir.list()[i].substring(dataDir.list()[i].lastIndexOf('.')+1).equals("gsb")){
400 441
					jComboNadFile.addItem(dataDir.list()[i]);
401 442
				}
402
			if (jComboNadFile.getItemCount()>1){
403
				jComboNadFile.setSelectedIndex(1);
404
				nad = "+nadgrids="+jComboNadFile.getItemAt(1).toString();
405
			}
443
			if (nadFile != null)
444
				jComboNadFile.setSelectedItem(nadFile);
445
			
446
			jComboNadFile.addItemListener(this);
406 447
		}
407 448
		return jComboNadFile;
408 449
	}
......
428 469
	}
429 470

  
430 471
	public void itemStateChanged(ItemEvent e) {
431
		if (getJComboNadFile().getSelectedIndex()==0)
432
			nad = "+nadgrids="+getJComboNadFile().getSelectedItem().toString();
472
		if (getJComboNadFile().getSelectedIndex()!=0){
473
			nadFile = getJComboNadFile().getSelectedItem().toString();
474
			getTreePanel().setRoot(PluginServices.getText(this,"grids_en")+": "+nadFile);
475
			initializeTree();
476
			// Guardar en persistencia nadFile:
477
			saveNadFileName(nadFile);
478
			
479
		}
480
		else{
481
			nadFile = null;
482
			getTreePanel().setRoot("");
483
		}
484
		
433 485
	}
434 486
	
487
	/**
488
	 * Guarda el nombre del fichero nadgrids mediante el modelo de persistencia
489
	 * de Andami
490
	 * @param name Nombre del fichero ndagrids
491
	 */
492
	private void saveNadFileName(String name){
493
		ps = PluginServices.getPluginServices(RecentCRSsPersistence.pluginClassInstance); 
494
		xml = ps.getPersistentXML();
495
		
496
		for (int child = 0; child<xml.getChildrenCount();child++)
497
			if (xml.getChild(child).getPropertyName(0).equals("nadFile"))
498
				xml.removeChild(child);
499
		
500
		
501
		XMLEntity xmlEnt = new XMLEntity();
502
		xmlEnt.putProperty("nadFile",name);
503
		xml.addChild(xmlEnt);
504
		ps.setPersistentXML(xml);
505
	}
506
	
507
	/**
508
	 * Obtiene el nombre del fichero nadgrids guardado mediante el
509
	 * modelo de persistencia de Andami.
510
	 * 
511
	 * @return nombre del fichero nadgrids o null si no ha sido guardado.
512
	 */
513
	private String restoreNadFileName(){
514
		String fileName;
515
		for (int child = 0; child<xml.getChildrenCount();child++)
516
			if (xml.getChild(child).getPropertyName(0).equals("nadFile")){
517
				fileName = xml.getChild(child).getPropertyValue(0);
518
				File dataDir = new File(dataPath);
519
				for (int i = 0; i<dataDir.list().length;i++)
520
					if (dataDir.list()[i].equals(fileName)){
521
						return fileName;
522
					}
523
			}
524
		
525
		return null;
526
	}
527
	
435 528
}
436 529

  
437 530
class FiltroNadgrids extends FileFilter {
trunk/libraries/libJCRS/src/org/gvsig/crs/persistence/RecentCRSsPersistence.java
61 61
 */
62 62
public class RecentCRSsPersistence {
63 63
	private XMLEntity xml = null;
64
	private XMLEntity recentsXml = null;
64 65
	private PluginServices ps = null;
66
	private static final String CRS_RECENTS = "recentCrss";
65 67
	private static final String CRS_AUTHORITY = "authority";
66 68
	private static final String CRS_NAME = "name";
67 69
	private static final String CRS_CODE = "code";
......
78 80
	public RecentCRSsPersistence(Object pluginClassInstance){
79 81
		ps = PluginServices.getPluginServices(pluginClassInstance);
80 82
		xml = ps.getPersistentXML();
83
		for (int child = 0; child<xml.getChildrenCount();child++)
84
			if (xml.getChild(child).getPropertyValue(0).equals(CRS_RECENTS))
85
				recentsXml = xml.getChild(child); 
86
		if (recentsXml == null){
87
			XMLEntity xmlEntity = new XMLEntity();
88
			xmlEntity.putProperty("groupName", CRS_RECENTS);
89
			xml.addChild(xmlEntity);
90
			recentsXml = xmlEntity;
91
		}
81 92
	}
82 93
	
83 94
	/**
......
86 97
	public RecentCRSsPersistence(){
87 98
		ps = PluginServices.getPluginServices(pluginClassInstance);
88 99
		xml = ps.getPersistentXML();
100
		for (int child = 0; child<xml.getChildrenCount();child++)
101
			if (xml.getChild(child).getPropertyValue(0).equals(CRS_RECENTS))
102
				recentsXml = xml.getChild(child); 
103
		if (recentsXml == null){
104
			XMLEntity xmlEntity = new XMLEntity();
105
			xmlEntity.putProperty("groupName", CRS_RECENTS);
106
			xml.addChild(xmlEntity); 
107
			recentsXml = xmlEntity;
108
		}
89 109
	}
90 110

  
91 111
	/**
......
102 122
	 * Array of crss
103 123
	 */
104 124
	public void setArrayOfCrsData(CrsData[] crss){
105
		xml.getXmlTag().removeAllXmlTag();
125
		recentsXml.getXmlTag().removeAllXmlTag();
106 126

  
107 127
		for (int i=0 ; i<crss.length ; i++){
108
			xml.addChild(crsDataToXml(crss[i]));
128
			recentsXml.addChild(crsDataToXml(crss[i]));
109 129
		}
110 130

  
111 131
	}
......
157 177
	 * CrsData[]
158 178
	 */
159 179
	public CrsData[] getArrayOfCrsData(){
160
		CrsData[] crss = new CrsData[xml.getChildrenCount()];
161
		for (int i=0 ; i<xml.getChildrenCount() ; i++){
162
			crss[i] = xmlToCrsData(xml.getChild(i));
180
		CrsData[] crss = new CrsData[recentsXml.getChildrenCount()];
181
		for (int i=0 ; i<recentsXml.getChildrenCount() ; i++){
182
			crss[i] = xmlToCrsData(recentsXml.getChild(i));
163 183
		}
164 184
		
165 185
		/*
trunk/extensions/extJCRS/config/text.properties
1 1
#Translations for language [es]
2 2
#Mon Sep 25 09:47:23 CEST 2006
3 3
abrir=Abrir
4
advertencia_nad=IMPORTANTE: La transformaci?n se aplicar? dentro de los l?mites de las rejillas. Fuera de estos se aplica una conversi?n.
4
advertencia_nad=IMPORTANTE: La transformaci?n se aplicar? dentro de los l?mites de las rejillas.
5 5
anterior=Anterior
6 6
aplicar_capa=CRS de la capa
7 7
aplicar_vista=CRS de la vista
......
37 37
lat_min=Latitud m?nima
38 38
long_max=Longitud m?xima 
39 39
long_min=Longitud m?nima
40
nadgrids=nadgrids
40
nadfile_not_found=No se encuentra el fichero de rejillas.
41
nadfile_bad_format=No se reconoce el formato del fichero de rejillas.
42
nadgrids=Rejillas
41 43
name_transformation=Nombre de la Transformaci?n
42 44
no=No
43 45
no_results=No se han encontrado resultados
......
57 59
proyeccion_actual=Proyecci?n actual
58 60
scale=Escala
59 61
seleccionar=Seleccionar
60
seleccion_nadgrids=Nadgrids asociado a
62
seleccion_nadgrids=Fichero rejilla calculado en
61 63
selecciona_sistema_de_referencia=Selecciona Sistema de Referencia
62 64
seleccionar_crs=Selecionar CRS
63 65
seleccione_crs_capa=Seleccione CRS de la capa

Also available in: Unified diff