Changeset 6164 in osm for applications/editors/josm
- Timestamp:
- 2007-12-26T23:48:57+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/surveyor
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/surveyor/build.xml
r6100 r6164 21 21 22 22 <!-- plugin meta data (enter new version number if anything changed!) --> 23 <property name="plugin.version" value="1. 3.3"/>23 <property name="plugin.version" value="1.4"/> 24 24 <property name="plugin.description" value="Allow adding markers/nodes on current gps positions (V${plugin.version})."/> 25 25 <property name="plugin.stage" value="60"/> -
applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveAction.java
r5429 r6164 57 57 58 58 String gpxFilename = MessageFormat.format(GPS_FILE_NAME_PATTERN, new Date()); 59 task = new AutoSaveGpsAndMarkerLayerTimeTask(gpxFilename, 60 LiveGpsLayer.LAYER_NAME, SetWaypointAction.MARKER_LAYER_NAME); 59 task = new AutoSaveGpsLayerTimerTask(gpxFilename, LiveGpsLayer.LAYER_NAME); 61 60 gpsDataTimer.schedule(task, 1000, AUTO_SAVE_PERIOD_SEC * 1000); 62 61 -
applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java
r5270 r6164 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 8 9 import java.io.BufferedWriter; 9 10 import java.io.File; 10 import java.io.File OutputStream;11 import java.io.FileWriter; 11 12 import java.io.IOException; 13 import java.io.PrintWriter; 12 14 import java.util.TimerTask; 13 15 … … 17 19 18 20 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.gui.layer.Layer; 20 import org.openstreetmap.josm.gui.layer.RawGpsLayer; 21 import org.openstreetmap.josm.gui.layer.GpxLayer; 21 22 import org.openstreetmap.josm.io.GpxWriter; 22 import org.openstreetmap.josm.io.XmlWriter; 23 24 import at.dallermassl.josm.plugin.surveyor.util.LayerUtil; 23 25 24 26 /** 25 * TimerTask that writes the data of a {@link RawGpsLayer} to a gpx file.27 * TimerTask that writes the data of a {@link GpxLayer} to a gpx file. 26 28 * Every time the task is run, the layer is retrieved from the map view so it even works 27 29 * if the layer does not exist at the start of the timer task. If the layer does not exist, … … 61 63 62 64 try { 63 XmlWriter.OsmWriterInterface writer = getXmlWriter(); 64 if(writer != null) { 65 // write to temporary file, on success, rename tmp file to target file: 66 File tmpFile = new File(file.getAbsoluteFile()+".tmp"); 67 System.out.println("AutoSaving data to file " + file.getAbsolutePath()); 68 // synchronize on layer to prevent concurrent adding of data to the layer 69 // quite a hack, but no other object to sync available :-( 70 // @see LiveGpsLayer 71 synchronized(LiveGpsLock.class) { 72 XmlWriter.output(new FileOutputStream(tmpFile), writer); 73 } 74 tmpFile.renameTo(file); 65 66 GpxLayer gpsLayer = LayerUtil.findGpsLayer(gpsLayerName, GpxLayer.class); 67 if(gpsLayer == null) { 68 return; 75 69 } 76 } catch (IOException x) { 77 x.printStackTrace(); 70 // write to temporary file, on success, rename tmp file to target file: 71 File tmpFile = new File(file.getAbsoluteFile()+".tmp"); 72 System.out.println("AutoSaving data to file " + file.getAbsolutePath()); 73 // synchronize on layer to prevent concurrent adding of data to the layer 74 // quite a hack, but no other object to sync available :-( 75 // @see LiveGpsLayer 76 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile))); 77 GpxWriter gpxWriter = new GpxWriter(out); 78 synchronized(LiveGpsLock.class) { 79 gpxWriter.write(gpsLayer.data); 80 } 81 tmpFile.renameTo(file); 82 } catch (IOException ioExc) { 83 ioExc.printStackTrace(); 78 84 JOptionPane.showMessageDialog(Main.parent, 79 tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), x.getMessage()),85 tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), ioExc.getMessage()), 80 86 tr("Error"), 81 87 JOptionPane.ERROR_MESSAGE); 82 88 } 83 89 } 84 85 /**86 * Returns the layer with the given name and type from the map view or <code>null</code>.87 * @param <LayerType> the type of the layer.88 * @param layerName the name of the layer.89 * @param layerType the type of the layer.90 * @return the layer or <code>null</code>.91 */92 public <LayerType extends Layer> LayerType findGpsLayer(String layerName, Class<LayerType> layerType) {93 LayerType result = null;94 if(Main.map != null && Main.map.mapView != null) {95 for(Layer layer : Main.map.mapView.getAllLayers()) {96 if(layerName.equals(layer.name) && layerType.isAssignableFrom(layer.getClass())) {97 result = (LayerType) layer;98 break;99 }100 }101 }102 return result;103 }104 105 106 /**107 * Returns the writer that writes the data. Override this method, if another type108 * of writer should be used.109 * @return the writer.110 */111 public XmlWriter.OsmWriterInterface getXmlWriter() {112 return null;113 114 /*115 * FIXME! this disables auto-save. need to work with new GPX writing code in JOSM.116 *117 RawGpsLayer gpsLayer = findGpsLayer(gpsLayerName, RawGpsLayer.class);118 if(gpsLayer == null) {119 return null;120 }121 return new GpxWriter.Trk(gpsLayer.data);122 */123 }124 125 126 90 } -
applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/SetWaypointAction.java
r5270 r6164 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 8 9 import java.util.ArrayList;10 9 import java.util.Collection; 11 10 12 11 import javax.swing.JToggleButton; 13 12 13 import livegps.LiveGpsLayer; 14 14 import livegps.LiveGpsLock; 15 15 … … 17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 18 import org.openstreetmap.josm.data.gpx.GpxData; 19 import org.openstreetmap.josm.data.gpx.WayPoint; 20 import org.openstreetmap.josm.gui.layer.GpxLayer; 19 21 import org.openstreetmap.josm.gui.layer.Layer; 20 22 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; … … 24 26 import at.dallermassl.josm.plugin.surveyor.SurveyorPlugin; 25 27 import at.dallermassl.josm.plugin.surveyor.action.gui.WaypointDialog; 28 import at.dallermassl.josm.plugin.surveyor.util.LayerUtil; 26 29 27 30 /** … … 33 36 */ 34 37 public class SetWaypointAction extends AbstractSurveyorAction { 38 private LiveGpsLayer liveGpsLayer; 35 39 private MarkerLayer markerLayer; 36 40 public static final String MARKER_LAYER_NAME = "surveyorwaypointlayer"; … … 38 42 39 43 /** 40 * Default Con dstructor44 * Default Constructor. 41 45 */ 42 46 public SetWaypointAction() { … … 51 55 LatLon coordinates = event.getCoordinates(); 52 56 System.out.println(getClass().getSimpleName() + " KOORD: " + coordinates.lat() + ", " + coordinates.lon()); 53 MarkerLayer layer = getGpsLayer();54 57 String markerTitle = getParameters().get(0); 55 58 Object source = event.getSource(); … … 74 77 75 78 String iconName = getParameters().size() > 1 ? getParameters().get(1) : null; 79 80 // add the waypoint to the marker layer AND to the gpx layer 81 // (easy export of data + waypoints): 82 MarkerLayer layer = getMarkerLayer(); 83 GpxLayer gpsLayer = getGpxLayer(); 84 WayPoint waypoint = new WayPoint(event.getCoordinates()); 85 waypoint.attr.put("name", markerText); 86 waypoint.attr.put("sym", iconName); 76 87 synchronized(LiveGpsLock.class) { 77 88 layer.data.add(new Marker(event.getCoordinates(), markerText, iconName)); 89 if(gpsLayer != null) { 90 gpsLayer.data.waypoints.add(waypoint); 91 } 78 92 } 93 79 94 Main.map.repaint(); 80 95 } 81 96 82 public MarkerLayer getGpsLayer() { 97 /** 98 * Returns the marker layer with the name {@link #MARKER_LAYER_NAME}. 99 * @return the marker layer with the name {@link #MARKER_LAYER_NAME}. 100 */ 101 public MarkerLayer getMarkerLayer() { 83 102 if(markerLayer == null) { 84 Collection<Layer> layers = Main.map.mapView.getAllLayers(); 85 for (Layer layer : layers) { 86 if(MARKER_LAYER_NAME.equals(layer.name)) { 87 markerLayer = (MarkerLayer) layer; 88 break; 89 } 90 } 91 // not found: 103 markerLayer = LayerUtil.findGpsLayer(MARKER_LAYER_NAME, MarkerLayer.class); 104 92 105 if(markerLayer == null) { 106 // not found, add a new one 93 107 markerLayer = new MarkerLayer(new GpxData(), MARKER_LAYER_NAME, null); 94 108 Main.main.addLayer(markerLayer); … … 97 111 return markerLayer; 98 112 } 113 114 /** 115 * Returns the gpx layer that is filled by the live gps data. 116 * @return the gpx layer that is filled by the live gps data. 117 */ 118 public GpxLayer getGpxLayer() { 119 if(liveGpsLayer == null) { 120 Collection<Layer> layers = Main.map.mapView.getAllLayers(); 121 for (Layer layer : layers) { 122 if(layer instanceof LiveGpsLayer) { 123 liveGpsLayer = (LiveGpsLayer) layer; 124 break; 125 } 126 } 127 } 128 return liveGpsLayer; 129 } 99 130 100 131 }
Note:
See TracChangeset
for help on using the changeset viewer.