- Timestamp:
- 2020-08-26T23:18:49+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r16867 r16941 157 157 public static String getTimespanForTrack(IGpxTrack trk) { 158 158 Date[] bounds = GpxData.getMinMaxTimeForTrack(trk); 159 return bounds != null ? formatTimespan(bounds) : ""; 160 } 161 162 /** 163 * Formats the timespan of the given track as a human readable string 164 * @param bounds The bounds to format, i.e., an array containing the min/max date 165 * @return The timespan as a string 166 */ 167 public static String formatTimespan(Date[] bounds) { 159 168 String ts = ""; 160 if (bounds != null) { 161 DateFormat df = DateUtils.getDateFormat(DateFormat.SHORT); 162 String earliestDate = df.format(bounds[0]); 163 String latestDate = df.format(bounds[1]); 164 165 if (earliestDate.equals(latestDate)) { 166 DateFormat tf = DateUtils.getTimeFormat(DateFormat.SHORT); 167 ts += earliestDate + ' '; 168 ts += tf.format(bounds[0]) + " - " + tf.format(bounds[1]); 169 } else { 170 DateFormat dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM); 171 ts += dtf.format(bounds[0]) + " - " + dtf.format(bounds[1]); 172 } 173 174 int diff = (int) (bounds[1].getTime() - bounds[0].getTime()) / 1000; 175 ts += String.format(" (%d:%02d)", diff / 3600, (diff % 3600) / 60); 176 } 169 DateFormat df = DateUtils.getDateFormat(DateFormat.SHORT); 170 String earliestDate = df.format(bounds[0]); 171 String latestDate = df.format(bounds[1]); 172 173 if (earliestDate.equals(latestDate)) { 174 DateFormat tf = DateUtils.getTimeFormat(DateFormat.SHORT); 175 ts += earliestDate + ' '; 176 ts += tf.format(bounds[0]) + " - " + tf.format(bounds[1]); 177 } else { 178 DateFormat dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM); 179 ts += dtf.format(bounds[0]) + " - " + dtf.format(bounds[1]); 180 } 181 182 int diff = (int) (bounds[1].getTime() - bounds[0].getTime()) / 1000; 183 ts += String.format(" (%d:%02d)", diff / 3600, (diff % 3600) / 60); 177 184 return ts; 178 185 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r16940 r16941 15 15 import java.util.Arrays; 16 16 import java.util.Comparator; 17 import java.util.Date; 17 18 import java.util.List; 18 19 import java.util.Map; … … 42 43 import org.openstreetmap.josm.data.SystemOfMeasurement; 43 44 import org.openstreetmap.josm.data.gpx.GpxConstants; 45 import org.openstreetmap.josm.data.gpx.GpxData; 44 46 import org.openstreetmap.josm.data.gpx.IGpxTrack; 45 47 import org.openstreetmap.josm.gui.ExtendedDialog; … … 86 88 String name = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_NAME)).orElse(""); 87 89 String desc = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_DESC)).orElse(""); 88 String time = GpxLayer.getTimespanForTrack(trk);90 Date[] time = GpxData.getMinMaxTimeForTrack(trk); 89 91 String url = (String) Optional.ofNullable(attr.get("url")).orElse(""); 90 92 tracks[i] = new Object[]{name, desc, time, trk.length(), url, trk}; … … 138 140 t.setRowSorter(rowSorter); 139 141 rowSorter.setModel(model); 142 rowSorter.setComparator(2, Comparator.comparing((Date[] d) -> d == null ? Long.MIN_VALUE : d[0].getTime())); 140 143 rowSorter.setComparator(3, Comparator.comparingDouble(length -> (double) length)); 141 144 // default column widths … … 143 146 t.getColumnModel().getColumn(1).setPreferredWidth(300); 144 147 t.getColumnModel().getColumn(2).setPreferredWidth(200); 148 t.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { 149 @Override 150 public Component getTableCellRendererComponent( 151 JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 152 if (value instanceof Date[]) { 153 value = GpxLayer.formatTimespan(((Date[]) value)); 154 } 155 return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 156 } 157 }); 145 158 t.getColumnModel().getColumn(3).setPreferredWidth(50); 146 159 t.getColumnModel().getColumn(3).setCellRenderer(new DefaultTableCellRenderer() {
Note:
See TracChangeset
for help on using the changeset viewer.