Changeset 30766 in osm
- Timestamp:
- 2014-10-27T23:30:49+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/merge-overlap
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/merge-overlap/build.xml
r30714 r30766 4 4 <property name="commit.message" value="MergeOverlap: help shortcut parser, rebuild"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="76 10"/>6 <property name="plugin.main.version" value="7661"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java
r30713 r30766 602 602 if (askForMergeTag(ways) || duplicateParentRelations(ways)) { 603 603 dialog.setVisible(true); 604 if (dialog.isCancel led())604 if (dialog.isCanceled()) 605 605 throw new UserCancelException(); 606 606 } -
applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/hack/MyCombinePrimitiveResolverDialog.java
r30714 r30766 43 43 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecision; 44 44 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecisionType; 45 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictResolver; 45 46 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolver; 46 47 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolverModel; 47 48 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 48 49 import org.openstreetmap.josm.gui.help.HelpUtil; 50 import org.openstreetmap.josm.gui.util.GuiHelper; 49 51 import org.openstreetmap.josm.tools.ImageProvider; 50 52 import org.openstreetmap.josm.tools.WindowGeometry; … … 55 57 * 56 58 * There is a singleton instance of this dialog which can be retrieved using 57 * {@ see#getInstance()}.59 * {@link #getInstance()}. 58 60 * 59 61 * The dialog uses two models: one for resolving tag conflicts, the other 60 62 * for resolving conflicts in relation memberships. For both models there are accessors, 61 * i.e {@ see#getTagConflictResolverModel()} and {@see#getRelationMemberConflictResolverModel()}.63 * i.e {@link #getTagConflictResolverModel()} and {@link #getRelationMemberConflictResolverModel()}. 62 64 * 63 65 * Models have to be <strong>populated</strong> before the dialog is launched. Example: … … 70 72 * 71 73 * You should also set the target primitive which other primitives (ways or nodes) are 72 * merged to, see {@ see#setTargetPrimitive(OsmPrimitive)}.74 * merged to, see {@link #setTargetPrimitive(OsmPrimitive)}. 73 75 * 74 * After the dialog is closed use {@ see#isCancelled()} to check whether the user canceled75 * the dialog. If it wasn't canceled you may build a collection of {@ seeCommand} objects76 * After the dialog is closed use {@link #isCanceled()} to check whether the user canceled 77 * the dialog. If it wasn't canceled you may build a collection of {@link Command} objects 76 78 * which reflect the conflict resolution decisions the user made in the dialog: 77 * see {@see #buildResolutionCommands()} 78 * 79 * 79 * see {@link #buildResolutionCommands()} 80 80 */ 81 81 public class MyCombinePrimitiveResolverDialog extends JDialog { 82 82 83 83 /** the unique instance of the dialog */ 84 staticprivate MyCombinePrimitiveResolverDialog instance;84 private static MyCombinePrimitiveResolverDialog instance; 85 85 86 86 /** … … 91 91 public static MyCombinePrimitiveResolverDialog getInstance() { 92 92 if (instance == null) { 93 instance = new MyCombinePrimitiveResolverDialog(Main.parent); 93 GuiHelper.runInEDTAndWait(new Runnable() { 94 @Override public void run() { 95 instance = new MyCombinePrimitiveResolverDialog(Main.parent); 96 } 97 }); 94 98 } 95 99 return instance; … … 98 102 private AutoAdjustingSplitPane spTagConflictTypes; 99 103 private TagConflictResolver pnlTagConflictResolver; 100 private MyRelationMemberConflictResolver pnlRelationMemberConflictResolver;101 private boolean cancel led;104 private RelationMemberConflictResolver pnlRelationMemberConflictResolver; 105 private boolean canceled; 102 106 private JPanel pnlButtons; 103 107 private OsmPrimitive targetPrimitive; … … 119 123 120 124 /** 121 * Sets the primitive the collection of primitives is merged or combined 122 * to. 125 * Sets the primitive the collection of primitives is merged or combined to. 123 126 * 124 127 * @param primitive the target primitive 125 128 */ 126 public void setTargetPrimitive(OsmPrimitive primitive) { 129 public void setTargetPrimitive(final OsmPrimitive primitive) { 127 130 this.targetPrimitive = primitive; 128 updateTitle(); 129 if (primitive instanceof Way) { 130 pnlRelationMemberConflictResolver.initForWayCombining(); 131 } else if (primitive instanceof Node) { 132 pnlRelationMemberConflictResolver.initForNodeMerging(); 133 } 131 GuiHelper.runInEDTAndWait(new Runnable() { 132 @Override public void run() { 133 updateTitle(); 134 if (primitive instanceof Way) { 135 pnlRelationMemberConflictResolver.initForWayCombining(); 136 } else if (primitive instanceof Node) { 137 pnlRelationMemberConflictResolver.initForNodeMerging(); 138 } 139 } 140 }); 134 141 } 135 142 … … 152 159 } 153 160 154 protected void build() { 161 protected final void build() { 155 162 getContentPane().setLayout(new BorderLayout()); 156 163 updateTitle(); … … 169 176 170 177 protected JPanel buildRelationMemberConflictResolverPanel() { 171 pnlRelationMemberConflictResolver = new MyRelationMemberConflictResolver ();178 pnlRelationMemberConflictResolver = new RelationMemberConflictResolver(new MyRelationMemberConflictResolverModel()); 172 179 return pnlRelationMemberConflictResolver; 173 180 } 174 181 175 182 protected JPanel buildButtonPanel() { 176 JPanel pnl = new JPanel(); 177 pnl.setLayout(new FlowLayout(FlowLayout.CENTER)); 183 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 178 184 179 185 // -- apply button … … 196 202 } 197 203 198 public MyCombinePrimitiveResolverDialog(Component owner) { 199 super(JOptionPane.getFrameForComponent(owner), ModalityType.DOCUMENT_MODAL); 204 /** 205 * Constructs a new {@code MyCombinePrimitiveResolverDialog}. 206 * @param parent The parent component in which this dialog will be displayed. 207 */ 208 public MyCombinePrimitiveResolverDialog(Component parent) { 209 super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 200 210 build(); 201 211 } 202 212 213 /** 214 * Replies the tag conflict resolver model. 215 * @return The tag conflict resolver model. 216 */ 203 217 public TagConflictResolverModel getTagConflictResolverModel() { 204 218 return pnlTagConflictResolver.getModel(); 205 219 } 206 220 221 /** 222 * Replies the relation membership conflict resolver model. 223 * @return The relation membership conflict resolver model. 224 */ 207 225 public MyRelationMemberConflictResolverModel getRelationMemberConflictResolverModel() { 208 return pnlRelationMemberConflictResolver.getModel(); 226 return (MyRelationMemberConflictResolverModel) pnlRelationMemberConflictResolver.getModel(); 209 227 } 210 228 … … 230 248 231 249 TagCollection allResolutions = getTagConflictResolverModel().getAllResolutions(); 232 if (allResolutions. size() > 0) {250 if (!allResolutions.isEmpty()) { 233 251 cmds.addAll(buildTagChangeCommand(targetPrimitive, allResolutions)); 234 252 } … … 279 297 } 280 298 299 /** 300 * Prepares the default decisions for populated tag and relation membership conflicts. 301 */ 281 302 public void prepareDefaultDecisions() { 282 303 prepareDefaultTagDecisions(); … … 285 306 286 307 protected JPanel buildEmptyConflictsPanel() { 287 JPanel pnl = new JPanel(); 288 pnl.setLayout(new BorderLayout()); 308 JPanel pnl = new JPanel(new BorderLayout()); 289 309 pnl.add(new JLabel(tr("No conflicts to resolve"))); 290 310 return pnl; … … 297 317 298 318 if (relModel.getNumDecisions() > 0 && tagModel.getNumDecisions() > 0) { 299 // display both, the dialog for resolving relation conflicts and for resolving 300 // tag conflicts 319 // display both, the dialog for resolving relation conflicts and for resolving tag conflicts 301 320 spTagConflictTypes.setTopComponent(pnlTagConflictResolver); 302 321 spTagConflictTypes.setBottomComponent(pnlRelationMemberConflictResolver); … … 304 323 } else if (relModel.getNumDecisions() > 0) { 305 324 // relation conflicts only 306 //307 325 getContentPane().add(pnlRelationMemberConflictResolver, BorderLayout.CENTER); 308 326 } else if (tagModel.getNumDecisions() > 0) { 309 327 // tag conflicts only 310 //311 328 getContentPane().add(pnlTagConflictResolver, BorderLayout.CENTER); 312 329 } else { … … 324 341 } 325 342 326 protected void setCancelled(boolean cancelled) { 327 this.cancelled = cancelled; 328 } 329 330 public boolean isCancelled() { 331 return cancelled; 343 protected void setCanceled(boolean canceled) { 344 this.canceled = canceled; 345 } 346 347 /** 348 * Determines if this dialog has been cancelled. 349 * @return true if this dialog has been cancelled, false otherwise. 350 */ 351 public boolean isCanceled() { 352 return canceled; 332 353 } 333 354 … … 338 359 new WindowGeometry(getClass().getName() + ".geometry", WindowGeometry.centerInWindow(Main.parent, 339 360 new Dimension(600, 400))).applySafe(this); 340 setCancel led(false);361 setCanceled(false); 341 362 btnApply.requestFocusInWindow(); 342 363 } else if (isShowing()) { // Avoid IllegalComponentStateException like in #8775 … … 357 378 @Override 358 379 public void actionPerformed(ActionEvent arg0) { 359 setCancel led(true);380 setCanceled(true); 360 381 setVisible(false); 361 382 } … … 377 398 } 378 399 379 protected void updateEnabledState() { 400 protected final void updateEnabledState() { 380 401 setEnabled(pnlTagConflictResolver.getModel().getNumConflicts() == 0 381 402 && pnlRelationMemberConflictResolver.getModel().getNumConflicts() == 0); -
applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/hack/MyRelationMemberConflictResolverModel.java
r30714 r30766 2 2 package mergeoverlap.hack; 3 3 4 import java.beans.PropertyChangeListener;5 import java.beans.PropertyChangeSupport;6 import java.util.ArrayList;7 4 import java.util.Collection; 8 import java.util.HashSet;9 5 import java.util.LinkedList; 10 6 import java.util.List; 11 7 import java.util.Map; 12 import java.util.Set;13 14 import javax.swing.table.DefaultTableModel;15 8 16 9 import mergeoverlap.MergeOverlapAction; 17 10 11 import org.openstreetmap.josm.command.Command; 18 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 13 import org.openstreetmap.josm.data.osm.Relation; 20 14 import org.openstreetmap.josm.data.osm.RelationMember; 21 import org.openstreetmap.josm.data.osm.RelationToChildReference;22 15 import org.openstreetmap.josm.data.osm.Way; 23 16 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecision; 24 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecisionType; 25 import org.openstreetmap.josm.gui.util.GuiHelper; 17 import org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictResolverModel; 26 18 27 19 /** … … 30 22 * It can be used as {@link javax.swing.table.TableModel}. 31 23 */ 32 public class MyRelationMemberConflictResolverModel extends DefaultTableModel {24 public class MyRelationMemberConflictResolverModel extends RelationMemberConflictResolverModel { 33 25 /** the property name for the number conflicts managed by this model */ 34 26 public static final String NUM_CONFLICTS_PROP = MyRelationMemberConflictResolverModel.class.getName() + ".numConflicts"; 35 27 36 /** the list of conflict decisions */ 37 private List<RelationMemberConflictDecision> decisions; 38 /** the collection of relations for which we manage conflicts */ 39 private Collection<Relation> relations; 40 /** the number of conflicts */ 41 private int numConflicts; 42 private PropertyChangeSupport support; 43 44 /** 45 * Replies true if each {@link MultiValueResolutionDecision} is decided. 46 * 47 * @return true if each {@link MultiValueResolutionDecision} is decided; false 48 * otherwise 49 */ 50 public boolean isResolvedCompletely() { 51 return numConflicts == 0; 28 @Override 29 protected String getProperty() { 30 return NUM_CONFLICTS_PROP; 52 31 } 53 54 /** 55 * Replies the current number of conflicts 56 * 57 * @return the current number of conflicts 58 */ 59 public int getNumConflicts() { 60 return numConflicts; 61 } 62 63 /** 64 * Updates the current number of conflicts from list of decisions and emits 65 * a property change event if necessary. 66 * 67 */ 68 protected void updateNumConflicts() { 69 int count = 0; 70 for (RelationMemberConflictDecision decision: decisions) { 71 if (!decision.isDecided()) { 72 count++; 73 } 74 } 75 int oldValue = numConflicts; 76 numConflicts = count; 77 if (numConflicts != oldValue) { 78 support.firePropertyChange(NUM_CONFLICTS_PROP, oldValue, numConflicts); 79 } 80 } 81 82 public void addPropertyChangeListener(PropertyChangeListener l) { 83 support.addPropertyChangeListener(l); 84 } 85 86 public void removePropertyChangeListener(PropertyChangeListener l) { 87 support.removePropertyChangeListener(l); 88 } 89 90 public MyRelationMemberConflictResolverModel() { 91 decisions = new ArrayList<>(); 92 support = new PropertyChangeSupport(this); 93 } 94 32 95 33 @Override 96 public int getRowCount() { 97 return getNumDecisions(); 98 } 99 100 @Override 101 public Object getValueAt(int row, int column) { 102 if (decisions == null) return null; 103 104 RelationMemberConflictDecision d = decisions.get(row); 105 switch(column) { 106 case 0: /* relation */ return d.getRelation(); 107 case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1 108 case 2: /* role */ return d.getRole(); 109 case 3: /* original */ return d.getOriginalPrimitive(); 110 case 4: /* decision */ return d.getDecision(); 111 } 112 return null; 113 } 114 115 @Override 116 public void setValueAt(Object value, int row, int column) { 117 RelationMemberConflictDecision d = decisions.get(row); 118 switch(column) { 119 case 2: /* role */ 120 d.setRole((String)value); 121 break; 122 case 4: /* decision */ 123 d.decide((RelationMemberConflictDecisionType)value); 124 refresh(); 125 break; 126 } 127 fireTableDataChanged(); 34 protected void populate(Relation relation, OsmPrimitive primitive) { 35 throw new UnsupportedOperationException("Use populate(Relation, OsmPrimitive, Map<Way, Way>) instead"); 128 36 } 129 37 … … 141 49 } 142 50 } 51 } 52 53 @Override 54 public void populate(Collection<Relation> relations, Collection<? extends OsmPrimitive> memberPrimitives) { 55 throw new UnsupportedOperationException("Use populate(Collection<Relation>, Collection<? extends OsmPrimitive>, Map<Way, Way>) instead"); 143 56 } 144 57 … … 163 76 } 164 77 165 /** 166 * Populates the model with the relation members represented as a collection of 167 * {@link RelationToChildReference}s. 168 * 169 * @param references the references. Empty list assumed if null. 170 */ 171 public void populate(Collection<RelationToChildReference> references) { 172 references = references == null ? new LinkedList<RelationToChildReference>() : references; 173 decisions.clear(); 174 this.relations = new HashSet<>(references.size()); 175 for (RelationToChildReference reference: references) { 176 decisions.add(new RelationMemberConflictDecision(reference.getParent(), reference.getPosition())); 177 relations.add(reference.getParent()); 178 } 179 refresh(); 180 } 181 182 /** 183 * Replies the decision at position <code>row</code> 184 * 185 * @param row 186 * @return the decision at position <code>row</code> 187 */ 188 public RelationMemberConflictDecision getDecision(int row) { 189 return decisions.get(row); 190 } 191 192 /** 193 * Replies the number of decisions managed by this model 194 * 195 * @return the number of decisions managed by this model 196 */ 197 public int getNumDecisions() { 198 return decisions == null ? 0 : decisions.size(); 199 } 200 201 /** 202 * Refreshes the model state. Invoke this method to trigger necessary change 203 * events after an update of the model data. 204 * 205 */ 206 public void refresh() { 207 updateNumConflicts(); 208 GuiHelper.runInEDTAndWait(new Runnable() { 209 @Override public void run() { 210 fireTableDataChanged(); 211 } 212 }); 213 } 214 215 /** 216 * Apply a role to all member managed by this model. 217 * 218 * @param role the role. Empty string assumed if null. 219 */ 220 public void applyRole(String role) { 221 role = role == null ? "" : role; 222 for (RelationMemberConflictDecision decision : decisions) { 223 decision.setRole(role); 224 } 225 refresh(); 226 } 227 228 protected RelationMemberConflictDecision getDecision(Relation relation, int pos) { 229 for(RelationMemberConflictDecision decision: decisions) { 230 if (decision.matches(relation, pos)) return decision; 231 } 232 return null; 78 @Override 79 protected Command buildResolveCommand(Relation relation, OsmPrimitive newPrimitive) { 80 throw new UnsupportedOperationException("Use buildResolveCorrespondance(Relation, OsmPrimitive, Map<Relation, Relation>, Map<Way, Way>) instead"); 233 81 } 234 82 … … 238 86 Relation modifiedRelation = MergeOverlapAction.getNew(relation, newRelations); 239 87 modifiedRelation.setMembers(null); 240 // boolean isChanged = false;241 88 for (int i=0; i < relationsMembers.size(); i++) { 242 89 RelationMember rm = relationsMembers.get(i); 243 // RelationMember rm = relation.getMember(i);244 // RelationMember rmNew;245 90 RelationMemberConflictDecision decision = getDecision(relation, i); 246 91 if (decision == null) { 247 92 modifiedRelation.addMember(rm); 248 93 } else { 249 System.out.println(modifiedRelation);250 System.out.println(111);251 94 switch(decision.getDecision()) { 252 95 case KEEP: 253 // modifiedRelation.removeMembersFor(newPrimitive);254 System.out.println(222);255 96 if (newPrimitive instanceof Way) { 256 97 modifiedRelation.addMember(new RelationMember(decision.getRole(), MergeOverlapAction.getOld((Way)newPrimitive, oldWays))); … … 259 100 modifiedRelation.addMember(new RelationMember(decision.getRole(), newPrimitive)); 260 101 } 261 // modifiedRelation.addMember(new RelationMember(decision.getRole(), newPrimitive));262 102 break; 263 103 case REMOVE: 264 System.out.println(333);265 // modifiedRelation.removeMembersFor(rm.getMember());266 // isChanged = true;267 104 // do nothing 268 105 break; … … 275 112 } 276 113 114 @Override 115 public List<Command> buildResolutionCommands(OsmPrimitive newPrimitive) { 116 throw new UnsupportedOperationException("Use buildRelationCorrespondance(OsmPrimitive, Map<Relation, Relation>, Map<Way, Way>) instead"); 117 } 118 277 119 /** 278 120 * Builds a collection of commands executing the decisions made in this model. … … 280 122 * @param newPrimitive the primitive which members shall refer to if the 281 123 * decision is {@see RelationMemberConflictDecisionType#REPLACE} 282 * @return a list of commands283 124 */ 284 125 public void buildRelationCorrespondance(OsmPrimitive newPrimitive, Map<Relation, Relation> newRelations, Map<Way, Way> oldWays) { … … 287 128 } 288 129 } 289 290 protected boolean isChanged(Relation relation, OsmPrimitive newPrimitive) {291 for (int i=0; i < relation.getMembersCount(); i++) {292 RelationMemberConflictDecision decision = getDecision(relation, i);293 if (decision == null) {294 continue;295 }296 switch(decision.getDecision()) {297 case REMOVE: return true;298 case KEEP:299 if (!relation.getMember(i).getRole().equals(decision.getRole()))300 return true;301 if (relation.getMember(i).getMember() != newPrimitive)302 return true;303 case UNDECIDED:304 // FIXME: handle error305 }306 }307 return false;308 }309 310 /**311 * Replies the set of relations which have to be modified according312 * to the decisions managed by this model.313 *314 * @param newPrimitive the primitive which members shall refer to if the315 * decision is {@see RelationMemberConflictDecisionType#REPLACE}316 *317 * @return the set of relations which have to be modified according318 * to the decisions managed by this model319 */320 public Set<Relation> getModifiedRelations(OsmPrimitive newPrimitive) {321 HashSet<Relation> ret = new HashSet<>();322 for (Relation relation: relations) {323 if (isChanged(relation, newPrimitive)) {324 ret.add(relation);325 }326 }327 return ret;328 }329 130 }
Note:
See TracChangeset
for help on using the changeset viewer.