source: subversion/applications/editors/josm/plugins/surveyor/src/org/openstreetmap/josm/plugins/surveyor/AutoSaveAction.java

Last change on this file was 34591, checked in by donvip, 8 months ago

rename packages, fix warnings

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.surveyor;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.text.MessageFormat;
9import java.util.Date;
10import java.util.Timer;
11import java.util.TimerTask;
12
13import javax.swing.AbstractButton;
14
15import org.openstreetmap.josm.actions.JosmAction;
16import org.openstreetmap.josm.tools.Shortcut;
17
18import livegps.LiveGpsLayer;
19
20/**
21 * @author cdaller
22 *
23 */
24public class AutoSaveAction extends JosmAction {
25    private static final long serialVersionUID = -8608679323231116043L;
26    private static final long AUTO_SAVE_PERIOD_SEC = 60; // once a minute
27    public static final String GPS_FILE_NAME_PATTERN = "surveyor-{0,date,yyyyMMdd-HHmmss}.gpx";
28    public static final String OSM_FILE_NAME_PATTERN = "surveyor-{0,date,yyyyMMdd-HHmmss}.osm";
29    private boolean autoSave = false;
30    private Timer gpsDataTimer;
31
32    public AutoSaveAction() {
33        super(tr("AutoSave LiveData"), "autosave.png", tr("Save captured data to file every minute."),
34        Shortcut.registerShortcut("surveyor:autosave", tr("Tool: {0}", tr("AutoSave LiveData")),
35        KeyEvent.VK_S, Shortcut.ALT_CTRL_SHIFT), true);
36    }
37
38    @Override
39    public void actionPerformed(ActionEvent e) {
40        if (e.getSource() instanceof AbstractButton) {
41            autoSave = ((AbstractButton) e.getSource()).isSelected();
42        }
43
44        if (autoSave) {
45            if (gpsDataTimer == null) {
46                gpsDataTimer = new Timer();
47            }
48            TimerTask task;
49
50            String gpxFilename = MessageFormat.format(GPS_FILE_NAME_PATTERN, new Date());
51            task = new AutoSaveGpsLayerTimerTask(gpxFilename, LiveGpsLayer.LAYER_NAME);
52            gpsDataTimer.schedule(task, 1000, AUTO_SAVE_PERIOD_SEC * 1000);
53
54            String osmFilename = MessageFormat.format(OSM_FILE_NAME_PATTERN, new Date());
55            task = new AutoSaveEditLayerTimerTask(osmFilename);
56            gpsDataTimer.schedule(task, 5000, AUTO_SAVE_PERIOD_SEC * 1000);
57        } else if (gpsDataTimer != null) {
58            gpsDataTimer.cancel();
59        }
60    }
61}
Note: See TracBrowser for help on using the repository browser.