1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.tags;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.BorderLayout;
|
---|
7 | import java.awt.GridBagConstraints;
|
---|
8 | import java.awt.GridBagLayout;
|
---|
9 |
|
---|
10 | import javax.swing.BorderFactory;
|
---|
11 | import javax.swing.JCheckBox;
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.JScrollPane;
|
---|
15 | import javax.swing.event.ChangeEvent;
|
---|
16 | import javax.swing.event.ChangeListener;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * This is a UI widget for resolving tag conflicts, i.e. differences of the tag values
|
---|
22 | * of multiple {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s.
|
---|
23 | *
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class TagConflictResolver extends JPanel {
|
---|
27 |
|
---|
28 | /** the model for the tag conflict resolver */
|
---|
29 | private TagConflictResolverModel model;
|
---|
30 | /** selects whether only tags with conflicts are displayed */
|
---|
31 | private JCheckBox cbShowTagsWithConflictsOnly;
|
---|
32 | private JCheckBox cbShowTagsWithMultiValuesOnly;
|
---|
33 |
|
---|
34 | protected JPanel buildInfoPanel() {
|
---|
35 | JPanel pnl = new JPanel();
|
---|
36 | pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
37 | pnl.setLayout(new GridBagLayout());
|
---|
38 | GridBagConstraints gc = new GridBagConstraints();
|
---|
39 | gc.fill = GridBagConstraints.BOTH;
|
---|
40 | gc.weighty = 1.0;
|
---|
41 | gc.weightx = 1.0;
|
---|
42 | gc.anchor = GridBagConstraints.LINE_START;
|
---|
43 | gc.gridwidth = 2;
|
---|
44 | pnl.add(new JLabel(tr("<html>Please select the values to keep for the following tags.</html>")), gc);
|
---|
45 |
|
---|
46 | gc.gridwidth = 1;
|
---|
47 | gc.gridy = 1;
|
---|
48 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
49 | gc.weighty = 0.0;
|
---|
50 | pnl.add(cbShowTagsWithConflictsOnly = new JCheckBox(tr("Show tags with conflicts only")), gc);
|
---|
51 | pnl.add(cbShowTagsWithMultiValuesOnly = new JCheckBox(tr("Show tags with multiple values only")), gc);
|
---|
52 | cbShowTagsWithConflictsOnly.addChangeListener(
|
---|
53 | new ChangeListener() {
|
---|
54 | @Override
|
---|
55 | public void stateChanged(ChangeEvent e) {
|
---|
56 | model.setShowTagsWithConflictsOnly(cbShowTagsWithConflictsOnly.isSelected());
|
---|
57 | cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected());
|
---|
58 | }
|
---|
59 | }
|
---|
60 | );
|
---|
61 | cbShowTagsWithConflictsOnly.setSelected(
|
---|
62 | Main.pref.getBoolean(getClass().getName() + ".showTagsWithConflictsOnly", false)
|
---|
63 | );
|
---|
64 | cbShowTagsWithMultiValuesOnly.addChangeListener(
|
---|
65 | new ChangeListener() {
|
---|
66 | @Override
|
---|
67 | public void stateChanged(ChangeEvent e) {
|
---|
68 | model.setShowTagsWithMultiValuesOnly(cbShowTagsWithMultiValuesOnly.isSelected());
|
---|
69 | }
|
---|
70 | }
|
---|
71 | );
|
---|
72 | cbShowTagsWithMultiValuesOnly.setSelected(
|
---|
73 | Main.pref.getBoolean(getClass().getName() + ".showTagsWithMultiValuesOnly", false)
|
---|
74 | );
|
---|
75 | cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected());
|
---|
76 | return pnl;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Remembers the current settings in the global preferences
|
---|
81 | *
|
---|
82 | */
|
---|
83 | public void rememberPreferences() {
|
---|
84 | Main.pref.put(getClass().getName() + ".showTagsWithConflictsOnly", cbShowTagsWithConflictsOnly.isSelected());
|
---|
85 | Main.pref.put(getClass().getName() + ".showTagsWithMultiValuesOnly", cbShowTagsWithMultiValuesOnly.isSelected());
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected void build() {
|
---|
89 | setLayout(new BorderLayout());
|
---|
90 | add(buildInfoPanel(), BorderLayout.NORTH);
|
---|
91 | add(new JScrollPane(new TagConflictResolverTable(model)), BorderLayout.CENTER);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Constructs a new {@code TagConflictResolver}.
|
---|
96 | */
|
---|
97 | public TagConflictResolver() {
|
---|
98 | this.model = new TagConflictResolverModel();
|
---|
99 | build();
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Replies the model used by this dialog
|
---|
104 | *
|
---|
105 | * @return the model
|
---|
106 | */
|
---|
107 | public TagConflictResolverModel getModel() {
|
---|
108 | return model;
|
---|
109 | }
|
---|
110 | }
|
---|