Changeset 19013 in josm


Ignore:
Timestamp:
2024-03-08T10:02:48+01:00 (2 months ago)
Author:
GerdP
Message:

see #23482: optimize the space in the history view (column width) and consider adding line wrapping

  • use TableHelper.adjustColumnWidth to adjust column widths each time when the displayed tag data changes
  • set maximum width for the "Since" column
Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java

    r18801 r19013  
    1212import javax.swing.JSplitPane;
    1313import javax.swing.JTabbedPane;
     14import javax.swing.event.ChangeEvent;
     15import javax.swing.event.ChangeListener;
    1416
    1517import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2325 * @since 1709
    2426 */
    25 public class HistoryBrowser extends JPanel implements Destroyable {
     27public class HistoryBrowser extends JPanel implements Destroyable, ChangeListener {
    2628
    2729    /** the model */
     
    116118        boolean samePrimitive = model.isSamePrimitive(history); // needs to be before setHistory
    117119        model.setHistory(history);
     120        model.addChangeListener(this);
    118121        if (samePrimitive) {
    119122            // no need to rebuild the UI
     
    160163        if (model != null) {
    161164            model.unlinkAsListener();
     165            model.removeChangeListener(this);
    162166            model = null;
    163167        }
     
    169173        coordinateInfoViewer = null;
    170174    }
     175
     176    @Override
     177    public void stateChanged(ChangeEvent e) {
     178        tagInfoViewer.adjustWidths();
     179    }
    171180}
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    r17471 r19013  
    1919import javax.swing.JOptionPane;
    2020import javax.swing.SwingUtilities;
     21import javax.swing.event.ChangeEvent;
    2122
    2223import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    148149            placeOnScreen(dialog);
    149150            dialog.setVisible(true);
     151            dialog.getHistoryBrowser().stateChanged(new ChangeEvent(this));
    150152            dialogs.put(h.getId(), dialog);
    151153        }
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r17921 r19013  
    3636 */
    3737public class TagInfoViewer extends HistoryViewerPanel {
     38    private JTable reference;
     39    private JTable current;
    3840    private static final class RepaintOnFocusChange implements FocusListener {
    3941        @Override
     
    6365    @Override
    6466    protected JTable buildReferenceTable() {
    65         return buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME);
     67        reference = buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME);
     68        return reference;
    6669    }
    6770
    6871    @Override
    6972    protected JTable buildCurrentTable() {
    70         return buildTable(PointInTimeType.CURRENT_POINT_IN_TIME);
     73        current = buildTable(PointInTimeType.CURRENT_POINT_IN_TIME);
     74        return current;
    7175    }
    7276
     
    106110        return table;
    107111    }
     112
     113    /**
     114     * Use current data to adjust preferredWidth for both tables.
     115     * @since 19013
     116     */
     117    public void adjustWidths() {
     118        // We have two tables with 3 columns each. no column should get more than 1/4 of the size
     119        int maxWidth = this.getWidth() / 4;
     120        if (maxWidth == 0)
     121            maxWidth = Integer.MAX_VALUE;
     122        adjustWidths(reference, maxWidth);
     123        adjustWidths(current, maxWidth);
     124    }
     125
     126    private static void adjustWidths(JTable table, int maxWidth) {
     127        for (int column = 0; column < table.getColumnCount(); column++) {
     128            TableHelper.adjustColumnWidth(table, column, maxWidth);
     129        }
     130    }
    108131}
  • trunk/src/org/openstreetmap/josm/gui/history/TagTableColumnModel.java

    r17887 r19013  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import javax.swing.JLabel;
    67import javax.swing.table.DefaultTableColumnModel;
    78import javax.swing.table.TableColumn;
     
    4243        col.setCellRenderer(renderer);
    4344        col.setPreferredWidth(10);
     45        col.setMaxWidth(new JLabel("v" + Long.MAX_VALUE).getMinimumSize().width); // See #23482
    4446        addColumn(col);
    4547    }
Note: See TracChangeset for help on using the changeset viewer.