1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.corrector;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JOptionPane;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JScrollPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.gui.JMultilineLabel;
|
---|
18 | import org.openstreetmap.josm.tools.GBC;
|
---|
19 |
|
---|
20 | public abstract class TagCorrector<P extends OsmPrimitive> {
|
---|
21 |
|
---|
22 | public abstract boolean execute(P primitive);
|
---|
23 |
|
---|
24 | protected boolean applyCorrections(List<TagCorrection> tagCorrections,
|
---|
25 | P primitive, String description) {
|
---|
26 |
|
---|
27 | boolean updated = false;
|
---|
28 |
|
---|
29 | if (tagCorrections != null && tagCorrections.size() > 0) {
|
---|
30 |
|
---|
31 | final TagCorrectionTable table = TagCorrectionTable
|
---|
32 | .create(tagCorrections);
|
---|
33 | final JScrollPane scrollPane = new JScrollPane(table);
|
---|
34 |
|
---|
35 | final JPanel p = new JPanel(new GridBagLayout());
|
---|
36 |
|
---|
37 | final JMultilineLabel label1 = new JMultilineLabel(description);
|
---|
38 | label1.setMaxWidth(400);
|
---|
39 | p.add(label1, GBC.eop());
|
---|
40 |
|
---|
41 | final JMultilineLabel label2 = new JMultilineLabel(tr("Please select which property changes you want to apply."));
|
---|
42 | label2.setMaxWidth(400);
|
---|
43 | p.add(label2, GBC.eop());
|
---|
44 | p.add(scrollPane, GBC.eol());
|
---|
45 |
|
---|
46 | int answer = JOptionPane.showConfirmDialog(Main.parent, p,
|
---|
47 | tr("Automatic tag correction"),
|
---|
48 | JOptionPane.OK_CANCEL_OPTION);
|
---|
49 |
|
---|
50 | if (answer == JOptionPane.OK_OPTION) {
|
---|
51 | for (int i = 0; i < tagCorrections.size(); i++) {
|
---|
52 | if (table.getTagCorrectionTableModel().getApply(i)) {
|
---|
53 | TagCorrection tagCorrection = tagCorrections.get(i);
|
---|
54 | if (tagCorrection.isKeyChanged())
|
---|
55 | primitive.remove(tagCorrection.oldKey);
|
---|
56 | primitive.put(tagCorrection.newKey, tagCorrection
|
---|
57 | .newValue);
|
---|
58 | updated = true;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | return updated;
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|