Changeset 31163 in osm for applications/editors/josm
- Timestamp:
- 2015-05-31T12:11:40+02:00 (10 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/MapillaryData.java
r31159 r31163 1 1 package org.openstreetmap.josm.plugins.mapillary; 2 2 3 import org.apache.commons.jcs.access.CacheAccess; 3 4 import org.openstreetmap.josm.Main; 4 5 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 6 import org.openstreetmap.josm.data.cache.CacheEntry; 7 import org.openstreetmap.josm.data.cache.CacheEntryAttributes; 8 import org.openstreetmap.josm.data.cache.ICachedLoaderListener; 9 import org.openstreetmap.josm.data.cache.JCSCacheManager; 10 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 11 12 import java.io.IOException; 5 13 import java.util.ArrayList; 14 import java.util.HashMap; 6 15 import java.util.List; 7 16 import java.util.concurrent.CopyOnWriteArrayList; … … 13 22 * 14 23 */ 15 public class MapillaryData {24 public class MapillaryData implements ICachedLoaderListener { 16 25 public volatile static MapillaryData INSTANCE; 17 26 … … 125 134 return; 126 135 if (getSelectedImage().getSequence() == null) 127 throw new IllegalStateException(); 128 if (getSelectedImage().next() != null) 129 setSelectedImage(getSelectedImage().next()); 136 return; 137 setSelectedImage(getSelectedImage().next()); 130 138 } 131 139 … … 139 147 if (getSelectedImage().getSequence() == null) 140 148 throw new IllegalStateException(); 141 if (getSelectedImage().previous() != null) 142 setSelectedImage(getSelectedImage().previous()); 149 setSelectedImage(getSelectedImage().previous()); 143 150 } 144 151 … … 163 170 MapillaryToggleDialog.getInstance().setImage(selectedImage); 164 171 MapillaryToggleDialog.getInstance().updateImage(); 172 CacheAccess<String, BufferedImageCacheEntry> prev = null; 173 try { 174 prev = JCSCacheManager.getCache("mapillary"); 175 } catch (IOException e) { 176 // TODO Auto-generated catch block 177 e.printStackTrace(); 178 } 179 if (image.next() != null) 180 new MapillaryCache(image.next().getKey(), 181 MapillaryCache.Type.FULL_IMAGE, prev, 200000, 200000, 182 new HashMap<String, String>()).submit(this, false); 183 if (image.previous() != null) 184 new MapillaryCache(image.previous().getKey(), 185 MapillaryCache.Type.FULL_IMAGE, prev, 200000, 200000, 186 new HashMap<String, String>()).submit(this, false); 165 187 } 166 188 if (Main.map != null) { … … 173 195 * click) 174 196 * 175 * @param image The MapillaryImage object to be added. 197 * @param image 198 * The MapillaryImage object to be added. 176 199 */ 177 200 public void addMultiSelectedImage(MapillaryImage image) { … … 183 206 return multiSelectedImages; 184 207 } 208 209 @Override 210 public void loadingFinished(CacheEntry data, 211 CacheEntryAttributes attributes, LoadResult result) { 212 // DO NOTHING 213 214 } 185 215 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryExportAction.java
r31158 r31163 25 25 26 26 public MapillaryExportAction() { 27 super(tr("Export images"), "icon24.png", tr("Export images."), 28 null,false);27 super(tr("Export images"), "icon24.png", tr("Export images."), null, 28 false); 29 29 } 30 30 … … 57 57 */ 58 58 public void export(List<MapillaryImage> images) { 59 Main.worker.submit(new MapillaryExportManager(tr("Downloading..."),60 images, dialog.chooser.getSelectedFile().toString()));59 new Thread(new MapillaryExportManager(tr("Downloading..."), images, 60 dialog.chooser.getSelectedFile().toString())).start(); 61 61 } 62 62 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31159 r31163 90 90 */ 91 91 public MapillaryImage next() { 92 if (this.getSequence() == null) 93 return null; 92 94 return this.getSequence().next(this); 93 95 } … … 100 102 */ 101 103 public MapillaryImage previous() { 104 if (this.getSequence() == null) 105 return null; 102 106 return this.getSequence().previous(this); 103 107 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31158 r31163 98 98 @Override 99 99 public void destroy() { 100 tgd.showDefault();100 MapillaryToggleDialog.getInstance().mapillaryImageDisplay.setImage(null); 101 101 INSTANCED = false; 102 102 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false); 103 103 MapillaryData.deleteInstance(); 104 Main.map.mapView.removeMouseListener(this); 105 MapView.removeEditLayerChangeListener(this); 106 Main.map.mapView.getEditLayer().data.removeDataSetListener(this); 104 107 super.destroy(); 105 108 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryToggleDialog.java
r31160 r31163 12 12 13 13 import org.apache.commons.jcs.access.CacheAccess; 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 15 16 import org.openstreetmap.josm.data.cache.CacheEntry; … … 20 21 import org.openstreetmap.josm.gui.SideButton; 21 22 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 22 import org.openstreetmap.josm.tools.ImageProvider;23 23 24 24 import javax.imageio.ImageIO; 25 import javax.swing.ImageIcon;26 import javax.swing.JLabel;27 25 import javax.swing.SwingUtilities; 28 26 import javax.swing.AbstractAction; … … 40 38 public static MapillaryToggleDialog INSTANCE; 41 39 42 public volatile JLabel active;43 40 public volatile MapillaryImage image; 44 41 … … 47 44 new previousPictureAction()); 48 45 46 public MapillaryImageDisplay mapillaryImageDisplay; 47 49 48 final JPanel buttons; 50 49 … … 52 51 super(tr("Mapillary image"), "mapillary", tr("Open Mapillary window"), 53 52 null, 200); 54 showDefault(); 53 mapillaryImageDisplay = new MapillaryImageDisplay(); 54 this.add(mapillaryImageDisplay); 55 55 buttons = new JPanel(); 56 56 buttons.setLayout(new FlowLayout(FlowLayout.CENTER)); … … 71 71 } 72 72 73 public void showDefault() { 74 if (active != null) 75 this.remove(active); 76 JLabel label = new JLabel("", new ImageProvider( 77 "mapillary_icon_960.png").setWidth(100).setHeight(100).get(), 78 JLabel.CENTER); 79 active = label; 80 this.add(active); 81 this.updateUI(); 82 } 83 73 /** 74 * Downloads the image of the selected MapillaryImage and sets in the 75 * MapillaryImageDisplay object. 76 */ 84 77 public synchronized void updateImage() { 85 78 if (!SwingUtilities.isEventDispatchThread()) { … … 92 85 } else { 93 86 if (MapillaryLayer.INSTANCED == false) { 94 showDefault();95 87 return; 96 88 } … … 99 91 try { 100 92 prev = JCSCacheManager.getCache("mapillary"); 101 HashMap<String, String> headers = new HashMap<>();102 93 MapillaryCache cache = new MapillaryCache(image.getKey(), 103 94 MapillaryCache.Type.FULL_IMAGE, prev, 200000, 104 200000, headers);105 cache.submit( MapillaryToggleDialog.getInstance(), false);95 200000, new HashMap<String, String>()); 96 cache.submit(this, false); 106 97 } catch (IOException e) { 107 98 // TODO Auto-generated catch block 108 99 e.printStackTrace(); 109 100 } 110 } else 111 showDefault(); 101 } 112 102 } 113 103 } … … 130 120 @Override 131 121 public void actionPerformed(ActionEvent e) { 132 if (MapillaryToggleDialog.getInstance().getImage() != null) 122 if (MapillaryToggleDialog.getInstance().getImage() != null) { 133 123 MapillaryData.getInstance().selectNext(); 124 Main.map.mapView.zoomTo(MapillaryData.getInstance() 125 .getSelectedImage().getLatLon()); 126 } 134 127 } 135 128 } … … 144 137 @Override 145 138 public void actionPerformed(ActionEvent e) { 146 if (MapillaryToggleDialog.getInstance().getImage() != null) 139 if (MapillaryToggleDialog.getInstance().getImage() != null) { 147 140 MapillaryData.getInstance().selectPrevious(); 141 Main.map.mapView.zoomTo(MapillaryData.getInstance() 142 .getSelectedImage().getLatLon()); 143 } 148 144 } 149 145 } … … 161 157 } else { 162 158 try { 159 /* 160 * BufferedImage img = ImageIO.read(new 161 * ByteArrayInputStream(data .getContent())); 162 * this.remove(active); JLabel label = new JLabel("", new 163 * ImageIcon(img), JLabel.CENTER); active = label; 164 * this.add(active); this.updateUI(); 165 */ 163 166 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data 164 167 .getContent())); 165 this.remove(active); 166 JLabel label = new JLabel("", new ImageIcon(img), JLabel.CENTER); 167 active = label; 168 this.add(active); 169 this.updateUI(); 168 mapillaryImageDisplay.setImage(img); 170 169 } catch (IOException e) { 171 170 // TODO Auto-generated catch block -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31158 r31163 1 1 package org.openstreetmap.josm.plugins.mapillary.downloads; 2 2 3 import org.openstreetmap.josm.Main; 3 4 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 4 5 import org.openstreetmap.josm.data.Bounds; … … 58 59 url2 += buildParameters(hash); 59 60 try { 60 new Thread(new MapillarySquareDownloadManagerThread(this.data,61 url1, url2, new Bounds(minLatLon, maxLatLon))) .start();61 Main.worker.submit(new MapillarySquareDownloadManagerThread(this.data, 62 url1, url2, new Bounds(minLatLon, maxLatLon))); 62 63 } catch (Exception e) { 63 64 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java
r31161 r31163 5 5 import java.io.IOException; 6 6 import java.net.MalformedURLException; 7 import java.net.URL;8 7 import java.util.HashMap; 9 8 import java.util.concurrent.ArrayBlockingQueue; 10 9 11 10 import javax.imageio.ImageIO; 12 import javax.imageio.ImageWriter;13 import javax.imageio.metadata.IIOMetadata;14 11 15 12 import org.apache.commons.jcs.access.CacheAccess; … … 23 20 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 24 21 25 //import com.sun.imageio.plugins.png.PNGMetadata; 22 26 23 27 24 public class MapillaryExportDownloadThread implements Runnable, … … 30 27 String url; 31 28 ArrayBlockingQueue<BufferedImage> queue; 29 ArrayBlockingQueue<MapillaryImage> queueImages; 30 32 31 ProgressMonitor monitor; 33 32 MapillaryImage image; 34 33 35 34 public MapillaryExportDownloadThread(MapillaryImage image, 36 ArrayBlockingQueue<BufferedImage> queue ) {35 ArrayBlockingQueue<BufferedImage> queue, ArrayBlockingQueue<MapillaryImage> queueImages) { 37 36 url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey() 38 37 + "/thumb-2048.jpg"; 39 38 this.queue = queue; 40 39 this.image = image; 40 this.queueImages = queueImages; 41 41 } 42 42 43 43 @Override 44 44 public void run() { 45 ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();46 //IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);47 45 try { 48 46 CacheAccess<String, BufferedImageCacheEntry> prev = JCSCacheManager … … 51 49 prev, 200000, 200000, new HashMap<String, String>()) 52 50 .submit(this, false); 53 queue.put(ImageIO.read(new URL(url)));54 51 } catch (MalformedURLException e) { 55 // TODO Auto-generated catch block56 e.printStackTrace();57 } catch (InterruptedException e) {58 52 // TODO Auto-generated catch block 59 53 e.printStackTrace(); … … 69 63 try { 70 64 queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent()))); 65 queueImages.put(image); 66 71 67 } catch (InterruptedException e) { 72 68 // TODO Auto-generated catch block -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java
r31158 r31163 17 17 18 18 ArrayBlockingQueue<BufferedImage> queue; 19 ArrayBlockingQueue<MapillaryImage> queueImages; 20 19 21 List<MapillaryImage> images; 20 22 String path; 21 23 22 public MapillaryExportManager(String title, List<MapillaryImage> images, String path) { 23 super(title, new PleaseWaitProgressMonitor("Exporting Mapillary Images"), true); 24 public MapillaryExportManager(String title, List<MapillaryImage> images, 25 String path) { 26 super(title, 27 new PleaseWaitProgressMonitor("Exporting Mapillary Images"), 28 true); 24 29 queue = new ArrayBlockingQueue<>(10); 30 queueImages = new ArrayBlockingQueue<>(10); 31 25 32 this.images = images; 26 33 this.path = path; … … 36 43 protected void realRun() throws SAXException, IOException, 37 44 OsmTransferException { 38 Thread writer = new Thread(new MapillaryExportWriterThread(path, queue, images.size(), this.getProgressMonitor())); 45 Thread writer = new Thread(new MapillaryExportWriterThread(path, queue, queueImages, 46 images.size(), this.getProgressMonitor())); 39 47 writer.start(); 40 48 ThreadPoolExecutor ex = new ThreadPoolExecutor(20, 35, 25, 41 49 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); 42 50 for (MapillaryImage image : images) { 43 ex.execute(new MapillaryExportDownloadThread(image, queue)); 51 try { 52 ex.execute(new MapillaryExportDownloadThread(image, queue, queueImages)); 53 } catch (Exception e) { 54 System.out.println("Exception"); 55 } 44 56 try { 45 57 while (ex.getQueue().remainingCapacity() == 0) … … 51 63 try { 52 64 writer.join(); 53 } 54 catch(Exception e){ 65 } catch (Exception e) { 55 66 } 56 67 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java
r31161 r31163 10 10 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 11 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 12 13 13 14 … … 16 17 private String path; 17 18 private ArrayBlockingQueue<BufferedImage> queue; 19 private ArrayBlockingQueue<MapillaryImage> queueImages; 18 20 private int amount; 19 21 private ProgressMonitor monitor; 20 22 21 23 public MapillaryExportWriterThread(String path, 22 ArrayBlockingQueue<BufferedImage> queue, int amount, ProgressMonitor monitor) {24 ArrayBlockingQueue<BufferedImage> queue,ArrayBlockingQueue<MapillaryImage> queueImages, int amount, ProgressMonitor monitor) { 23 25 this.path = path; 24 26 this.queue = queue; 27 this.queueImages = queueImages; 25 28 this.amount = amount; 26 29 this.monitor = monitor; … … 30 33 public void run() { 31 34 monitor.setCustomText("Downloaded 0/" + amount); 32 File outputfile ;35 File outputfile = null; 33 36 BufferedImage img; 37 MapillaryImage mimg = null; 38 String finalPath = ""; 34 39 for (int i = 0; i < amount; i++) { 35 40 try { 36 41 img = queue.take(); 37 outputfile = new File(path + "/" + i + ".jpg"); 38 ImageIO.write(img, "jpg", outputfile); 42 mimg = queueImages.take(); 43 finalPath = path + "/" + mimg.getKey() + ".jpeg"; 44 outputfile = new File(finalPath); 45 ImageIO.write(img, "jpeg", outputfile); 39 46 } catch (InterruptedException e1) { 40 47 // TODO Auto-generated catch block … … 44 51 e.printStackTrace(); 45 52 } 53 46 54 monitor.worked(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX / amount); 47 55 monitor.setCustomText("Downloaded " + (i + 1) + "/" + amount);
Note:
See TracChangeset
for help on using the changeset viewer.