Changeset 17712 in josm for trunk/src/org
- Timestamp:
- 2021-04-07T22:34:03+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/notes/Note.java
r16953 r17712 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.time.Instant; 6 7 import java.util.ArrayList; 7 8 import java.util.Comparator; 8 import java.util.Date;9 9 import java.util.List; 10 10 import java.util.Objects; 11 11 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.tools.date.DateUtils;14 13 15 14 /** … … 66 65 private long id; 67 66 private LatLon latLon; 68 private DatecreatedAt;69 private DateclosedAt;67 private Instant createdAt; 68 private Instant closedAt; 70 69 private State state; 71 70 private List<NoteComment> comments = new ArrayList<>(); … … 107 106 * @return Date that this note was submitted 108 107 */ 109 public DategetCreatedAt() {110 return DateUtils.cloneDate(createdAt);108 public Instant getCreatedAt() { 109 return createdAt; 111 110 } 112 111 … … 115 114 * @param createdAt date at which this note has been created 116 115 */ 117 public void setCreatedAt( DatecreatedAt) {118 this.createdAt = DateUtils.cloneDate(createdAt);116 public void setCreatedAt(Instant createdAt) { 117 this.createdAt = createdAt; 119 118 } 120 119 … … 123 122 * @return Date that this note was closed. Null if it is still open. 124 123 */ 125 public DategetClosedAt() {126 return DateUtils.cloneDate(closedAt);124 public Instant getClosedAt() { 125 return closedAt; 127 126 } 128 127 … … 131 130 * @param closedAt date at which this note has been closed 132 131 */ 133 public void setClosedAt( DateclosedAt) {134 this.closedAt = DateUtils.cloneDate(closedAt);132 public void setClosedAt(Instant closedAt) { 133 this.closedAt = closedAt; 135 134 } 136 135 … … 191 190 public void updateWith(Note note) { 192 191 this.comments = note.comments; 193 this.createdAt = DateUtils.cloneDate(note.createdAt);192 this.createdAt = note.createdAt; 194 193 this.id = note.id; 195 194 this.state = note.state; -
trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java
r16953 r17712 2 2 package org.openstreetmap.josm.data.notes; 3 3 4 import java.time.Instant; 4 5 import java.util.Comparator; 5 import java.util.Date;6 6 7 7 import org.openstreetmap.josm.data.osm.User; 8 import org.openstreetmap.josm.tools.date.DateUtils;9 8 10 9 /** … … 17 16 private final String text; 18 17 private final User user; 19 private final DatecommentTimestamp;18 private final Instant commentTimestamp; 20 19 private final Action action; 21 20 … … 50 49 * @param isNew Whether or not this comment is new and needs to be uploaded 51 50 */ 52 public NoteComment( DatecreateDate, User user, String commentText, Action action, boolean isNew) {51 public NoteComment(Instant createDate, User user, String commentText, Action action, boolean isNew) { 53 52 this.text = commentText; 54 53 this.user = user; 55 this.commentTimestamp = DateUtils.cloneDate(createDate);54 this.commentTimestamp = createDate; 56 55 this.action = action; 57 56 this.isNew = isNew; … … 78 77 * @return The time at which this comment was created 79 78 */ 80 public DategetCommentTimestamp() {81 return DateUtils.cloneDate(commentTimestamp);79 public Instant getCommentTimestamp() { 80 return commentTimestamp; 82 81 } 83 82 -
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r16548 r17712 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import java.time.Instant; 4 5 import java.util.ArrayList; 5 6 import java.util.Collection; 6 7 import java.util.Collections; 7 8 import java.util.Comparator; 8 import java.util.Date;9 9 import java.util.List; 10 10 import java.util.Map; … … 177 177 } 178 178 Note note = new Note(location); 179 note.setCreatedAt( new Date());179 note.setCreatedAt(Instant.now()); 180 180 note.setState(State.OPEN); 181 181 note.setId(newNoteId--); 182 NoteComment comment = new NoteComment( new Date(), getCurrentUser(), text, NoteComment.Action.OPENED, true);182 NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.OPENED, true); 183 183 note.addComment(comment); 184 184 if (Logging.isDebugEnabled()) { … … 204 204 Logging.debug("Adding comment to note {0}: {1}", note.getId(), text); 205 205 } 206 NoteComment comment = new NoteComment( new Date(), getCurrentUser(), text, NoteComment.Action.COMMENTED, true);206 NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.COMMENTED, true); 207 207 note.addComment(comment); 208 208 dataUpdated(); … … 224 224 Logging.debug("closing note {0} with comment: {1}", note.getId(), text); 225 225 } 226 NoteComment comment = new NoteComment( new Date(), getCurrentUser(), text, NoteComment.Action.CLOSED, true);226 NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.CLOSED, true); 227 227 note.addComment(comment); 228 228 note.setState(State.CLOSED); 229 note.setClosedAt( new Date());229 note.setClosedAt(Instant.now()); 230 230 dataUpdated(); 231 231 } … … 244 244 } 245 245 Logging.debug("reopening note {0} with comment: {1}", note.getId(), text); 246 NoteComment comment = new NoteComment( new Date(), getCurrentUser(), text, NoteComment.Action.REOPENED, true);246 NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.REOPENED, true); 247 247 note.addComment(comment); 248 248 note.setState(State.OPEN); -
trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
r17522 r17712 10 10 import java.awt.event.MouseAdapter; 11 11 import java.awt.event.MouseEvent; 12 import java.text.DateFormat; 12 import java.time.format.DateTimeFormatter; 13 import java.time.format.FormatStyle; 13 14 import java.util.ArrayList; 14 15 import java.util.Arrays; … … 232 233 233 234 private final DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer(); 234 private final Date Format dateFormat = DateUtils.getDateTimeFormat(DateFormat.MEDIUM, DateFormat.SHORT);235 private final DateTimeFormatter dateFormat = DateUtils.getDateTimeFormatter(FormatStyle.MEDIUM, FormatStyle.SHORT); 235 236 236 237 @Override -
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r17361 r17712 15 15 import java.io.File; 16 16 import java.io.IOException; 17 import java.t ext.DateFormat;17 import java.time.format.FormatStyle; 18 18 import java.util.Collection; 19 19 import java.util.Collections; … … 319 319 sb.append(userName) 320 320 .append(" on ") 321 .append(DateUtils.getDateFormat (DateFormat.MEDIUM).format(comment.getCommentTimestamp()))321 .append(DateUtils.getDateFormatter(FormatStyle.MEDIUM).format(comment.getCommentTimestamp())) 322 322 .append(":<br>"); 323 323 String htmlText = XmlWriter.encode(comment.getText(), true); -
trunk/src/org/openstreetmap/josm/io/NoteReader.java
r14436 r17712 6 6 import java.io.InputStream; 7 7 import java.nio.charset.StandardCharsets; 8 import java.time.Instant; 8 9 import java.util.ArrayList; 9 import java.util.Date;10 10 import java.util.List; 11 11 import java.util.Locale; … … 60 60 private String commentUsername; 61 61 private Action noteAction; 62 private DatecommentCreateDate;62 private Instant commentCreateDate; 63 63 private boolean commentIsNew; 64 64 private List<Note> notes; … … 100 100 commentUsername = attrs.getValue("user"); 101 101 noteAction = Action.valueOf(attrs.getValue("action").toUpperCase(Locale.ENGLISH)); 102 commentCreateDate = DateUtils. fromString(attrs.getValue("timestamp"));102 commentCreateDate = DateUtils.parseInstant(attrs.getValue("timestamp")); 103 103 commentIsNew = Boolean.parseBoolean(Optional.ofNullable(attrs.getValue("is_new")).orElse("false")); 104 104 break; … … 143 143 break; 144 144 case "date_created": 145 thisNote.setCreatedAt(DateUtils. fromString(buffer.toString()));145 thisNote.setCreatedAt(DateUtils.parseInstant(buffer.toString())); 146 146 break; 147 147 case "date_closed": 148 thisNote.setClosedAt(DateUtils. fromString(buffer.toString()));148 thisNote.setClosedAt(DateUtils.parseInstant(buffer.toString())); 149 149 break; 150 150 case "date": 151 commentCreateDate = DateUtils. fromString(buffer.toString());151 commentCreateDate = DateUtils.parseInstant(buffer.toString()); 152 152 break; 153 153 case "user": … … 205 205 } else { 206 206 note.setState(Note.State.CLOSED); 207 note.setClosedAt(DateUtils. fromString(closedTimeStr));207 note.setClosedAt(DateUtils.parseInstant(closedTimeStr)); 208 208 } 209 209 String createdAt = attrs.apply("created_at"); 210 210 if (createdAt != null) { 211 note.setCreatedAt(DateUtils. fromString(createdAt));211 note.setCreatedAt(DateUtils.parseInstant(createdAt)); 212 212 } 213 213 return note; -
trunk/src/org/openstreetmap/josm/io/NoteWriter.java
r17333 r17712 13 13 import org.openstreetmap.josm.data.osm.NoteData; 14 14 import org.openstreetmap.josm.data.osm.User; 15 import org.openstreetmap.josm.tools.date.DateUtils;16 15 17 16 /** … … 53 52 out.print("lat=\"" + LatLon.cDdHighPrecisionFormatter.format(ll.lat()) + "\" "); 54 53 out.print("lon=\"" + LatLon.cDdHighPrecisionFormatter.format(ll.lon()) + "\" "); 55 out.print("created_at=\"" + DateUtils.fromDate(note.getCreatedAt()) + "\" ");54 out.print("created_at=\"" + note.getCreatedAt() + "\" "); 56 55 if (note.getClosedAt() != null) { 57 out.print("closed_at=\"" + DateUtils.fromDate(note.getClosedAt()) + "\" ");56 out.print("closed_at=\"" + note.getClosedAt() + "\" "); 58 57 } 59 58 … … 72 71 out.print(" <comment"); 73 72 out.print(" action=\"" + comment.getNoteAction() + "\" "); 74 out.print("timestamp=\"" + DateUtils.fromDate(comment.getCommentTimestamp()) + "\" ");73 out.print("timestamp=\"" + comment.getCommentTimestamp() + "\" "); 75 74 if (comment.getUser() != null && !comment.getUser().equals(User.getAnonymous())) { 76 75 out.print("uid=\"" + comment.getUser().getId() + "\" "); -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r17653 r17712 7 7 import java.time.DateTimeException; 8 8 import java.time.Instant; 9 import java.time.ZoneId; 9 10 import java.time.ZoneOffset; 10 11 import java.time.ZonedDateTime; 11 12 import java.time.format.DateTimeFormatter; 12 13 import java.time.format.DateTimeParseException; 14 import java.time.format.FormatStyle; 13 15 import java.util.Date; 14 16 import java.util.Locale; … … 270 272 271 273 /** 274 * Returns the date formatter to be used for current user, based on user preferences. 275 * @param dateStyle The date style. Ignored if "ISO dates" option is set. 276 * @return The date format 277 */ 278 public static DateTimeFormatter getDateFormatter(FormatStyle dateStyle) { 279 DateTimeFormatter formatter = PROP_ISO_DATES.get() 280 ? DateTimeFormatter.ISO_LOCAL_DATE 281 : DateTimeFormatter.ofLocalizedDate(dateStyle); 282 return formatter.withZone(ZoneId.systemDefault()); 283 } 284 285 /** 272 286 * Returns the date format used for GPX waypoints. 273 287 * @return the date format used for GPX waypoints … … 305 319 return DateFormat.getTimeInstance(timeStyle, Locale.getDefault()); 306 320 } 321 } 322 323 /** 324 * Returns the time formatter to be used for current user, based on user preferences. 325 * @param timeStyle The time style. Ignored if "ISO dates" option is set. 326 * @return The time format 327 */ 328 public static DateTimeFormatter getTimeFormatter(FormatStyle timeStyle) { 329 DateTimeFormatter formatter = PROP_ISO_DATES.get() 330 ? DateTimeFormatter.ISO_LOCAL_TIME 331 : DateTimeFormatter.ofLocalizedTime(timeStyle); 332 return formatter.withZone(ZoneId.systemDefault()); 307 333 } 308 334 … … 337 363 338 364 /** 365 * Returns the date/time formatter to be used for current user, based on user preferences. 366 * @param dateStyle The date style. Ignored if "ISO dates" option is set. 367 * @param timeStyle The time style. Ignored if "ISO dates" option is set. 368 * @return The date/time format 369 */ 370 public static DateTimeFormatter getDateTimeFormatter(FormatStyle dateStyle, FormatStyle timeStyle) { 371 DateTimeFormatter formatter = PROP_ISO_DATES.get() 372 ? DateTimeFormatter.ISO_LOCAL_DATE_TIME 373 : DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle); 374 return formatter.withZone(ZoneId.systemDefault()); 375 } 376 377 /** 339 378 * Formats a date/time to be displayed to current user, based on user preferences. 340 379 * @param datetime The date/time to display. Must not be {@code null}
Note:
See TracChangeset
for help on using the changeset viewer.