source: josm/trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java

Last change on this file was 18466, checked in by taylor.smock, 23 months ago

Fix #21813: Improve marker handling in sessions and #21923: Improve session workflow/Add "save session" (patch by Bjoeni)

  • Allow saving a previously saved session
  • Add "File" -> "Save Session"
  • Add shortcuts for saving sessions
  • Add warning if a layer in a session is being removed when saving over the session
  • Improve GPX marker handling
  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.io.File;
10import java.util.ArrayList;
11import java.util.List;
12
13import javax.swing.AbstractAction;
14import javax.swing.JLabel;
15import javax.swing.JOptionPane;
16import javax.swing.JPanel;
17
18import org.openstreetmap.josm.actions.SimplifyWayAction;
19import org.openstreetmap.josm.data.osm.DataSet;
20import org.openstreetmap.josm.data.osm.Way;
21import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
22import org.openstreetmap.josm.gui.MainApplication;
23import org.openstreetmap.josm.gui.layer.Layer;
24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
25import org.openstreetmap.josm.gui.widgets.UrlLabel;
26import org.openstreetmap.josm.spi.preferences.Config;
27import org.openstreetmap.josm.tools.GBC;
28import org.openstreetmap.josm.tools.ImageProvider;
29
30/**
31 * An abstract action for a conversion from a {@code T} {@link Layer} to a {@link OsmDataLayer}.
32 * @param <T> the source layer class
33 */
34public abstract class ConvertToDataLayerAction<T extends Layer> extends AbstractAction {
35 /** source layer */
36 protected final transient T layer;
37
38 /**
39 * Constructs a new {@code ConvertToDataLayerAction}
40 * @param layer source layer
41 */
42 protected ConvertToDataLayerAction(final T layer) {
43 super(tr("Convert to data layer"));
44 new ImageProvider("converttoosm").getResource().attachImageIcon(this, true);
45 this.layer = layer;
46 putValue("help", ht("/Action/ConvertToDataLayer"));
47 }
48
49 /**
50 * Performs the conversion to a {@link DataSet}.
51 * @return the resulting dataset
52 */
53 public abstract DataSet convert();
54
55 @Override
56 public void actionPerformed(ActionEvent e) {
57 JPanel msg = new JPanel(new GridBagLayout());
58 msg.add(new JLabel(
59 tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>"
60 + "If you want to upload traces, look here:</html>")),
61 GBC.eol());
62 msg.add(new UrlLabel(Config.getUrls().getOSMWebsite() + "/traces", 2), GBC.eop());
63 if (!ConditionalOptionPaneUtil.showConfirmationDialog("convert_to_data", MainApplication.getMainFrame(), msg, tr("Warning"),
64 JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_OPTION)) {
65 return;
66 }
67 final DataSet ds = convert();
68 if (ds != null) {
69 List<Way> ways = new ArrayList<>(ds.getWays());
70 double err = SimplifyWayAction.askSimplifyWays(ways, tr("Would you like to simplify the ways in the converted layer?"), true);
71 if (err > 0) {
72 SimplifyWayAction.simplifyWays(ways, err);
73 }
74 String name = layer.getName().replaceAll("^" + tr("Converted from: {0}", ""), "");
75 final OsmDataLayer osmLayer = new OsmDataLayer(ds, tr("Converted from: {0}", name), null);
76 if (layer.getAssociatedFile() != null) {
77 osmLayer.setAssociatedFile(new File(layer.getAssociatedFile().getParentFile(),
78 layer.getAssociatedFile().getName() + ".osm"));
79 }
80 osmLayer.setUploadDiscouraged(true);
81 MainApplication.getLayerManager().addLayer(osmLayer, false);
82 MainApplication.getLayerManager().removeLayer(layer);
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.