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 * @since 2008 024 */ 025public class TagConflictResolver extends JPanel { 026 027 /** the model for the tag conflict resolver */ 028 private final TagConflictResolverModel model; 029 /** selects whether only tags with conflicts are displayed */ 030 private final JCheckBox cbShowTagsWithConflictsOnly = new JCheckBox(tr("Show tags with conflicts only")); 031 private final JCheckBox cbShowTagsWithMultiValuesOnly = new JCheckBox(tr("Show tags with multiple values only")); 032 033 /** 034 * Constructs a new {@code TagConflictResolver}. 035 */ 036 public TagConflictResolver() { 037 this.model = new TagConflictResolverModel(); 038 build(); 039 } 040 041 protected JPanel buildInfoPanel() { 042 JPanel pnl = new JPanel(new GridBagLayout()); 043 pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 044 GridBagConstraints gc = new GridBagConstraints(); 045 gc.fill = GridBagConstraints.BOTH; 046 gc.weighty = 1.0; 047 gc.weightx = 1.0; 048 gc.anchor = GridBagConstraints.LINE_START; 049 gc.gridwidth = 2; 050 pnl.add(new JLabel(tr("<html>Please select the values to keep for the following tags.</html>")), gc); 051 052 gc.gridwidth = 1; 053 gc.gridy = 1; 054 gc.fill = GridBagConstraints.HORIZONTAL; 055 gc.weighty = 0.0; 056 pnl.add(cbShowTagsWithConflictsOnly, gc); 057 pnl.add(cbShowTagsWithMultiValuesOnly, gc); 058 cbShowTagsWithConflictsOnly.addChangeListener( 059 new ChangeListener() { 060 @Override 061 public void stateChanged(ChangeEvent e) { 062 model.setShowTagsWithConflictsOnly(cbShowTagsWithConflictsOnly.isSelected()); 063 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected()); 064 } 065 } 066 ); 067 cbShowTagsWithConflictsOnly.setSelected( 068 Main.pref.getBoolean(getClass().getName() + ".showTagsWithConflictsOnly", false) 069 ); 070 cbShowTagsWithMultiValuesOnly.addChangeListener( 071 new ChangeListener() { 072 @Override 073 public void stateChanged(ChangeEvent e) { 074 model.setShowTagsWithMultiValuesOnly(cbShowTagsWithMultiValuesOnly.isSelected()); 075 } 076 } 077 ); 078 cbShowTagsWithMultiValuesOnly.setSelected( 079 Main.pref.getBoolean(getClass().getName() + ".showTagsWithMultiValuesOnly", false) 080 ); 081 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected()); 082 return pnl; 083 } 084 085 /** 086 * Remembers the current settings in the global preferences 087 * 088 */ 089 public void rememberPreferences() { 090 Main.pref.put(getClass().getName() + ".showTagsWithConflictsOnly", cbShowTagsWithConflictsOnly.isSelected()); 091 Main.pref.put(getClass().getName() + ".showTagsWithMultiValuesOnly", cbShowTagsWithMultiValuesOnly.isSelected()); 092 } 093 094 protected final void build() { 095 setLayout(new BorderLayout()); 096 add(buildInfoPanel(), BorderLayout.NORTH); 097 add(new JScrollPane(new TagConflictResolverTable(model)), BorderLayout.CENTER); 098 } 099 100 /** 101 * Replies the model used by this dialog 102 * 103 * @return the model 104 */ 105 public TagConflictResolverModel getModel() { 106 return model; 107 } 108}