source: josm/trunk/src/org/openstreetmap/josm/command/ConflictAddCommand.java @ 5241

Revision 5077, 2.5 KB checked in by xeen, 2 months ago (diff)

Bring area icon to most (all?) places in core. Fixes #6318 (related: #7036)

  • Property svn:eol-style set to native
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.Icon;
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.DefaultNameFormatter;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18public class ConflictAddCommand extends Command {
19    private Conflict<? extends OsmPrimitive> conflict;
20
21    public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
22        super(layer);
23        this.conflict  = conflict;
24    }
25
26    protected void warnBecauseOfDoubleConflict() {
27        JOptionPane.showMessageDialog(
28                Main.parent,
29                tr("<html>Layer ''{0}'' already has a conflict for object<br>"
30                        + "''{1}''.<br>"
31                        + "This conflict cannot be added.</html>",
32                        getLayer().getName(),
33                        conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
34                ),
35                tr("Double conflict"),
36                JOptionPane.ERROR_MESSAGE
37        );
38    }
39    @Override public boolean executeCommand() {
40        try {
41            getLayer().getConflicts().add(conflict);
42        } catch(IllegalStateException e) {
43            e.printStackTrace();
44            warnBecauseOfDoubleConflict();
45        }
46        return true;
47    }
48
49    @Override public void undoCommand() {
50        if (! Main.map.mapView.hasLayer(getLayer())) {
51            System.out.println(tr("Warning: Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
52                    getLayer().getName(),
53                    conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
54            ));
55            return;
56        }
57        getLayer().getConflicts().remove(conflict);
58    }
59
60    @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
61        // nothing to fill
62    }
63
64    @Override
65    public String getDescriptionText() {
66        return tr("Add conflict for ''{0}''",
67                conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance()));
68    }
69
70    @Override
71    public Icon getDescriptionIcon() {
72        return ImageProvider.get(conflict.getMy().getDisplayType());
73    }
74}
Note: See TracBrowser for help on using the repository browser.