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

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

fixed #3281: OsmPrimitiveType fails for fusional and/or agglutinative languages

File size: 25.3 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.Observable;
13import java.util.Observer;
14
15import javax.swing.AbstractAction;
16import javax.swing.Action;
17import javax.swing.BorderFactory;
18import javax.swing.JButton;
19import javax.swing.JLabel;
20import javax.swing.JOptionPane;
21import javax.swing.JPanel;
22import javax.swing.SwingUtilities;
23
24import org.openstreetmap.josm.Main;
25import org.openstreetmap.josm.data.coor.LatLon;
26import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
27import org.openstreetmap.josm.gui.OptionPaneUtil;
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 {
37 private static DecimalFormat COORD_FORMATTER = new DecimalFormat("###0.0000");
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 final PropertiesMergeModel model;
60
61 protected JLabel buildValueLabel(String name) {
62 JLabel lbl = new JLabel();
63 lbl.setName(name);
64 lbl.setHorizontalAlignment(JLabel.CENTER);
65 lbl.setOpaque(true);
66 lbl.setBorder(BorderFactory.createLoweredBevelBorder());
67 return lbl;
68 }
69
70 protected void buildHeaderRow() {
71 GridBagConstraints gc = new GridBagConstraints();
72
73 gc.gridx = 1;
74 gc.gridy = 0;
75 gc.gridwidth = 1;
76 gc.gridheight = 1;
77 gc.fill = GridBagConstraints.NONE;
78 gc.anchor = GridBagConstraints.CENTER;
79 gc.weightx = 0.0;
80 gc.weighty = 0.0;
81 gc.insets = new Insets(10,0,10,0);
82 lblMyVersion = new JLabel(tr("My version"));
83 lblMyVersion.setToolTipText(tr("Properties in my dataset, i.e. the local dataset"));
84 add(lblMyVersion, gc);
85
86 gc.gridx = 3;
87 gc.gridy = 0;
88 lblMergedVersion = new JLabel(tr("Merged version"));
89 lblMergedVersion.setToolTipText(tr("Properties in the merged element. They will replace properties in my elements when merge decisions are applied."));
90 add(lblMergedVersion, gc);
91
92 gc.gridx = 5;
93 gc.gridy = 0;
94 lblTheirVersion = new JLabel(tr("Their version"));
95 lblTheirVersion.setToolTipText(tr("Properties in their dataset, i.e. the server dataset"));
96 add(lblTheirVersion, gc);
97 }
98
99 protected void buildCoordinateConflictRows() {
100 GridBagConstraints gc = new GridBagConstraints();
101
102 gc.gridx = 0;
103 gc.gridy = 1;
104 gc.gridwidth = 1;
105 gc.gridheight = 1;
106 gc.fill = GridBagConstraints.HORIZONTAL;
107 gc.anchor = GridBagConstraints.LINE_START;
108 gc.weightx = 0.0;
109 gc.weighty = 0.0;
110 gc.insets = new Insets(0,5,0,5);
111 add(new JLabel(tr("Coordinates:")), gc);
112
113 gc.gridx = 1;
114 gc.gridy = 1;
115 gc.fill = GridBagConstraints.BOTH;
116 gc.anchor = GridBagConstraints.CENTER;
117 gc.weightx = 0.33;
118 gc.weighty = 0.0;
119 add(lblMyCoordinates = buildValueLabel("label.mycoordinates"), gc);
120
121 gc.gridx = 2;
122 gc.gridy = 1;
123 gc.fill = GridBagConstraints.NONE;
124 gc.anchor = GridBagConstraints.CENTER;
125 gc.weightx = 0.0;
126 gc.weighty = 0.0;
127 KeepMyCoordinatesAction actKeepMyCoordinates = new KeepMyCoordinatesAction();
128 model.addObserver(actKeepMyCoordinates);
129 JButton btnKeepMyCoordinates = new JButton(actKeepMyCoordinates);
130 btnKeepMyCoordinates.setName("button.keepmycoordinates");
131 add(btnKeepMyCoordinates, gc);
132
133
134 gc.gridx = 3;
135 gc.gridy = 1;
136 gc.fill = GridBagConstraints.BOTH;
137 gc.anchor = GridBagConstraints.CENTER;
138 gc.weightx = 0.33;
139 gc.weighty = 0.0;
140 add(lblMergedCoordinates = buildValueLabel("label.mergedcoordinates"), gc);
141
142 gc.gridx = 4;
143 gc.gridy = 1;
144 gc.fill = GridBagConstraints.NONE;
145 gc.anchor = GridBagConstraints.CENTER;
146 gc.weightx = 0.0;
147 gc.weighty = 0.0;
148 KeepTheirCoordinatesAction actKeepTheirCoordinates = new KeepTheirCoordinatesAction();
149 model.addObserver(actKeepTheirCoordinates);
150 JButton btnKeepTheirCoordinates = new JButton(actKeepTheirCoordinates);
151 add(btnKeepTheirCoordinates, gc);
152
153 gc.gridx = 5;
154 gc.gridy = 1;
155 gc.fill = GridBagConstraints.BOTH;
156 gc.anchor = GridBagConstraints.CENTER;
157 gc.weightx = 0.33;
158 gc.weighty = 0.0;
159 add(lblTheirCoordinates = buildValueLabel("label.theircoordinates"), gc);
160
161 // ---------------------------------------------------
162 gc.gridx = 3;
163 gc.gridy = 2;
164 gc.fill = GridBagConstraints.NONE;
165 gc.anchor = GridBagConstraints.CENTER;
166 gc.weightx = 0.0;
167 gc.weighty = 0.0;
168 gc.insets = new Insets(0,5,20,5);
169 UndecideCoordinateConflictAction actUndecideCoordinates = new UndecideCoordinateConflictAction();
170 model.addObserver(actUndecideCoordinates);
171 JButton btnUndecideCoordinates = new JButton(actUndecideCoordinates);
172 add(btnUndecideCoordinates, gc);
173 }
174
175 protected void buildDeletedStateConflictRows() {
176 GridBagConstraints gc = new GridBagConstraints();
177
178 gc.gridx = 0;
179 gc.gridy = 3;
180 gc.gridwidth = 1;
181 gc.gridheight = 1;
182 gc.fill = GridBagConstraints.BOTH;
183 gc.anchor = GridBagConstraints.LINE_START;
184 gc.weightx = 0.0;
185 gc.weighty = 0.0;
186 gc.insets = new Insets(0,5,0,5);
187 add(new JLabel(tr("Deleted State:")), gc);
188
189 gc.gridx = 1;
190 gc.gridy = 3;
191 gc.fill = GridBagConstraints.BOTH;
192 gc.anchor = GridBagConstraints.CENTER;
193 gc.weightx = 0.33;
194 gc.weighty = 0.0;
195 add(lblMyDeletedState = buildValueLabel("label.mydeletedstate"), gc);
196
197 gc.gridx = 2;
198 gc.gridy = 3;
199 gc.fill = GridBagConstraints.NONE;
200 gc.anchor = GridBagConstraints.CENTER;
201 gc.weightx = 0.0;
202 gc.weighty = 0.0;
203 KeepMyDeletedStateAction actKeepMyDeletedState = new KeepMyDeletedStateAction();
204 model.addObserver(actKeepMyDeletedState);
205 JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState);
206 btnKeepMyDeletedState.setName("button.keepmydeletedstate");
207 add(btnKeepMyDeletedState, gc);
208
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 build() {
329 setLayout(new GridBagLayout());
330 buildHeaderRow();
331 buildCoordinateConflictRows();
332 buildDeletedStateConflictRows();
333 buildVisibleStateRows();
334 }
335
336 public PropertiesMerger() {
337 model = new PropertiesMergeModel();
338 model.addObserver(this);
339 build();
340 }
341
342 public String coordToString(LatLon coord) {
343 if (coord == null)
344 return tr("(none)");
345 StringBuilder sb = new StringBuilder();
346 sb.append("(")
347 .append(COORD_FORMATTER.format(coord.lat()))
348 .append(",")
349 .append(COORD_FORMATTER.format(coord.lon()))
350 .append(")");
351 return sb.toString();
352 }
353
354 public String deletedStateToString(Boolean deleted) {
355 if (deleted == null)
356 return tr("(none)");
357 if (deleted)
358 return tr("deleted");
359 else
360 return tr("not deleted");
361 }
362
363 public String visibleStateToString(Boolean visible) {
364 if (visible == null)
365 return tr("(none)");
366 if (visible)
367 return tr("visible (on the server)");
368 else
369 return tr("not visible (on the server)");
370 }
371
372 public String visibleStateToStringMerged(Boolean visible) {
373 if (visible == null)
374 return tr("(none)");
375 if (visible)
376 return tr("Keep a clone of the local version");
377 else
378 return tr("Physically delete from local dataset");
379 }
380
381 protected void updateCoordinates() {
382 lblMyCoordinates.setText(coordToString(model.getMyCoords()));
383 lblMergedCoordinates.setText(coordToString(model.getMergedCoords()));
384 lblTheirCoordinates.setText(coordToString(model.getTheirCoords()));
385 if (! model.hasCoordConflict()) {
386 lblMyCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
387 lblMergedCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
388 lblTheirCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
389 } else {
390 if (!model.isDecidedCoord()) {
391 lblMyCoordinates.setBackground(BGCOLOR_UNDECIDED);
392 lblMergedCoordinates.setBackground(BGCOLOR_NO_CONFLICT);
393 lblTheirCoordinates.setBackground(BGCOLOR_UNDECIDED);
394 } else {
395 lblMyCoordinates.setBackground(
396 model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE)
397 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
398 );
399 lblMergedCoordinates.setBackground(BGCOLOR_DECIDED);
400 lblTheirCoordinates.setBackground(
401 model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR)
402 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
403 );
404 }
405 }
406 }
407
408 protected void updateDeletedState() {
409 lblMyDeletedState.setText(deletedStateToString(model.getMyDeletedState()));
410 lblMergedDeletedState.setText(deletedStateToString(model.getMergedDeletedState()));
411 lblTheirDeletedState.setText(deletedStateToString(model.getTheirDeletedState()));
412
413 if (! model.hasDeletedStateConflict()) {
414 lblMyDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
415 lblMergedDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
416 lblTheirDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
417 } else {
418 if (!model.isDecidedDeletedState()) {
419 lblMyDeletedState.setBackground(BGCOLOR_UNDECIDED);
420 lblMergedDeletedState.setBackground(BGCOLOR_NO_CONFLICT);
421 lblTheirDeletedState.setBackground(BGCOLOR_UNDECIDED);
422 } else {
423 lblMyDeletedState.setBackground(
424 model.isDeletedStateDecision(MergeDecisionType.KEEP_MINE)
425 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
426 );
427 lblMergedDeletedState.setBackground(BGCOLOR_DECIDED);
428 lblTheirDeletedState.setBackground(
429 model.isDeletedStateDecision(MergeDecisionType.KEEP_THEIR)
430 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
431 );
432 }
433 }
434 }
435
436 protected void updateVisibleState() {
437 lblMyVisibleState.setText(visibleStateToString(model.getMyVisibleState()));
438 lblMergedVisibleState.setText(visibleStateToStringMerged(model.getMergedVisibleState()));
439 lblTheirVisibleState.setText(visibleStateToString(model.getTheirVisibleState()));
440
441 if (! model.hasVisibleStateConflict()) {
442 lblMyVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
443 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
444 lblTheirVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
445 } else {
446 if (!model.isDecidedVisibleState()) {
447 lblMyVisibleState.setBackground(BGCOLOR_UNDECIDED);
448 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT);
449 lblTheirVisibleState.setBackground(BGCOLOR_UNDECIDED);
450 } else {
451 lblMyVisibleState.setBackground(
452 model.isVisibleStateDecision(MergeDecisionType.KEEP_MINE)
453 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
454 );
455 lblMergedVisibleState.setBackground(BGCOLOR_DECIDED);
456 lblTheirVisibleState.setBackground(
457 model.isVisibleStateDecision(MergeDecisionType.KEEP_THEIR)
458 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT
459 );
460 }
461 }
462 }
463
464 public void update(Observable o, Object arg) {
465 updateCoordinates();
466 updateDeletedState();
467 updateVisibleState();
468 }
469
470 public PropertiesMergeModel getModel() {
471 return model;
472 }
473
474 class KeepMyCoordinatesAction extends AbstractAction implements Observer {
475 public KeepMyCoordinatesAction() {
476 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
477 putValue(Action.SHORT_DESCRIPTION, tr("Keep my coordiates"));
478 }
479
480 public void actionPerformed(ActionEvent e) {
481 model.decideCoordsConflict(MergeDecisionType.KEEP_MINE);
482 }
483
484 public void update(Observable o, Object arg) {
485 setEnabled(model.hasCoordConflict() && ! model.isDecidedCoord());
486 }
487 }
488
489 class KeepTheirCoordinatesAction extends AbstractAction implements Observer {
490 public KeepTheirCoordinatesAction() {
491 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
492 putValue(Action.SHORT_DESCRIPTION, tr("Keep their coordiates"));
493 }
494
495 public void actionPerformed(ActionEvent e) {
496 model.decideCoordsConflict(MergeDecisionType.KEEP_THEIR);
497 }
498
499 public void update(Observable o, Object arg) {
500 setEnabled(model.hasCoordConflict() && ! model.isDecidedCoord());
501 }
502 }
503
504 class UndecideCoordinateConflictAction extends AbstractAction implements Observer {
505 public UndecideCoordinateConflictAction() {
506 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
507 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between different coordinates"));
508 }
509
510 public void actionPerformed(ActionEvent e) {
511 model.decideCoordsConflict(MergeDecisionType.UNDECIDED);
512 }
513
514 public void update(Observable o, Object arg) {
515 setEnabled(model.hasCoordConflict() && model.isDecidedCoord());
516 }
517 }
518
519 class KeepMyDeletedStateAction extends AbstractAction implements Observer {
520 public KeepMyDeletedStateAction() {
521 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
522 putValue(Action.SHORT_DESCRIPTION, tr("Keep my deleted state"));
523 }
524
525 public void actionPerformed(ActionEvent e) {
526 model.decideDeletedStateConflict(MergeDecisionType.KEEP_MINE);
527 }
528
529 public void update(Observable o, Object arg) {
530 setEnabled(model.hasDeletedStateConflict() && ! model.isDecidedDeletedState());
531 }
532 }
533
534 class KeepTheirDeletedStateAction extends AbstractAction implements Observer {
535 public KeepTheirDeletedStateAction() {
536 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
537 putValue(Action.SHORT_DESCRIPTION, tr("Keep their deleted state"));
538 }
539
540 public void actionPerformed(ActionEvent e) {
541 model.decideDeletedStateConflict(MergeDecisionType.KEEP_THEIR);
542 }
543
544 public void update(Observable o, Object arg) {
545 setEnabled(model.hasDeletedStateConflict() && ! model.isDecidedDeletedState());
546 }
547 }
548
549 class UndecideDeletedStateConflictAction extends AbstractAction implements Observer {
550 public UndecideDeletedStateConflictAction() {
551 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
552 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between deleted state"));
553 }
554
555 public void actionPerformed(ActionEvent e) {
556 model.decideDeletedStateConflict(MergeDecisionType.UNDECIDED);
557 }
558
559 public void update(Observable o, Object arg) {
560 setEnabled(model.hasDeletedStateConflict() && model.isDecidedDeletedState());
561 }
562 }
563
564 class KeepMyVisibleStateAction extends AbstractAction implements Observer {
565 public KeepMyVisibleStateAction() {
566 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine"));
567 putValue(Action.SHORT_DESCRIPTION, tr("Keep my visible state"));
568 }
569
570 public void actionPerformed(ActionEvent e) {
571 if (confirmKeepMine()) {
572 model.decideVisibleStateConflict(MergeDecisionType.KEEP_MINE);
573 }
574 }
575
576 public void update(Observable o, Object arg) {
577 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState());
578 }
579
580 protected boolean confirmKeepMine() {
581 String [] options = {
582 tr("Yes, reset the id"),
583 tr("No, abort")
584 };
585 int ret = OptionPaneUtil.showOptionDialog(
586 null,
587 tr("<html>To keep your local version, JOSM<br>"
588 + "has to reset the id of primitive {0} to 0.<br>"
589 + "On the next upload the server will assign<br>"
590 + "it a new id.<br>"
591 + "Do yo agree?</html>",
592 model.getMyPrimitive().id
593 ),
594 tr("Reset id to 0"),
595 JOptionPane.YES_NO_OPTION,
596 JOptionPane.QUESTION_MESSAGE,
597 options,
598 options[1]
599 );
600 return ret == JOptionPane.YES_OPTION;
601 }
602 }
603
604 class KeepTheirVisibleStateAction extends AbstractAction implements Observer {
605 public KeepTheirVisibleStateAction() {
606 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir"));
607 putValue(Action.SHORT_DESCRIPTION, tr("Keep their visible state"));
608 }
609
610 public void actionPerformed(ActionEvent e) {
611 if (confirmKeepTheir()){
612 model.decideVisibleStateConflict(MergeDecisionType.KEEP_THEIR);
613 }
614 }
615
616 public void update(Observable o, Object arg) {
617 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState());
618 }
619
620 protected boolean confirmKeepTheir() {
621 String [] options = {
622 tr("Yes, purge it"),
623 tr("No, abort")
624 };
625 int ret = OptionPaneUtil.showOptionDialog(
626 null,
627 tr("<html>JOSM will have to remove your local primitive with id {0}<br>"
628 + "from the dataset.<br>"
629 + "Do you agree?</html>",
630 model.getMyPrimitive().id
631 ),
632 tr("Remove from dataset"),
633 JOptionPane.YES_NO_OPTION,
634 JOptionPane.QUESTION_MESSAGE,
635 options,
636 options[1]
637 );
638 return ret == JOptionPane.YES_OPTION;
639 }
640 }
641
642 class UndecideVisibleStateConflictAction extends AbstractAction implements Observer {
643 public UndecideVisibleStateConflictAction() {
644 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide"));
645 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between visible state"));
646 }
647
648 public void actionPerformed(ActionEvent e) {
649 model.decideVisibleStateConflict(MergeDecisionType.UNDECIDED);
650 }
651
652 public void update(Observable o, Object arg) {
653 setEnabled(model.hasVisibleStateConflict() && model.isDecidedVisibleState());
654 }
655 }
656}
Note: See TracBrowser for help on using the repository browser.