Revision 8676

View differences:

trunk/libraries/libJCRS/.classpath
9 9
	<classpathentry kind="lib" path="lib/jGridShiftApi.jar"/>
10 10
	<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/>
11 11
	<classpathentry kind="lib" path="/libCq CMS for java/lib/jogr.jar"/>
12
	<classpathentry sourcepath="/Utiles/src" kind="lib" path="/_fwAndami/lib/iver-utiles.jar"/>
13
	<classpathentry sourcepath="/libUI/src" kind="lib" path="/_fwAndami/lib/beans.jar"/>
14
	<classpathentry sourcepath="/libInternationalization/src" kind="lib" path="/_fwAndami/lib/gvsig-i18n.jar"/>
15
	<classpathentry kind="lib" path="/libCq CMS for java/lib/gvsig-ui.jar"/>
12
	<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/Utiles/src"/>
13
	<classpathentry kind="lib" path="/_fwAndami/lib/beans.jar" sourcepath="/libUI/src"/>
14
	<classpathentry kind="lib" path="/_fwAndami/lib/gvsig-i18n.jar" sourcepath="/libInternationalization/src"/>
16 15
	<classpathentry kind="output" path="bin"/>
17 16
</classpath>
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/TransformationNadgridsPanel.java
28 28
import org.gvsig.crs.CrsFactory;
29 29
import org.gvsig.crs.CrsWkt;
30 30
import org.gvsig.crs.ICrs;
31
import org.gvsig.gui.beans.treelist.TreeListContainer;
32 31

  
33 32
import au.com.objectix.jgridshift.GridShiftFile;
34 33
import au.com.objectix.jgridshift.SubGrid;
......
60 59
	private JTextField jTextOpen;
61 60
	private JFileChooser openFileChooser;
62 61
	private JButton jButtonOpen;
63
	private TreeListContainer treeList = null;
62
	//private TreeListContainer treeList = null;
63
	private TreePanel treePanel = null;
64 64
	
65 65
	
66 66
	private JPanel jPanel;	
......
89 89
			jPanel.add(getJLabelChooser());
90 90
			jPanel.add(getGroupRadioButton());
91 91
			initializeTreeList();
92
			jPanel.add(getTreeList());
92
			jPanel.add(getTreePanel());
93 93
		}
94 94
		return jPanel;
95 95
	}
......
203 203
			try {
204 204
				setNad(false);
205 205
				crs = new CrsFactory().getCRS(getCode(),
206
						getWKT(),nad);
206
						getWKT());
207
				crs.setNadGrid(nad);
207 208
				return crs;
208 209
			} catch (org.gvsig.crs.CrsException e) {
209 210
				e.printStackTrace();
......
215 216
			try {
216 217
				crs = new CrsFactory().getCRS(getCode(),
217 218
						getWKT());
218
				crs.setNadTarget(nad);
219
				crs.setNadGrid(nad);
220
				crs.setNadInTarget(true);
219 221
				
220 222
				return crs;
221 223
			} catch (CrsException e) {				
......
312 314
		}
313 315
	}
314 316

  
315
	public TreeListContainer getTreeList() {
316
		if (treeList == null){
317
	public TreePanel getTreePanel() {
318
		/*if (treeList == null){
317 319
			treeList = new TreeListContainer(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb");
318 320
			treeList.getTree().expandRow(0);
319 321
			treeList.setComponentSize(530,220);
320 322
		}
321
		return treeList;
323
		return treeList;*/
324
		if (treePanel == null){
325
			treePanel = new TreePanel(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb");
326
			treePanel.getTree().expandRow(0);
327
			treePanel.setPanelSize(530,220);
328
		}
329
		return treePanel;
322 330
	}
323 331
	
324 332
	private void initializeTreeList(){
......
341 349
		SubGrid subGrid[] = gsf.getSubGridTree(); 
342 350
		
343 351
		for (int i=0;i<subGrid.length;i++){
344
			getTreeList().addClass(subGrid[i].getSubGridName(),i);
345
			getTreeList().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMinLon()),subGrid[i].getSubGridName(), "");
346
			getTreeList().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()),subGrid[i].getSubGridName(), "");
347
			getTreeList().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMaxLon()),subGrid[i].getSubGridName(), "");
348
			getTreeList().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()),subGrid[i].getSubGridName(), "");
349
			getTreeList().addEntry(PluginServices.getText(this,"node_count")+": "+String.valueOf(subGrid[i].getNodeCount()),subGrid[i].getSubGridName(), "");
350
			getTreeList().addEntry(PluginServices.getText(this,"detalles")+": "+String.valueOf(subGrid[i].getDetails()),subGrid[i].getSubGridName(), "");
352
			getTreePanel().addClass(subGrid[i].getSubGridName(),i);
353
			getTreePanel().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMinLon()),subGrid[i].getSubGridName(), "");
354
			getTreePanel().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()),subGrid[i].getSubGridName(), "");
355
			getTreePanel().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMaxLon()),subGrid[i].getSubGridName(), "");
356
			getTreePanel().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()),subGrid[i].getSubGridName(), "");
357
			getTreePanel().addEntry(PluginServices.getText(this,"node_count")+": "+String.valueOf(subGrid[i].getNodeCount()),subGrid[i].getSubGridName(), "");
358
			getTreePanel().addEntry(PluginServices.getText(this,"detalles")+": "+String.valueOf(subGrid[i].getDetails()),subGrid[i].getSubGridName(), "");
351 359
		}
352
		getTreeList().getTree().expandRow(0);
360
		getTreePanel().getTree().expandRow(0);
361
		getTreePanel().getList().setText(PluginServices.getText(this,"advertencia_nad"));
353 362
	}
354 363
	
355 364
}
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/TreePanel.java
1
package org.gvsig.crs.gui.panels;
2

  
3
import java.awt.FlowLayout;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.util.Hashtable;
7

  
8
import javax.swing.JPanel;
9
import javax.swing.JScrollPane;
10
import javax.swing.JTextArea;
11
import javax.swing.JTree;
12
import javax.swing.tree.DefaultMutableTreeNode;
13
import javax.swing.tree.DefaultTreeModel;
14

  
15
/**
16
 * 
17
 * @author Diego Guerrero (diego.guerrero@uclm.es)
18
 *
19
 */
20
public class TreePanel extends JPanel {
21
	
22
	private int 		wComp = 190;
23
	private int 		hComp = 360;
24
	private int 		hTree = (int)Math.floor(hComp * 0.68);
25
	private int 		hList = hComp - hTree;
26
	private JScrollPane pTree = null;
27
	private JScrollPane pList = null;
28
	private JTree tree = null;
29
	//private JList list = null;
30
	private JTextArea list = null;
31
	private DefaultMutableTreeNode raiz = null;
32
	private Hashtable	map;
33
	String rootName = "";
34

  
35
	public TreePanel(String rootName) {
36
		super();
37
		this.rootName = rootName;
38
		initialize();
39
	}
40
	
41
	private void initialize() {
42
		map = new Hashtable();
43
		raiz =  new DefaultMutableTreeNode(rootName);
44
        FlowLayout flowLayout = new FlowLayout();
45
        flowLayout.setHgap(0);
46
        flowLayout.setVgap(0);
47
        this.setLayout(flowLayout);
48
		
49
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
50
		gridBagConstraints1.gridx = 0;
51
		gridBagConstraints1.gridy = 1;
52
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
53
		gridBagConstraints.gridx = 0;
54
		gridBagConstraints.gridy = 0;
55
		setLayout(new GridBagLayout());
56
		setPreferredSize(new java.awt.Dimension(wComp,hComp));
57
		add(getPTree(), gridBagConstraints);
58
		add(getPList(), gridBagConstraints1);
59

  
60
	}
61
	
62
	/**
63
	 * This method initializes jPanel	
64
	 * 	
65
	 * @return javax.swing.JPanel	
66
	 */
67
	private JScrollPane getPTree() {
68
		if (pTree == null) {
69
			pTree = new JScrollPane();
70
			pTree.setPreferredSize(new java.awt.Dimension(wComp, hTree));
71
			pTree.setViewportBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
72
			pTree.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
73
			pTree.setViewportView(getTree());
74
		}
75
		return pTree;
76
	}
77

  
78
	/**
79
	 * This method initializes jPanel1	
80
	 * 	
81
	 * @return javax.swing.JPanel	
82
	 */
83
	private JScrollPane getPList() {
84
		if (pList == null) {
85
			pList = new JScrollPane();
86
			pList.setPreferredSize(new java.awt.Dimension(wComp, hList));
87
			pList.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
88
			pList.setBackground(java.awt.Color.white);
89
			pList.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
90
			pList.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
91
			pList.setViewportView(getList());
92
		}
93
		return pList;
94
	}
95

  
96
	/**
97
	 * This method initializes jTree	
98
	 * 	
99
	 * @return javax.swing.JTree	
100
	 */
101
	public JTree getTree() {
102
		if (tree == null) {
103
			tree = new JTree(raiz);
104
		}
105
		return tree;
106
	}
107

  
108
	/**
109
	 * This method initializes jList	
110
	 * 	
111
	 * @return javax.swing.JList	
112
	 */
113
	public JTextArea getList() {
114
		if (list == null) {
115
			list = new JTextArea();
116
			list.setLineWrap(true);
117
			list.setWrapStyleWord(true);
118
			list.setEditable(false);
119
		}
120
		return list;
121
	}
122
	
123
	public void setPanelSize(int w, int h){
124
		wComp = w;
125
		hComp = h;
126
		hTree = (int)Math.floor(hComp * 0.68);
127
		hList = hComp - hTree;
128
        this.setPreferredSize(new java.awt.Dimension(wComp, hComp));
129
		setPreferredSize(new java.awt.Dimension(wComp, hComp));
130
		pTree.setPreferredSize(new java.awt.Dimension(wComp, hTree));
131
		pList.setPreferredSize(new java.awt.Dimension(wComp, hList));
132
	}
133
	
134
	/**
135
	 * A?ade una nueva categoria al arbol
136
	 * @param name	Etiqueta que aparece en el arbol. 
137
	 * @param pos	Posici?n en el arbol de la nueva categoria
138
	 */
139
	public void addClass(String name, int pos){
140
		DefaultTreeModel model =(DefaultTreeModel)tree.getModel();
141
		DefaultMutableTreeNode r = new DefaultMutableTreeNode( name );
142
		model.insertNodeInto(r, raiz, pos);
143
	}
144
	
145
	/**
146
	 * A?ade una entrada a una categoria
147
	 * @param name Nombre de la entrada a a?adir
148
	 * @param parentName Categoria a la que a?adimos
149
	 * @param value Valor asociado a la entrada
150
	 */
151
	public void addEntry(String name, String parentName, String value){
152
		DefaultTreeModel model =(DefaultTreeModel)tree.getModel();
153
		for(int i = 0; i < model.getChildCount(raiz); i++){
154
			if(model.getChild(raiz, i).toString().equals(parentName)){
155
				DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getChild(raiz, i);
156
				node.add(new DefaultMutableTreeNode(name));
157
				if (value!=null)
158
					map.put(name,value);
159
			}
160
		}
161
	}
162
}
0 163

  
trunk/libraries/libJCRS/src/org/gvsig/crs/Crs.java
396 396
		return this.wkt;
397 397
	}
398 398
	
399
	public void setNadTarget(String nad){
399
	public void setNadGrid(String nad){
400 400
		this.nad = nad;
401 401
	}
402 402
	
403
	public String getNadTarget(){
403
	public String getNadGrid(){
404 404
		return this.nad;
405 405
	}
406 406
	
407 407
	public ICOperation getCOp(ICrs target) throws CrsException {		
408
		if (!this.getNadTarget().equals("")) {			
409
			ICrs crs = new Crs(target.getCode(), target.getWKT(), this.getNadTarget());
408
		if (!this.getNadGrid().equals("")) {			
409
			ICrs crs = new Crs(target.getCode(), target.getWKT(), this.getNadGrid());
410 410
			return new COperation(this, crs);
411 411
		}
412 412
		else return new COperation(this, target);
413 413
	}
414 414
	
415
	protected CrsProj getCrsEpsg() {
415
	protected CrsProj getCrsProj() {
416 416
		return crsProj4;
417 417
	}
418 418

  
......
434 434
	}
435 435

  
436 436
	public ICoordTrans getCT(IProjection dest) {
437
		ICrs crs = (ICrs) dest;		
437
		COperation operation = null;
438
		Crs crsDest = (Crs)dest;
438 439
		try {
439
			if (!this.getNadTarget().equals("")) {
440
				crs = new Crs(crs.getCode(), crs.getWKT(), this.getNadTarget());
440
			operation = new COperation(this, (ICrs)dest);
441
		} catch (CrsException e) {
442
			// TODO Auto-generated catch block
443
			e.printStackTrace();
444
		}
445
		
446
		if (!getNadGrid().equals("")){
447
			if (isTargetNad())
448
				operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getNadGrid()), true);
449
			else
450
				operation.setNadCrsProj(new CrsProj(getProj4()+getNadGrid()), false);
451
			
452
			return operation;
453
		}
454
		
455
		return operation;
456
		
457
		/*ICrs crs = (ICrs) dest;		
458
		try {
459
			if (!this.getNadGrid().equals("")) {
460
				crs = new Crs(crs.getCode(), crs.getWKT(), this.getNadGrid());
441 461
				return new COperation(this, crs);
442 462
			}
443 463
			else return new COperation(this, crs);
......
445 465
			// TODO Auto-generated catch block
446 466
			e.printStackTrace();
447 467
		}
448
		return null;
468
		return null;*/
449 469
	}
450 470
	
451 471
	public Point2D toGeo(Point2D pt) {
......
508 528
		// TODO Auto-generated method stub
509 529
		return null;
510 530
	}
531

  
532
	public boolean isTargetNad() {
533
		return targetNad;
534
	}
535

  
536
	public void setNadInTarget(boolean targetNad) {
537
		this.targetNad = targetNad;
538
	}
539

  
540
	public String getProj4() {
541
		return proj4;
542
	}
511 543
	
512 544
}
trunk/libraries/libJCRS/src/org/gvsig/crs/ICrs.java
31 31
	
32 32
	/**
33 33
	 * M?todo para la aplicaci?n de la propiedad de nadgrids
34
	 * sobre el CRS destino (el de la vista) 
34
	 * sobre el CRS destino o fuente 
35 35
	 * @param nad
36 36
	 */
37
	void setNadTarget(String nad);
37
	void setNadGrid(String nad);
38 38
	
39 39
	/**
40
	 * Cadena nadgrids a utilizar por el CRS de la vista
40
	 * Cadena nadgrids a utilizar en el crs fuente o destino en una transformacion
41 41
	 * @return
42 42
	 */
43
	String getNadTarget();
43
	String getNadGrid();
44 44
	
45 45
	/**
46
	 * true si el nadgrid se asocia al crs destino
47
	 * @return
48
	 */
49
	boolean isTargetNad();
50

  
51
	/**
52
	 * Le indicamos al crs si el nadgrid est? asociado al crs destion al fuente
53
	 * en una transformaci?n.
54
	 * @param targetNad true si el nadgrid se asocia al crs destino
55
	 * @return
56
	 */
57
	void setNadInTarget(boolean targetNad);
58
	
59
	
60
	/**
46 61
	 * Obtiene una operaci?n de cambio de CRS.
47 62
	 * @param target
48 63
	 * @return
trunk/libraries/libJCRS/src/org/gvsig/crs/COperation.java
5 5

  
6 6
import org.cresques.cts.ICoordTrans;
7 7
import org.cresques.cts.IProjection;
8
import org.gvsig.crs.proj.CrsProj;
8 9
import org.gvsig.crs.proj.CrsProjException;
9 10
import org.gvsig.crs.proj.JNIBaseCrs;
10 11
import org.gvsig.crs.proj.OperationCrsException;
......
14 15
public class COperation implements ICOperation {
15 16
	private Crs sourceCrs;
16 17
	private Crs targetCrs;
18
	private CrsProj nadCrsProj = null;
19
	private boolean nadInTarget;
17 20
	public COperation(ICrs from, ICrs to) throws CrsException {
18 21
		sourceCrs = (Crs) from;
19 22
		targetCrs = (Crs) to;
......
31 34
		double x[] = {pt.getX()};
32 35
		double y[] = {pt.getY()};
33 36
		double z[] = {0D};
37
		int errno = 0;
34 38
		try {
35
			JNIBaseCrs.operate( x , y, z,
36
				sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg());
39
			if (nadCrsProj != null){
40
				if (nadInTarget)
41
					errno = JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), nadCrsProj);
42
				else
43
					errno = JNIBaseCrs.operate( x , y, z,nadCrsProj,targetCrs.getCrsProj());
44
				if (errno != -38)
45
					return new Point2D.Double(x[0],y[0]);
46
			}
47
			
48
			// Si el punto estaba fuera del ?mbito del nadgrid operamos sin nadgrid (convertimos)
49
			x[0] = pt.getX();
50
			y[0] = pt.getY();
51
			z[0] = 0D;
52
			JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), targetCrs.getCrsProj());
53
			return new Point2D.Double(x[0],y[0]);
54
			
37 55
		} catch (OperationCrsException e) {
38 56
			throw new CrsException(e);
39 57
		} catch (CrsProjException e) {
......
43 61
	//	if(!targetCrs.isProjected())
44 62
	//		return new Point2D.Double(x[0]*((180)/Math.PI),y[0]*((180)/Math.PI));
45 63
	//	else
46
			return new Point2D.Double(x[0],y[0]);
47 64
	}
48 65

  
49 66
	public double [] operate(double []ptOrig) throws CrsException {
50 67
		double x[] = {ptOrig[0]};
51 68
		double y[] = {ptOrig[1]};
52 69
		double z[] = {ptOrig[2]};
70
		int errno = 0;
53 71
		try {
54
			JNIBaseCrs.operate(x, y, z,
55
				sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg());
72
			if (nadCrsProj != null){
73
				if (nadInTarget)
74
					errno = JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), nadCrsProj);
75
				else
76
					errno = JNIBaseCrs.operate( x , y, z,nadCrsProj,targetCrs.getCrsProj());
77
				if (errno != -38){
78
					double ptDest[] = {x[0], y[0], z[0]};
79
					return ptDest;
80
				}
81
			}
82
			
83
			// Si el punto estaba fuera del ?mbito del nadgrid operamos sin nadgrid (convertimos)
84
			 x[0] = ptOrig[0];
85
			 y[0] = ptOrig[1];
86
			 z[0] = ptOrig[2];
87
			 JNIBaseCrs.operate(x, y, z,sourceCrs.getCrsProj(), targetCrs.getCrsProj());
88
			 double ptDest[] = {x[0], y[0], z[0]};
89
			 return ptDest;
56 90
		} catch (OperationCrsException e) {
57 91
			throw new CrsException(e);
58 92
		} catch (CrsProjException e) {
59 93
			throw new CrsException(e);
60 94
		}
61

  
62
		double ptDest[] = {x[0], y[0], z[0]};
63
		return ptDest;
64 95
	}
65 96

  
66 97
	public IProjection getPOrig() {
......
105 136
		return null;
106 137
	}
107 138
	
139
	public void setNadCrsProj(CrsProj nadCrs, boolean inTarget){
140
		this.nadInTarget = inTarget;
141
		this.nadCrsProj = nadCrs;
142
	}
108 143
}

Also available in: Unified diff