Changeset 9149 in josm for trunk/src/org


Ignore:
Timestamp:
2015-12-25T20:01:23+01:00 (9 years ago)
Author:
simon04
Message:

see #9775 - Allow plugins to change display of keys/values in properties dialog

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/properties
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r8540 r9149  
    99import java.awt.Component;
    1010import java.awt.Font;
     11import java.util.Collection;
    1112import java.util.Map;
    1213import java.util.Objects;
     14import java.util.concurrent.CopyOnWriteArrayList;
    1315
    1416import javax.swing.JLabel;
     
    1618import javax.swing.UIDefaults;
    1719import javax.swing.table.DefaultTableCellRenderer;
     20import javax.swing.table.TableCellRenderer;
    1821
    1922import org.openstreetmap.josm.Main;
     
    2528 */
    2629public class PropertiesCellRenderer extends DefaultTableCellRenderer {
     30
     31    private final Collection<TableCellRenderer> customRenderer = new CopyOnWriteArrayList<>();
    2732
    2833    private void setColors(Component c, String key, boolean isSelected) {
     
    4550    @Override
    4651    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     52        for (TableCellRenderer renderer : customRenderer) {
     53            final Component component = renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     54            if (component != null) {
     55                return component;
     56            }
     57        }
    4758        Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    4859        if (value == null)
     
    106117        return c;
    107118    }
     119
     120    /**
     121     * Adds a custom table cell renderer to render cells of the tags table.
     122     *
     123     * If the renderer is not capable performing a {@link TableCellRenderer#getTableCellRendererComponent},
     124     * it should return {@code null} to fall back to the
     125     * {@link PropertiesCellRenderer#getTableCellRendererComponent default implementation}.
     126     * @param renderer the renderer to add
     127     * @since 9149
     128     */
     129    public void addCustomRenderer(TableCellRenderer renderer) {
     130        customRenderer.add(renderer);
     131    }
     132
     133    /**
     134     * Removes a custom table cell renderer.
     135     * @param renderer the renderer to remove
     136     * @since 9149
     137     */
     138    public void removeCustomRenderer(TableCellRenderer renderer) {
     139        customRenderer.remove(renderer);
     140    }
    108141}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r9147 r9149  
    4848import javax.swing.table.DefaultTableCellRenderer;
    4949import javax.swing.table.DefaultTableModel;
     50import javax.swing.table.TableCellRenderer;
    5051import javax.swing.table.TableColumnModel;
    5152import javax.swing.table.TableModel;
     
    137138     */
    138139    private final ReadOnlyTableModel tagData = new ReadOnlyTableModel();
     140    private final PropertiesCellRenderer cellRenderer = new PropertiesCellRenderer();
    139141    private final TableRowSorter<ReadOnlyTableModel> tagRowSorter = new TableRowSorter<>(tagData);
    140142    private final JosmTextField tagTableFilter;
     
    304306        tagTable.getTableHeader().setReorderingAllowed(false);
    305307
    306         PropertiesCellRenderer cellRenderer = new PropertiesCellRenderer();
    307308        tagTable.getColumnModel().getColumn(0).setCellRenderer(cellRenderer);
    308309        tagTable.getColumnModel().getColumn(1).setCellRenderer(cellRenderer);
     
    818819
    819820    /**
     821     * Adds a custom table cell renderer to render cells of the tags table.
     822     *
     823     * If the renderer is not capable performing a {@link TableCellRenderer#getTableCellRendererComponent},
     824     * it should return {@code null} to fall back to the
     825     * {@link PropertiesCellRenderer#getTableCellRendererComponent default implementation}.
     826     * @param renderer the renderer to add
     827     * @since 9149
     828     */
     829    public void addCustomPropertiesCellRenderer(TableCellRenderer renderer) {
     830        cellRenderer.addCustomRenderer(renderer);
     831    }
     832
     833    /**
     834     * Removes a custom table cell renderer.
     835     * @param renderer the renderer to remove
     836     * @since 9149
     837     */
     838    public void removeCustomPropertiesCellRenderer(TableCellRenderer renderer) {
     839        cellRenderer.removeCustomRenderer(renderer);
     840    }
     841
     842    /**
    820843     * Class that watches for mouse clicks
    821844     * @author imi
Note: See TracChangeset for help on using the changeset viewer.