Changeset 17842 in josm for trunk/src/org


Ignore:
Timestamp:
2021-05-01T13:11:58+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate DateFilterPanel to Instant

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r17718 r17842  
    5858import java.util.Arrays;
    5959import java.util.Collections;
    60 import java.util.Date;
    6160import java.util.List;
    6261import java.util.NoSuchElementException;
     
    350349     * @param showWithoutDate Include tracks that don't have any date set..
    351350     */
    352     public void filterTracksByDate(Date fromDate, Date toDate, boolean showWithoutDate) {
     351    public void filterTracksByDate(Instant fromDate, Instant toDate, boolean showWithoutDate) {
    353352        int i = 0;
    354         long from = fromDate.getTime();
    355         long to = toDate.getTime();
     353        long from = fromDate.toEpochMilli();
     354        long to = toDate.toEpochMilli();
    356355        for (IGpxTrack trk : data.getTracks()) {
    357356            Instant[] t = GpxData.getMinMaxTimeForTrack(trk);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DateFilterPanel.java

    r17715 r17842  
    1010import java.time.ZoneId;
    1111import java.time.ZonedDateTime;
    12 import java.util.Date;
    1312
    1413import javax.swing.JCheckBox;
     
    5251        this.layer = layer;
    5352
    54         final Date startTime, endTime;
     53        final Instant startTime, endTime;
    5554        Instant[] bounds = layer.data.getMinMaxTimeForAllTracks();
    5655        if (bounds.length == 0) {
    57             startTime = Date.from(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant());
    58             endTime = new Date();
     56            startTime = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant();
     57            endTime = Instant.now();
    5958        } else {
    60             startTime = Date.from(bounds[0]);
    61             endTime = Date.from(bounds[1]);
     59            startTime = bounds[0];
     60            endTime = bounds[1];
    6261        }
    6362
     
    109108     */
    110109    public void saveInPrefs() {
    111         Config.getPref().putLong(prefDateMin, dateFrom.getDate().getTime());
    112         Config.getPref().putLong(prefDateMax, dateTo.getDate().getTime());
     110        Config.getPref().putLong(prefDateMin, dateFrom.getDate().toEpochMilli());
     111        Config.getPref().putLong(prefDateMax, dateTo.getDate().toEpochMilli());
    113112        Config.getPref().putBoolean(prefDate0, noTimestampCb.isSelected());
    114113    }
     
    120119    public void loadFromPrefs() {
    121120        long t1 = Config.getPref().getLong(prefDateMin, 0);
    122         if (t1 != 0) dateFrom.setDate(new Date(t1));
     121        if (t1 != 0) dateFrom.setDate(Instant.ofEpochMilli(t1));
    123122        long t2 = Config.getPref().getLong(prefDateMax, 0);
    124         if (t2 != 0) dateTo.setDate(new Date(t2));
     123        if (t2 != 0) dateTo.setDate(Instant.ofEpochMilli(t2));
    125124        noTimestampCb.setSelected(Config.getPref().getBoolean(prefDate0, false));
    126125    }
     
    135134
    136135    private void filterTracksByDate() {
    137         Date from = dateFrom.getDate();
    138         Date to = dateTo.getDate();
     136        Instant from = dateFrom.getDate();
     137        Instant to = dateTo.getDate();
    139138        layer.filterTracksByDate(from, to, noTimestampCb.isSelected());
    140139    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/DateEditorWithSlider.java

    r12304 r17842  
    77import java.text.DateFormat;
    88import java.text.SimpleDateFormat;
     9import java.time.Instant;
    910import java.util.ArrayList;
    1011import java.util.Date;
     
    2930    private final JSpinner spinner;
    3031    private final JSlider slider;
    31     private Date dateMin;
    32     private Date dateMax;
     32    private Instant dateMin;
     33    private Instant dateMax;
    3334    private static final int MAX_SLIDER = 300;
    3435    private boolean watchSlider = true;
     
    7677        add(slider, GBC.eol().insets(10, 0, 0, 0).fill(GBC.HORIZONTAL));
    7778
    78         dateMin = new Date(0);
    79         dateMax = new Date();
     79        dateMin = Instant.EPOCH;
     80        dateMax = Instant.now();
    8081    }
    8182
    8283    protected Date dateFromInt(int value) {
    8384        double k = 1.0*value/MAX_SLIDER;
    84         return new Date((long) (dateMax.getTime()*k+ dateMin.getTime()*(1-k)));
     85        return new Date((long) (dateMax.toEpochMilli()*k+ dateMin.toEpochMilli()*(1-k)));
    8586    }
    8687
    8788    protected int intFromDate(Date date) {
    88         return (int) (300.0*(date.getTime()-dateMin.getTime()) /
    89                 (dateMax.getTime()-dateMin.getTime()));
     89        return (int) (300.0*(date.getTime()-dateMin.getEpochSecond()) /
     90                (dateMax.getEpochSecond()-dateMin.getEpochSecond()));
    9091    }
    9192
     
    9596     * @param dateMax The max date
    9697     */
    97     public void setRange(Date dateMin, Date dateMax) {
    98         this.dateMin = DateUtils.cloneDate(dateMin);
    99         this.dateMax = DateUtils.cloneDate(dateMax);
     98    public void setRange(Instant dateMin, Instant dateMax) {
     99        this.dateMin = dateMin;
     100        this.dateMax = dateMax;
    100101    }
    101102
     
    104105     * @param date The date
    105106     */
    106     public void setDate(Date date) {
    107         spinner.setValue(DateUtils.cloneDate(date));
     107    public void setDate(Instant date) {
     108        spinner.setValue(Date.from(date));
    108109    }
    109110
     
    112113     * @return The date
    113114     */
    114     public Date getDate() {
    115         return DateUtils.cloneDate((Date) spinner.getValue());
     115    public Instant getDate() {
     116        return ((Date) spinner.getValue()).toInstant();
    116117    }
    117118
Note: See TracChangeset for help on using the changeset viewer.