source: josm/trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java@ 729

Last change on this file since 729 was 729, checked in by stoecker, 16 years ago

added automatic tag correction system by Robin Rattay

File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.corrector;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.GridBagLayout;
8import java.util.List;
9
10import javax.swing.JLabel;
11import javax.swing.JOptionPane;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.gui.JMultilineLabel;
18import org.openstreetmap.josm.tools.GBC;
19
20public 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}
Note: See TracBrowser for help on using the repository browser.