Ignore:
Timestamp:
2015-08-13T00:07:14+02:00 (9 years ago)
Author:
nokutu
Message:

When zooming to show a set of images, the zoom level has a maximum value, so it can't too high.

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

Legend:

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

    r31490 r31495  
    190190  public void destroy() {
    191191    setMode(null);
    192 
     192    MapillaryRecord.getInstance().reset();
    193193    AbstractMode.resetThread();
    194194    MapillaryDownloader.stopAll();
     
    211211  public static void clearInstance() {
    212212    INSTANCE = null;
    213   }
    214 
    215   /**
    216    * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map
    217    * view.
    218    */
    219   public void showAllPictures() {
    220     double minLat = 90;
    221     double minLon = 180;
    222     double maxLat = -90;
    223     double maxLon = -180;
    224     for (MapillaryAbstractImage img : this.data.getImages()) {
    225       if (img.getLatLon().lat() < minLat)
    226         minLat = img.getLatLon().lat();
    227       if (img.getLatLon().lon() < minLon)
    228         minLon = img.getLatLon().lon();
    229       if (img.getLatLon().lat() > maxLat)
    230         maxLat = img.getLatLon().lat();
    231       if (img.getLatLon().lon() > maxLon)
    232         maxLon = img.getLatLon().lon();
    233     }
    234     Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon(
    235         maxLat, maxLon)));
    236213  }
    237214
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31490 r31495  
    118118      }
    119119      MapillaryRecord.getInstance().addCommand(new CommandImport(images));
    120       MapillaryLayer.getInstance().showAllPictures();
     120      MapillaryUtils.showAllPictures();
    121121    }
    122122  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31490 r31495  
    116116      MapillaryRecord.getInstance().addCommand(new CommandImport(this.images));
    117117    }
    118     MapillaryLayer.getInstance().showAllPictures();
     118    MapillaryUtils.showAllPictures();
    119119  }
    120120
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/FinishedUploadDialog.java

    r31473 r31495  
    3636    text.setAlignmentX(Component.CENTER_ALIGNMENT);
    3737    this.add(text);
    38     JButton web = new JButton("Approve upload in the website.");
     38    JButton web = new JButton("Approve upload on the website.");
    3939    web.addActionListener(new WebAction());
    4040    web.setAlignmentX(Component.CENTER_ALIGNMENT);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r31492 r31495  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.awt.event.MouseEvent;
     12import java.awt.event.MouseListener;
    1113import java.util.ArrayList;
    1214import java.util.Arrays;
     15import java.util.concurrent.ConcurrentHashMap;
    1316
    1417import javax.swing.AbstractAction;
     
    1821import javax.swing.JTree;
    1922import javax.swing.SwingUtilities;
     23import javax.swing.event.TreeSelectionEvent;
     24import javax.swing.event.TreeSelectionListener;
    2025import javax.swing.tree.DefaultTreeCellRenderer;
    2126import javax.swing.tree.DefaultTreeModel;
     27import javax.swing.tree.TreeSelectionModel;
    2228
    2329import org.openstreetmap.josm.gui.SideButton;
     
    2531import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
    2632import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecordListener;
     33import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
    2734import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand;
     35import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2836import org.openstreetmap.josm.tools.GBC;
    2937import org.openstreetmap.josm.tools.ImageProvider;
     
    4856  private static MapillaryHistoryDialog INSTANCE;
    4957
     58  private transient UndoRedoSelectionListener undoSelectionListener;
     59  private transient UndoRedoSelectionListener redoSelectionListener;
     60
    5061  private final DefaultTreeModel undoTreeModel = new DefaultTreeModel(
    5162      new DefaultMutableTreeNode());
     
    6172  private SideButton redoButton;
    6273
     74  private ConcurrentHashMap<Object, MapillaryCommand> map;
     75
    6376  private MapillaryHistoryDialog() {
    6477    super(tr("Mapillary history"), "mapillaryhistory.png",
     
    6982    MapillaryRecord.getInstance().addListener(this);
    7083
     84    this.map = new ConcurrentHashMap<>();
     85
    7186    this.undoTree.expandRow(0);
    7287    this.undoTree.setShowsRootHandles(true);
    7388    this.undoTree.setRootVisible(false);
    7489    this.undoTree.setCellRenderer(new MapillaryCellRenderer());
     90    this.undoTree.getSelectionModel().setSelectionMode(
     91        TreeSelectionModel.SINGLE_TREE_SELECTION);
     92    this.undoTree.addMouseListener(new MouseEventHandler());
     93    this.undoSelectionListener = new UndoRedoSelectionListener(this.undoTree);
     94    this.undoTree.getSelectionModel().addTreeSelectionListener(
     95        this.undoSelectionListener);
     96
    7597    this.redoTree.expandRow(0);
    7698    this.redoTree.setCellRenderer(new MapillaryCellRenderer());
    7799    this.redoTree.setShowsRootHandles(true);
    78100    this.redoTree.setRootVisible(false);
     101    this.redoTree.getSelectionModel().setSelectionMode(
     102        TreeSelectionModel.SINGLE_TREE_SELECTION);
     103    this.redoTree.addMouseListener(new MouseEventHandler());
     104    this.redoSelectionListener = new UndoRedoSelectionListener(this.redoTree);
     105    this.redoTree.getSelectionModel().addTreeSelectionListener(
     106        this.redoSelectionListener);
    79107
    80108    JPanel treesPanel = new JPanel(new GridBagLayout());
     
    130158    DefaultMutableTreeNode undoRoot = new DefaultMutableTreeNode();
    131159
     160    this.map.clear();
    132161    for (MapillaryCommand command : undoCommands) {
    133       if (command != null)
    134         undoRoot.add(new DefaultMutableTreeNode(command.toString()));
     162      if (command != null) {
     163        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
     164            command.toString());
     165        this.map.put(node, command);
     166        undoRoot.add(node);
     167      }
    135168    }
    136169    for (MapillaryCommand command : redoCommands) {
    137       if (command != null)
    138         redoRoot.add(new DefaultMutableTreeNode(command.toString()));
     170      if (command != null) {
     171        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
     172            command.toString());
     173        this.map.put(node, command);
     174        redoRoot.add(node);
     175      }
    139176    }
    140177
     
    213250    MapillaryHistoryDialog.INSTANCE = null;
    214251  }
     252
     253  private class MouseEventHandler implements MouseListener {
     254
     255    @Override
     256    public void mouseClicked(MouseEvent e) {
     257    }
     258
     259    @Override
     260    public void mouseEntered(MouseEvent e) {
     261    }
     262
     263    @Override
     264    public void mouseExited(MouseEvent e) {
     265    }
     266
     267    @Override
     268    public void mousePressed(MouseEvent e) {
     269      if (e.getClickCount() == 2) {
     270        if (MapillaryHistoryDialog.this.undoTree.getSelectionPath() != null) {
     271          MapillaryCommand cmd = MapillaryHistoryDialog.this.map
     272              .get(MapillaryHistoryDialog.this.undoTree.getSelectionPath()
     273                  .getLastPathComponent());
     274          if (!(cmd instanceof CommandDelete))
     275            MapillaryUtils.showPictures(cmd.images, true);
     276        } else
     277          MapillaryUtils.showPictures(MapillaryHistoryDialog.this.map
     278              .get(MapillaryHistoryDialog.this.redoTree.getSelectionPath()
     279                  .getLastPathComponent()).images, true);
     280      }
     281    }
     282
     283    @Override
     284    public void mouseReleased(MouseEvent e) {
     285    }
     286  }
     287
     288  private class UndoRedoSelectionListener implements TreeSelectionListener {
     289
     290    private JTree source;
     291
     292    private UndoRedoSelectionListener(JTree source) {
     293      this.source = source;
     294    }
     295
     296    @Override
     297    public void valueChanged(TreeSelectionEvent e) {
     298      if (this.source == MapillaryHistoryDialog.this.undoTree) {
     299        MapillaryHistoryDialog.this.redoTree.getSelectionModel()
     300            .removeTreeSelectionListener(
     301                MapillaryHistoryDialog.this.redoSelectionListener);
     302        MapillaryHistoryDialog.this.redoTree.clearSelection();
     303        MapillaryHistoryDialog.this.redoTree.getSelectionModel()
     304            .addTreeSelectionListener(
     305                MapillaryHistoryDialog.this.redoSelectionListener);
     306      }
     307      if (this.source == MapillaryHistoryDialog.this.redoTree) {
     308        MapillaryHistoryDialog.this.undoTree.getSelectionModel()
     309            .removeTreeSelectionListener(
     310                MapillaryHistoryDialog.this.undoSelectionListener);
     311        MapillaryHistoryDialog.this.undoTree.clearSelection();
     312        MapillaryHistoryDialog.this.undoTree.getSelectionModel()
     313            .addTreeSelectionListener(
     314                MapillaryHistoryDialog.this.undoSelectionListener);
     315      }
     316    }
     317  }
    215318}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

    r31492 r31495  
    127127        lis.recordChanged();
    128128  }
     129
     130  /**
     131   * Resets the object to its start state.
     132   */
     133  public void reset() {
     134    this.commandList.clear();
     135    this.position = -1;
     136  }
    129137}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31489 r31495  
    88import java.net.URL;
    99import java.util.ArrayList;
     10import java.util.List;
     11
     12import javax.swing.SwingUtilities;
    1013
    1114import org.apache.commons.imaging.common.RationalNumber;
    1215import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    1316import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.data.Bounds;
     18import org.openstreetmap.josm.data.coor.LatLon;
    1419import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    1520import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     
    2530 */
    2631public class MapillaryUtils {
     32
     33  private static double MIN_ZOOM_SQUARE_SIDE = 0.002;
     34
    2735  /**
    2836   * Updates the help text at the bottom of the window.
     
    199207      MapillaryData.dataUpdated();
    200208  }
     209
     210  /**
     211   * Zooms to fit all the given {@link MapillaryAbstractImage} objects.
     212   *
     213   * @param images
     214   *          The images your are zooming to.
     215   * @param select
     216   *          Whether the added images must be selected or not.
     217   */
     218  public static void showPictures(final List<MapillaryAbstractImage> images,
     219      final boolean select) {
     220    if (!SwingUtilities.isEventDispatchThread()) {
     221      SwingUtilities.invokeLater(new Runnable() {
     222        @Override
     223        public void run() {
     224          showPictures(images, select);
     225        }
     226      });
     227    } else {
     228      double minLat = 90;
     229      double minLon = 180;
     230      double maxLat = -90;
     231      double maxLon = -180;
     232      for (MapillaryAbstractImage img : images) {
     233        if (img.getLatLon().lat() < minLat)
     234          minLat = img.getLatLon().lat();
     235        if (img.getLatLon().lon() < minLon)
     236          minLon = img.getLatLon().lon();
     237        if (img.getLatLon().lat() > maxLat)
     238          maxLat = img.getLatLon().lat();
     239        if (img.getLatLon().lon() > maxLon)
     240          maxLon = img.getLatLon().lon();
     241      }
     242      Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon), new LatLon(
     243          maxLat, maxLon));
     244      // The zoom rectangle must have a minimum size.
     245      double latExtent = zoomBounds.getMaxLat() - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
     246          .getMaxLat() - zoomBounds.getMinLat()
     247          : MIN_ZOOM_SQUARE_SIDE;
     248      double lonExtent = zoomBounds.getMaxLon() - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
     249          .getMaxLon() - zoomBounds.getMinLon()
     250          : MIN_ZOOM_SQUARE_SIDE;
     251      zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
     252
     253      Main.map.mapView.zoomTo(zoomBounds);
     254      MapillaryLayer.getInstance().getData().setSelectedImage(null);
     255      if (select)
     256        MapillaryLayer.getInstance().getData().addMultiSelectedImage(images);
     257      if (Main.main != null)
     258        MapillaryData.dataUpdated();
     259    }
     260  }
     261
     262  /**
     263   * Zooms to fit all the {@link MapillaryAbstractImage} objects stored in the
     264   * database.
     265   */
     266  public static void showAllPictures() {
     267    showPictures(MapillaryLayer.getInstance().getData().getImages(), false);
     268  }
    201269}
Note: See TracChangeset for help on using the changeset viewer.