Ignore:
Timestamp:
2015-05-29T14:41:55+02:00 (9 years ago)
Author:
nokutu
Message:

Solve upload errors

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

Legend:

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

    r31158 r31159  
    1515public class MapillaryData {
    1616        public volatile static MapillaryData INSTANCE;
    17        
     17
    1818        private final List<MapillaryImage> images;
    1919        private MapillaryImage selectedImage = null;
    2020        private List<MapillaryImage> multiSelectedImages;
    21 
    2221
    2322        public MapillaryData() {
     
    169168                }
    170169        }
    171        
     170
     171        /**
     172         * Adds a MapillaryImage object to the list of selected images, (when ctrl +
     173         * click)
     174         *
     175         * @param image The MapillaryImage object to be added.
     176         */
    172177        public void addMultiSelectedImage(MapillaryImage image) {
    173178                this.multiSelectedImages.add(image);
    174179                Main.map.mapView.repaint();
    175180        }
    176        
    177         public List<MapillaryImage> getMultiSelectedImages(){
     181
     182        public List<MapillaryImage> getMultiSelectedImages() {
    178183                return multiSelectedImages;
    179184        }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31158 r31159  
    11package org.openstreetmap.josm.plugins.mapillary;
    2 
    32
    43import org.openstreetmap.josm.data.coor.LatLon;
     
    6160        }
    6261
    63 
    6462        /**
    6563         * Sets the MapillarySequence object which contains the MapillaryImage.
     
    7169                this.sequence = sequence;
    7270        }
    73 
    7471
    7572        public MapillarySequence getSequence() {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31041 r31159  
    11package org.openstreetmap.josm.plugins.mapillary;
    22
     3import javax.swing.ImageIcon;
     4import javax.swing.JMenuItem;
     5
     6import org.openstreetmap.josm.gui.MainMenu;
     7import org.openstreetmap.josm.Main;
    38import org.openstreetmap.josm.gui.MapFrame;
    49import org.openstreetmap.josm.plugins.Plugin;
    510import org.openstreetmap.josm.plugins.PluginInformation;
     11import org.openstreetmap.josm.tools.ImageProvider;
    612
    713/**
    814 * This is the main class for the mapillary plugin.
     15 *
     16 * @author nokutu
    917 *
    1018 */
    11 public class MapillaryPlugin extends Plugin{
     19public class MapillaryPlugin extends Plugin {
    1220
    13     public MapillaryPlugin(PluginInformation info) {
    14         super(info);
    15     }
     21        public static final ImageIcon ICON = new ImageProvider("icon24.png").get();
     22        public static final ImageIcon ICON16 = new ImageProvider("icon16.png").get();
     23        public static final ImageIcon ICON16SELECTED = new ImageProvider("icon16selected.png").get();
     24        public static final int ICON_SIZE = 24;
     25       
     26        MapillaryDownloadAction downloadAction;
     27        MapillaryExportAction exportAction;
     28       
     29        public static JMenuItem DOWNLOAD_MENU;
     30        public static JMenuItem EXPORT_MENU;
    1631
    17     /**
    18      * Called when the JOSM map frame is created or destroyed.
    19      */
    20     @Override
    21     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    22         if (oldFrame == null && newFrame != null) { // map frame added
     32        public MapillaryPlugin(PluginInformation info) {
     33                super(info);
     34                downloadAction = new MapillaryDownloadAction();
     35                exportAction = new MapillaryExportAction();
    2336
    24         }
    25     }
     37                DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, downloadAction, false, 0);
     38                EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, false, 14);
     39                EXPORT_MENU.setEnabled(false);
     40
     41        }
     42
     43        /**
     44         * Called when the JOSM map frame is created or destroyed.
     45         */
     46        @Override
     47        public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     48                if (oldFrame == null && newFrame != null) { // map frame added
     49                        MapillaryToggleDialog.deleteInstance ();
     50                }
     51        }
     52       
     53        public static void setMenuEnabled(JMenuItem menu, boolean value) {
     54                menu.setEnabled(value);
     55        }
    2656}
     57
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryToggleDialog.java

    r31158 r31159  
    3535 *
    3636 */
    37 public class MapillaryToggleDialog extends ToggleDialog implements ICachedLoaderListener{
     37public class MapillaryToggleDialog extends ToggleDialog implements
     38                ICachedLoaderListener {
    3839
    3940        public static MapillaryToggleDialog INSTANCE;
     
    6566                return INSTANCE;
    6667        }
    67        
     68
    6869        public static void deleteInstance() {
    6970                INSTANCE = null;
     
    99100                                        prev = JCSCacheManager.getCache("mapillary");
    100101                                        HashMap<String, String> headers = new HashMap<>();
    101                                         MapillaryCache cache = new MapillaryCache(image.getKey(), MapillaryCache.Type.FULL_IMAGE, prev, 200000, 200000, headers);
     102                                        MapillaryCache cache = new MapillaryCache(image.getKey(),
     103                                                        MapillaryCache.Type.FULL_IMAGE, prev, 200000,
     104                                                        200000, headers);
    102105                                        cache.submit(MapillaryToggleDialog.getInstance(), false);
    103106                                } catch (IOException e) {
    104107                                        // TODO Auto-generated catch block
    105108                                        e.printStackTrace();
    106                                 } catch (Exception e) {
    107                                         System.out.println("Hello");
    108109                                }
    109                                 /*if (image.getImage() != null) {
    110                                         showImage();
    111                                 } else if (image.getThumbnail() != null) {
    112                                         showThumbnail();
    113                                 }*/
    114110                        } else
    115111                                showDefault();
     
    156152        public void loadingFinished(CacheEntry data,
    157153                        CacheEntryAttributes attributes, LoadResult result) {
    158                 System.out.println("Listener");
    159                 try {
    160                         BufferedImage img = ImageIO.read(new ByteArrayInputStream(data.getContent()));
    161                         this.remove(active);
    162                         JLabel label = new JLabel("", new ImageIcon(img), JLabel.CENTER);
    163                         active = label;
    164                         this.add(active);
    165                         this.updateUI();
    166                 } catch (IOException e) {
    167                         // TODO Auto-generated catch block
    168                         e.printStackTrace();
     154                if (!SwingUtilities.isEventDispatchThread()) {
     155                        SwingUtilities.invokeLater(new Runnable() {
     156                                @Override
     157                                public void run() {
     158                                        updateImage();
     159                                }
     160                        });
     161                } else {
     162                        try {
     163                                BufferedImage img = ImageIO.read(new ByteArrayInputStream(data
     164                                                .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();
     170                        } catch (IOException e) {
     171                                // TODO Auto-generated catch block
     172                                e.printStackTrace();
     173                        }
    169174                }
    170                        
    171                
    172                
     175
    173176        }
    174177}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java

    r31158 r31159  
    5555                return new BufferedImageCacheEntry(content);
    5656        }
    57        
     57
    5858        @Override
    59     protected boolean isObjectLoadable() {
     59        protected boolean isObjectLoadable() {
    6060                if (cacheData == null)
    6161                        return false;
    62         byte[] content = cacheData.getContent();
    63         return content != null && content.length > 0;
    64     }
     62                byte[] content = cacheData.getContent();
     63                return content != null && content.length > 0;
     64        }
    6565
    66         //@Override
     66        // @Override
    6767        protected boolean handleNotFound() {
    6868                // TODO Auto-generated method stub
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java

    r31158 r31159  
    22
    33import java.awt.image.BufferedImage;
     4import java.io.ByteArrayInputStream;
    45import java.io.IOException;
    56import java.net.MalformedURLException;
    67import java.net.URL;
     8import java.util.HashMap;
    79import java.util.concurrent.ArrayBlockingQueue;
    810
    911import javax.imageio.ImageIO;
    1012
     13import org.apache.commons.jcs.access.CacheAccess;
     14import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
     15import org.openstreetmap.josm.data.cache.CacheEntry;
     16import org.openstreetmap.josm.data.cache.CacheEntryAttributes;
     17import org.openstreetmap.josm.data.cache.ICachedLoaderListener;
     18import org.openstreetmap.josm.data.cache.JCSCacheManager;
    1119import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1220import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
     21import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache;
    1322
    14 public class MapillaryExportDownloadThread implements Runnable {
     23public class MapillaryExportDownloadThread implements Runnable,
     24                ICachedLoaderListener {
    1525
    1626        String url;
    1727        ArrayBlockingQueue<BufferedImage> queue;
    1828        ProgressMonitor monitor;
     29        MapillaryImage image;
    1930
    20         public MapillaryExportDownloadThread(MapillaryImage image, ArrayBlockingQueue<BufferedImage> queue) {
     31        public MapillaryExportDownloadThread(MapillaryImage image,
     32                        ArrayBlockingQueue<BufferedImage> queue) {
    2133                url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey()
    2234                                + "/thumb-2048.jpg";
    2335                this.queue = queue;
     36                this.image = image;
    2437        }
    2538
     
    2740        public void run() {
    2841                try {
     42                        CacheAccess<String, BufferedImageCacheEntry> prev = JCSCacheManager
     43                                        .getCache("mapillary");
     44                        new MapillaryCache(image.getKey(), MapillaryCache.Type.FULL_IMAGE,
     45                                        prev, 200000, 200000, new HashMap<String, String>())
     46                                        .submit(this, false);
    2947                        queue.put(ImageIO.read(new URL(url)));
    3048                } catch (MalformedURLException e) {
     
    4058        }
    4159
     60        @Override
     61        public void loadingFinished(CacheEntry data,
     62                        CacheEntryAttributes attributes, LoadResult result) {
     63                try {
     64                        queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent())));
     65                } catch (InterruptedException e) {
     66                        // TODO Auto-generated catch block
     67                        e.printStackTrace();
     68                } catch (IOException e) {
     69                        // TODO Auto-generated catch block
     70                        e.printStackTrace();
     71                }
     72
     73        }
     74
    4275}
Note: See TracChangeset for help on using the changeset viewer.