source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java@ 2940

Last change on this file since 2940 was 2940, checked in by mjulius, 14 years ago

display list of referrers in ConflictResolutionDialog

File size: 26.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.pair.properties;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9import java.awt.Insets;
10import java.awt.event.ActionEvent;
11import java.text.DecimalFormat;
12import java.util.List;
13import java.util.Observable;
14import java.util.Observer;
15
16import javax.swing.AbstractAction;
17import javax.swing.Action;
18import javax.swing.BorderFactory;
19import javax.swing.JButton;
20import javax.swing.JLabel;
21import javax.swing.JOptionPane;
22import javax.swing.JPanel;
23
24import org.openstreetmap.josm.data.coor.LatLon;
25import org.openstreetmap.josm.data.osm.OsmPrimitive;
26import org.openstreetmap.josm.gui.DefaultNameFormatter;
27import org.openstreetmap.josm.gui.conflict.pair.IConflictResolver;
28import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
29import org.openstreetmap.josm.tools.ImageProvider;
30
31/**
32 * This class represents a UI component for resolving conflicts in some properties
33 * of {@see OsmPrimitive}.
34 *
35 */
36public class PropertiesMerger extends JPanel implements Observer, IConflictResolver {
37 private static DecimalFormat COORD_FORMATTER = new DecimalFormat("###0.0000000");
38
39 public final static Color BGCOLOR_NO_CONFLICT = new Color(234,234,234);
40 public final static Color BGCOLOR_UNDECIDED = new Color(255,197,197);
41 public final static Color BGCOLOR_DECIDED = new Color(217,255,217);
42
43 private JLabel lblMyVersion;
44 private JLabel lblMergedVersion;
45 private JLabel lblTheirVersion;
46
47 private JLabel lblMyCoordinates;
48 private JLabel lblMergedCoordinates;
49 private JLabel lblTheirCoordinates;
50
51 private JLabel lblMyDeletedState;
52 private JLabel lblMergedDeletedState;
53 private JLabel lblTheirDeletedState;
54
55 private JLabel lblMyVisibleState;
56 private JLabel lblMergedVisibleState;
57 private JLabel lblTheirVisibleState;
58
59 private JLabel lblMyReferrers;
60 private JLabel lblTheirReferrers;
61
62 private final PropertiesMergeModel model;
63
64 protected JLabel buildValueLabel(String name) {
65 JLabel lbl = new JLabel();
66 lbl.setName(name);
67 lbl.setHorizontalAlignment(JLabel.CENTER);
68 lbl.setOpaque(true);
69 lbl.setBorder(BorderFactory.createLoweredBevelBorder());
70 return lbl;
71 }
72
73 protected void buildHeaderRow() {
74 GridBagConstraints gc = new GridBagConstraints();
75
76 gc.gridx = 1;
77 gc.gridy = 0;
78 gc.gridwidth = 1;
79 gc.gridheight = 1;
80 gc.fill = GridBagConstraints.NONE;
81 gc.anchor = GridBagConstraints.CENTER;
82 gc.weightx = 0.0;
83 gc.weighty = 0.0;
84 gc.insets = new Insets(10,0,10,0);
85 lblMyVersion = new JLabel(tr("My version"));
86 lblMyVersion.setToolTipText(tr("Properties in my dataset, i.e. the local dataset"));
87 add(lblMyVersion, gc);
88
89 gc.gridx = 3;
90 gc.gridy = 0;
91 lblMergedVersion = new JLabel(tr("Merged version"));
92 lblMergedVersion.setToolTipText(tr("Properties in the merged element. They will replace properties in my elements when merge decisions are applied."));
93 add(lblMergedVersion, gc);
94
95 gc.gridx = 5;
96 gc.gridy = 0;
97 lblTheirVersion = new JLabel(tr("Their version"));
98 lblTheirVersion.setToolTipText(tr("Properties in their dataset, i.e. the server dataset"));
99 add(lblTheirVersion, gc);
100 }
101
102 protected void buildCoordinateConflictRows() {
103 GridBagConstraints gc = new GridBagConstraints();
104
105 gc.gridx = 0;
106 gc.gridy = 1;
107 gc.gridwidth = 1;
108 gc.gridheight = 1;
109 gc.fill = GridBagConstraints.HORIZONTAL;
110 gc.anchor = GridBagConstraints.LINE_START;
111 gc.weightx = 0.0;
112 gc.weighty = 0.0;
113 gc.insets = new Insets(0,5,0,5);
114 add(new JLabel(tr("Coordinates:")), gc);
115
116 gc.gridx = 1;
117 gc.gridy = 1;
118 gc.fill = GridBagConstraints.BOTH;
119 gc.anchor = GridBagConstraints.CENTER;
120 gc.weightx = 0.33;
121 gc.weighty = 0.0;
122 add(lblMyCoordinates = buildValueLabel("label.mycoordinates"), gc);
123
124 gc.gridx = 2;
125 gc.gridy = 1;
126 gc.fill = GridBagConstraints.NONE;
127 gc.anchor = GridBagConstraints.CENTER;
128 gc.weightx = 0.0;
129 gc.weighty = 0.0;
130 KeepMyCoordinatesAction actKeepMyCoordinates = new KeepMyCoordinatesAction();
131 model.addObserver(actKeepMyCoordinates);
132 JButton btnKeepMyCoordinates = new JButton(actKeepMyCoordinates);
133 btnKeepMyCoordinates.setName("button.keepmycoordinates");
134 add(btnKeepMyCoordinates, gc);
135
136 gc.gridx = 3;
137 gc.gridy = 1;
138 gc.fill = GridBagConstraints.BOTH;
139 gc.anchor = GridBagConstraints.CENTER;
140 gc.weightx = 0.33;
141 gc.weighty = 0.0;
142 add(lblMergedCoordinates = buildValueLabel("label.mergedcoordinates"), gc);
143
144 gc.gridx = 4;
145 gc.gridy = 1;
146 gc.fill = GridBagConstraints.NONE;
147 gc.anchor = GridBagConstraints.CENTER;
148 gc.weightx = 0.0;
149 gc.weighty = 0.0;
150 KeepTheirCoordinatesAction actKeepTheirCoordinates = new KeepTheirCoordinatesAction();
151 model.addObserver(actKeepTheirCoordinates);
152 JButton btnKeepTheirCoordinates = new JButton(actKeepTheirCoordinates);
153 add(btnKeepTheirCoordinates, gc);
154
155 gc.gridx = 5;
156 gc.gridy = 1;
157 gc.fill = GridBagConstraints.BOTH;
158 gc.anchor = GridBagConstraints.CENTER;
159 gc.weightx = 0.33;
160 gc.weighty = 0.0;
161 add(lblTheirCoordinates = buildValueLabel("label.theircoordinates"), gc);
162
163 // ---------------------------------------------------
164 gc.gridx = 3;
165 gc.gridy = 2;
166 gc.fill = GridBagConstraints.NONE;
167 gc.anchor = GridBagConstraints.CENTER;
168 gc.weightx = 0.0;
169 gc.weighty = 0.0;
170 UndecideCoordinateConflictAction actUndecideCoordinates = new UndecideCoordinateConflictAction();
171 model.addObserver(actUndecideCoordinates);
172 JButton btnUndecideCoordinates = new JButton(actUndecideCoordinates);
173 add(btnUndecideCoordinates, gc);
174 }
175
176 protected void buildDeletedStateConflictRows() {
177 GridBagConstraints gc = new GridBagConstraints();
178
179 gc.gridx = 0;
180 gc.gridy = 3;
181 gc.gridwidth = 1;
182 gc.gridheight = 1;
183 gc.fill = GridBagConstraints.BOTH;
184 gc.anchor = GridBagConstraints.LINE_START;
185 gc.weightx = 0.0;
186 gc.weighty = 0.0;
187 gc.insets = new Insets(0,5,0,5);
188 add(new JLabel(tr("Deleted State:")), gc);
189
190 gc.gridx = 1;
191 gc.gridy = 3;
192 gc.fill = GridBagConstraints.BOTH;
193 gc.anchor = GridBagConstraints.CENTER;
194 gc.weightx = 0.33;
195 gc.weighty = 0.0;
196 add(lblMyDeletedState = buildValueLabel("label.mydeletedstate"), gc);
197
198 gc.gridx = 2;
199 gc.gridy = 3;
200 gc.fill = GridBagConstraints.NONE;
201 gc.anchor = GridBagConstraints.CENTER;
202 gc.weightx = 0.0;
203 gc.weighty = 0.0;
204 KeepMyDeletedStateAction actKeepMyDeletedState = new KeepMyDeletedStateAction();
205 model.addObserver(actKeepMyDeletedState);
206 JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState);
207 btnKeepMyDeletedState.setName("button.keepmydeletedstate");
208 add(btnKeepMyDeletedState, gc);
209
210 gc.gridx = 3;
211 gc.gridy = 3;
212 gc.fill = GridBagConstraints.BOTH;
213 gc.anchor = GridBagConstraints.CENTER;
214 gc.weightx = 0.33;
215 gc.weighty = 0.0;
216 add(lblMergedDeletedState = buildValueLabel("label.mergeddeletedstate"), gc);
217
218 gc.gridx = 4;
219 gc.gridy = 3;
220 gc.fill = GridBagConstraints.NONE;
221 gc.anchor = GridBagConstraints.CENTER;
222 gc.weightx = 0.0;
223 gc.weighty = 0.0;
224 KeepTheirDeletedStateAction actKeepTheirDeletedState = new KeepTheirDeletedStateAction();
225 model.addObserver(actKeepTheirDeletedState);
226 JButton btnKeepTheirDeletedState = new JButton(actKeepTheirDeletedState);
227 btnKeepTheirDeletedState.setName("button.keeptheirdeletedstate");
228 add(btnKeepTheirDeletedState, gc);
229
230 gc.gridx = 5;
231 gc.gridy = 3;
232 gc.fill = GridBagConstraints.BOTH;
233 gc.anchor = GridBagConstraints.CENTER;
234 gc.weightx = 0.33;
235 gc.weighty = 0.0;
236 add(lblTheirDeletedState = buildValueLabel("label.theirdeletedstate"), gc);
237
238 // ---------------------------------------------------
239 gc.gridx = 3;
240 gc.gridy = 4;
241 gc.fill = GridBagConstraints.NONE;
242 gc.anchor = GridBagConstraints.CENTER;
243 gc.weightx = 0.0;
244 gc.weighty = 0.0;
245 UndecideDeletedStateConflictAction actUndecideDeletedState = new UndecideDeletedStateConflictAction();
246 model.addObserver(actUndecideDeletedState);
247 JButton btnUndecideDeletedState = new JButton(actUndecideDeletedState);
248 btnUndecideDeletedState.setName("button.undecidedeletedstate");
249 add(btnUndecideDeletedState, gc);
250 }
251
252 protected void buildVisibleStateRows() {
253 GridBagConstraints gc = new GridBagConstraints();
254
255 gc.gridx = 0;
256 gc.gridy = 5;
257 gc.gridwidth = 1;
258 gc.gridheight = 1;
259 gc.fill = GridBagConstraints.BOTH;
260 gc.anchor = GridBagConstraints.LINE_START;
261 gc.weightx = 0.0;
262 gc.weighty = 0.0;
263 gc.insets = new Insets(0,5,0,5);
264 add(new JLabel(tr("Visible State:")), gc);
265
266 gc.gridx = 1;
267 gc.gridy = 5;
268 gc.fill = GridBagConstraints.BOTH;
269 gc.anchor = GridBagConstraints.CENTER;
270 gc.weightx = 0.33;
271 gc.weighty = 0.0;
272 add(lblMyVisibleState = buildValueLabel("label.myvisiblestate"), gc);
273
274 gc.gridx = 2;
275 gc.gridy = 5;
276 gc.fill = GridBagConstraints.NONE;
277 gc.anchor = GridBagConstraints.CENTER;
278 gc.weightx = 0.0;
279 gc.weighty = 0.0;
280 KeepMyVisibleStateAction actKeepMyVisibleState = new KeepMyVisibleStateAction();
281 model.addObserver(actKeepMyVisibleState);
282 JButton btnKeepMyVisibleState = new JButton(actKeepMyVisibleState);
283 btnKeepMyVisibleState.setName("button.keepmyvisiblestate");
284 add(btnKeepMyVisibleState, gc);
285
286 gc.gridx = 3;
287 gc.gridy = 5;
288 gc.fill = GridBagConstraints.BOTH;
289 gc.anchor = GridBagConstraints.CENTER;
290 gc.weightx = 0.33;
291 gc.weighty = 0.0;
292 add(lblMergedVisibleState = buildValueLabel("label.mergedvisiblestate"), gc);
293
294 gc.gridx = 4;
295 gc.gridy = 5;
296 gc.fill = GridBagConstraints.NONE;
297 gc.anchor = GridBagConstraints.CENTER;
298 gc.weightx = 0.0;
299 gc.weighty = 0.0;
300 KeepTheirVisibleStateAction actKeepTheirVisibleState = new KeepTheirVisibleStateAction();
301 model.addObserver(actKeepTheirVisibleState);
302 JButton btnKeepTheirVisibleState = new JButton(actKeepTheirVisibleState);
303 btnKeepTheirVisibleState.setName("button.keeptheirvisiblestate");
304 add(btnKeepTheirVisibleState, gc);
305
306 gc.gridx = 5;
307 gc.gridy = 5;
308 gc.fill = GridBagConstraints.BOTH;
309 gc.anchor = GridBagConstraints.CENTER;
310 gc.weightx = 0.33;
311 gc.weighty = 0.0;
312 add(lblTheirVisibleState = buildValueLabel("label.theirvisiblestate"), gc);
313
314 // ---------------------------------------------------
315 gc.gridx = 3;
316 gc.gridy = 6;
317 gc.fill = GridBagConstraints.NONE;
318 gc.anchor = GridBagConstraints.CENTER;
319 gc.weightx = 0.0;
320 gc.weighty = 0.0;
321 UndecideVisibleStateConflictAction actUndecideVisibleState = new UndecideVisibleStateConflictAction();
322 model.addObserver(actUndecideVisibleState);
323 JButton btnUndecideVisibleState = new JButton(actUndecideVisibleState);
324 btnUndecideVisibleState.setName("button.undecidevisiblestate");
325 add(btnUndecideVisibleState, gc);
326 }
327
328 protected void buildReferrersRow() {
329 GridBagConstraints gc = new GridBagConstraints();
330
331 gc.gridx = 0;
332 gc.gridy = 7;
333 gc.gridwidth = 1;
334 gc.gridheight = 1;
335 gc.fill = GridBagConstraints.BOTH;
336 gc.anchor = GridBagConstraints.LINE_START;
337 gc.weightx = 0.0;
338 gc.weighty = 0.0;
339 gc.insets = new Insets(0,5,0,5);
340 add(new JLabel(tr("Referenced by:")), gc);
341
342 gc.gridx = 1;
343 gc.gridy = 7;
344 gc.fill = GridBagConstraints.BOTH;
345 gc.anchor = GridBagConstraints.CENTER;
346 gc.weightx = 0.33;
347 gc.weighty = 0.0;
348 add(lblMyReferrers = buildValueLabel("label.myreferrers"), gc);
349
350 gc.gridx = 5;
351 gc.gridy = 7;
352 gc.fill = GridBagConstraints.BOTH;
353 gc.anchor = GridBagConstraints.CENTER;
354 gc.weightx = 0.33;
355 gc.weighty = 0.0;
356 add(lblTheirReferrers = buildValueLabel("label.theirreferrers"), gc);
357 }
358
359 protected void build() {
360 setLayout(new GridBagLayout());
361 buildHeaderRow();
362 buildCoordinateConflictRows();
363 buildDeletedStateConflictRows();
364 buildVisibleStateRows();
365 buildReferrersRow();
366 }
367
368 public PropertiesMerger() {
369 model = new PropertiesMergeModel();
370 model.addObserver(this);
371 build();
372 }
373
374 public String coordToString(LatLon coord) {
375 if (coord == null)
376 return tr("(none)");
377 StringBuilder sb = new StringBuilder();
378 sb.append("(")
379 .append(COORD_FORMATTER.format(coord.lat()))
380 .append(",")
381 .append(COORD_FORMATTER.format(coord.lon()))
382 .append(")");
383 return sb.toString();
384 }
385
386 public String deletedStateToString(Boolean deleted) {
387 if (deleted == null)
388 return tr("(none)");
389 if (deleted)
390 return tr("deleted");
391 else
392 return tr("not deleted");
393 }
394
395 public String visibleStateToString(Boolean visible) {
396 if (visible == null)
397 return tr("(none)");
398 if (visible)
399 return tr("visible (on the server)");
400 else
401 return tr("not visible (on the server)");
402 }
403
404 public String visibleStateToStringMerged(Boolean visible) {
405 if (visible == null)
406 return tr("(none)");
407 if (visible)
408 return tr("Keep a clone of the local version");
409 else
410 return tr("Physically delete from local dataset");
411 }
412
413 public String referrersToString(List<OsmPrimitive> referrers) {
414 if (referrers.isEmpty())
415 return tr("(none)");
416 String str = "<html>";
417 for (OsmPrimitive r: referrers) {
418 str = str + r.getDisplayName(DefaultNameFormatter.getInstance()) + "<br>";
419 }
420 str = str + "</html>";
421 return str;
422 }
423
424 protected void updateCoordinates() {
425 lblMyCoordinates.setText(coordToString(model.getMyCoords()));
426 lblMergedCoordinates.setText(coordToString(model.getMergedCoords()));
427 lblTheirCoordinates.setText(coordToString(model.getTheirCoords()));
428 if (! model.hasCoordConflict()) {
429 lblMyCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
430 lblMergedCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
431 lblTheirCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
432 } else {
433 if (!model.isDecidedCoord()) {
434 lblMyCoordinates.setBackground(BGCOLOR_UNDECIDED);
435 lblMergedCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
436 lblTheirCoordinates.setBackground(BGCOLOR_UNDECIDED);
437 } else {
438 lblMyCoordinates.setBackground(
439 model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE)
440 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
441 );
442 lblMergedCoordinates.setBackground(BGCOLOR_DECIDED);
443 lblTheirCoordinates.setBackground(
444 model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR)
445 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
446 );
447 }
448 }
449 }
450
451 protected void updateDeletedState() {
452 lblMyDeletedState.setText(deletedStateToString(model.getMyDeletedState()));
453 lblMergedDeletedState.setText(deletedStateToString(model.getMergedDeletedState()));
454 lblTheirDeletedState.setText(deletedStateToString(model.getTheirDeletedState()));
455
456 if (! model.hasDeletedStateConflict()) {
457 lblMyDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
458 lblMergedDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
459 lblTheirDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
460 } else {
461 if (!model.isDecidedDeletedState()) {
462 lblMyDeletedState.setBackground(BGCOLOR_UNDECIDED);
463 lblMergedDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
464 lblTheirDeletedState.setBackground(BGCOLOR_UNDECIDED);
465 } else {
466 lblMyDeletedState.setBackground(
467 model.isDeletedStateDecision(MergeDecisionType.KEEP_MINE)
468 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
469 );
470 lblMergedDeletedState.setBackground(BGCOLOR_DECIDED);
471 lblTheirDeletedState.setBackground(
472 model.isDeletedStateDecision(MergeDecisionType.KEEP_THEIR)
473 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
474 );
475 }
476 }
477 }
478
479 protected void updateVisibleState() {
480 lblMyVisibleState.setText(visibleStateToString(model.getMyVisibleState()));
481 lblMergedVisibleState.setText(visibleStateToStringMerged(model.getMergedVisibleState()));
482 lblTheirVisibleState.setText(visibleStateToString(model.getTheirVisibleState()));
483
484 if (! model.hasVisibleStateConflict()) {
485 lblMyVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
486 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
487 lblTheirVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
488 } else {
489 if (!model.isDecidedVisibleState()) {
490 lblMyVisibleState.setBackground(BGCOLOR_UNDECIDED);
491 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
492 lblTheirVisibleState.setBackground(BGCOLOR_UNDECIDED);
493 } else {
494 lblMyVisibleState.setBackground(
495 model.isVisibleStateDecision(MergeDecisionType.KEEP_MINE)
496 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
497 );
498 lblMergedVisibleState.setBackground(BGCOLOR_DECIDED);
499 lblTheirVisibleState.setBackground(
500 model.isVisibleStateDecision(MergeDecisionType.KEEP_THEIR)
501 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
502 );
503 }
504 }
505 }
506
507 protected void updateReferrers() {
508 lblMyReferrers.setText(referrersToString(model.getMyReferrers()));
509 lblMyReferrers.setBackground(BGCOLOR_NO_CONFLICT);
510 lblTheirReferrers.setText(referrersToString(model.getTheirReferrers()));
511 lblTheirReferrers.setBackground(BGCOLOR_NO_CONFLICT);
512 }
513
514 public void update(Observable o, Object arg) {
515 updateCoordinates();
516 updateDeletedState();
517 updateVisibleState();
518 updateReferrers();
519 }
520
521 public PropertiesMergeModel getModel() {
522 return model;
523 }
524
525 class KeepMyCoordinatesAction extends AbstractAction implements Observer {
526 public KeepMyCoordinatesAction() {
527 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
528 putValue(Action.SHORT_DESCRIPTION, tr("Keep my coordiates"));
529 }
530
531 public void actionPerformed(ActionEvent e) {
532 model.decideCoordsConflict(MergeDecisionType.KEEP_MINE);
533 }
534
535 public void update(Observable o, Object arg) {
536 setEnabled(model.hasCoordConflict() && ! model.isDecidedCoord());
537 }
538 }
539
540 class KeepTheirCoordinatesAction extends AbstractAction implements Observer {
541 public KeepTheirCoordinatesAction() {
542 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
543 putValue(Action.SHORT_DESCRIPTION, tr("Keep their coordiates"));
544 }
545
546 public void actionPerformed(ActionEvent e) {
547 model.decideCoordsConflict(MergeDecisionType.KEEP_THEIR);
548 }
549
550 public void update(Observable o, Object arg) {
551 setEnabled(model.hasCoordConflict() && ! model.isDecidedCoord());
552 }
553 }
554
555 class UndecideCoordinateConflictAction extends AbstractAction implements Observer {
556 public UndecideCoordinateConflictAction() {
557 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
558 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between different coordinates"));
559 }
560
561 public void actionPerformed(ActionEvent e) {
562 model.decideCoordsConflict(MergeDecisionType.UNDECIDED);
563 }
564
565 public void update(Observable o, Object arg) {
566 setEnabled(model.hasCoordConflict() && model.isDecidedCoord());
567 }
568 }
569
570 class KeepMyDeletedStateAction extends AbstractAction implements Observer {
571 public KeepMyDeletedStateAction() {
572 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
573 putValue(Action.SHORT_DESCRIPTION, tr("Keep my deleted state"));
574 }
575
576 public void actionPerformed(ActionEvent e) {
577 model.decideDeletedStateConflict(MergeDecisionType.KEEP_MINE);
578 }
579
580 public void update(Observable o, Object arg) {
581 setEnabled(model.hasDeletedStateConflict() && ! model.isDecidedDeletedState());
582 }
583 }
584
585 class KeepTheirDeletedStateAction extends AbstractAction implements Observer {
586 public KeepTheirDeletedStateAction() {
587 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
588 putValue(Action.SHORT_DESCRIPTION, tr("Keep their deleted state"));
589 }
590
591 public void actionPerformed(ActionEvent e) {
592 model.decideDeletedStateConflict(MergeDecisionType.KEEP_THEIR);
593 }
594
595 public void update(Observable o, Object arg) {
596 setEnabled(model.hasDeletedStateConflict() && ! model.isDecidedDeletedState());
597 }
598 }
599
600 class UndecideDeletedStateConflictAction extends AbstractAction implements Observer {
601 public UndecideDeletedStateConflictAction() {
602 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
603 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between deleted state"));
604 }
605
606 public void actionPerformed(ActionEvent e) {
607 model.decideDeletedStateConflict(MergeDecisionType.UNDECIDED);
608 }
609
610 public void update(Observable o, Object arg) {
611 setEnabled(model.hasDeletedStateConflict() && model.isDecidedDeletedState());
612 }
613 }
614
615 class KeepMyVisibleStateAction extends AbstractAction implements Observer {
616 public KeepMyVisibleStateAction() {
617 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
618 putValue(Action.SHORT_DESCRIPTION, tr("Keep my visible state"));
619 }
620
621 public void actionPerformed(ActionEvent e) {
622 if (confirmKeepMine()) {
623 model.decideVisibleStateConflict(MergeDecisionType.KEEP_MINE);
624 }
625 }
626
627 public void update(Observable o, Object arg) {
628 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState());
629 }
630
631 protected boolean confirmKeepMine() {
632 String [] options = {
633 tr("Yes, reset the id"),
634 tr("No, abort")
635 };
636 int ret = JOptionPane.showOptionDialog(
637 null,
638 tr("<html>To keep your local version, JOSM<br>"
639 + "has to reset the id of primitive {0} to 0.<br>"
640 + "On the next upload the server will assign<br>"
641 + "it a new id.<br>"
642 + "Do yo agree?</html>",
643 model.getMyPrimitive().getId()
644 ),
645 tr("Reset id to 0"),
646 JOptionPane.YES_NO_OPTION,
647 JOptionPane.QUESTION_MESSAGE,
648 null,
649 options,
650 options[1]
651 );
652 return ret == JOptionPane.YES_OPTION;
653 }
654 }
655
656 class KeepTheirVisibleStateAction extends AbstractAction implements Observer {
657 public KeepTheirVisibleStateAction() {
658 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
659 putValue(Action.SHORT_DESCRIPTION, tr("Keep their visible state"));
660 }
661
662 public void actionPerformed(ActionEvent e) {
663 if (confirmKeepTheir()){
664 model.decideVisibleStateConflict(MergeDecisionType.KEEP_THEIR);
665 }
666 }
667
668 public void update(Observable o, Object arg) {
669 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState());
670 }
671
672 protected boolean confirmKeepTheir() {
673 String [] options = {
674 tr("Yes, purge it"),
675 tr("No, abort")
676 };
677 int ret = JOptionPane.showOptionDialog(
678 null,
679 tr("<html>JOSM will have to remove your local primitive with id {0}<br>"
680 + "from the dataset.<br>"
681 + "Do you agree?</html>",
682 model.getMyPrimitive().getId()
683 ),
684 tr("Remove from dataset"),
685 JOptionPane.YES_NO_OPTION,
686 JOptionPane.QUESTION_MESSAGE,
687 null,
688 options,
689 options[1]
690 );
691 return ret == JOptionPane.YES_OPTION;
692 }
693 }
694
695 class UndecideVisibleStateConflictAction extends AbstractAction implements Observer {
696 public UndecideVisibleStateConflictAction() {
697 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
698 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between visible state"));
699 }
700
701 public void actionPerformed(ActionEvent e) {
702 model.decideVisibleStateConflict(MergeDecisionType.UNDECIDED);
703 }
704
705 public void update(Observable o, Object arg) {
706 setEnabled(model.hasVisibleStateConflict() && model.isDecidedVisibleState());
707 }
708 }
709
710 public void deletePrimitive(boolean deleted) {
711 if (deleted) {
712 if (model.getMergedCoords() == null) {
713 model.decideCoordsConflict(MergeDecisionType.KEEP_MINE);
714 }
715 } else {
716 model.decideCoordsConflict(MergeDecisionType.UNDECIDED);
717 }
718 }
719}
Note: See TracBrowser for help on using the repository browser.