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

Last change on this file since 14875 was 14153, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.parent and Main itself

  • Property svn:eol-style set to native
File size: 3.0 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;
10
11import javax.swing.AbstractAction;
12import javax.swing.JLabel;
13import javax.swing.JOptionPane;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
18import org.openstreetmap.josm.gui.MainApplication;
19import org.openstreetmap.josm.gui.layer.Layer;
20import org.openstreetmap.josm.gui.layer.OsmDataLayer;
21import org.openstreetmap.josm.gui.widgets.UrlLabel;
22import org.openstreetmap.josm.spi.preferences.Config;
23import org.openstreetmap.josm.tools.GBC;
24import org.openstreetmap.josm.tools.ImageProvider;
25
26/**
27 * An abstract action for a conversion from a {@code T} {@link Layer} to a {@link OsmDataLayer}.
28 * @param <T> the source layer class
29 */
30public abstract class ConvertToDataLayerAction<T extends Layer> extends AbstractAction {
31 /** source layer */
32 protected final transient T layer;
33
34 /**
35 * Constructs a new {@code ConvertToDataLayerAction}
36 * @param layer source layer
37 */
38 protected ConvertToDataLayerAction(final T layer) {
39 super(tr("Convert to data layer"));
40 new ImageProvider("converttoosm").getResource().attachImageIcon(this, true);
41 this.layer = layer;
42 putValue("help", ht("/Action/ConvertToDataLayer"));
43 }
44
45 /**
46 * Performs the conversion to a {@link DataSet}.
47 * @return the resulting dataset
48 */
49 public abstract DataSet convert();
50
51 @Override
52 public void actionPerformed(ActionEvent e) {
53 JPanel msg = new JPanel(new GridBagLayout());
54 msg.add(new JLabel(
55 tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>"
56 + "If you want to upload traces, look here:</html>")),
57 GBC.eol());
58 msg.add(new UrlLabel(Config.getUrls().getOSMWebsite() + "/traces", 2), GBC.eop());
59 if (!ConditionalOptionPaneUtil.showConfirmationDialog("convert_to_data", MainApplication.getMainFrame(), msg, tr("Warning"),
60 JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_OPTION)) {
61 return;
62 }
63 final DataSet ds = convert();
64 if (ds != null) {
65 final OsmDataLayer osmLayer = new OsmDataLayer(ds, tr("Converted from: {0}", layer.getName()), null);
66 if (layer.getAssociatedFile() != null) {
67 osmLayer.setAssociatedFile(new File(layer.getAssociatedFile().getParentFile(),
68 layer.getAssociatedFile().getName() + ".osm"));
69 }
70 osmLayer.setUploadDiscouraged(true);
71 MainApplication.getLayerManager().addLayer(osmLayer, false);
72 MainApplication.getLayerManager().removeLayer(layer);
73 }
74 }
75}
Note: See TracBrowser for help on using the repository browser.