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

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

replaced JOptionDialog.show... by OptionPaneUtil.show....
improved relation editor

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