svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / tools / PointCalibrate.java @ 4827
History | View | Annotate | Download (4.18 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: PointCalibrate.java 4827 2006-04-12 06:51:56Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.7 2006-04-12 06:51:35 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.5 2006/04/11 13:27:30 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.4 2006/04/11 13:25:54 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.3 2006/04/11 13:19:51 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.2 2006/04/10 11:21:52 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.1 2006/04/07 12:45:55 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
*
|
65 |
*/
|
66 |
package org.gvsig.gps.tools; |
67 |
|
68 |
import java.awt.Component; |
69 |
import java.awt.Cursor; |
70 |
import java.awt.geom.Point2D; |
71 |
|
72 |
import javax.swing.JOptionPane; |
73 |
|
74 |
import org.cresques.cts.ICoordTrans; |
75 |
import org.cresques.cts.IProjection; |
76 |
import org.cresques.cts.ProjectionPool; |
77 |
import org.cresques.cts.gt2.CoordSys; |
78 |
import org.cresques.cts.gt2.CoordTrans; |
79 |
import org.gvsig.gps.GPSDriver; |
80 |
import org.gvsig.gps.panel.GPSConfigPanel; |
81 |
|
82 |
import com.iver.andami.PluginServices; |
83 |
import com.iver.andami.ui.mdiManager.SingletonView; |
84 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
85 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
86 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
87 |
import com.iver.cit.gvsig.gui.View; |
88 |
|
89 |
public class PointCalibrate implements PointListener { |
90 |
|
91 |
private View view; |
92 |
private Cursor cur = java.awt.Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); |
93 |
private String previousToolName; |
94 |
|
95 |
public PointCalibrate(View v, String previousToolName) { |
96 |
this.view = v;
|
97 |
this.previousToolName = previousToolName;
|
98 |
} |
99 |
|
100 |
public void point(PointEvent event) throws BehaviorException { |
101 |
Point2D pReal = view.getMapControl().getMapContext().getViewPort().toMapPoint(event.getPoint());
|
102 |
|
103 |
// the geodesic projection
|
104 |
IProjection latLonProj = ProjectionPool.get("EPSG:4326");
|
105 |
|
106 |
// create a translator from view's projection to geodesic to the current
|
107 |
ICoordTrans ct = new CoordTrans((CoordSys) view.getMapControl().getProjection(), (CoordSys) latLonProj);
|
108 |
|
109 |
Point2D pGeo = new Point2D.Double(); |
110 |
pGeo = ct.convert(pReal, pGeo); |
111 |
GPSDriver gps = GPSDriver.getInstance(); |
112 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "LON: "+ pGeo.getX() + "\nLAT: "+pGeo.getY()); |
113 |
Point2D currPos = gps.getCurrentPosition();
|
114 |
if (currPos!=null) |
115 |
gps.setPosOffset(currPos.getX() - pGeo.getX(), currPos.getY() - pGeo.getY()); |
116 |
else
|
117 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "gps_not_ready") ); |
118 |
|
119 |
view.getMapControl().setTool(previousToolName); |
120 |
com.iver.andami.ui.mdiManager.View views[] = PluginServices.getMDIManager().getAllViews();
|
121 |
for (int i = 0; i < views.length; i++) { |
122 |
if (views[i] instanceof SingletonView) { |
123 |
SingletonView s = (SingletonView) views[i]; |
124 |
if (s.getViewModel().equals(GPSConfigPanel.viewModel))
|
125 |
PluginServices.getMDIManager().addView(s); |
126 |
} |
127 |
} |
128 |
|
129 |
} |
130 |
|
131 |
public void pointDoubleClick(PointEvent event) throws BehaviorException {} |
132 |
|
133 |
public Cursor getCursor() { |
134 |
return cur;
|
135 |
} |
136 |
|
137 |
public boolean cancelDrawing() { |
138 |
return false; |
139 |
} |
140 |
|
141 |
} |