Changeset 17890 in josm for trunk


Ignore:
Timestamp:
2021-05-13T00:19:28+02:00 (4 years ago)
Author:
simon04
Message:

fix #20880 - History browser: show color gutter based on timestamp

Location:
trunk
Files:
6 edited

Legend:

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

    r16694 r17890  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Color;
    67import java.util.HashSet;
    78import java.util.Objects;
     
    4445import org.openstreetmap.josm.gui.util.ChangeNotifier;
    4546import org.openstreetmap.josm.tools.CheckParameterUtil;
     47import org.openstreetmap.josm.tools.ColorScale;
    4648import org.openstreetmap.josm.tools.Logging;
    4749
     
    8991    private final DiffTableModel referenceNodeListTableModel;
    9092    private final DiffTableModel currentNodeListTableModel;
     93    private final ColorScale dateScale;
    9194
    9295    /**
     
    101104        currentRelationMemberTableModel = new DiffTableModel();
    102105        referenceRelationMemberTableModel = new DiffTableModel();
     106        dateScale = ColorScale.createHSBScale(256);
    103107
    104108        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     
    193197            setLatest(newLatest);
    194198        }
     199        if (!history.isEmpty()) {
     200            this.dateScale.setRange(
     201                    history.getEarliest().getInstant().toEpochMilli(),
     202                    history.getLatest().getInstant().toEpochMilli());
     203        }
    195204        initTagTableModels();
    196205        fireModelChange();
     
    689698    }
    690699
     700    /**
     701     * Returns the color for the primitive in the given row
     702     * @param row row number
     703     * @return the color for the primitive in the given row
     704     */
     705    public Color getVersionColor(int row) {
     706        HistoryOsmPrimitive primitive = getPrimitive(row);
     707        return primitive != null && primitive.getInstant() != null ? getVersionColor(primitive) : null;
     708    }
     709
     710    /**
     711     * Returns the color for the given primitive timestamp
     712     * @param primitive the history primitive
     713     * @return the color for the given primitive timestamp
     714     */
     715    public Color getVersionColor(HistoryOsmPrimitive primitive) {
     716        return dateScale.getColor(primitive.getInstant().toEpochMilli());
     717    }
    691718}
  • trunk/src/org/openstreetmap/josm/gui/history/TagTableCellRenderer.java

    r17887 r17890  
    55import java.awt.Component;
    66
     7import javax.swing.BorderFactory;
    78import javax.swing.JLabel;
    89import javax.swing.JTable;
     
    4849        String text = "";
    4950        String tooltip = null;
     51        setBorder(null);
    5052        if (model.hasTag(key)) {
    5153            switch(column) {
     
    6365                    text = "v" + primitive.getVersion();
    6466                    tooltip = tr("Key ''{0}'' was changed in version {1}", key, primitive.getVersion());
     67                    setBorder(BorderFactory.createMatteBorder(0, 0, 0, 2, model.getVersionColor(primitive)));
    6568                }
    6669            default: // Do nothing
  • trunk/src/org/openstreetmap/josm/gui/history/TagTableModel.java

    r17887 r17890  
    22package org.openstreetmap.josm.gui.history;
    33
     4import java.awt.Color;
    45import java.util.ArrayList;
    56import java.util.Collections;
     
    9697
    9798    /**
     99     * Returns the color for the given primitive timestamp
     100     * @param primitive the history primitive
     101     * @return the color for the given primitive timestamp
     102     */
     103    public Color getVersionColor(HistoryOsmPrimitive primitive) {
     104        return model.getVersionColor(primitive);
     105    }
     106
     107    /**
    98108     * Determines if a tag exists in the opposite point in time for the given key.
    99109     * @param key tag key
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTableCellRenderer.java

    r17889 r17890  
    22package org.openstreetmap.josm.gui.history;
    33
     4import javax.swing.BorderFactory;
    45import javax.swing.JLabel;
    56import javax.swing.JTable;
    67import javax.swing.SwingConstants;
    78import javax.swing.table.TableCellRenderer;
     9import java.awt.Color;
    810import java.awt.Component;
    911
     
    2830        }
    2931        setText(v);
     32        Color color = ((VersionTableModel) table.getModel()).getVersionColor(row);
     33        if (color != null) {
     34            setBorder(BorderFactory.createMatteBorder(0, 2, 0, 0, color));
     35        } else {
     36            setBorder(null);
     37        }
    3038        return this;
    3139    }
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTableModel.java

    r17838 r17890  
    22package org.openstreetmap.josm.gui.history;
    33
     4import java.awt.Color;
    45import java.time.format.FormatStyle;
    56
     
    7879    }
    7980
     81    /**
     82     * Returns the color for the primitive in the given row
     83     * @param row row number
     84     * @return the color for the primitive in the given row
     85     */
     86    public Color getVersionColor(int row) {
     87        return model.getVersionColor(row);
     88    }
     89
    8090    @Override
    8191    public void setValueAt(Object aValue, int row, int column) {
  • trunk/test/unit/org/openstreetmap/josm/gui/history/HistoryBrowserModelTest.java

    r17275 r17890  
    2020
    2121import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     22
     23import java.awt.Color;
    2224
    2325/**
     
    172174        assertEquals(1, model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
    173175        assertEquals(1, model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     176        assertEquals(new Color(0xff0000), model.getVersionColor(0));
     177        assertEquals(new Color(0xff00e5), model.getVersionColor(1));
     178        assertNull(model.getVersionColor(2));
    174179    }
    175180}
Note: See TracChangeset for help on using the changeset viewer.