Changeset 31261 in osm for applications
- Timestamp:
- 2015-06-12T12:39:14+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 3 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31259 r31261 6 6 import org.openstreetmap.josm.data.cache.ICachedLoaderListener; 7 7 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog;9 8 10 9 import java.util.ArrayList; … … 26 25 private MapillaryAbstractImage selectedImage; 27 26 private final List<MapillaryAbstractImage> multiSelectedImages; 27 28 private List<MapillaryDataListener> listeners= new ArrayList<>(); 28 29 29 30 public MapillaryData() { … … 63 64 } 64 65 dataUpdated(); 66 } 67 68 public void addListener(MapillaryDataListener lis) { 69 listeners.add(lis); 70 } 71 72 public void removeListener(MapillaryDataListener lis) { 73 listeners.remove(lis); 65 74 } 66 75 … … 156 165 public void setSelectedImage(MapillaryAbstractImage image) { 157 166 selectedImage = image; 158 if (image instanceof MapillaryImage)159 System.out.println(((MapillaryImage) image).getLocation());160 167 multiSelectedImages.clear(); 161 168 multiSelectedImages.add(image); 162 169 if (image != null) { 163 MapillaryToggleDialog.getInstance().setImage(selectedImage);164 MapillaryToggleDialog.getInstance().updateImage();165 170 if (image instanceof MapillaryImage) { 166 171 MapillaryImage mapillaryImage = (MapillaryImage) image; … … 186 191 Main.map.mapView.repaint(); 187 192 } 193 fireSelectedImageChanged(); 194 } 195 196 private void fireSelectedImageChanged() { 197 if (listeners.isEmpty()) 198 return; 199 for (MapillaryDataListener lis : listeners) 200 lis.selectedImageChanged(); 188 201 } 189 202 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31256 r31261 19 19 return ImageIO.read(file); 20 20 } 21 22 public File getFile() { 23 return file; 24 } 21 25 22 26 @Override -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31259 r31261 54 54 public final static int SEQUENCE_MAX_JUMP_DISTANCE = 100; 55 55 56 public static Boolean INSTANCED = false;57 56 public static MapillaryLayer INSTANCE; 58 57 public static CacheAccess<String, BufferedImageCacheEntry> CACHE; … … 79 78 */ 80 79 private void init() { 81 INSTANCED = true;82 80 MapillaryLayer.INSTANCE = this; 83 81 startMouseAdapter(); … … 110 108 } 111 109 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true); 110 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.SIGNAL_MENU, true); 112 111 download(); 113 112 Main.map.mapView.setActiveLayer(this); … … 156 155 MapillaryToggleDialog.getInstance().mapillaryImageDisplay 157 156 .setImage(null); 158 INSTANCED = false;159 157 MapillaryLayer.INSTANCE = null; 160 158 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false); 159 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.SIGNAL_MENU, false); 161 160 MapillaryData.INSTANCE = null; 162 161 Main.map.mapView.removeMouseListener(mouseAdapter); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31259 r31261 50 50 private final MapillaryExportAction exportAction; 51 51 private final MapillaryImportAction importAction; 52 private final MapillarySignalAction signalAction; 52 53 53 54 public static JMenuItem DOWNLOAD_MENU; 54 55 public static JMenuItem EXPORT_MENU; 55 56 public static JMenuItem IMPORT_MENU; 57 public static JMenuItem SIGNAL_MENU; 56 58 57 59 public MapillaryPlugin(PluginInformation info) { … … 60 62 exportAction = new MapillaryExportAction(); 61 63 importAction = new MapillaryImportAction(); 64 signalAction = new MapillarySignalAction(); 62 65 63 66 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, … … 67 70 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, 68 71 false, 14); 72 SIGNAL_MENU = MainMenu.add(Main.main.menu.dataMenu, signalAction, 73 false); 69 74 70 75 EXPORT_MENU.setEnabled(false); 71 76 DOWNLOAD_MENU.setEnabled(false); 72 77 IMPORT_MENU.setEnabled(false); 78 SIGNAL_MENU.setEnabled(false); 73 79 74 80 MapView.addEditLayerChangeListener(this); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r31260 r31261 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.io.IOException; 8 9 import java.util.ArrayList; 9 10 import java.util.List; … … 67 68 } else if (dialog.group.isSelected(dialog.selected.getModel())) { 68 69 export(MapillaryData.getInstance().getMultiSelectedImages()); 69 } else if (dialog.group.isSelected(dialog.rewrite.getModel())) { 70 ArrayList<MapillaryAbstractImage> images = new ArrayList<>(); 71 for (MapillaryAbstractImage image : MapillaryData.getInstance().getMultiSelectedImages()) 72 if (image instanceof MapillaryImportedImage) { 73 images.addAll(((MapillaryImage) image).getSequence().getImages()); 74 } 75 else 76 images.add(image); 77 export(images); 70 } 71 } else if (dialog.group.isSelected(dialog.rewrite.getModel())) { 72 ArrayList<MapillaryImportedImage> images = new ArrayList<>(); 73 for (MapillaryAbstractImage image : MapillaryData.getInstance().getImages()) 74 if (image instanceof MapillaryImportedImage) { 75 images.add(((MapillaryImportedImage) image)); 76 } 77 try { 78 Main.worker.submit(new Thread(new MapillaryExportManager(images))); 79 } catch (IOException e1) { 80 Main.error(e1); 78 81 } 79 82 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31256 r31261 39 39 tr("Import pictures into Mapillary layer"), 40 40 KeyEvent.VK_M, Shortcut.NONE), false, 41 "mapillary Download", false);41 "mapillaryImport", false); 42 42 } 43 43 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java
r31256 r31261 48 48 this.path = path; 49 49 } 50 51 /** 52 * Constructor used to rewrite imported images. 53 * @param images 54 * @throws IOException 55 */ 56 public MapillaryExportManager(List<MapillaryImportedImage> images) throws IOException { 57 super(tr("Downloading") + "...", new PleaseWaitProgressMonitor( 58 "Exporting Mapillary Images"), true); 59 queue = new ArrayBlockingQueue<>(10); 60 queueImages = new ArrayBlockingQueue<>(10); 61 for (MapillaryImportedImage image : images) { 62 queue.add(image.getImage()); 63 queueImages.add(image); 64 } 65 } 50 66 51 67 @Override … … 57 73 protected void realRun() throws SAXException, IOException, 58 74 OsmTransferException { 75 59 76 // Starts a writer thread in order to write the pictures on the disk. 60 77 Thread writer = new Thread(new MapillaryExportWriterThread(path, queue, 61 queueImages, images.size(), this.getProgressMonitor()));78 queueImages, queue.size(), this.getProgressMonitor())); 62 79 writer.start(); 80 if (path == null) { 81 try { 82 writer.join(); 83 } catch (InterruptedException e) { 84 Main.error(e); 85 } 86 return; 87 } 63 88 ThreadPoolExecutor ex = new ThreadPoolExecutor(20, 35, 25, 64 89 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java
r31256 r31261 23 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 24 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 25 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 25 26 26 27 /** … … 60 61 img = queue.take(); 61 62 mimg = queueImages.take(); 62 if (mimg instanceof MapillaryImage) 63 if (path == null && mimg instanceof MapillaryImportedImage) { 64 String path = ((MapillaryImportedImage) mimg).getFile().getPath(); 65 finalPath = path.substring(0, path.lastIndexOf('.')); 66 } 67 else if (mimg instanceof MapillaryImage) 63 68 finalPath = path + "/" + ((MapillaryImage) mimg).getKey(); 64 69 else -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySignalDownloaderThread.java
r31260 r31261 48 48 for (MapillaryAbstractImage image : MapillaryData 49 49 .getInstance().getImages()) { 50 if ( ((MapillaryImage) image).getKey().equals(key)) {51 if ( image instanceof MapillaryImage) {50 if (image instanceof MapillaryImage) { 51 if (((MapillaryImage) image).getKey().equals(key)) { 52 52 if (((MapillaryImage) image).getKey().equals( 53 53 key)) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31259 r31261 40 40 downloadSequences(); 41 41 completeImages(); 42 Main.map.statusLine.setHelpText("Downloading signals information"); 42 43 downloadSignals(); 43 44 } catch (InterruptedException e) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31256 r31261 4 4 5 5 import java.awt.event.ActionEvent; 6 import java.awt.event.KeyEvent; 6 7 import java.awt.image.BufferedImage; 7 8 import java.awt.BorderLayout; … … 23 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 24 25 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 26 import org.openstreetmap.josm.plugins.mapillary.MapillaryDataListener; 25 27 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 26 28 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 27 29 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 28 30 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 31 import org.openstreetmap.josm.tools.Shortcut; 29 32 30 33 import javax.imageio.ImageIO; … … 40 43 */ 41 44 public class MapillaryToggleDialog extends ToggleDialog implements 42 ICachedLoaderListener {45 ICachedLoaderListener, MapillaryDataListener { 43 46 44 47 public static MapillaryToggleDialog INSTANCE; … … 46 49 public volatile MapillaryAbstractImage image; 47 50 48 final SideButton nextButton = new SideButton(new nextPictureAction());49 final SideButton previousButton = new SideButton(51 public final SideButton nextButton = new SideButton(new nextPictureAction()); 52 public final SideButton previousButton = new SideButton( 50 53 new previousPictureAction()); 51 54 public final SideButton redButton = new SideButton(new redAction()); 52 55 public final SideButton blueButton = new SideButton(new blueAction()); 56 private List<SideButton> normalMode; 57 58 public final SideButton nextSignalButton = new SideButton( 59 new NextSignalAction()); 60 public final SideButton previousSignalButton = new SideButton( 61 new PreviousSignalAction()); 62 private List<SideButton> signalMode; 63 // TODO change to enum 64 private int mode; 65 66 public final static int NORMAL_MODE = 0; 67 public final static int SIGNAL_MODE = 0; 53 68 54 69 private JPanel buttonsPanel; … … 62 77 public MapillaryToggleDialog() { 63 78 super(tr("Mapillary image"), "mapillary.png", 64 tr("Open Mapillary window"), null, 200); 79 tr("Open Mapillary window"), Shortcut.registerShortcut( 80 tr("Mapillary dialog"), 81 tr("Open Mapillary main dialog"), KeyEvent.VK_M, 82 Shortcut.NONE), 200); 83 MapillaryData.getInstance().addListener(this); 84 65 85 mapillaryImageDisplay = new MapillaryImageDisplay(); 66 86 … … 68 88 redButton.setForeground(Color.RED); 69 89 90 normalMode = Arrays.asList(new SideButton[] { blueButton, 91 previousButton, nextButton, redButton }); 92 signalMode = Arrays.asList(new SideButton[] { previousSignalButton, 93 nextSignalButton }); 94 95 mode = NORMAL_MODE; 70 96 this.setLayout(new BorderLayout()); 71 97 top = new JPanel(); 72 98 top.setLayout(new BorderLayout()); 73 99 top.add(titleBar, BorderLayout.NORTH); 74 75 createLayout( 76 mapillaryImageDisplay, 77 Arrays.asList(new SideButton[] { blueButton, previousButton, 78 nextButton, redButton }), 100 createLayout(mapillaryImageDisplay, normalMode, 79 101 Main.pref.getBoolean("mapillary.reverse-buttons")); 80 102 } … … 88 110 public static void destroyInstance() { 89 111 INSTANCE = null; 112 } 113 114 public void switchMode() { 115 this.removeAll(); 116 List<SideButton> list = null; 117 if (mode == NORMAL_MODE) { 118 list = signalMode; 119 mode = SIGNAL_MODE; 120 } else if (mode == SIGNAL_MODE) { 121 list = normalMode; 122 mode = NORMAL_MODE; 123 } 124 this.setLayout(new BorderLayout()); 125 top = new JPanel(); 126 top.setLayout(new BorderLayout()); 127 top.add(titleBar, BorderLayout.NORTH); 128 createLayout(mapillaryImageDisplay, list, 129 Main.pref.getBoolean("mapillary.reverse-buttons")); 90 130 } 91 131 … … 103 143 }); 104 144 } else { 105 if (MapillaryLayer.INSTANCE D == false) {145 if (MapillaryLayer.INSTANCE == null) { 106 146 return; 107 147 } … … 109 149 return; 110 150 if (image instanceof MapillaryImage) { 111 this.nextButton.setEnabled(true);112 this.previousButton.setEnabled(true);113 151 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 114 if (mapillaryImage.next() == null) 115 this.nextButton.setEnabled(false); 116 if (mapillaryImage.previous() == null) 117 this.previousButton.setEnabled(false); 152 if (mode == NORMAL_MODE) { 153 this.nextButton.setEnabled(true); 154 this.previousButton.setEnabled(true); 155 if (mapillaryImage.next() == null) 156 this.nextButton.setEnabled(false); 157 if (mapillaryImage.previous() == null) 158 this.previousButton.setEnabled(false); 159 } else if (mode == SIGNAL_MODE) { 160 previousSignalButton.setEnabled(true); 161 nextSignalButton.setEnabled(true); 162 int i = MapillaryData 163 .getInstance() 164 .getImages() 165 .indexOf( 166 MapillaryData.getInstance() 167 .getSelectedImage()); 168 int first = -1; 169 int last = -1; 170 int c = 0; 171 for (MapillaryAbstractImage img : MapillaryData 172 .getInstance().getImages()) { 173 if (img instanceof MapillaryImage) 174 if (!((MapillaryImage) img).getSignals().isEmpty()) { 175 if (first == -1) 176 first = c; 177 last = c; 178 } 179 c++; 180 } 181 if (first >= i) { 182 previousSignalButton.setEnabled(false); 183 } 184 if (last <= i) { 185 nextSignalButton.setEnabled(false); 186 } 187 } 118 188 119 189 mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey()); … … 130 200 MapillaryCache.Type.FULL_IMAGE); 131 201 imageCache.submit(this, false); 132 } 133 else if (image instanceof MapillaryImportedImage) { 202 } else if (image instanceof MapillaryImportedImage) { 134 203 this.nextButton.setEnabled(false); 135 204 this.previousButton.setEnabled(false); … … 314 383 add(top, BorderLayout.NORTH); 315 384 } 385 386 @Override 387 public void selectedImageChanged() { 388 setImage(MapillaryData.getInstance().getSelectedImage()); 389 updateImage(); 390 } 391 392 class NextSignalAction extends AbstractAction { 393 public NextSignalAction() { 394 putValue(NAME, tr("Next Signal")); 395 putValue(SHORT_DESCRIPTION, 396 tr("Jumps to the next picture that contains a siganl")); 397 } 398 399 @Override 400 public void actionPerformed(ActionEvent e) { 401 if (MapillaryToggleDialog.getInstance().getImage() != null) { 402 int i = MapillaryData 403 .getInstance() 404 .getImages() 405 .indexOf(MapillaryData.getInstance().getSelectedImage()); 406 for (int j = i + 1; j < MapillaryData.getInstance().getImages() 407 .size(); j++) { 408 MapillaryAbstractImage img = MapillaryData.getInstance() 409 .getImages().get(j); 410 if (img instanceof MapillaryImage) 411 if (!((MapillaryImage) img).getSignals().isEmpty()) { 412 MapillaryData.getInstance().setSelectedImage(img); 413 return; 414 } 415 } 416 } 417 } 418 } 419 420 class PreviousSignalAction extends AbstractAction { 421 public PreviousSignalAction() { 422 putValue(NAME, tr("Previous Signal")); 423 putValue(SHORT_DESCRIPTION, 424 tr("Jumps to the previous picture that contains a siganl")); 425 } 426 427 @Override 428 public void actionPerformed(ActionEvent e) { 429 if (MapillaryToggleDialog.getInstance().getImage() != null) { 430 int i = MapillaryData 431 .getInstance() 432 .getImages() 433 .indexOf(MapillaryData.getInstance().getSelectedImage()); 434 for (int j = i - 1; j >= 0; j--) { 435 MapillaryAbstractImage img = MapillaryData.getInstance() 436 .getImages().get(j); 437 if (img instanceof MapillaryImage) 438 if (!((MapillaryImage) img).getSignals().isEmpty()) { 439 MapillaryData.getInstance().setSelectedImage(img); 440 return; 441 } 442 } 443 } 444 } 445 } 316 446 }
Note:
See TracChangeset
for help on using the changeset viewer.