Changeset 31399 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-07-23T17:40:03+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31398 r31399 18 18 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 19 19 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 20 import org.openstreetmap.josm.gui.NavigatableComponent; 20 21 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 21 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 63 64 * 64 65 */ 65 public class MapillaryLayer extends AbstractModifiableLayer implements DataSetListener, EditLayerChangeListener,66 LayerChangeListener {66 public class MapillaryLayer extends AbstractModifiableLayer implements 67 DataSetListener, EditLayerChangeListener, LayerChangeListener { 67 68 68 69 /** Maximum distance for the red/blue lines. */ 69 public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref 70 .getInteger("mapillary.sequence-max-jump-distance", 100); 71 72 private boolean TEMP_MANUAL = false; 70 public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref.getInteger( 71 "mapillary.sequence-max-jump-distance", 100); 72 73 /** If the download is in manual mode during the rest of the session */ 74 public boolean TEMP_SEMIAUTOMATIC = false; 73 75 74 76 /** Unique instance of the class */ … … 105 107 */ 106 108 private void init() { 107 mode = new SelectMode();108 109 if (Main.map != null && Main.map.mapView != null) { 109 Main.map.mapView.addMouseListener(mode); 110 Main.map.mapView.addMouseMotionListener(mode); 110 setMode(new SelectMode()); 111 111 Main.map.mapView.addLayer(this); 112 112 MapView.addEditLayerChangeListener(this, false); … … 130 130 * 131 131 * @param mode 132 * The mode that is going to be activated.132 * The mode that is going to be activated. 133 133 */ 134 134 public void setMode(AbstractMode mode) { 135 Main.map.mapView.removeMouseListener(this.mode); 136 Main.map.mapView.removeMouseMotionListener(this.mode); 135 if (this.mode != null) { 136 Main.map.mapView.removeMouseListener(this.mode); 137 Main.map.mapView.removeMouseMotionListener(this.mode); 138 NavigatableComponent.removeZoomChangeListener(this.mode); 139 } 137 140 this.mode = mode; 138 141 Main.map.mapView.setNewCursor(mode.cursor, this); 139 142 Main.map.mapView.addMouseListener(mode); 140 143 Main.map.mapView.addMouseMotionListener(mode); 144 NavigatableComponent.addZoomChangeListener(mode); 141 145 updateHelpText(); 142 146 } … … 145 149 * Returns the unique instance of this class. 146 150 * 147 * @return The unique i sntance of this class.151 * @return The unique instance of this class. 148 152 */ 149 153 public synchronized static MapillaryLayer getInstance() { … … 159 163 public void download() { 160 164 checkAreaTooBig(); 161 if (Main.pref.getBoolean("mapillary.download-manually") || TEMP_MANUAL) 165 if (!Main.pref.get("mapillary.download-mode").equals( 166 MapillaryDownloader.MODES[0]) 167 || TEMP_SEMIAUTOMATIC) 162 168 return; 163 169 for (Bounds bounds : Main.map.mapView.getEditLayer().data … … 165 171 if (!this.bounds.contains(bounds)) { 166 172 this.bounds.add(bounds); 167 new MapillaryDownloader().getImages(bounds.getMin(), bounds.getMax());173 MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax()); 168 174 } 169 175 } … … 183 189 } 184 190 if (area > MapillaryDownloadViewAction.MAX_AREA) { 185 TEMP_ MANUAL= true;191 TEMP_SEMIAUTOMATIC = true; 186 192 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true); 187 193 JOptionPane … … 223 229 224 230 /** 225 * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map view. 231 * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map 232 * view. 226 233 */ 227 234 public void showAllPictures() { … … 240 247 maxLon = img.getLatLon().lon(); 241 248 } 242 Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon (maxLat, maxLon))); 249 Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon( 250 maxLat, maxLon))); 243 251 } 244 252 … … 437 445 double locationX = width / 2; 438 446 double locationY = height / 2; 439 AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY); 440 AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); 441 442 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), Main.map.mapView); 447 AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, 448 locationX, locationY); 449 AffineTransformOp op = new AffineTransformOp(tx, 450 AffineTransformOp.TYPE_BILINEAR); 451 452 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), 453 Main.map.mapView); 443 454 if (data.getHighlighted() == image) { 444 455 drawPointHighlight(g, p, 16); … … 458 469 @Override 459 470 public void mergeFrom(Layer from) { 460 throw new UnsupportedOperationException("This layer does not support merging yet"); 471 throw new UnsupportedOperationException( 472 "This layer does not support merging yet"); 461 473 } 462 474 … … 480 492 MapillaryImage selected = (MapillaryImage) data.getSelectedImage(); 481 493 MapillaryImage[] ret = new MapillaryImage[2]; 482 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, SEQUENCE_MAX_JUMP_DISTANCE }; 494 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, 495 SEQUENCE_MAX_JUMP_DISTANCE }; 483 496 LatLon selectedCoords = data.getSelectedImage().getLatLon(); 484 497 for (MapillaryAbstractImage imagePrev : data.getImages()) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31396 r31399 15 15 import org.openstreetmap.josm.plugins.Plugin; 16 16 import org.openstreetmap.josm.plugins.PluginInformation; 17 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 17 18 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; 18 19 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryHistoryDialog; … … 134 135 Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false); 135 136 setMenuEnabled(DOWNLOAD_MENU, true); 136 if (Main.pref.getBoolean("mapillary.download-manually")) 137 if (Main.pref.get("mapillary.download-mode").equals( 138 MapillaryDownloader.MODES[2])) 137 139 setMenuEnabled(DOWNLOAD_VIEW_MENU, true); 138 140 setMenuEnabled(IMPORT_MENU, true); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java
r31386 r31399 27 27 /** Max area to be downloaded */ 28 28 public static final double MAX_AREA = Main.pref.getDouble( 29 "mapillary.max-download-area", 0.0 20);29 "mapillary.max-download-area", 0.015); 30 30 31 31 /** … … 45 45 MapillaryLayer.getInstance().bounds.add(Main.map.mapView.getRealBounds()); 46 46 if (Main.map.mapView.getRealBounds().getArea() <= MAX_AREA) { 47 new MapillaryDownloader().getImages(Main.map.mapView.getRealBounds());47 MapillaryDownloader.getImages(Main.map.mapView.getRealBounds()); 48 48 } else { 49 49 JOptionPane.showMessageDialog(Main.parent, -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31387 r31399 9 9 import org.openstreetmap.josm.data.coor.LatLon; 10 10 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 11 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction; 11 12 12 13 /** … … 19 20 public class MapillaryDownloader { 20 21 22 /** Possible download modes.*/ 23 public static final String[] MODES = new String[] { "Automatic", "Semiautomatic", 24 "Manual" }; 25 21 26 /** Base URL of the Mapillary API. */ 22 27 public final static String BASE_URL = "https://a.mapillary.com/v2/"; … … 25 30 /** Executor that will run the petitions */ 26 31 public final static Executor EXECUTOR = Executors.newSingleThreadExecutor(); 27 28 32 29 33 /** … … 36 40 * The maximum latitude and longitude of the rectangle 37 41 */ 38 public void getImages(LatLon minLatLon, LatLon maxLatLon) {42 public static void getImages(LatLon minLatLon, LatLon maxLatLon) { 39 43 ConcurrentHashMap<String, Double> queryStringParts = new ConcurrentHashMap<>(); 40 44 queryStringParts.put("min_lat", minLatLon.lat()); … … 44 48 45 49 try { 46 EXECUTOR.execute(new MapillarySquareDownloadManagerThread(queryStringParts, MapillaryLayer.getInstance())); 50 EXECUTOR.execute(new MapillarySquareDownloadManagerThread( 51 queryStringParts, MapillaryLayer.getInstance())); 47 52 } catch (Exception e) { 48 53 Main.error(e); 49 54 } 55 } 56 57 /** 58 * If some part of the current view has not been downloaded, it is downloaded. 59 * 60 */ 61 public static void completeView() { 62 Bounds view = Main.map.mapView.getRealBounds(); 63 if (view.getArea() > MapillaryDownloadViewAction.MAX_AREA) 64 return; 65 for (Bounds bound : MapillaryLayer.getInstance().bounds) { 66 if (!view.intersects(bound)) 67 continue; 68 if (bound.equals(view)) { 69 // Already downloaded 70 return; 71 } 72 } 73 MapillaryLayer.getInstance().bounds.add(view); 74 getImages(view); 50 75 } 51 76 … … 55 80 * @param bounds 56 81 */ 57 public void getImages(Bounds bounds) {82 public static void getImages(Bounds bounds) { 58 83 getImages(bounds.getMin(), bounds.getMax()); 59 84 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31391 r31399 40 40 /** 41 41 * Main constructor. 42 * 42 * 43 43 * @param ex 44 44 * @param queryString … … 90 90 jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at") 91 91 .longValue()); 92 93 92 List<MapillaryImage> finalImages = new ArrayList<>(images); 94 93 // Here it gets only those images which are in the downloaded -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31391 r31399 36 36 /** 37 37 * Main constructor. 38 * 38 * 39 39 * @param queryStringParts 40 40 * @param layer 41 * 41 * 42 42 */ 43 43 public MapillarySquareDownloadManagerThread( -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r31390 r31399 47 47 @Override 48 48 public void setText(String text) { 49 super.setText("<html><font color=\"#0000CF\" size=\"2\">" + text + "</font></html>"); //$NON-NLS-1$ //$NON-NLS-2$ 49 super 50 .setText("<html><font color=\"#0000CF\" size=\"2\">" + text + "</font></html>"); //$NON-NLS-1$ //$NON-NLS-2$ 50 51 this.text = text; 51 52 } … … 70 71 /** 71 72 * Returns the text set by the user. 72 * 73 * 73 74 * @return The plain-text written in the label. 74 75 */ … … 84 85 super.processMouseEvent(evt); 85 86 if (evt.getID() == MouseEvent.MOUSE_CLICKED) 86 fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getNormalText())); 87 fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, 88 getNormalText())); 87 89 } 88 90 … … 90 92 * Adds an ActionListener to the list of listeners receiving notifications 91 93 * when the label is clicked. 92 * 94 * 93 95 * @param listener 94 96 */ … … 100 102 * Removes the given ActionListener from the list of listeners receiving 101 103 * notifications when the label is clicked. 102 * 104 * 103 105 * @param listener 104 106 */ … … 109 111 /** 110 112 * Fires an ActionEvent to all interested listeners. 111 * @param evt 113 * 114 * @param evt 112 115 */ 113 116 protected void fireActionPerformed(ActionEvent evt) { … … 126 129 return; 127 130 Desktop desktop = Desktop.getDesktop(); 128 try { 129 desktop.browse(url.toURI()); 130 } catch (IOException | URISyntaxException ex) { 131 ex.printStackTrace(); 132 } catch (UnsupportedOperationException ex) { 131 if (desktop.isSupported(Desktop.Action.BROWSE)) { 132 try { 133 desktop.browse(url.toURI()); 134 } catch (IOException | URISyntaxException e1) { 135 Main.error(e1); 136 } 137 } else { 133 138 Runtime runtime = Runtime.getRuntime(); 134 139 try { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31396 r31399 13 13 import javax.swing.JButton; 14 14 import javax.swing.JCheckBox; 15 import javax.swing.JComboBox; 16 import javax.swing.JLabel; 15 17 import javax.swing.JPanel; 16 18 … … 20 22 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 21 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 24 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 22 25 import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener; 23 26 … … 32 35 private JCheckBox reverseButtons = new JCheckBox( 33 36 tr("Reverse buttons position when displaying images.")); 34 private JCheckBox downloadMode = new JCheckBox(tr("Download images manually")); 37 private JComboBox<String> downloadMode = new JComboBox<>( 38 MapillaryDownloader.MODES); 35 39 private JCheckBox displayHour = new JCheckBox( 36 40 tr("Display hour when the picture was taken")); … … 50 54 reverseButtons.setSelected(Main.pref 51 55 .getBoolean("mapillary.reverse-buttons")); 52 downloadMode.setSelected(Main.pref53 .getBoolean("mapillary.download-manually"));54 56 displayHour.setSelected(Main.pref 55 57 .getBoolean("mapillary.display-hour", true)); … … 59 61 panel.setLayout(new FlowLayout(FlowLayout.LEFT)); 60 62 panel.add(reverseButtons); 61 panel.add(downloadMode); 63 64 JPanel downloadModePanel = new JPanel(); 65 downloadModePanel.add(new JLabel(tr("Download mode: "))); 66 downloadModePanel.add(downloadMode); 67 panel.add(downloadModePanel); 68 62 69 panel.add(displayHour); 63 70 panel.add(format24); … … 67 74 oauth.setText("Login"); 68 75 else 69 76 oauth.setText("Already loged in, click to relogin."); 70 77 panel.add(oauth); 71 78 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); … … 76 83 boolean mod = false; 77 84 Main.pref.put("mapillary.reverse-buttons", reverseButtons.isSelected()); 78 Main.pref.put("mapillary.download-manually", downloadMode.isSelected()); 79 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, 80 downloadMode.isSelected()); 85 86 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false); 87 if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0])) 88 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]); 89 if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1])) 90 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]); 91 if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) { 92 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]); 93 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true); 94 } 81 95 82 96 Main.pref.put("mapillary.display-hour", displayHour.isSelected()); … … 108 122 String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email"; 109 123 Desktop desktop = Desktop.getDesktop(); 110 try { 111 desktop.browse(new URI(url)); 112 } catch (IOException | URISyntaxException ex) { 113 ex.printStackTrace(); 114 } catch (UnsupportedOperationException ex) { 124 if (desktop.isSupported(Desktop.Action.BROWSE)) { 125 try { 126 desktop.browse(new URI(url)); 127 } catch (IOException | URISyntaxException e1) { 128 Main.error(e1); 129 } 130 } else { 115 131 Runtime runtime = Runtime.getRuntime(); 116 132 try { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java
r31389 r31399 5 5 import java.awt.Point; 6 6 import java.awt.event.MouseAdapter; 7 import java.util.Calendar; 7 8 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.data.Bounds; 10 11 import org.openstreetmap.josm.gui.MapView; 12 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 11 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 12 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 16 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 13 17 14 18 /** … … 19 23 * 20 24 */ 21 public abstract class AbstractMode extends MouseAdapter { 25 public abstract class AbstractMode extends MouseAdapter implements 26 ZoomChangeListener { 22 27 23 28 protected MapillaryData data = MapillaryData.getInstance(); 29 30 private long lastDownload; 24 31 25 32 /** … … 54 61 public abstract void paint(Graphics2D g, MapView mv, Bounds box); 55 62 63 @Override 64 public synchronized void zoomChanged() { 65 if (Main.pref.get("mapillary.download-mode").equals( 66 MapillaryDownloader.MODES[1]) 67 || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC) { 68 if (Calendar.getInstance().getTimeInMillis() - lastDownload >= 2000) { 69 lastDownload = Calendar.getInstance().getTimeInMillis(); 70 MapillaryDownloader.completeView(); 71 } else { 72 new Thread() { 73 @Override 74 public synchronized void run() { 75 try { 76 wait(100); 77 } catch (InterruptedException e) { 78 } 79 zoomChanged(); 80 } 81 }.start(); 82 } 83 } 84 } 56 85 }
Note:
See TracChangeset
for help on using the changeset viewer.