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

Last change on this file since 1990 was 1990, checked in by Gubaer, 15 years ago

fixed #3261: Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists
new: new checkbox in LAF preferences for enabling/disabling localized names for primitives

File size: 3.0 KB
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.JLabel;
9import javax.swing.JOptionPane;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.conflict.Conflict;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.gui.DefaultNameFormatter;
18import org.openstreetmap.josm.gui.OptionPaneUtil;
19import org.openstreetmap.josm.gui.layer.OsmDataLayer;
20import org.openstreetmap.josm.tools.ImageProvider;
21
22public class ConflictAddCommand extends Command {
23 private Conflict<? extends OsmPrimitive> conflict;
24
25 public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
26 super(layer);
27 this.conflict = conflict;
28 }
29
30 protected void warnBecauseOfDoubleConflict() {
31 OptionPaneUtil.showMessageDialog(
32 Main.parent,
33 tr("<html>Layer ''{0}'' already has a conflict for primitive<br>"
34 + "''{1}''.<br>"
35 + "This conflict can't be added.</html>",
36 getLayer().getName(),
37 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
38 ),
39 tr("Double conflict"),
40 JOptionPane.ERROR_MESSAGE
41 );
42 }
43 @Override public boolean executeCommand() {
44 try {
45 getLayer().getConflicts().add(conflict);
46 } catch(IllegalStateException e) {
47 e.printStackTrace();
48 warnBecauseOfDoubleConflict();
49 }
50 return true;
51 }
52
53 @Override public void undoCommand() {
54 if (! Main.map.mapView.hasLayer(getLayer())) {
55 System.out.println(tr("Warning: layer ''{0}'' doesn't exist anymore. Can't remove conflict for primitmive ''{1}''",
56 getLayer().getName(),
57 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
58 ));
59 return;
60 }
61 getLayer().getConflicts().remove(conflict);
62 }
63
64 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
65 // nothing to fill
66 }
67
68 @Override public MutableTreeNode description() {
69 return new DefaultMutableTreeNode(
70 new JLabel(
71 tr("Add conflict for ''{0}''",
72 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
73 ),
74 ImageProvider.get(OsmPrimitiveType.from(conflict.getMy())),
75 JLabel.HORIZONTAL
76 )
77 );
78 }
79}
Note: See TracBrowser for help on using the repository browser.