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