001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.dialogs.changeset; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.BorderLayout; 007import java.beans.PropertyChangeEvent; 008import java.beans.PropertyChangeListener; 009import java.util.Map; 010 011import javax.swing.BorderFactory; 012import javax.swing.JPanel; 013import javax.swing.JScrollPane; 014import javax.swing.JTable; 015 016import org.openstreetmap.josm.data.osm.Changeset; 017import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog.ReadOnlyTableModel; 018 019/** 020 * This panel displays the tags of the currently selected changeset in the {@link ChangesetCacheManager} 021 * 022 */ 023public class ChangesetTagsPanel extends JPanel implements PropertyChangeListener { 024 025 private ReadOnlyTableModel model; 026 027 protected void build() { 028 setLayout(new BorderLayout()); 029 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 030 model = new ReadOnlyTableModel(); 031 model.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")}); 032 JTable tblTags = new JTable(model); 033 tblTags.setAutoCreateRowSorter(true); 034 tblTags.getTableHeader().setReorderingAllowed(false); 035 add(new JScrollPane(tblTags), BorderLayout.CENTER); 036 } 037 038 /** 039 * Constructs a new {@code ChangesetTagsPanel}. 040 */ 041 public ChangesetTagsPanel() { 042 build(); 043 } 044 045 /* ---------------------------------------------------------------------------- */ 046 /* interface PropertyChangeListener */ 047 /* ---------------------------------------------------------------------------- */ 048 @Override 049 public void propertyChange(PropertyChangeEvent evt) { 050 if (!evt.getPropertyName().equals(ChangesetCacheManagerModel.CHANGESET_IN_DETAIL_VIEW_PROP)) 051 return; 052 model.setRowCount(0); 053 Changeset cs = (Changeset) evt.getNewValue(); 054 if (cs != null) { 055 for (Map.Entry<String, String> tag : cs.getKeys().entrySet()) { 056 model.addRow(new String[] {tag.getKey(), tag.getValue()}); 057 } 058 } 059 } 060}