| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.plugins.imageryxmlbounds.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.io.File;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.actions.SaveActionBase;
|
|---|
| 11 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 12 | import org.openstreetmap.josm.gui.layer.Layer.LayerSaveAction;
|
|---|
| 13 | import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsLayer;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * Save the current data.
|
|---|
| 17 | * @author Don-vip
|
|---|
| 18 | */
|
|---|
| 19 | public class BoundsLayerSaveAction extends LayerSaveAction {
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * Save the current data.
|
|---|
| 23 | */
|
|---|
| 24 | public static class SaveBoundsAction extends SaveActionBase {
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * Constructs a new {@code SaveBoundsAction}.
|
|---|
| 28 | */
|
|---|
| 29 | public SaveBoundsAction() {
|
|---|
| 30 | super(tr("Save"), "save", tr("Save the current data."), null);
|
|---|
| 31 | putValue("help", ht("/Action/Save"));
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public File getFile(Layer layer) {
|
|---|
| 36 | File f = layer.getAssociatedFile();
|
|---|
| 37 | if (f != null && !f.exists()) {
|
|---|
| 38 | f = null;
|
|---|
| 39 | }
|
|---|
| 40 | return f == null ? BoundsLayerSaveAsAction.SaveBoundsAsAction.openFileDialog(layer) : f;
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | protected final XmlBoundsLayer layer;
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * Constructs a new {@code BoundsLayerSaveAction}.
|
|---|
| 48 | * @param layer XML bounds layer
|
|---|
| 49 | */
|
|---|
| 50 | public BoundsLayerSaveAction(XmlBoundsLayer layer) {
|
|---|
| 51 | super(layer);
|
|---|
| 52 | this.layer = layer;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | @Override
|
|---|
| 56 | public void actionPerformed(ActionEvent e) {
|
|---|
| 57 | new SaveBoundsAction().doSave(layer);
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|