Changeset 17841 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2021-05-01T12:37:47+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate various classes to Instant

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

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

    r16671 r17841  
    1616import java.util.Collection;
    1717import java.util.Collections;
    18 import java.util.Date;
    1918import java.util.HashSet;
    2019import java.util.LinkedList;
     
    924923    private final transient Stack<ZoomData> zoomUndoBuffer = new Stack<>();
    925924    private final transient Stack<ZoomData> zoomRedoBuffer = new Stack<>();
    926     private Date zoomTimestamp = new Date();
     925    private long zoomTimestamp = System.currentTimeMillis();
    927926
    928927    private void pushZoomUndo(EastNorth center, double scale) {
    929         Date now = new Date();
    930         if ((now.getTime() - zoomTimestamp.getTime()) > (Config.getPref().getDouble("zoom.undo.delay", 1.0) * 1000)) {
     928        long now = System.currentTimeMillis();
     929        if ((now - zoomTimestamp) > (Config.getPref().getDouble("zoom.undo.delay", 1.0) * 1000)) {
    931930            zoomUndoBuffer.push(new ZoomData(center, scale));
    932931            if (zoomUndoBuffer.size() > Config.getPref().getInt("zoom.undo.max", 50)) {
  • trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java

    r16553 r17841  
    77import java.awt.event.ActionEvent;
    88import java.net.HttpURLConnection;
    9 import java.text.DateFormat;
     9import java.time.Instant;
     10import java.time.format.FormatStyle;
    1011import java.util.ArrayList;
    1112import java.util.Arrays;
    1213import java.util.Collection;
    1314import java.util.Collections;
    14 import java.util.Date;
    1515import java.util.regex.Matcher;
    1616import java.util.regex.Pattern;
     
    215215     * @param d changeset date
    216216     */
    217     protected void handleUploadConflictForClosedChangeset(long changesetId, Date d) {
     217    protected void handleUploadConflictForClosedChangeset(long changesetId, Instant d) {
    218218        String msg = tr("<html>Uploading <strong>failed</strong> because you have been using<br>"
    219219                + "changeset {0} which was already closed at {1}.<br>"
    220220                + "Please upload again with a new or an existing open changeset.</html>",
    221                 changesetId, DateUtils.formatDateTime(d, DateFormat.SHORT, DateFormat.SHORT)
     221                changesetId, DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(d)
    222222        );
    223223        JOptionPane.showMessageDialog(
     
    293293            m = p.matcher(errorHeader);
    294294            if (m.matches()) {
    295                 handleUploadConflictForClosedChangeset(Long.parseLong(m.group(1)), DateUtils.fromString(m.group(2)));
     295                handleUploadConflictForClosedChangeset(Long.parseLong(m.group(1)), DateUtils.parseInstant(m.group(2)));
    296296                return;
    297297            }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r17786 r17841  
    2626import java.net.MalformedURLException;
    2727import java.net.URL;
    28 import java.text.SimpleDateFormat;
     28import java.time.Instant;
    2929import java.util.ArrayList;
    3030import java.util.Arrays;
     
    3232import java.util.Collections;
    3333import java.util.Comparator;
    34 import java.util.Date;
    3534import java.util.LinkedList;
    3635import java.util.List;
     
    479478                    String value = e.getValue();
    480479                    if ("lastModification".equals(e.getKey()) || "expirationTime".equals(e.getKey())) {
    481                         value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(Long.parseLong(value)));
     480                        value = Instant.ofEpochMilli(Long.parseLong(value)).toString();
    482481                    }
    483482                    panel.add(layer.createTextField(value), GBC.eol().fill(GBC.HORIZONTAL));
  • trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java

    r17181 r17841  
    1414import java.nio.file.Files;
    1515import java.nio.file.Path;
     16import java.time.Instant;
    1617import java.util.ArrayList;
    1718import java.util.Arrays;
     
    190191    }
    191192
    192     protected File getNewLayerFile(AutosaveLayerInfo<?> layer, Date now, int startIndex) {
     193    protected File getNewLayerFile(AutosaveLayerInfo<?> layer, Instant now, int startIndex) {
    193194        int index = startIndex;
    194195        while (true) {
    195196            String filename = String.format(Locale.ENGLISH, "%1$s_%2$tY%2$tm%2$td_%2$tH%2$tM%2$tS%2$tL%3$s",
    196                     layer.layerFileName, now, index == 0 ? "" : ('_' + Integer.toString(index)));
     197                    layer.layerFileName, Date.from(now), index == 0 ? "" : ('_' + Integer.toString(index)));
    197198            File result = new File(autosaveDir, filename + '.' +
    198199                    (layer.layer instanceof NoteLayer ?
     
    234235            Data data = info.layer.getData();
    235236            if (data != null && changedData.remove(data)) {
    236                 File file = getNewLayerFile(info, new Date(), 0);
     237                File file = getNewLayerFile(info, Instant.now(), 0);
    237238                if (file != null) {
    238239                    info.backupFiles.add(file);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r17715 r17841  
    1616import java.util.Arrays;
    1717import java.util.Comparator;
    18 import java.util.Date;
    1918import java.util.List;
    2019import java.util.Map;
     
    328327                JComponent jc = (JComponent) c;
    329328                Object value = getValueAt(row, col);
    330                 jc.setToolTipText(col == 2 ? Arrays.toString((Date[]) value) : String.valueOf(value));
     329                jc.setToolTipText(col == 2 ? Arrays.toString((Instant[]) value) : String.valueOf(value));
    331330                if (content.length > row
    332331                        && content[row].length > 5
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java

    r17706 r17841  
    66import java.awt.Component;
    77import java.awt.GridBagLayout;
    8 import java.text.DateFormat;
    9 import java.util.Date;
     8import java.time.LocalDate;
     9import java.time.ZoneId;
     10import java.time.format.DateTimeFormatter;
     11import java.time.format.FormatStyle;
    1012
    1113import javax.swing.BorderFactory;
     
    177179        panel.add(dynamicButtons, GBC.eop().insets(20, 0, 0, 0));
    178180
    179         Date today = new Date();
     181        LocalDate today = LocalDate.now(ZoneId.systemDefault());
    180182        isoDates.setToolTipText(tr("Format dates according to {0}. Today''s date will be displayed as {1} instead of {2}",
    181183                tr("ISO 8601"),
    182                 DateUtils.newIsoDateFormat().format(today),
    183                 DateFormat.getDateInstance(DateFormat.SHORT).format(today)));
     184                today.toString(),
     185                DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(today)));
    184186        isoDates.setSelected(DateUtils.PROP_ISO_DATES.get());
    185187        panel.add(isoDates, GBC.eop().insets(20, 0, 0, 0));
  • trunk/src/org/openstreetmap/josm/io/ValidatorErrorWriter.java

    r16333 r17841  
    88import java.io.PrintWriter;
    99import java.nio.charset.StandardCharsets;
     10import java.time.Instant;
    1011import java.util.ArrayList;
    1112import java.util.Collection;
    12 import java.util.Date;
    1313import java.util.HashMap;
    1414import java.util.List;
     
    3232import org.openstreetmap.josm.tools.LanguageInfo;
    3333import org.openstreetmap.josm.tools.Logging;
    34 import org.openstreetmap.josm.tools.date.DateUtils;
    3534
    3635/**
     
    6564    public void write(Collection<TestError> validationErrors) throws IOException {
    6665        Set<Test> analysers = validationErrors.stream().map(TestError::getTester).collect(Collectors.toCollection(TreeSet::new));
    67         String timestamp = DateUtils.fromDate(new Date());
     66        String timestamp = Instant.now().toString();
    6867
    6968        out.println("<?xml version='1.0' encoding='UTF-8'?>");
  • trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java

    r17715 r17841  
    99import java.text.ParsePosition;
    1010import java.text.SimpleDateFormat;
     11import java.time.Instant;
    1112import java.util.ArrayList;
    1213import java.util.Arrays;
     
    176177    private final SimpleDateFormat rmcTimeFmt = new SimpleDateFormat("ddMMyyHHmmss.SSS", Locale.ENGLISH);
    177178
    178     private Date readTime(String p) throws IllegalDataException {
     179    private Instant readTime(String p) throws IllegalDataException {
    179180        // NMEA defines time with "a variable number of digits for decimal-fraction of seconds"
    180181        // This variable decimal fraction cannot be parsed by SimpleDateFormat
     
    190191            Date d = rmcTimeFmt.parse(date, new ParsePosition(0));
    191192            if (d != null)
    192                 return d;
     193                return d.toInstant();
    193194        }
    194195        throw new IllegalDataException("Date is malformed: '" + p + "'");
     
    355356                // time
    356357                accu = e[GGA.TIME.position];
    357                 Date d = readTime(currentDate+accu);
     358                Instant instant = readTime(currentDate+accu);
    358359
    359360                if ((ps.pTime == null) || (currentwp == null) || !ps.pTime.equals(accu)) {
     
    366367                    // As this sentence has no complete time only use it
    367368                    // if there is no time so far
    368                     currentwp.setInstant(d.toInstant());
     369                    currentwp.setInstant(instant);
    369370                }
    370371                // elevation
     
    486487                String time = e[RMC.TIME.position];
    487488
    488                 Date d = readTime(currentDate+time);
     489                Instant instant = readTime(currentDate+time);
    489490
    490491                if (ps.pTime == null || currentwp == null || !ps.pTime.equals(time)) {
     
    494495                }
    495496                // time: this sentence has complete time so always use it.
    496                 currentwp.setInstant(d.toInstant());
     497                currentwp.setInstant(instant);
    497498                // speed
    498499                accu = e[RMC.SPEED.position];
Note: See TracChangeset for help on using the changeset viewer.