Changeset 31357 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-07-09T11:57:35+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31355 r31357 106 106 * @return The image under the mouse cursor. 107 107 */ 108 public MapillaryAbstractImage getH overedImage() {108 public MapillaryAbstractImage getHighlighted() { 109 109 return highlightedImage; 110 110 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31356 r31357 10 10 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; 11 11 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; 12 import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode; 13 import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode; 12 14 import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode; 13 15 import org.openstreetmap.josm.Main; … … 44 46 import java.awt.Rectangle; 45 47 import java.awt.TexturePaint; 46 import java.awt.event.MouseAdapter;47 48 import java.awt.geom.AffineTransform; 48 49 import java.awt.geom.Area; … … 59 60 import java.util.ArrayList; 60 61 61 public class MapillaryLayer extends AbstractModifiableLayer implements 62 DataSetListener, EditLayerChangeListener,LayerChangeListener {63 64 public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref .getInteger(65 "mapillary.sequence-max-jump-distance", 100);62 public class MapillaryLayer extends AbstractModifiableLayer implements DataSetListener, EditLayerChangeListener, 63 LayerChangeListener { 64 65 public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref 66 .getInteger("mapillary.sequence-max-jump-distance", 100); 66 67 67 68 private boolean TEMP_MANUAL = false; … … 76 77 public ArrayList<Bounds> bounds; 77 78 78 private MouseAdapter mode; 79 80 private int highlightPointRadius = Main.pref.getInteger( 81 "mappaint.highlight.radius", 7); 82 private int highlightStep = Main.pref 83 .getInteger("mappaint.highlight.step", 4); 79 public AbstractMode mode; 80 81 private int highlightPointRadius = Main.pref.getInteger("mappaint.highlight.radius", 7); 82 private int highlightStep = Main.pref.getInteger("mappaint.highlight.step", 4); 84 83 85 84 private volatile TexturePaint hatched; … … 120 119 data.dataUpdated(); 121 120 } 122 123 public void setMode( MouseAdaptermode) {121 122 public void setMode(AbstractMode mode) { 124 123 Main.map.mapView.removeMouseListener(this.mode); 125 124 Main.map.mapView.removeMouseMotionListener(this.mode); … … 143 142 if (Main.pref.getBoolean("mapillary.download-manually") || TEMP_MANUAL) 144 143 return; 145 for (Bounds bounds : Main.map.mapView.getEditLayer().data 146 .getDataSourceBounds()) { 144 for (Bounds bounds : Main.map.mapView.getEditLayer().data.getDataSourceBounds()) { 147 145 if (!this.bounds.contains(bounds)) { 148 146 this.bounds.add(bounds); … … 160 158 private void checkAreaTooBig() { 161 159 double area = 0; 162 for (Bounds bounds : Main.map.mapView.getEditLayer().data 163 .getDataSourceBounds()) { 160 for (Bounds bounds : Main.map.mapView.getEditLayer().data.getDataSourceBounds()) { 164 161 area += bounds.getArea(); 165 162 } … … 272 269 Point p1 = mv.getPoint(bounds.getMin()); 273 270 Point p2 = mv.getPoint(bounds.getMax()); 274 Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), 275 Math.abs(p2.x - p1.x), Math.abs(p2.y- p1.y));271 Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y 272 - p1.y)); 276 273 a.subtract(new Area(r)); 277 274 } … … 294 291 MapillaryLayer.BLUE = closestImages[0]; 295 292 g.setColor(Color.BLUE); 296 g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x, 297 mv.getPoint(closestImages[0].getLatLon()).y,selected.x, selected.y);293 g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x, mv.getPoint(closestImages[0].getLatLon()).y, 294 selected.x, selected.y); 298 295 MapillaryMainDialog.getInstance().blueButton.setEnabled(true); 299 296 } … … 301 298 MapillaryLayer.RED = closestImages[1]; 302 299 g.setColor(Color.RED); 303 g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x, 304 mv.getPoint(closestImages[1].getLatLon()).y,selected.x, selected.y);300 g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x, mv.getPoint(closestImages[1].getLatLon()).y, 301 selected.x, selected.y); 305 302 MapillaryMainDialog.getInstance().redButton.setEnabled(true); 306 303 } … … 311 308 continue; 312 309 Point p = mv.getPoint(imageAbs.getLatLon()); 313 310 314 311 Point nextp = null; 315 312 // Draw sequence line … … 326 323 g.drawLine(p.x, p.y, nextp.x, nextp.y); 327 324 } 328 325 329 326 if (imageAbs instanceof MapillaryImage) { 330 327 MapillaryImage image = (MapillaryImage) imageAbs; … … 336 333 draw(g, image, icon, p); 337 334 if (!image.getSigns().isEmpty()) { 338 g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(), 339 p.x + icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2, 340 Main.map.mapView); 335 g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(), p.x + icon.getIconWidth() / 2, p.y - icon.getIconHeight() 336 / 2, Main.map.mapView); 341 337 } 342 338 } else if (imageAbs instanceof MapillaryImportedImage) { … … 350 346 } 351 347 } 348 if (mode instanceof JoinMode) { 349 mode.paint(g, mv, box); 350 } 352 351 } 353 352 … … 362 361 Color oldColor = g.getColor(); 363 362 Color highlightColor = PaintColors.HIGHLIGHT.get(); 364 Color highlightColorTransparent = new Color(highlightColor.getRed(), 365 highlightColor.get Green(), highlightColor.getBlue(), 100);363 Color highlightColorTransparent = new Color(highlightColor.getRed(), highlightColor.getGreen(), 364 highlightColor.getBlue(), 100); 366 365 g.setColor(highlightColorTransparent); 367 366 int s = size + highlightPointRadius; … … 383 382 * @param p 384 383 */ 385 private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, 386 Point p) { 384 private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, Point p) { 387 385 Image imagetemp = icon.getImage(); 388 386 BufferedImage bi = (BufferedImage) imagetemp; … … 394 392 double locationX = width / 2; 395 393 double locationY = height / 2; 396 AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, 397 locationX, locationY); 398 AffineTransformOp op = new AffineTransformOp(tx, 399 AffineTransformOp.TYPE_BILINEAR); 400 401 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), 402 Main.map.mapView); 403 if (data.getHoveredImage() == image) { 394 AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY); 395 AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); 396 397 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), Main.map.mapView); 398 if (data.getHighlighted() == image) { 404 399 drawPointHighlight(g, p, 16); 405 400 } … … 418 413 @Override 419 414 public void mergeFrom(Layer from) { 420 throw new UnsupportedOperationException( 421 "This layer does not support merging yet"); 415 throw new UnsupportedOperationException("This layer does not support merging yet"); 422 416 } 423 417 … … 441 435 MapillaryImage selected = (MapillaryImage) data.getSelectedImage(); 442 436 MapillaryImage[] ret = new MapillaryImage[2]; 443 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, 444 SEQUENCE_MAX_JUMP_DISTANCE }; 437 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, SEQUENCE_MAX_JUMP_DISTANCE }; 445 438 LatLon selectedCoords = data.getSelectedImage().getLatLon(); 446 439 for (MapillaryAbstractImage imagePrev : data.getImages()) { … … 457 450 ret[0] = image; 458 451 distances[0] = image.getLatLon().greatCircleDistance(selectedCoords); 459 } else if ((ret[1] == null || image.getLatLon().greatCircleDistance( 460 selectedCoords) < distances[1]) 452 } else if ((ret[1] == null || image.getLatLon().greatCircleDistance(selectedCoords) < distances[1]) 461 453 && image.getSequence() != ret[0].getSequence()) { 462 454 ret[1] = image; … … 467 459 // Predownloads the thumbnails 468 460 if (ret[0] != null) 469 new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL) 470 .submit(data, false); 461 new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL).submit(data, false); 471 462 if (ret[1] != null) 472 new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL) 473 .submit(data, false); 463 new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL).submit(data, false); 474 464 return ret; 475 465 } … … 566 556 else 567 557 Main.map.statusLine.setHelpText(tr("No images found")); 568 } 558 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, true); 559 } else 560 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, false); 569 561 } 570 562 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31355 r31357 10 10 import org.openstreetmap.josm.data.cache.JCSCacheManager; 11 11 import org.openstreetmap.josm.gui.MainMenu; 12 import org.openstreetmap.josm.gui.MapView;13 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;14 12 import org.openstreetmap.josm.Main; 15 13 import org.openstreetmap.josm.gui.MapFrame; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;17 14 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 18 15 import org.openstreetmap.josm.plugins.Plugin; … … 27 24 /** 28 25 * This is the main class of the Mapillary plugin. 29 * 26 * 30 27 * @author nokutu 31 28 * 32 29 */ 33 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener{30 public class MapillaryPlugin extends Plugin { 34 31 35 32 public static final ImageIcon ICON24 = new ImageProvider("icon24.png").get(); … … 49 46 private final MapillaryDownloadViewAction downloadViewAction; 50 47 private final MapillaryImportIntoSequenceAction importIntoSequenceAction; 48 private final MapillaryJoinAction joinAction; 51 49 52 50 public static JMenuItem DOWNLOAD_MENU; … … 56 54 public static JMenuItem DOWNLOAD_VIEW_MENU; 57 55 public static JMenuItem IMPORT_INTO_SEQUENCE_MENU; 56 public static JMenuItem JOIN_MENU; 58 57 59 58 public MapillaryPlugin(PluginInformation info) { … … 65 64 downloadViewAction = new MapillaryDownloadViewAction(); 66 65 importIntoSequenceAction = new MapillaryImportIntoSequenceAction(); 66 joinAction = new MapillaryJoinAction(); 67 67 68 68 if (Main.main != null) { // important for headless mode … … 73 73 ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15); 74 74 DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu, downloadViewAction, false, 14); 75 JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false); 75 76 } 76 77 … … 81 82 ZOOM_MENU.setEnabled(false); 82 83 DOWNLOAD_VIEW_MENU.setEnabled(false); 84 JOIN_MENU.setEnabled(false); 83 85 84 MapView.addEditLayerChangeListener(this);85 86 try { 86 87 CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, this.getPluginDir() + "/cache/"); … … 125 126 return new MapillaryPreferenceSetting(); 126 127 } 127 128 @Override129 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {130 if (oldLayer == null && newLayer != null) {131 } else if (oldLayer != null && newLayer == null) {132 }133 }134 128 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31355 r31357 62 62 for (int i = 0; i < chooser.getSelectedFiles().length; i++) { 63 63 File file = chooser.getSelectedFiles()[i]; 64 MapillaryLayer.getInstance(); 64 65 if (file.isDirectory()) { 65 66 // TODO import directory -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java
r31356 r31357 1 1 package org.openstreetmap.josm.plugins.mapillary.mode; 2 2 3 import java.awt.Graphics2D; 3 4 import java.awt.Point; 4 5 import java.awt.event.MouseAdapter; 5 6 6 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.gui.MapView; 7 10 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 8 11 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; … … 10 13 public abstract class AbstractMode extends MouseAdapter { 11 14 12 protected MapillaryData data ;15 protected MapillaryData data = MapillaryData.getInstance(); 13 16 14 17 public AbstractMode() { … … 32 35 } 33 36 37 public abstract void paint(Graphics2D g, MapView mv, Bounds box); 38 39 34 40 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java
r31356 r31357 1 1 package org.openstreetmap.josm.plugins.mapillary.mode; 2 2 3 import java.awt.event.MouseAdapter; 3 import java.awt.Color; 4 import java.awt.Graphics2D; 5 import java.awt.Point; 4 6 import java.awt.event.MouseEvent; 5 7 6 8 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 9 import org.openstreetmap.josm.data.Bounds; 10 import org.openstreetmap.josm.gui.MapView; 8 11 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 9 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 14 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence; 10 15 11 16 public class JoinMode extends AbstractMode { 12 17 18 public MapillaryImportedImage lastClick; 19 public MouseEvent lastPos; 20 13 21 @Override 14 22 public void mousePressed(MouseEvent e) { 15 23 if (data.getHighlighted() == null) 24 return; 25 if (lastClick == null && data.getHighlighted() instanceof MapillaryImportedImage) { 26 if (data.getHighlighted().previous() == null || data.getHighlighted().next() == null) 27 lastClick = (MapillaryImportedImage) data.getHighlighted(); 28 } else if (lastClick != null && data.getHighlighted() instanceof MapillaryImportedImage) { 29 if ((data.getHighlighted().previous() == null && lastClick.next() == null) 30 || (data.getHighlighted().next() == null && lastClick.previous() == null)) { 31 join(lastClick, (MapillaryImportedImage) data.getHighlighted()); 32 } else if (lastClick.next() == data.getHighlighted() || lastClick.previous() == data.getHighlighted()) 33 unjoin(lastClick, (MapillaryImportedImage) data.getHighlighted()); 34 lastClick = null; 35 } 36 data.dataUpdated(); 16 37 } 17 38 18 39 @Override 19 40 public void mouseMoved(MouseEvent e) { 20 MapillaryAbstractImage closestTemp = getClosest(e.getPoint());41 lastPos = e; 21 42 if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer)) 22 43 return; 44 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 23 45 data.setHighlightedImage(closestTemp); 46 data.dataUpdated(); 47 } 48 49 @Override 50 public void paint(Graphics2D g, MapView mv, Bounds box) { 51 if (lastClick != null) { 52 g.setColor(Color.WHITE); 53 Point p0 = mv.getPoint(lastClick.getLatLon()); 54 Point p1 = lastPos.getPoint(); 55 g.drawLine(p0.x, p0.y, p1.x, p1.y); 56 } 57 } 58 59 private void join(MapillaryImportedImage img1, MapillaryImportedImage img2) { 60 if (img1.next() != null) { 61 MapillaryImportedImage temp = img1; 62 img1 = img2; 63 img2 = temp; 64 } 65 if (img1.getSequence() == null) { 66 MapillarySequence seq = new MapillarySequence(); 67 seq.add(img1); 68 img1.setSequence(seq); 69 } 70 if (img2.getSequence() == null) { 71 MapillarySequence seq = new MapillarySequence(); 72 seq.add(img2); 73 img2.setSequence(seq); 74 } 75 76 for (MapillaryAbstractImage img : img2.getSequence().getImages()) { 77 img1.getSequence().add(img); 78 img.setSequence(img1.getSequence()); 79 } 80 } 81 82 private void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) { 83 // TODO 24 84 } 25 85 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java
r31356 r31357 1 1 package org.openstreetmap.josm.plugins.mapillary.mode; 2 2 3 import java.awt.Graphics2D; 3 4 import java.awt.Point; 4 5 import java.awt.event.MouseEvent; … … 6 7 7 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.data.Bounds; 8 10 import org.openstreetmap.josm.data.coor.LatLon; 9 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.gui.MapView; 10 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; … … 21 24 /** 22 25 * Handles the input event related with the layer. Mainly clicks. 23 * 26 * 24 27 * @author nokutu 25 28 * … … 178 181 } 179 182 180 if (MapillaryData.getInstance().getH overedImage() != closestTemp && closestTemp != null) {183 if (MapillaryData.getInstance().getHighlighted() != closestTemp && closestTemp != null) { 181 184 MapillaryData.getInstance().setHighlightedImage(closestTemp); 182 185 MapillaryMainDialog.getInstance().setImage(closestTemp); 183 186 MapillaryMainDialog.getInstance().updateImage(); 184 } else if (MapillaryData.getInstance().getH overedImage() != closestTemp && closestTemp == null) {187 } else if (MapillaryData.getInstance().getHighlighted() != closestTemp && closestTemp == null) { 185 188 MapillaryData.getInstance().setHighlightedImage(null); 186 189 MapillaryMainDialog.getInstance().setImage(MapillaryData.getInstance().getSelectedImage()); … … 189 192 MapillaryData.getInstance().dataUpdated(); 190 193 } 194 195 @Override 196 public void paint(Graphics2D g, MapView mv, Bounds box) { 197 } 191 198 }
Note:
See TracChangeset
for help on using the changeset viewer.