Ticket #14666: 0002-Automatically-recompute-tags-and-membership-tables-c.patch

File 0002-Automatically-recompute-tags-and-membership-tables-c.patch, 2.2 KB (added by bagage, 8 years ago)

patch version 2 (simplified version)

  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    From 2c15882d0dca7f712adec4dc9c118d0dd88fa4e8 Mon Sep 17 00:00:00 2001
    From: Gautier Pelloux-Prayer <gautier+git@damsy.net>
    Date: Mon, 12 Nov 2018 21:29:01 +0100
    Subject: [PATCH] Automatically recompute tags and membership tables' columns
     width to fit content
    
    ---
     .../dialogs/properties/PropertiesDialog.java    | 17 +++++++++++++++++
     1 file changed, 17 insertions(+)
    
    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
    index 1b1d9c4ab..23b7e8056 100644
    a b implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdap  
    303303        return HelpUtil.ht("/Dialog/TagsMembership");
    304304    }
    305305
     306    private void computeColumnsWidth(JTable table) {
     307        final TableColumnModel columnModel = table.getColumnModel();
     308        for (int column = 0; column < table.getColumnCount(); column++) {
     309            int width = 15; // Min width
     310            for (int row = 0; row < table.getRowCount(); row++) {
     311                TableCellRenderer renderer = table.getCellRenderer(row, column);
     312                Component comp = table.prepareRenderer(renderer, row, column);
     313                width = Math.max(comp.getPreferredSize().width +1 , width);
     314            }
     315            columnModel.getColumn(column).setPreferredWidth(width);
     316        }
     317    }
     318
    306319    private void buildTagsTable() {
    307320        // setting up the tags table
    308321        tagData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});
    implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdap  
    667680        selectSth.setVisible(!hasSelection);
    668681        pluginHook.setVisible(hasSelection);
    669682
     683        // resize tables to fit content
     684        computeColumnsWidth(tagTable);
     685        computeColumnsWidth(membershipTable);
     686
    670687        int selectedIndex;
    671688        if (selectedTag != null && (selectedIndex = findViewRow(tagTable, tagData, selectedTag)) != -1) {
    672689            tagTable.changeSelection(selectedIndex, 0, false, false);