Ticket #23482: 23482-2.patch

File 23482-2.patch, 5.2 KB (added by GerdP, 2 years ago)

improved patch that uses existing code in TableHelper and also works with modified data

  • src/org/openstreetmap/josm/gui/history/HistoryBrowser.java

     
    1111import javax.swing.JScrollPane;
    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;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2224 *
    2325 * @since 1709
    2426 */
    25 public class HistoryBrowser extends JPanel implements Destroyable {
     27public class HistoryBrowser extends JPanel implements Destroyable, ChangeListener {
    2628
    2729    /** the model */
    2830    private transient HistoryBrowserModel model;
     
    115117    public void populate(History history) {
    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
    120123            return;
     
    159162    public void destroy() {
    160163        if (model != null) {
    161164            model.unlinkAsListener();
     165            model.removeChangeListener(this);
    162166            model = null;
    163167        }
    164168        Stream.of(tagInfoViewer, nodeListViewer, relationMemberListViewer, coordinateInfoViewer)
     
    168172        relationMemberListViewer = null;
    169173        coordinateInfoViewer = null;
    170174    }
     175
     176    @Override
     177    public void stateChanged(ChangeEvent e) {
     178        tagInfoViewer.adjustWidths();
     179    }
    171180}
  • src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

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

     
    3535 * @since 1709
    3636 */
    3737public class TagInfoViewer extends HistoryViewerPanel {
     38    private JTable reference;
     39    private JTable current;
    3840    private static final class RepaintOnFocusChange implements FocusListener {
    3941        @Override
    4042        public void focusLost(FocusEvent e) {
     
    6264
    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
    7377    private JTable buildTable(PointInTimeType pointInTime) {
     
    105109        table.addMouseListener(new PopupMenuLauncher(tagMenu));
    106110        return table;
    107111    }
     112
     113    /**
     114     * Use current data to adjust preferredWidth for both tables.
     115     */
     116    public void adjustWidths() {
     117        // We have two tables with 3 columns each. no column should get more than 1/4 of the size
     118        int maxWidth = this.getWidth() / 4;
     119        if (maxWidth == 0)
     120            maxWidth = Integer.MAX_VALUE;
     121        adjustWidths(reference, maxWidth);
     122        adjustWidths(current, maxWidth);
     123    }
     124
     125    private static void adjustWidths(JTable table, int maxWidth) {
     126        for (int column = 0; column < table.getColumnCount(); column++) {
     127            TableHelper.adjustColumnWidth(table, column, maxWidth);
     128        }
     129    }
     130
    108131}
  • src/org/openstreetmap/josm/gui/history/TagTableColumnModel.java

     
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import javax.swing.JLabel;
    67import javax.swing.table.DefaultTableColumnModel;
    78import javax.swing.table.TableColumn;
    89
     
    4142        col.setHeaderValue(tr("Since"));
    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    }
    4648}