Changeset 31491 in osm


Ignore:
Timestamp:
2015-08-12T12:39:50+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed EDT errors and added option to delete the images after upload.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31457 r31491  
    55import javax.swing.ImageIcon;
    66import javax.swing.JMenuItem;
     7import javax.swing.SwingUtilities;
    78
    89import org.apache.commons.jcs.access.CacheAccess;
     
    118119      IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, false,
    119120          14);
    120       UPLOAD_MENU = MainMenu.add(Main.main.menu.fileMenu, uploadAction,
    121           false, 14);
    122       ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false,
    123           15);
     121      UPLOAD_MENU = MainMenu.add(Main.main.menu.fileMenu, uploadAction, false,
     122          14);
     123      ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
    124124      DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,
    125125          this.downloadViewAction, false, 14);
     
    182182   *          true to enable the JMenuItem; false to disable it.
    183183   */
    184   public static void setMenuEnabled(JMenuItem menu, boolean value) {
    185     menu.setEnabled(value);
    186     menu.getAction().setEnabled(value);
     184  public static void setMenuEnabled(final JMenuItem menu, final boolean value) {
     185    if (!SwingUtilities.isEventDispatchThread()) {
     186      SwingUtilities.invokeLater(new Runnable() {
     187        @Override
     188        public void run() {
     189          setMenuEnabled(menu, value);
     190        }
     191      });
     192    } else {
     193      menu.setEnabled(value);
     194      menu.getAction().setEnabled(value);
     195    }
    187196  }
    188197
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31456 r31491  
    5353      if (dialog.sequence.isSelected()) {
    5454        UploadUtils.uploadSequence(MapillaryLayer.getInstance().getData()
    55             .getSelectedImage().getSequence());
     55            .getSelectedImage().getSequence(), dialog.delete.isSelected());
    5656      }
    5757    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryUploadDialog.java

    r31451 r31491  
    11package org.openstreetmap.josm.plugins.mapillary.gui;
    22
     3import javax.swing.BoxLayout;
    34import javax.swing.ButtonGroup;
     5import javax.swing.JCheckBox;
    46import javax.swing.JPanel;
    57import javax.swing.JRadioButton;
    68
     9import org.openstreetmap.josm.Main;
    710import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    811import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     
    2023  /** Upload the whole sequence. */
    2124  public JRadioButton sequence;
     25  /** Whether the images must be deleted after upload or not */
     26  public JCheckBox delete;
    2227
    2328  /**
     
    2530   */
    2631  public MapillaryUploadDialog() {
     32    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
     33
    2734    this.group = new ButtonGroup();
    2835
     
    3340    this.group.add(this.sequence);
    3441    add(this.sequence);
     42    this.group.setSelected(this.sequence.getModel(), true);
    3543
    36     this.group.setSelected(this.sequence.getModel(), true);
     44    this.delete = new JCheckBox("Delete after uplaod");
     45    this.delete.setSelected(Main.pref.getBoolean(
     46        "mapillary.delete-after-upload", true));
     47    add(this.delete);
    3748
    3849  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

    r31490 r31491  
    22
    33import java.util.ArrayList;
     4
     5import javax.swing.SwingUtilities;
    46
    57import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     
    7072   *          The command to be added.
    7173   */
    72   public void addCommand(MapillaryCommand command) {
    73     if (command instanceof MapillaryExecutableCommand)
    74       ((MapillaryExecutableCommand) command).execute();
    75     // Checks if it is a continuation of last command
    76     if (this.position != -1) {
    77       boolean equalSets = true;
    78       for (MapillaryAbstractImage img : this.commandList.get(this.position).images)
    79         if (!command.images.contains(img))
    80           equalSets = false;
    81       for (MapillaryAbstractImage img : command.images)
    82         if (!this.commandList.get(this.position).images.contains(img))
    83           equalSets = false;
    84       if (equalSets
    85           && this.commandList.get(this.position).getClass() == command
    86               .getClass()) {
    87         this.commandList.get(this.position).sum(command);
    88         fireRecordChanged();
    89         return;
     74  public void addCommand(final MapillaryCommand command) {
     75    if (!SwingUtilities.isEventDispatchThread()) {
     76      SwingUtilities.invokeLater(new Runnable() {
     77        @Override
     78        public void run() {
     79          addCommand(command);
     80        }
     81      });
     82    } else {
     83      if (command instanceof MapillaryExecutableCommand)
     84        ((MapillaryExecutableCommand) command).execute();
     85      // Checks if it is a continuation of last command
     86      if (this.position != -1) {
     87        boolean equalSets = true;
     88        for (MapillaryAbstractImage img : this.commandList.get(this.position).images)
     89          if (!command.images.contains(img))
     90            equalSets = false;
     91        for (MapillaryAbstractImage img : command.images)
     92          if (!this.commandList.get(this.position).images.contains(img))
     93            equalSets = false;
     94        if (equalSets
     95            && this.commandList.get(this.position).getClass() == command
     96                .getClass()) {
     97          this.commandList.get(this.position).sum(command);
     98          fireRecordChanged();
     99          return;
     100        }
    90101      }
     102      // Adds the command to the last position of the list.
     103      this.commandList.add(this.position + 1, command);
     104      this.position++;
     105      while (this.commandList.size() > this.position + 1) {
     106        this.commandList.remove(this.position + 1);
     107      }
     108      fireRecordChanged();
    91109    }
    92     // Adds the command to the last position of the list.
    93     this.commandList.add(this.position + 1, command);
    94     this.position++;
    95     while (this.commandList.size() > this.position + 1) {
    96       this.commandList.remove(this.position + 1);
    97     }
    98     fireRecordChanged();
    99110  }
    100111
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandImport.java

    r31490 r31491  
    2929  @Override
    3030  public void execute() {
    31     this.redo();
     31    MapillaryLayer.getInstance().getData().add(this.images);
    3232  }
    3333
     
    4242  @Override
    4343  public void redo() {
    44     MapillaryLayer.getInstance().getData().add(this.images);
     44    this.execute();
    4545  }
    4646
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31482 r31491  
    4141import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    4242import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
     43import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     44import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
    4345import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    4446import org.openstreetmap.josm.plugins.mapillary.utils.PluginState;
     
    141143   *          The sequence to upload. It must contain only
    142144   *          {@link MapillaryImportedImage} objects.
    143    */
    144   public static void uploadSequence(MapillarySequence sequence) {
    145     Main.worker.submit(new SequenceUploadThread(sequence.getImages()));
     145   * @param delete
     146   *          Whether the images must be deleted after upload or not.
     147   */
     148  public static void uploadSequence(MapillarySequence sequence, boolean delete) {
     149    Main.worker.submit(new SequenceUploadThread(sequence.getImages(), delete));
    146150  }
    147151
     
    149153    private List<MapillaryAbstractImage> images;
    150154    private UUID uuid;
     155    private boolean delete;
    151156    ThreadPoolExecutor ex;
    152157
    153     private SequenceUploadThread(List<MapillaryAbstractImage> images) {
     158    private SequenceUploadThread(List<MapillaryAbstractImage> images,
     159        boolean delete) {
    154160      this.images = images;
    155161      this.uuid = UUID.randomUUID();
    156162      this.ex = new ThreadPoolExecutor(8, 8, 25, TimeUnit.SECONDS,
    157163          new ArrayBlockingQueue<Runnable>(15));
     164      this.delete = delete;
    158165    }
    159166
     
    176183      }
    177184      this.ex.shutdown();
     185      try {
     186        this.ex.awaitTermination(15, TimeUnit.SECONDS);
     187      } catch (InterruptedException e) {
     188        Main.error(e);
     189      }
     190      System.out.println(this.images.size());
     191      if (this.delete)
     192        MapillaryRecord.getInstance().addCommand(new CommandDelete(this.images));
    178193    }
    179194  }
Note: See TracChangeset for help on using the changeset viewer.