Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / tools / PointCalibrate.java @ 13455

History | View | Annotate | Download (5.65 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 13455 2007-09-03 11:50:04Z jaume $
45
* $Log$
46
* Revision 1.18  2007-09-03 11:50:04  jaume
47
* removed unnecessary imports
48
*
49
* Revision 1.17  2006/10/18 07:56:41  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.16  2006/10/02 06:34:51  jaume
53
* refactoring gvSIG documents
54
*
55
* Revision 1.15  2006/09/29 14:12:51  luisw2
56
* CRSFactory.getCRS substitutes ProjectionPool.get
57
*
58
* Revision 1.14  2006/09/20 13:21:14  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.13  2006/09/18 08:02:46  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.12  2006/09/14 07:06:00  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.11  2006/08/29 11:52:17  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.10  2006/08/29 07:45:35  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.9  2006/07/31 06:46:02  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.7  2006/04/12 06:51:35  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.5  2006/04/11 13:27:30  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.4  2006/04/11 13:25:54  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.3  2006/04/11 13:19:51  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.2  2006/04/10 11:21:52  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.1  2006/04/07 12:45:55  jaume
92
* *** empty log message ***
93
*
94
*
95
*/
96
package org.gvsig.gps.tools;
97

    
98
import java.awt.Component;
99
import java.awt.Cursor;
100
import java.awt.geom.Point2D;
101

    
102
import javax.swing.JOptionPane;
103

    
104
import org.cresques.cts.ICoordTrans;
105
import org.cresques.cts.IProjection;
106
import org.gvsig.gps.GPSDriver;
107
import org.gvsig.gps.panel.GPSConfigPanel;
108
import org.gvsig.gps.panel.GPSControlPanel;
109

    
110
import com.iver.andami.PluginServices;
111
import com.iver.andami.ui.mdiManager.IWindow;
112
import com.iver.andami.ui.mdiManager.SingletonWindow;
113
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
114
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
115
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
116
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
117
import com.iver.cit.gvsig.project.documents.view.gui.View;
118
import com.iver.utiles.XMLEntity;
119

    
120
public class PointCalibrate implements PointListener {
121

    
122
        private View view;
123
        private Cursor cur = java.awt.Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
124
        private String previousToolName;
125

    
126
        public PointCalibrate(View v, String previousToolName) {
127
                this.view = v;
128
                this.previousToolName = previousToolName;
129
        }
130

    
131
        public void point(PointEvent event) throws BehaviorException {
132
                Point2D pReal = view.getMapControl().getMapContext().getViewPort().toMapPoint(event.getPoint());
133

    
134
                // the geodesic projection
135
                IProjection latLonProj = CRSFactory.getCRS("EPSG:4326");
136

    
137
                // create a translator from view's projection to geographic to the current
138
                ICoordTrans ct = view.getMapControl().getProjection().getCT(latLonProj);
139

    
140
                Point2D pGeo = new Point2D.Double();
141
                pGeo = ct.convert(pReal, pGeo);
142
                GPSDriver gps = GPSDriver.getInstance();
143
                Point2D currPos = gps.getCurrentPosition();
144

    
145
                // Compute offset
146
                if (currPos==null) {
147
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "gps_not_ready") );
148
                } else {
149
                        Point2D pOffset = new Point2D.Double(currPos.getX() - pGeo.getX(), currPos.getY() - pGeo.getY());
150

    
151
                        // Show a message asking the user for saving the calibration for next sessions
152
                        if (JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),
153
                                        "LON: " + pGeo.getX() + "\n" +
154
                                        "LAT: " + pGeo.getY() + "\n" +
155
                                        PluginServices.getText(this, "save_calibration_for_next_sessions"),
156
                                        PluginServices.getText(this, "selected_point"),
157
                                        JOptionPane.YES_OPTION) == JOptionPane.YES_OPTION) {
158
                                PluginServices ps = PluginServices.getPluginServices(this);
159
                                XMLEntity xml = ps.getPersistentXML();
160
                                if (xml.contains(GPSControlPanel.POSITION_OFFSET)) {
161
                                        xml.remove(GPSControlPanel.POSITION_OFFSET);
162
                                }
163

    
164
                                xml.putProperty(GPSControlPanel.POSITION_OFFSET, pOffset.getX()+" ,"+ pOffset.getY());
165
                        }
166

    
167
                        gps.setPosOffset(pOffset.getX(), pOffset.getY());
168
                }
169
                view.getMapControl().setTool(previousToolName);
170
                IWindow views[] = PluginServices.getMDIManager().getAllWindows();
171
                for (int i = 0; i < views.length; i++) {
172
                        if (views[i] instanceof SingletonWindow) {
173
                                SingletonWindow s = (SingletonWindow) views[i];
174
                                if (s.getWindowModel().equals(GPSConfigPanel.viewModel))
175
                                        PluginServices.getMDIManager().addWindow(s);
176
                        }
177
                }
178

    
179
        }
180

    
181
        public void pointDoubleClick(PointEvent event) throws BehaviorException {}
182

    
183
        public Cursor getCursor() {
184
                return cur;
185
        }
186

    
187
        public boolean cancelDrawing() {
188
                return false;
189
        }
190

    
191
}