Ignore:
Timestamp:
2015-07-23T17:39:58+02:00 (9 years ago)
Author:
nokutu
Message:

Added buttons when in walk mode, so it can be paused, resumed and stopped. Each button has its own icon.

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  
    22
    33import 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;
     4import org.openstreetmap.josm.plugins.mapillary.cache.Utils;
    85
    96import java.util.ArrayList;
     
    1916 *
    2017 */
    21 public class MapillaryData implements ICachedLoaderListener {
     18public class MapillaryData {
    2219
    2320  /** Unique instance of the class */
     
    4138    multiSelectedImages = new ArrayList<>();
    4239    selectedImage = null;
    43    
     40
    4441    addListener(MapillaryPlugin.walkAction);
    4542  }
     
    249246        // Downloading thumbnails of surrounding pictures.
    250247        if (mapillaryImage.next() != null) {
    251           new MapillaryCache(((MapillaryImage) mapillaryImage.next()).getKey(), MapillaryCache.Type.THUMBNAIL).submit(
    252               this, false);
     248          Utils.downloadPicture(mapillaryImage.next());
    253249          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());
    256251        }
    257252        if (mapillaryImage.previous() != null) {
    258           new MapillaryCache(((MapillaryImage) mapillaryImage.previous()).getKey(), MapillaryCache.Type.THUMBNAIL)
    259               .submit(this, false);
     253          Utils.downloadPicture(mapillaryImage.previous());
    260254          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());
    263256        }
    264257      }
     
    324317
    325318  /**
    326    * This is empty because it is used just to make sure that certain images have
    327    * already been downloaded.
    328    */
    329   @Override
    330   public void loadingFinished(CacheEntry data, CacheEntryAttributes attributes, LoadResult result) {
    331     // DO NOTHING
    332   }
    333 
    334   /**
    335319   * Returns the amount of images contained by this object.
    336320   *
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31387 r31398  
    55
    66import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction;
    7 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache;
     7import org.openstreetmap.josm.plugins.mapillary.cache.Utils;
    88import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    99import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
     
    221221    super.destroy();
    222222  }
    223  
     223
    224224  /**
    225225   * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map view.
     
    505505    // Predownloads the thumbnails
    506506    if (ret[0] != null)
    507       new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL)
    508           .submit(data, false);
     507      Utils.downloadPicture(ret[0]);
    509508    if (ret[1] != null)
    510       new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL)
    511           .submit(data, false);
     509      Utils.downloadPicture(ret[1]);
    512510    return ret;
    513511  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java

    r31396 r31398  
    66import java.awt.event.ActionEvent;
    77import java.awt.event.KeyEvent;
    8 import java.awt.image.BufferedImage;
    9 import java.util.concurrent.locks.Lock;
    10 import java.util.concurrent.locks.ReentrantLock;
     8import java.util.ArrayList;
    119
    1210import javax.swing.JDialog;
     
    1614import org.openstreetmap.josm.actions.JosmAction;
    1715import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    18 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    1916import org.openstreetmap.josm.plugins.mapillary.MapillaryDataListener;
    20 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    2117import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    2218import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     
    2723/**
    2824 * Walks forward at a given interval.
    29  * 
     25 *
    3026 * @author nokutu
    3127 *
     
    3632  private static final long serialVersionUID = 3454223919402245818L;
    3733
     34  private WalkThread thread = null;
     35  private ArrayList<WalkListener> listeners = new ArrayList<>();
     36
    3837  /**
    39    * 
     38   *
    4039   */
    4140  public MapillaryWalkAction() {
     
    5756    if (pane.getValue() != null
    5857        && (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);
    6163    }
    6264  }
     
    6567  public void imagesAdded() {
    6668    // 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);
    6794  }
    6895
     
    76103  }
    77104
    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;
    85105
    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     @Override
    94     public void run() {
    95       try {
    96         while (!end && data.getSelectedImage().next() != null) {
    97           try {
    98             synchronized (this) {
    99               if (waitForPicture) {
    100                 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay
    101                     .getImage() == lastImage
    102                     || MapillaryMainDialog.getInstance().mapillaryImageDisplay
    103                         .getImage() == null
    104                     || MapillaryMainDialog.getInstance().mapillaryImageDisplay
    105                         .getImage().getWidth() < 2048)
    106                   wait(100);
    107               }
    108               wait(interval);
    109             }
    110             lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay
    111                 .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     @Override
    125     public void interrupt() {
    126       end = true;
    127       data.removeListener(this);
    128       super.interrupt();
    129     }
    130 
    131     @Override
    132     public void imagesAdded() {
    133       // Nothing
    134     }
    135 
    136     @Override
    137     public void selectedImageChanged(MapillaryAbstractImage oldImage,
    138         MapillaryAbstractImage newImage) {
    139       if (newImage != oldImage.next()) {
    140         synchronized (lock) {
    141           interrupt();
    142         }
    143       }
    144     }
    145   }
    146106}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r31397 r31398  
    2020import javax.swing.JSpinner;
    2121import javax.swing.JTextField;
    22 import javax.swing.SpinnerModel;
    2322import javax.swing.SpinnerNumberModel;
    24 import javax.swing.SwingUtilities;
    2523
    2624import org.openstreetmap.josm.Main;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31396 r31398  
    2828import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2929import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     30import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     31import org.openstreetmap.josm.plugins.mapillary.actions.WalkListener;
     32import org.openstreetmap.josm.plugins.mapillary.actions.WalkThread;
    3033import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache;
     34import org.openstreetmap.josm.tools.ImageProvider;
    3135import org.openstreetmap.josm.tools.Shortcut;
    3236
     
    6266  /** Button used to jump to the image following the blue line */
    6367  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  }
    6485
    6586  private JPanel buttonsPanel;
     
    119140      INSTANCE = new MapillaryMainDialog();
    120141    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
    121166  }
    122167
     
    284329   *
    285330   */
    286   class nextPictureAction extends AbstractAction {
     331  private class nextPictureAction extends AbstractAction {
    287332
    288333    private static final long serialVersionUID = 3023827221453154340L;
     
    305350   *
    306351   */
    307   class previousPictureAction extends AbstractAction {
     352  private class previousPictureAction extends AbstractAction {
    308353
    309354    private static final long serialVersionUID = -6420511632957956012L;
     
    327372   *
    328373   */
    329   class redAction extends AbstractAction {
     374  private class redAction extends AbstractAction {
    330375
    331376    private static final long serialVersionUID = -6480229431481386376L;
     
    351396   *
    352397   */
    353   class blueAction extends AbstractAction {
     398  private class blueAction extends AbstractAction {
    354399
    355400    private static final long serialVersionUID = 6250690644594703314L;
     
    366411        MapillaryData.getInstance().setSelectedImage(MapillaryLayer.BLUE, true);
    367412      }
     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;
    368487    }
    369488  }
Note: See TracChangeset for help on using the changeset viewer.