root / trunk / extensions / extGPS / src / org / gvsig / gps / GPSExtension.java @ 6567
History | View | Annotate | Download (5.82 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: GPSExtension.java 6567 2006-07-31 06:48:50Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.11 2006-07-31 06:46:02 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.9 2006/05/02 15:57:53 jorpiell
|
50 |
* Se ha cambiado la interfaz Extension por dos clases: una interfaz (IExtension) y una clase abstract(Extension). A partir de ahora todas las extensiones deben heredar de Extension
|
51 |
*
|
52 |
* Revision 1.8 2006/04/10 11:21:52 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.7 2006/04/07 12:45:55 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.6 2006/04/07 11:10:26 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.5 2006/04/07 08:27:48 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.4 2006/04/06 10:34:58 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.3 2006/04/05 17:08:18 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.2 2006/04/05 16:02:09 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2006/04/03 16:10:27 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.1 2006/03/31 09:55:34 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
*
|
80 |
*/
|
81 |
package org.gvsig.gps; |
82 |
|
83 |
import java.awt.Color; |
84 |
import java.awt.geom.Point2D; |
85 |
import java.io.BufferedReader; |
86 |
import java.io.File; |
87 |
import java.io.FileReader; |
88 |
import java.util.ArrayList; |
89 |
|
90 |
import org.cresques.cts.ICoordTrans; |
91 |
import org.cresques.cts.IProjection; |
92 |
import org.cresques.cts.ProjectionPool; |
93 |
import org.gvsig.gps.panel.GPSControlPanel; |
94 |
|
95 |
import com.iver.andami.PluginServices; |
96 |
import com.iver.andami.plugins.Extension; |
97 |
import com.iver.cit.gvsig.fmap.MapControl; |
98 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
99 |
import com.iver.cit.gvsig.fmap.core.FShape; |
100 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
101 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
102 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
103 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
104 |
import com.iver.cit.gvsig.gui.View; |
105 |
|
106 |
public class GPSExtension extends Extension{ |
107 |
|
108 |
public void execute(String actionCommand) { |
109 |
if (actionCommand.equals("GPS_CONTROL_PANEL")) |
110 |
PluginServices.getMDIManager().addView(GPSControlPanel.getInstance()); |
111 |
else if (actionCommand.equals("PAINT_POINTS")) { |
112 |
paintPointsFromFile(null, null, new File("c:/gps-capture")); |
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
public boolean isEnabled() { |
118 |
return true; |
119 |
} |
120 |
|
121 |
public boolean isVisible() { |
122 |
return true; |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Takes an array of gvSIG views and draws an symbol in the specified location.
|
127 |
* If views[] is empty (vies.length == 0) then no drawing in applied.
|
128 |
* If views[] is null, then the symbol is drawn in every view in the project.
|
129 |
* If the symbol is null, then a simple point is used as symbol.
|
130 |
* @param views
|
131 |
* @param location
|
132 |
* @param symbol
|
133 |
* @param refreshing, tells if the view will be refreshed (old points will be removed)
|
134 |
*/
|
135 |
public void drawSymbol(View[] views, FSymbol symbol, Point2D location, boolean refreshing) { |
136 |
if (location == null || location.getX()==0 || location.getY()==0) return; |
137 |
if (views == null) |
138 |
{ |
139 |
com.iver.andami.ui.mdiManager.View[] aViews = PluginServices.getMDIManager().getAllViews();
|
140 |
ArrayList gvViews = new ArrayList(); |
141 |
for (int i = 0; i < aViews.length; i++) { |
142 |
if (aViews[i] instanceof View) { |
143 |
gvViews.add((View) aViews[i]);
|
144 |
} |
145 |
} |
146 |
views = (View[]) gvViews.toArray(new View[0]); |
147 |
} |
148 |
|
149 |
if (symbol == null) { |
150 |
symbol = new FSymbol(FShape.POINT, Color.ORANGE); |
151 |
symbol.setSize(10);
|
152 |
} |
153 |
|
154 |
for (int i = 0; i < views.length; i++) { |
155 |
MapControl mc = views[i].getMapControl(); |
156 |
GraphicLayer graph = mc.getMapContext().getGraphicsLayer(); |
157 |
|
158 |
if (refreshing) {
|
159 |
// Remove old graphics
|
160 |
graph.clearAllGraphics(); |
161 |
graph.clearSymbolsGraphics(); |
162 |
mc.drawGraphics(); |
163 |
} |
164 |
|
165 |
// Obtain the current view's projection
|
166 |
IProjection reqProj = mc.getProjection(); |
167 |
|
168 |
// the geodesic projection
|
169 |
IProjection latLonProj = ProjectionPool.get("EPSG:4326");
|
170 |
|
171 |
// create a translator from geodesic to the current view's projection
|
172 |
ICoordTrans ct = latLonProj.getCT(reqProj); |
173 |
|
174 |
Point2D pDst = new Point2D.Double(); |
175 |
|
176 |
// reproject the point
|
177 |
pDst = ct.convert(location, pDst); |
178 |
|
179 |
// add and draw the FSymbol to the reprojected location.
|
180 |
graph.addSymbol(symbol); |
181 |
graph.addGraphic(new FGraphic(ShapeFactory.createPoint2D(new FPoint2D(pDst)), 0)); |
182 |
mc.drawGraphics(); |
183 |
} |
184 |
} |
185 |
|
186 |
private void paintPointsFromFile(View[] views, FSymbol symbol, File f){ |
187 |
try {
|
188 |
|
189 |
BufferedReader br = new BufferedReader(new FileReader(f)); |
190 |
String line;
|
191 |
for (line = br.readLine(); line!=null; line = br.readLine()){ |
192 |
String[] numbers = line.split(","); |
193 |
|
194 |
double lon = Double.parseDouble(numbers[0]); |
195 |
double lat = Double.parseDouble(numbers[1]); |
196 |
drawSymbol(views, symbol, new Point2D.Double(lon, lat), false); |
197 |
} |
198 |
} catch (Exception e) { |
199 |
e.printStackTrace(); |
200 |
} |
201 |
} |
202 |
|
203 |
public void initialize() { |
204 |
} |
205 |
} |