Revision 4763 trunk/extensions/extGPS/src/org/gvsig/gps/GPSExtension.java

View differences:

GPSExtension.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.5  2006-04-07 08:27:48  jaume
46
* Revision 1.6  2006-04-07 11:10:26  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.5  2006/04/07 08:27:48  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.4  2006/04/06 10:34:58  jaume
50 53
* *** empty log message ***
51 54
*
......
67 70

  
68 71
import java.awt.Color;
69 72
import java.awt.geom.Point2D;
73
import java.io.BufferedReader;
74
import java.io.File;
75
import java.io.FileNotFoundException;
76
import java.io.FileReader;
77
import java.io.IOException;
70 78
import java.util.ArrayList;
71 79

  
72 80
import org.cresques.cts.ICoordTrans;
......
75 83
import org.cresques.cts.gt2.CoordSys;
76 84
import org.cresques.cts.gt2.CoordTrans;
77 85
import org.gvsig.gps.panel.GPSControlPanel;
78
import org.gvsig.gps.panel.TestPanel;
79 86

  
80 87
import com.iver.andami.PluginServices;
81 88
import com.iver.andami.plugins.Extension;
......
83 90
import com.iver.cit.gvsig.fmap.core.FPoint2D;
84 91
import com.iver.cit.gvsig.fmap.core.FShape;
85 92
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
86
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
87 93
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
88 94
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
89 95
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
......
97 103
	}
98 104

  
99 105
	public void execute(String actionCommand) {
100
		PluginServices.getMDIManager().addView(GPSControlPanel.getInstance());
106
		if (actionCommand.equals("GPS_CONTROL_PANEL"))
107
			PluginServices.getMDIManager().addView(GPSControlPanel.getInstance());
108
		else if (actionCommand.equals("PAINT_POINTS"))
109
			paintPointsFromFile(new File("c:/gps-capture"));
101 110
	}
102 111

  
103 112
	public boolean isEnabled() {
......
116 125
	 * @param views
117 126
	 * @param location
118 127
	 * @param symbol
128
	 * @param refreshing, tells if the view will be refreshed (last points will be removed)
119 129
	 */
120
	public void drawSymbol(View[] views, FSymbol symbol, Point2D location) {
130
	public void drawSymbol(View[] views, FSymbol symbol, Point2D location, boolean refreshing) {
121 131
		//if (views == null || point == null) return;
122 132
		if (location == null || location.getX()==0 || location.getY()==0) return;
123 133
		if (views == null) 
......
141 151
			MapControl mc = views[i].getMapControl();
142 152
			GraphicLayer graph = mc.getMapContext().getGraphicsLayer();
143 153
			
144
			// Remove old graphics
145
			graph.clearAllGraphics();
146
			graph.clearSymbolsGraphics();
154
			if (refreshing) {
155
				// Remove old graphics
156
				graph.clearAllGraphics();
157
				graph.clearSymbolsGraphics();
158
				mc.drawGraphics();
159
			}
147 160
			
148 161
			// Obtain the current view's projection
149 162
			IProjection reqProj = mc.getProjection();
......
165 178
			mc.drawGraphics();
166 179
		}
167 180
	}
181
	
182
	private void paintPointsFromFile(File f){
183
		try {
184
			com.iver.andami.ui.mdiManager.View[] aViews = PluginServices.getMDIManager().getAllViews();
185
			ArrayList gvViews = new ArrayList();
186
			
187
			for (int i = 0; i < aViews.length; i++) {
188
				if (aViews[i] instanceof View) {
189
					gvViews.add((View) aViews[i]);
190
				}
191
			}
192
			
193
			View[] views = (View[]) gvViews.toArray(new View[0]);
194
			for (int i = 0; i < views.length; i++) {
195
				views[i].getMapControl().getMapContext().getGraphicsLayer().clearAllGraphics();
196
			}
197
			
198
			BufferedReader br = new BufferedReader(new FileReader(f));
199
			String line;
200
			for (line = br.readLine(); line!=null; line = br.readLine()){
201
				String[] numbers = line.split(",");
202
				
203
				double lonOffset = 0D;
204
				double latOffset = 0D;
205
				double lon = Double.parseDouble(numbers[0]) - lonOffset;
206
				double lat = Double.parseDouble(numbers[1]) - latOffset;
207
				drawSymbol(null, null, new Point2D.Double(lon, lat), false);
208
			}
209
		} catch (FileNotFoundException e) {
210
			// TODO Auto-generated catch block
211
			e.printStackTrace();
212
		} catch (IOException e) {
213
			// TODO Auto-generated catch block
214
			e.printStackTrace();
215
		}
216
	}
168 217
}

Also available in: Unified diff