001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.gui.conflict.tags;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.awt.BorderLayout;
007 import java.awt.GridBagConstraints;
008 import java.awt.GridBagLayout;
009
010 import javax.swing.BorderFactory;
011 import javax.swing.JCheckBox;
012 import javax.swing.JLabel;
013 import javax.swing.JPanel;
014 import javax.swing.JScrollPane;
015 import javax.swing.event.ChangeEvent;
016 import javax.swing.event.ChangeListener;
017
018 import org.openstreetmap.josm.Main;
019
020 /**
021 * This is a UI widget for resolving tag conflicts, i.e. differences of the tag values
022 * of multiple {@link OsmPrimitive}s.
023 *
024 *
025 */
026 public class TagConflictResolver extends JPanel {
027
028 /** the model for the tag conflict resolver */
029 private TagConflictResolverModel model;
030 /** selects whether only tags with conflicts are displayed */
031 private JCheckBox cbShowTagsWithConflictsOnly;
032 private JCheckBox cbShowTagsWithMultiValuesOnly;
033
034 protected JPanel buildInfoPanel() {
035 JPanel pnl = new JPanel();
036 pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
037 pnl.setLayout(new GridBagLayout());
038 GridBagConstraints gc = new GridBagConstraints();
039 gc.fill = GridBagConstraints.BOTH;
040 gc.weighty = 1.0;
041 gc.weightx = 1.0;
042 gc.anchor = GridBagConstraints.LINE_START;
043 gc.gridwidth = 2;
044 pnl.add(new JLabel(tr("<html>Please select the values to keep for the following tags.</html>")), gc);
045
046 gc.gridwidth = 1;
047 gc.gridy = 1;
048 gc.fill = GridBagConstraints.HORIZONTAL;
049 gc.weighty = 0.0;
050 pnl.add(cbShowTagsWithConflictsOnly = new JCheckBox(tr("Show tags with conflicts only")), gc);
051 pnl.add(cbShowTagsWithMultiValuesOnly = new JCheckBox(tr("Show tags with multiple values only")), gc);
052 cbShowTagsWithConflictsOnly.addChangeListener(
053 new ChangeListener() {
054 public void stateChanged(ChangeEvent e) {
055 model.setShowTagsWithConflictsOnly(cbShowTagsWithConflictsOnly.isSelected());
056 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected());
057 }
058 }
059 );
060 cbShowTagsWithConflictsOnly.setSelected(
061 Main.pref.getBoolean(getClass().getName() + ".showTagsWithConflictsOnly", false)
062 );
063 cbShowTagsWithMultiValuesOnly.addChangeListener(
064 new ChangeListener() {
065 public void stateChanged(ChangeEvent e) {
066 model.setShowTagsWithMultiValuesOnly(cbShowTagsWithMultiValuesOnly.isSelected());
067 }
068 }
069 );
070 cbShowTagsWithMultiValuesOnly.setSelected(
071 Main.pref.getBoolean(getClass().getName() + ".showTagsWithMultiValuesOnly", false)
072 );
073 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected());
074 return pnl;
075 }
076
077 /**
078 * Remembers the current settings in the global preferences
079 *
080 */
081 public void rememberPreferences() {
082 Main.pref.put(getClass().getName() + ".showTagsWithConflictsOnly", cbShowTagsWithConflictsOnly.isSelected());
083 Main.pref.put(getClass().getName() + ".showTagsWithMultiValuesOnly", cbShowTagsWithMultiValuesOnly.isSelected());
084 }
085
086 protected void build() {
087 setLayout(new BorderLayout());
088 add(buildInfoPanel(), BorderLayout.NORTH);
089 add(new JScrollPane(new TagConflictResolverTable(model)), BorderLayout.CENTER);
090 }
091
092 public TagConflictResolver() {
093 this.model = new TagConflictResolverModel();
094 build();
095 }
096
097 /**
098 * Replies the model used by this dialog
099 *
100 * @return the model
101 */
102 public TagConflictResolverModel getModel() {
103 return model;
104 }
105 }