Changeset 31398 in osm for applications/editors/josm/plugins/mapillary
- Timestamp:
- 2015-07-23T17:39:58+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 6 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31396 r31398 2 2 3 3 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm.data.cache.CacheEntry; 5 import org.openstreetmap.josm.data.cache.CacheEntryAttributes; 6 import org.openstreetmap.josm.data.cache.ICachedLoaderListener; 7 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 4 import org.openstreetmap.josm.plugins.mapillary.cache.Utils; 8 5 9 6 import java.util.ArrayList; … … 19 16 * 20 17 */ 21 public class MapillaryData implements ICachedLoaderListener{18 public class MapillaryData { 22 19 23 20 /** Unique instance of the class */ … … 41 38 multiSelectedImages = new ArrayList<>(); 42 39 selectedImage = null; 43 40 44 41 addListener(MapillaryPlugin.walkAction); 45 42 } … … 249 246 // Downloading thumbnails of surrounding pictures. 250 247 if (mapillaryImage.next() != null) { 251 new MapillaryCache(((MapillaryImage) mapillaryImage.next()).getKey(), MapillaryCache.Type.THUMBNAIL).submit( 252 this, false); 248 Utils.downloadPicture(mapillaryImage.next()); 253 249 if (mapillaryImage.next().next() != null) 254 new MapillaryCache(((MapillaryImage) mapillaryImage.next().next()).getKey(), MapillaryCache.Type.THUMBNAIL) 255 .submit(this, false); 250 Utils.downloadPicture(mapillaryImage.next().next()); 256 251 } 257 252 if (mapillaryImage.previous() != null) { 258 new MapillaryCache(((MapillaryImage) mapillaryImage.previous()).getKey(), MapillaryCache.Type.THUMBNAIL) 259 .submit(this, false); 253 Utils.downloadPicture(mapillaryImage.previous()); 260 254 if (mapillaryImage.previous().previous() != null) 261 new MapillaryCache(((MapillaryImage) mapillaryImage.previous().previous()).getKey(), 262 MapillaryCache.Type.THUMBNAIL).submit(this, false); 255 Utils.downloadPicture(mapillaryImage.previous().previous()); 263 256 } 264 257 } … … 324 317 325 318 /** 326 * This is empty because it is used just to make sure that certain images have327 * already been downloaded.328 */329 @Override330 public void loadingFinished(CacheEntry data, CacheEntryAttributes attributes, LoadResult result) {331 // DO NOTHING332 }333 334 /**335 319 * Returns the amount of images contained by this object. 336 320 * -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31387 r31398 5 5 6 6 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction; 7 import org.openstreetmap.josm.plugins.mapillary.cache. MapillaryCache;7 import org.openstreetmap.josm.plugins.mapillary.cache.Utils; 8 8 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 9 9 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; … … 221 221 super.destroy(); 222 222 } 223 223 224 224 /** 225 225 * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map view. … … 505 505 // Predownloads the thumbnails 506 506 if (ret[0] != null) 507 new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL) 508 .submit(data, false); 507 Utils.downloadPicture(ret[0]); 509 508 if (ret[1] != null) 510 new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL) 511 .submit(data, false); 509 Utils.downloadPicture(ret[1]); 512 510 return ret; 513 511 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java
r31396 r31398 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.awt.image.BufferedImage; 9 import java.util.concurrent.locks.Lock; 10 import java.util.concurrent.locks.ReentrantLock; 8 import java.util.ArrayList; 11 9 12 10 import javax.swing.JDialog; … … 16 14 import org.openstreetmap.josm.actions.JosmAction; 17 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;19 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryDataListener; 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;21 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 22 18 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; … … 27 23 /** 28 24 * Walks forward at a given interval. 29 * 25 * 30 26 * @author nokutu 31 27 * … … 36 32 private static final long serialVersionUID = 3454223919402245818L; 37 33 34 private WalkThread thread = null; 35 private ArrayList<WalkListener> listeners = new ArrayList<>(); 36 38 37 /** 39 * 38 * 40 39 */ 41 40 public MapillaryWalkAction() { … … 57 56 if (pane.getValue() != null 58 57 && (int) pane.getValue() == JOptionPane.OK_OPTION) { 59 new WalkThread((int) dialog.spin.getValue(), 60 dialog.waitForPicture.isSelected()).start(); 58 thread = new WalkThread((int) dialog.spin.getValue(), 59 dialog.waitForPicture.isSelected()); 60 fireWalkStarted(); 61 thread.start(); 62 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.Mode.WALK); 61 63 } 62 64 } … … 65 67 public void imagesAdded() { 66 68 // Nothing 69 } 70 71 /** 72 * Adds a listener. 73 * 74 * @param lis 75 */ 76 public void addListener(WalkListener lis) { 77 listeners.add(lis); 78 } 79 80 /** 81 * Removes a listener. 82 * 83 * @param lis 84 */ 85 public void removeListener(WalkListener lis) { 86 listeners.remove(lis); 87 } 88 89 private void fireWalkStarted() { 90 if (listeners.isEmpty()) 91 return; 92 for (WalkListener lis : listeners) 93 lis.walkStarted(thread); 67 94 } 68 95 … … 76 103 } 77 104 78 private class WalkThread extends Thread implements MapillaryDataListener {79 private int interval;80 private MapillaryData data;81 private Lock lock = new ReentrantLock();82 private boolean end = false;83 private boolean waitForPicture;84 private BufferedImage lastImage;85 105 86 private WalkThread(int interval, boolean waitForPicture) {87 this.interval = interval;88 this.waitForPicture = waitForPicture;89 data = MapillaryLayer.getInstance().getMapillaryData();90 data.addListener(this);91 }92 93 @Override94 public void run() {95 try {96 while (!end && data.getSelectedImage().next() != null) {97 try {98 synchronized (this) {99 if (waitForPicture) {100 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay101 .getImage() == lastImage102 || MapillaryMainDialog.getInstance().mapillaryImageDisplay103 .getImage() == null104 || MapillaryMainDialog.getInstance().mapillaryImageDisplay105 .getImage().getWidth() < 2048)106 wait(100);107 }108 wait(interval);109 }110 lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay111 .getImage();112 synchronized (lock) {113 data.selectNext();114 }115 } catch (InterruptedException e) {116 return;117 }118 }119 } catch (NullPointerException e) {120 return;121 }122 }123 124 @Override125 public void interrupt() {126 end = true;127 data.removeListener(this);128 super.interrupt();129 }130 131 @Override132 public void imagesAdded() {133 // Nothing134 }135 136 @Override137 public void selectedImageChanged(MapillaryAbstractImage oldImage,138 MapillaryAbstractImage newImage) {139 if (newImage != oldImage.next()) {140 synchronized (lock) {141 interrupt();142 }143 }144 }145 }146 106 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java
r31397 r31398 20 20 import javax.swing.JSpinner; 21 21 import javax.swing.JTextField; 22 import javax.swing.SpinnerModel;23 22 import javax.swing.SpinnerNumberModel; 24 import javax.swing.SwingUtilities;25 23 26 24 import org.openstreetmap.josm.Main; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r31396 r31398 28 28 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 29 29 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 30 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 31 import org.openstreetmap.josm.plugins.mapillary.actions.WalkListener; 32 import org.openstreetmap.josm.plugins.mapillary.actions.WalkThread; 30 33 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 34 import org.openstreetmap.josm.tools.ImageProvider; 31 35 import org.openstreetmap.josm.tools.Shortcut; 32 36 … … 62 66 /** Button used to jump to the image following the blue line */ 63 67 public final SideButton blueButton = new SideButton(new blueAction()); 68 69 private final SideButton playButton = new SideButton(new playAction()); 70 private final SideButton pauseButton = new SideButton(new pauseAction()); 71 private final SideButton stopButton = new SideButton(new stopAction()); 72 73 /** 74 * Buttons mode. 75 * 76 * @author nokutu 77 * 78 */ 79 public static enum Mode { 80 /** Standard mode to view pictures. */ 81 NORMAL, 82 /** Mode when in walk. */ 83 WALK; 84 } 64 85 65 86 private JPanel buttonsPanel; … … 119 140 INSTANCE = new MapillaryMainDialog(); 120 141 return INSTANCE; 142 } 143 144 /** 145 * @param mode 146 */ 147 public void setMode(Mode mode) { 148 switch (mode) { 149 case NORMAL: 150 createLayout( 151 mapillaryImageDisplay, 152 Arrays.asList(new SideButton[] { blueButton, previousButton, 153 nextButton, redButton }), 154 Main.pref.getBoolean("mapillary.reverse-buttons")); 155 break; 156 case WALK: 157 createLayout( 158 mapillaryImageDisplay, 159 Arrays.asList(new SideButton[] { playButton, pauseButton, 160 stopButton }), 161 Main.pref.getBoolean("mapillary.reverse-buttons")); 162 break; 163 } 164 disableAllButtons(); 165 121 166 } 122 167 … … 284 329 * 285 330 */ 286 class nextPictureAction extends AbstractAction {331 private class nextPictureAction extends AbstractAction { 287 332 288 333 private static final long serialVersionUID = 3023827221453154340L; … … 305 350 * 306 351 */ 307 class previousPictureAction extends AbstractAction {352 private class previousPictureAction extends AbstractAction { 308 353 309 354 private static final long serialVersionUID = -6420511632957956012L; … … 327 372 * 328 373 */ 329 class redAction extends AbstractAction {374 private class redAction extends AbstractAction { 330 375 331 376 private static final long serialVersionUID = -6480229431481386376L; … … 351 396 * 352 397 */ 353 class blueAction extends AbstractAction {398 private class blueAction extends AbstractAction { 354 399 355 400 private static final long serialVersionUID = 6250690644594703314L; … … 366 411 MapillaryData.getInstance().setSelectedImage(MapillaryLayer.BLUE, true); 367 412 } 413 } 414 } 415 416 private class stopAction extends AbstractAction implements WalkListener { 417 418 private static final long serialVersionUID = -6561451575815789198L; 419 420 private WalkThread thread; 421 422 public stopAction() { 423 putValue(NAME, tr("Stop")); 424 putValue(SHORT_DESCRIPTION, tr("Stops the walk.")); 425 putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryStop.png")); 426 MapillaryPlugin.walkAction.addListener(this); 427 } 428 429 @Override 430 public void actionPerformed(ActionEvent e) { 431 if (thread != null) 432 thread.stopWalk(); 433 } 434 435 @Override 436 public void walkStarted(WalkThread thread) { 437 this.thread = thread; 438 } 439 } 440 441 private class playAction extends AbstractAction implements WalkListener { 442 443 private static final long serialVersionUID = -17943404752082788L; 444 private WalkThread thread; 445 446 public playAction() { 447 putValue(NAME, tr("Play")); 448 putValue(SHORT_DESCRIPTION, tr("Continues with the paused walk.")); 449 putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryPlay.png")); 450 MapillaryPlugin.walkAction.addListener(this); 451 } 452 453 @Override 454 public void actionPerformed(ActionEvent e) { 455 if (thread != null) 456 thread.play(); 457 } 458 459 @Override 460 public void walkStarted(WalkThread thread) { 461 if (thread != null) 462 this.thread = thread; 463 } 464 } 465 466 private class pauseAction extends AbstractAction implements WalkListener { 467 468 private static final long serialVersionUID = 4400240686337741192L; 469 470 private WalkThread thread; 471 472 public pauseAction() { 473 putValue(NAME, tr("Pause")); 474 putValue(SHORT_DESCRIPTION, tr("Pauses the walk.")); 475 putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryPause.png")); 476 MapillaryPlugin.walkAction.addListener(this); 477 } 478 479 @Override 480 public void actionPerformed(ActionEvent e) { 481 thread.pause(); 482 } 483 484 @Override 485 public void walkStarted(WalkThread thread) { 486 this.thread = thread; 368 487 } 369 488 }
Note:
See TracChangeset
for help on using the changeset viewer.