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; 015 016import org.openstreetmap.josm.spi.preferences.Config; 017 018/** 019 * This is a UI widget for resolving tag conflicts, i.e. differences of the tag values 020 * of multiple {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s. 021 * @since 2008 022 */ 023public class TagConflictResolver extends JPanel { 024 025 /** the model for the tag conflict resolver */ 026 private final TagConflictResolverModel model; 027 /** selects whether only tags with conflicts are displayed */ 028 private final JCheckBox cbShowTagsWithConflictsOnly = new JCheckBox(tr("Show tags with conflicts only")); 029 private final JCheckBox cbShowTagsWithMultiValuesOnly = new JCheckBox(tr("Show tags with multiple values only")); 030 031 /** 032 * Constructs a new {@code TagConflictResolver}. 033 * @param model tag conflict resolver model 034 * @since 11772 035 */ 036 public TagConflictResolver(TagConflictResolverModel model) { 037 this.model = model; 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(e -> { 059 model.setShowTagsWithConflictsOnly(cbShowTagsWithConflictsOnly.isSelected()); 060 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected()); 061 }); 062 cbShowTagsWithConflictsOnly.setSelected(Config.getPref().getBoolean(getClass().getName() + ".showTagsWithConflictsOnly", false) 063 ); 064 cbShowTagsWithMultiValuesOnly.addChangeListener( 065 e -> model.setShowTagsWithMultiValuesOnly(cbShowTagsWithMultiValuesOnly.isSelected()) 066 ); 067 cbShowTagsWithMultiValuesOnly.setSelected(Config.getPref().getBoolean(getClass().getName() + ".showTagsWithMultiValuesOnly", false) 068 ); 069 cbShowTagsWithMultiValuesOnly.setEnabled(cbShowTagsWithConflictsOnly.isSelected()); 070 return pnl; 071 } 072 073 /** 074 * Remembers the current settings in the global preferences 075 * 076 */ 077 public void rememberPreferences() { 078 Config.getPref().putBoolean(getClass().getName() + ".showTagsWithConflictsOnly", cbShowTagsWithConflictsOnly.isSelected()); 079 Config.getPref().putBoolean(getClass().getName() + ".showTagsWithMultiValuesOnly", cbShowTagsWithMultiValuesOnly.isSelected()); 080 } 081 082 protected final void build() { 083 setLayout(new BorderLayout()); 084 add(buildInfoPanel(), BorderLayout.NORTH); 085 add(new JScrollPane(new TagConflictResolverTable(model)), BorderLayout.CENTER); 086 } 087 088 /** 089 * Replies the model used by this dialog 090 * 091 * @return the model 092 */ 093 public TagConflictResolverModel getModel() { 094 return model; 095 } 096}