source: osm/applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/hack/MyCombinePrimitiveResolverDialog.java

Last change on this file was 34530, checked in by donvip, 8 years ago

update to JOSM 14153

File size: 4.9 KB
RevLine 
[26575]1// License: GPL. For details, see LICENSE file.
[30712]2package mergeoverlap.hack;
[26575]3
4import java.awt.Component;
5import java.beans.PropertyChangeEvent;
6import java.util.LinkedList;
7import java.util.List;
8import java.util.Map;
9
10import org.openstreetmap.josm.command.ChangePropertyCommand;
11import org.openstreetmap.josm.command.Command;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.data.osm.TagCollection;
15import org.openstreetmap.josm.data.osm.Way;
[34530]16import org.openstreetmap.josm.gui.MainApplication;
[30778]17import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog;
[34056]18import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolverModel;
[30766]19import org.openstreetmap.josm.gui.util.GuiHelper;
[26575]20
21/**
22 * This dialog helps to resolve conflicts occurring when ways are combined or
23 * nodes are merged.
24 *
25 * There is a singleton instance of this dialog which can be retrieved using
[30766]26 * {@link #getInstance()}.
[26575]27 *
28 * The dialog uses two models: one for resolving tag conflicts, the other
29 * for resolving conflicts in relation memberships. For both models there are accessors,
[30766]30 * i.e {@link #getTagConflictResolverModel()} and {@link #getRelationMemberConflictResolverModel()}.
[26575]31 *
32 * Models have to be <strong>populated</strong> before the dialog is launched. Example:
33 * <pre>
34 * CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance();
35 * dialog.getTagConflictResolverModel().populate(aTagCollection);
36 * dialog.getRelationMemberConflictResolverModel().populate(aRelationLinkCollection);
37 * dialog.prepareDefaultDecisions();
38 * </pre>
39 *
40 * You should also set the target primitive which other primitives (ways or nodes) are
[30766]41 * merged to, see {@link #setTargetPrimitive(OsmPrimitive)}.
[26575]42 *
[30766]43 * After the dialog is closed use {@link #isCanceled()} to check whether the user canceled
44 * the dialog. If it wasn't canceled you may build a collection of {@link Command} objects
[26575]45 * which reflect the conflict resolution decisions the user made in the dialog:
[30766]46 * see {@link #buildResolutionCommands()}
[26575]47 */
[30778]48public class MyCombinePrimitiveResolverDialog extends CombinePrimitiveResolverDialog {
[26575]49
50 /** the unique instance of the dialog */
[30766]51 private static MyCombinePrimitiveResolverDialog instance;
[26575]52
53 /**
[33154]54 * Constructs a new {@code MyCombinePrimitiveResolverDialog}.
55 * @param parent The parent component in which this dialog will be displayed.
56 */
57 public MyCombinePrimitiveResolverDialog(Component parent) {
[34056]58 super(parent, new TagConflictResolverModel(), new MyRelationMemberConflictResolverModel());
[33154]59 }
60
61 /**
[26575]62 * Replies the unique instance of the dialog
63 *
64 * @return the unique instance of the dialog
65 */
66 public static MyCombinePrimitiveResolverDialog getInstance() {
67 if (instance == null) {
[34530]68 GuiHelper.runInEDTAndWait(() -> instance = new MyCombinePrimitiveResolverDialog(MainApplication.getMainFrame()));
[26575]69 }
70 return instance;
71 }
72
[30778]73 @Override
74 protected ApplyAction buildApplyAction() {
75 return new ApplyAction() {
76 @Override
77 public void propertyChange(PropertyChangeEvent evt) {
78 super.propertyChange(evt);
79 if (evt.getPropertyName().equals(MyRelationMemberConflictResolverModel.NUM_CONFLICTS_PROP)) {
80 updateEnabledState();
81 }
82 }
83 };
[26575]84 }
85
[30766]86 /**
87 * Replies the relation membership conflict resolver model.
88 * @return The relation membership conflict resolver model.
89 */
[30778]90 @Override
[26575]91 public MyRelationMemberConflictResolverModel getRelationMemberConflictResolverModel() {
[30766]92 return (MyRelationMemberConflictResolverModel) pnlRelationMemberConflictResolver.getModel();
[26575]93 }
94
[30778]95 /**
96 * Replies the list of {@link Command commands} needed to apply resolution choices.
97 * @return The list of {@link Command commands} needed to apply resolution choices.
98 */
[26575]99 public List<Command> buildWayResolutionCommands() {
[30714]100 List<Command> cmds = new LinkedList<>();
[26575]101
102 TagCollection allResolutions = getTagConflictResolverModel().getAllResolutions();
[30766]103 if (!allResolutions.isEmpty()) {
[26575]104 cmds.addAll(buildTagChangeCommand(targetPrimitive, allResolutions));
105 }
106 if (targetPrimitive.get("created_by") != null) {
107 cmds.add(new ChangePropertyCommand(targetPrimitive, "created_by", null));
108 }
109
110 Command cmd = pnlRelationMemberConflictResolver.buildTagApplyCommands(getRelationMemberConflictResolverModel()
111 .getModifiedRelations(targetPrimitive));
112 if (cmd != null) {
113 cmds.add(cmd);
114 }
115 return cmds;
116 }
117
118 public void buildRelationCorrespondance(Map<Relation, Relation> newRelations, Map<Way, Way> oldWays) {
[30782]119 getRelationMemberConflictResolverModel().buildRelationCorrespondance(targetPrimitive, newRelations, oldWays);
[26575]120 }
121}
Note: See TracBrowser for help on using the repository browser.