Changeset 32638 in osm for applications/editors/josm/plugins/NanoLog
- Timestamp:
- 2016-07-11T23:01:43+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/NanoLog
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/NanoLog/.project
r32286 r32638 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/NanoLog/build.xml
r32329 r32638 5 5 <property name="commit.message" value="NanoLog"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="10 279"/>7 <property name="plugin.main.version" value="10420"/> 8 8 <property name="plugin.author" value="Ilya Zverev"/> 9 9 <property name="plugin.class" value="nanolog.NanoLogPlugin"/> -
applications/editors/josm/plugins/NanoLog/src/nanolog/Correlator.java
r31981 r32638 25 25 * @author zverik 26 26 */ 27 public class Correlator { 27 public final class Correlator { 28 29 private Correlator() { 30 // Hide default constructor for utilities classes 31 } 28 32 29 33 /** 30 34 * Matches entries to GPX so most points are on the trace. 31 35 */ 32 public static long crudeMatch( 36 public static long crudeMatch(List<NanoLogEntry> entries, GpxData data) { 33 37 List<NanoLogEntry> sortedEntries = new ArrayList<>(entries); 34 38 Collections.sort(sortedEntries); … … 36 40 long firstGPXDate = -1; 37 41 outer: 38 for (GpxTrack trk : data.tracks39 for (GpxTrackSegment segment : trk.getSegments()40 for (WayPoint curWp : segment.getWayPoints()41 String curDateWpStr = (String)curWp.attr.get("time"); 42 if (curDateWpStr == null42 for (GpxTrack trk : data.tracks) { 43 for (GpxTrackSegment segment : trk.getSegments()) { 44 for (WayPoint curWp : segment.getWayPoints()) { 45 String curDateWpStr = (String) curWp.attr.get("time"); 46 if (curDateWpStr == null) { 43 47 continue; 44 48 } … … 47 51 firstGPXDate = DateUtils.fromString(curDateWpStr).getTime(); 48 52 break outer; 49 } catch (Exception e53 } catch (Exception e) { 50 54 Main.warn(e); 51 55 } … … 55 59 56 60 // No GPX timestamps found, exit 57 if (firstGPXDate < 061 if (firstGPXDate < 0) { 58 62 JOptionPane.showMessageDialog(Main.parent, 59 63 tr("The selected GPX track does not contain timestamps. Please select another one."), … … 65 69 } 66 70 67 public static void revertPos( 68 for (NanoLogEntry entry : entries71 public static void revertPos(List<NanoLogEntry> entries) { 72 for (NanoLogEntry entry : entries) { 69 73 entry.setPos(entry.getBasePos()); 70 74 } … … 73 77 /** 74 78 * Offset is in 1/1000 of a second. 75 * @param entries76 * @param data77 * @param offset78 79 */ 79 public static void correlate( 80 public static void correlate(List<NanoLogEntry> entries, GpxData data, long offset) { 80 81 List<NanoLogEntry> sortedEntries = new ArrayList<>(entries); 81 82 //int ret = 0; 82 83 Collections.sort(sortedEntries); 83 for (GpxTrack track : data.tracks84 for (GpxTrackSegment segment : track.getSegments()84 for (GpxTrack track : data.tracks) { 85 for (GpxTrackSegment segment : track.getSegments()) { 85 86 long prevWpTime = 0; 86 87 WayPoint prevWp = null; 87 88 88 for (WayPoint curWp : segment.getWayPoints()89 90 String curWpTimeStr = (String)curWp.attr.get("time"); 91 if (curWpTimeStr != null89 for (WayPoint curWp : segment.getWayPoints()) { 90 91 String curWpTimeStr = (String) curWp.attr.get("time"); 92 if (curWpTimeStr != null) { 92 93 try { 93 94 long curWpTime = DateUtils.fromString(curWpTimeStr).getTime() + offset; … … 97 98 prevWpTime = curWpTime; 98 99 99 } catch (UncheckedParseException e100 } catch (UncheckedParseException e) { 100 101 Main.error("Error while parsing date \"" + curWpTimeStr + '"'); 101 102 Main.error(e); … … 112 113 } 113 114 114 private static int matchPoints( 115 WayPoint curWp, long curWpTime, long offset 115 private static int matchPoints(List<NanoLogEntry> entries, WayPoint prevWp, long prevWpTime, 116 WayPoint curWp, long curWpTime, long offset) { 116 117 // Time between the track point and the previous one, 5 sec if first point, i.e. photos take 117 118 // 5 sec before the first track point can be assumed to be take at the starting position … … 123 124 124 125 // no photos match 125 if ( i < 0)126 if (i < 0) 126 127 return 0; 127 128 128 129 Integer direction = null; 129 if (prevWp != null130 if (prevWp != null) { 130 131 direction = Long.valueOf(Math.round(180.0 / Math.PI * prevWp.getCoor().heading(curWp.getCoor()))).intValue(); 131 132 } … … 133 134 // First trackpoint, then interval is set to five seconds, i.e. photos up to five seconds 134 135 // before the first point will be geotagged with the starting point 135 if (prevWpTime == 0 || curWpTime <= prevWpTime136 while ( true) {137 if ( i < 0) {136 if (prevWpTime == 0 || curWpTime <= prevWpTime) { 137 while (true) { 138 if (i < 0) { 138 139 break; 139 140 } 140 141 final NanoLogEntry curImg = entries.get(i); 141 142 long time = curImg.getTime().getTime(); 142 if (time > curWpTime || time < curWpTime - interval143 if (time > curWpTime || time < curWpTime - interval) { 143 144 break; 144 145 } 145 if (curImg.getPos() == null146 if (curImg.getPos() == null) { 146 147 curImg.setPos(curWp.getCoor()); 147 148 curImg.setDirection(direction); … … 155 156 // This code gives a simple linear interpolation of the coordinates between current and 156 157 // previous track point assuming a constant speed in between 157 while ( true) {158 if ( i < 0) {158 while (true) { 159 if (i < 0) { 159 160 break; 160 161 } 161 162 NanoLogEntry curImg = entries.get(i); 162 163 long imgTime = curImg.getTime().getTime(); 163 if (imgTime < prevWpTime164 if (imgTime < prevWpTime) { 164 165 break; 165 166 } 166 167 167 if (curImg.getPos() == null && prevWp != null168 if (curImg.getPos() == null && prevWp != null) { 168 169 // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable 169 double timeDiff = (double)(imgTime - prevWpTime) / interval; 170 double timeDiff = (double) (imgTime - prevWpTime) / interval; 170 171 curImg.setPos(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff)); 171 172 curImg.setDirection(direction); … … 179 180 180 181 private static int getLastIndexOfListBefore(List<NanoLogEntry> entries, long searchedTime) { 181 int lstSize= entries.size(); 182 int lstSize = entries.size(); 182 183 183 184 // No photos or the first photo taken is later than the search period 184 if(lstSize == 0 || searchedTime < entries.get(0).getTime().getTime()) 185 if (lstSize == 0 || searchedTime < entries.get(0).getTime().getTime()) 185 186 return -1; 186 187 … … 190 191 191 192 // The searched index is somewhere in the middle, do a binary search from the beginning 192 int curIndex= 0; 193 int startIndex= 0; 194 int endIndex= lstSize-1; 193 int curIndex = 0; 194 int startIndex = 0; 195 int endIndex = lstSize-1; 195 196 while (endIndex - startIndex > 1) { 196 curIndex= (endIndex + startIndex) / 2; 197 curIndex = (endIndex + startIndex) / 2; 197 198 if (searchedTime > entries.get(curIndex).getTime().getTime()) { 198 startIndex= curIndex; 199 startIndex = curIndex; 199 200 } else { 200 endIndex= curIndex; 201 endIndex = curIndex; 201 202 } 202 203 } … … 215 216 * Returns date of a potential point on GPX track (which can be between points). 216 217 */ 217 public static long getGpxDate( 218 public static long getGpxDate(GpxData data, LatLon pos) { 218 219 EastNorth en = Main.getProjection().latlon2eastNorth(pos); 219 for (GpxTrack track : data.tracks220 for (GpxTrackSegment segment : track.getSegments()220 for (GpxTrack track : data.tracks) { 221 for (GpxTrackSegment segment : track.getSegments()) { 221 222 long prevWpTime = 0; 222 223 WayPoint prevWp = null; 223 for (WayPoint curWp : segment.getWayPoints()224 String curWpTimeStr = (String)curWp.attr.get("time"); 225 if (curWpTimeStr != null224 for (WayPoint curWp : segment.getWayPoints()) { 225 String curWpTimeStr = (String) curWp.attr.get("time"); 226 if (curWpTimeStr != null) { 226 227 try { 227 228 long curWpTime = DateUtils.fromString(curWpTimeStr).getTime(); 228 if (prevWp != null229 if (prevWp != null) { 229 230 EastNorth c1 = Main.getProjection().latlon2eastNorth(prevWp.getCoor()); 230 231 EastNorth c2 = Main.getProjection().latlon2eastNorth(curWp.getCoor()); 231 if (!c1.equals(c2)232 if (!c1.equals(c2)) { 232 233 EastNorth middle = getSegmentAltitudeIntersection(c1, c2, en); 233 if (middle != null && en.distance(middle) < 1234 if (middle != null && en.distance(middle) < 1) { 234 235 // found our point, no further search is neccessary 235 236 double prop = c1.east() == c2.east() 236 237 ? (middle.north() - c1.north()) / (c2.north() - c1.north()) 237 238 : (middle.east() - c1.east()) / (c2.east() - c1.east()); 238 if (prop >= 0 && prop <= 1239 if (prop >= 0 && prop <= 1) { 239 240 return Math.round(prevWpTime + prop * (curWpTime - prevWpTime)); 240 241 } … … 245 246 prevWp = curWp; 246 247 prevWpTime = curWpTime; 247 } catch (UncheckedParseException e248 } catch (UncheckedParseException e) { 248 249 Main.error("Error while parsing date \"" + curWpTimeStr + '"'); 249 250 Main.error(e); … … 265 266 * to it starting at point p. If the line defined with p1-p2 intersects 266 267 * its altitude out of p1-p2, null is returned. 267 * @param p1268 * @param p2269 * @param point270 268 * @return Intersection coordinate or null 271 269 **/ -
applications/editors/josm/plugins/NanoLog/src/nanolog/GPXChooser.java
r32329 r32638 1 1 package nanolog; 2 2 3 import javax.swing.*; 3 import javax.swing.JDialog; 4 4 5 import org.openstreetmap.josm.Main; 5 6 import org.openstreetmap.josm.gui.layer.GpxLayer; … … 19 20 public static GpxLayer topLayer() { 20 21 // return first found local layer 21 for (Layer layer : Main.getLayerManager().getLayers()22 if (layer instanceof GpxLayer && ((GpxLayer)layer).isLocalFile()23 return (GpxLayer)layer; 22 for (Layer layer : Main.getLayerManager().getLayers()) { 23 if (layer instanceof GpxLayer && ((GpxLayer) layer).isLocalFile()) 24 return (GpxLayer) layer; 24 25 } 25 26 return null; -
applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogEntry.java
r31981 r32638 7 7 /** 8 8 * This holds one NanoLog entry. 9 * 9 * 10 10 * @author zverik 11 11 */ … … 18 18 private LatLon basePos; 19 19 20 public NanoLogEntry( 20 public NanoLogEntry(Date time, String message, LatLon basePos, Integer baseDir) { 21 21 this.basePos = basePos; 22 22 this.baseDir = baseDir; … … 27 27 } 28 28 29 public NanoLogEntry( 29 public NanoLogEntry(Date time, String message) { 30 30 this(time, message, null, null); 31 31 } 32 32 33 33 public Integer getDirection() { 34 34 return direction; … … 43 43 } 44 44 45 public void setPos( 45 public void setPos(LatLon pos) { 46 46 this.pos = pos; 47 47 } 48 48 49 public void setDirection( 49 public void setDirection(Integer direction) { 50 50 this.direction = direction; 51 51 } … … 64 64 65 65 @Override 66 public int compareTo( 66 public int compareTo(NanoLogEntry t) { 67 67 return time.compareTo(t.time); 68 68 } -
applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogLayer.java
r32329 r32638 57 57 private NLLMouseAdapter mouseListener; 58 58 59 public NanoLogLayer( 59 public NanoLogLayer(List<NanoLogEntry> entries) { 60 60 super(tr("NanoLog")); 61 61 log = new ArrayList<>(entries); … … 76 76 } 77 77 78 public NanoLogLayer( 78 public NanoLogLayer(File file) throws IOException { 79 79 this(readNanoLog(file)); 80 80 } 81 81 82 public void addListener( 82 public void addListener(NanoLogLayerListener listener) { 83 83 listeners.add(listener); 84 84 } 85 85 86 public void removeListener( 86 public void removeListener(NanoLogLayerListener listener) { 87 87 listeners.remove(listener); 88 88 } 89 89 90 90 protected void fireMarkersChanged() { 91 for (NanoLogLayerListener listener : listeners)91 for (NanoLogLayerListener listener : listeners) { 92 92 listener.markersUpdated(this); 93 } 93 94 } 94 95 95 96 protected void fireMarkerSelected() { 96 for (NanoLogLayerListener listener : listeners)97 for (NanoLogLayerListener listener : listeners) { 97 98 listener.markerActivated(this, selectedEntry < 0 ? null : log.get(selectedEntry)); 99 } 98 100 } 99 101 … … 102 104 } 103 105 104 public static List<NanoLogEntry> readNanoLog( 106 public static List<NanoLogEntry> readNanoLog(File file) throws IOException { 105 107 final Pattern NANOLOG_LINE = Pattern.compile("(.+?)\\t(.+?)(?:\\s*\\{\\{(-?\\d+\\.\\d+),\\s*(-?\\d+\\.\\d+)(?:,\\s*(\\d+))?\\}\\})?"); 106 108 final SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SS"); 107 109 List<NanoLogEntry> result = new ArrayList<>(); 108 110 try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"))) { 109 while( r.ready() ) { 110 String line = r.readLine(); 111 if( line != null ) { 112 Matcher m = NANOLOG_LINE.matcher(line); 113 if( m.matches() ) { 114 String time = m.group(1); 115 String message = m.group(2); 116 String lat = m.group(3); 117 String lon = m.group(4); 118 String dir = m.group(5); 119 Date timeDate = null; 120 try { 121 timeDate = fmt.parse(time); 122 } catch( ParseException e ) { 123 } 124 if( message == null || message.length() == 0 || timeDate == null ) 125 continue; 126 LatLon pos = null; 127 Integer direction = null; 128 if( lat != null && lon != null ) { 129 try { 130 pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon)); 131 direction = new Integer(dir); 132 } catch( NumberFormatException e ) { 133 // well... 134 } 135 } 136 NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction); 137 result.add(entry); 138 } 139 } 140 } 111 while (r.ready()) { 112 String line = r.readLine(); 113 if (line != null) { 114 Matcher m = NANOLOG_LINE.matcher(line); 115 if (m.matches()) { 116 String time = m.group(1); 117 String message = m.group(2); 118 String lat = m.group(3); 119 String lon = m.group(4); 120 String dir = m.group(5); 121 Date timeDate = null; 122 try { 123 timeDate = fmt.parse(time); 124 } catch (ParseException e) { 125 Main.warn(e); 126 } 127 if (message == null || message.length() == 0 || timeDate == null) 128 continue; 129 LatLon pos = null; 130 Integer direction = null; 131 if (lat != null && lon != null) { 132 try { 133 pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon)); 134 direction = new Integer(dir); 135 } catch (NumberFormatException e) { 136 Main.trace(e); 137 } 138 } 139 NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction); 140 result.add(entry); 141 } 142 } 143 } 141 144 } 142 145 return result; … … 144 147 145 148 @Override 146 public void paint( 149 public void paint(Graphics2D g, MapView mv, Bounds box) { 147 150 // todo 148 for (int i = 0; i < log.size(); i++151 for (int i = 0; i < log.size(); i++) { 149 152 NanoLogEntry entry = log.get(i); 150 153 int radius = 4; 151 if (entry.getPos() != null154 if (entry.getPos() != null) { 152 155 Point p = mv.getPoint(entry.getPos()); 153 156 g.setColor(selectedEntry == i ? Color.red : Color.yellow); … … 168 171 169 172 @Override 170 public void mergeFrom( 173 public void mergeFrom(Layer from) { 171 174 // todo 172 175 } 173 176 174 177 @Override 175 public boolean isMergable( 178 public boolean isMergable(Layer other) { 176 179 return other instanceof NanoLogLayer; 177 180 } 178 181 179 182 @Override 180 public void visitBoundingBox( 181 for (NanoLogEntry entry : log)183 public void visitBoundingBox(BoundingXYVisitor v) { 184 for (NanoLogEntry entry : log) { 182 185 v.visit(entry.getPos()); 186 } 183 187 } 184 188 … … 187 191 StringBuilder b = new StringBuilder(); 188 192 int cnt = 0; 189 for (NanoLogEntry e : log)190 if (e.getPos() != null193 for (NanoLogEntry e : log) { 194 if (e.getPos() != null) 191 195 cnt++; 196 } 192 197 b.append(tr("NanoLog of {0} lines, {1} of them with coordinates.", log.size(), cnt)); 193 198 return b.toString(); … … 212 217 public void jumpToNextMarker() { 213 218 selectedEntry++; 214 if (selectedEntry < 0219 if (selectedEntry < 0) 215 220 selectedEntry = 0; 216 else if (selectedEntry >= log.size()221 else if (selectedEntry >= log.size()) 217 222 selectedEntry = log.size() - 1; 218 223 Main.map.repaint(); … … 222 227 public void jumpToPreviousMarker() { 223 228 selectedEntry--; 224 if (selectedEntry < 0229 if (selectedEntry < 0) 225 230 selectedEntry = 0; 226 else if (selectedEntry >= log.size()231 else if (selectedEntry >= log.size()) 227 232 selectedEntry = log.size() - 1; 228 233 Main.map.repaint(); 229 234 } 230 235 231 protected void setSelected( int i) {236 protected void setSelected(int i) { 232 237 int newSelected = i >= 0 && i < log.size() ? i : -1; 233 if (newSelected != selectedEntry238 if (newSelected != selectedEntry) { 234 239 // System.out.println("selected: " + log.get(newSelected).getMessage()); 235 240 selectedEntry = newSelected; … … 239 244 } 240 245 241 public void setSelected( 242 if (entry == null246 public void setSelected(NanoLogEntry entry) { 247 if (entry == null) 243 248 setSelected(-1); 244 249 else { 245 for (int i = 0; i < log.size(); i++246 if (entry.equals(log.get(i))250 for (int i = 0; i < log.size(); i++) { 251 if (entry.equals(log.get(i))) { 247 252 setSelected(i); 248 253 break; … … 255 260 private int dragging; 256 261 257 public int nearestEntry( 262 public int nearestEntry(MouseEvent e) { 258 263 LatLon ll = Main.map.mapView.getLatLon(e.getX(), e.getY()); 259 264 int radius = 8; 260 if (ll != null265 if (ll != null) { 261 266 LatLon lld = Main.map.mapView.getLatLon(e.getX() + radius, e.getY() + radius); 262 267 double distance = Math.max(lld.lat() - ll.lat(), lld.lon() - ll.lon()); 263 268 boolean selectedIsSelected = false; 264 269 int newSelected = -1; 265 for (int i = 0; i < log.size(); i++266 if (log.get(i).getPos() != null && log.get(i).getPos().distance(ll) < distance270 for (int i = 0; i < log.size(); i++) { 271 if (log.get(i).getPos() != null && log.get(i).getPos().distance(ll) < distance) { 267 272 newSelected = i; 268 if (i == selectedEntry273 if (i == selectedEntry) 269 274 selectedIsSelected = true; 270 275 } 271 276 } 272 if (newSelected >= 0277 if (newSelected >= 0) 273 278 return selectedIsSelected ? selectedEntry : newSelected; 274 279 } … … 277 282 278 283 @Override 279 public void mouseMoved( 284 public void mouseMoved(MouseEvent e) { 280 285 int nearest = nearestEntry(e); 281 if (nearest > 0286 if (nearest > 0) 282 287 setSelected(nearest); 283 288 } 284 289 285 290 @Override 286 public void mouseDragged( 291 public void mouseDragged(MouseEvent e) { 287 292 doDrag(e); 288 293 } 289 294 290 295 @Override 291 public void mouseReleased( 292 if (dragging > 0296 public void mouseReleased(MouseEvent e) { 297 if (dragging > 0) { 293 298 dragging = 0; 294 299 } … … 296 301 297 302 @Override 298 public void mousePressed( 303 public void mousePressed(MouseEvent e) { 299 304 int nearest = nearestEntry(e); 300 if (nearest > 0 && Main.getLayerManager().getActiveLayer() == NanoLogLayer.this305 if (nearest > 0 && Main.getLayerManager().getActiveLayer() == NanoLogLayer.this) { 301 306 dragging = nearest; 302 307 doDrag(e); … … 304 309 } 305 310 306 private void doDrag( 307 if (dragging > 0311 private void doDrag(MouseEvent e) { 312 if (dragging > 0) 308 313 dragTo(dragging, e.getX(), e.getY()); 309 314 } 310 315 } 311 316 312 protected void dragTo( 317 protected void dragTo(int entry, int x, int y) { 313 318 GpxLayer gpx = GPXChooser.topLayer(); 314 if (gpx == null319 if (gpx == null) 315 320 return; 316 321 EastNorth eastNorth = Main.map.mapView.getEastNorth(x, y); 317 322 double tolerance = eastNorth.distance(Main.map.mapView.getEastNorth(x + 300, y)); 318 323 WayPoint wp = gpx.data.nearestPointOnTrack(eastNorth, tolerance); 319 if (wp == null324 if (wp == null) 320 325 return; 321 326 long newTime = Correlator.getGpxDate(gpx.data, wp.getCoor()); 322 if (newTime <= 0327 if (newTime <= 0) 323 328 return; 324 329 Correlator.revertPos(log); … … 330 335 private boolean toZero; 331 336 332 public CorrelateEntries( boolean toZero ) { 333 super(toZero ? tr("Correlate with GPX...") : tr("Put on GPX..."), "nanolog/correlate", tr("Correlate entries with GPS trace"), null, false); 337 CorrelateEntries(boolean toZero) { 338 super(toZero ? tr("Correlate with GPX...") : tr("Put on GPX..."), "nanolog/correlate", 339 tr("Correlate entries with GPS trace"), null, false); 334 340 this.toZero = toZero; 335 341 } 336 342 337 343 @Override 338 public void actionPerformed( 344 public void actionPerformed(ActionEvent e) { 339 345 // 1. Select GPX trace or display message to load one 340 346 // (better yet, disable when no GPX traces) … … 342 348 // 2. Correlate by default, sticking by date 343 349 // (if does not match, shift so hours-minutes stay) 344 if (layer != null350 if (layer != null) { 345 351 long offset = toZero ? 0 : Correlator.crudeMatch(log, layer.data); 346 352 Correlator.revertPos(log); … … 356 362 private class SaveLayer extends JosmAction { 357 363 358 publicSaveLayer() {364 SaveLayer() { 359 365 super(tr("Save layer..."), "nanolog/save", tr("Save NanoLog layer"), null, false); 360 366 } 361 367 362 368 @Override 363 public void actionPerformed( 369 public void actionPerformed(ActionEvent e) { 364 370 // todo 365 371 JOptionPane.showMessageDialog(Main.parent, "Sorry, no saving yet", "NanoLog", JOptionPane.ERROR_MESSAGE); … … 367 373 } 368 374 369 public static interface NanoLogLayerListener { 370 void markersUpdated( NanoLogLayer layer ); 371 void markerActivated( NanoLogLayer layer, NanoLogEntry entry ); 375 public interface NanoLogLayerListener { 376 void markersUpdated(NanoLogLayer layer); 377 378 void markerActivated(NanoLogLayer layer, NanoLogEntry entry); 372 379 } 373 380 } -
applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPanel.java
r32447 r32638 11 11 import javax.swing.JList; 12 12 13 import nanolog.NanoLogLayer.NanoLogLayerListener;14 15 13 import org.openstreetmap.josm.Main; 16 14 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; … … 20 18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 21 19 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 20 21 import nanolog.NanoLogLayer.NanoLogLayerListener; 22 22 23 23 /** … … 40 40 public void updateMarkers() { 41 41 List<NanoLogEntry> entries = new ArrayList<>(); 42 for (NanoLogLayer l : Main.getLayerManager().getLayersOfType(NanoLogLayer.class)42 for (NanoLogLayer l : Main.getLayerManager().getLayersOfType(NanoLogLayer.class)) { 43 43 entries.addAll(l.getEntries()); 44 44 } … … 53 53 public void layerAdded(LayerAddEvent e) { 54 54 Layer newLayer = e.getAddedLayer(); 55 if (newLayer instanceof NanoLogLayer 55 if (newLayer instanceof NanoLogLayer) 56 56 ((NanoLogLayer) newLayer).addListener(this); 57 57 updateMarkers(); … … 64 64 65 65 @Override 66 public void markersUpdated( 66 public void markersUpdated(NanoLogLayer layer) { 67 67 updateMarkers(); 68 68 } 69 69 70 70 @Override 71 public void markerActivated( 71 public void markerActivated(NanoLogLayer layer, NanoLogEntry entry) { 72 72 int idx = entry == null ? -1 : listModel.find(entry); 73 if (idx >= 073 if (idx >= 0) { 74 74 logPanel.setSelectedIndex(idx); 75 75 Rectangle rect = logPanel.getCellBounds(Math.max(0, idx-2), Math.min(idx+4, listModel.getSize())); … … 83 83 84 84 @Override 85 85 public int getSize() { 86 86 return entries.size(); 87 87 } 88 88 89 89 @Override 90 90 public String getElementAt(int index) { 91 91 return TIME_FORMAT.format(entries.get(index).getTime()) + " " + entries.get(index).getMessage(); 92 92 } 93 93 94 public void setEntries( 94 public void setEntries(List<NanoLogEntry> entries) { 95 95 this.entries = entries; 96 96 fireContentsChanged(this, 0, entries.size()); 97 97 } 98 98 99 public int find( 99 public int find(NanoLogEntry entry) { 100 100 return entries.indexOf(entry); 101 101 } -
applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPlugin.java
r32447 r32638 18 18 /** 19 19 * Add NanoLog opening menu item and the panel. 20 * 20 * 21 21 * @author zverik 22 22 */ 23 23 public class NanoLogPlugin extends Plugin { 24 public NanoLogPlugin( 24 public NanoLogPlugin(PluginInformation info) { 25 25 super(info); 26 26 Main.main.menu.fileMenu.insert(new OpenNanoLogLayerAction(), 4); 27 27 } 28 28 29 29 @Override 30 public void mapFrameInitialized( 31 if (oldFrame == null && newFrame != null30 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 31 if (oldFrame == null && newFrame != null) { 32 32 NanoLogPanel panel = new NanoLogPanel(); 33 33 newFrame.addToggleDialog(panel); … … 35 35 } 36 36 } 37 37 38 38 private class OpenNanoLogLayerAction extends JosmAction { 39 39 40 publicOpenNanoLogLayerAction() {40 OpenNanoLogLayerAction() { 41 41 super(tr("Open NanoLog file..."), "nanolog.png", tr("Open NanoLog file..."), null, false); 42 42 } 43 43 44 public void actionPerformed( ActionEvent e ) { 44 @Override 45 public void actionPerformed(ActionEvent e) { 45 46 JFileChooser fc = new JFileChooser(); 46 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION47 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 47 48 try { 48 49 List<NanoLogEntry> entries = NanoLogLayer.readNanoLog(fc.getSelectedFile()); 49 if (!entries.isEmpty()50 if (!entries.isEmpty()) { 50 51 NanoLogLayer layer = new NanoLogLayer(entries); 51 52 Main.getLayerManager().addLayer(layer); 52 53 layer.setupListeners(); 53 54 } 54 } catch (IOException ex55 } catch (IOException ex) { 55 56 JOptionPane.showMessageDialog(Main.parent, tr("Could not read NanoLog file:") + "\n" + ex.getMessage()); 56 57 } 57 58 } 58 } 59 } 59 60 } 60 61 }
Note:
See TracChangeset
for help on using the changeset viewer.