Ignore:
Timestamp:
2015-07-02T13:57:34+02:00 (9 years ago)
Author:
nokutu
Message:

Improved exportation and code cleaned

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

Legend:

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

    r31328 r31331  
    2020 */
    2121public abstract class MapillaryAbstractImage {
    22    
     22
    2323    public static Lock lock = new ReentrantLock();
    2424
     
    3030    public final double ca;
    3131    public boolean isModified = false;
    32     /** Temporal position of the picture until it is uplaoded */
     32    /** Temporal position of the picture until it is uploaded */
    3333    public LatLon tempLatLon;
    3434    /**
     
    3737     */
    3838    public LatLon movingLatLon;
    39     /** Temporal direction of the picture until it is uplaoded */
     39    /** Temporal direction of the picture until it is uploaded */
    4040    public double tempCa;
    4141    /**
     
    7575    }
    7676
     77    /**
     78     * Returns whether the image is visible on the map or not.
     79     *
     80     * @return
     81     */
    7782    public boolean isVisible() {
    7883        return visible;
     
    8489
    8590    /**
    86      * Returns the last fixed coorditanes of the object.
     91     * Returns the last fixed coordinates of the object.
    8792     *
    8893     * @return
     
    95100     * Moves the image temporally to another position
    96101     *
    97      * @param pos
     102     * @param x
     103     * @param y
    98104     */
    99105    public void move(double x, double y) {
     
    182188    }
    183189
     190    /**
     191     * Parses a string with a given format and returns the Epoch time.
     192     *
     193     * @param date
     194     * @param format
     195     * @return
     196     */
    184197    public long getEpoch(String date, String format) {
    185198
     
    194207    }
    195208
     209    /**
     210     * Returns current time in Epoch format
     211     *
     212     * @return
     213     */
    196214    private long currentTime() {
    197215        Calendar cal = Calendar.getInstance();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31328 r31331  
    2525    private final List<MapillaryAbstractImage> images;
    2626    private MapillaryAbstractImage selectedImage;
    27     private MapillaryAbstractImage hoveredImage;
     27    /** The image under the cursor */
     28    private MapillaryAbstractImage highlightedImage;
    2829    private final List<MapillaryAbstractImage> multiSelectedImages;
    2930
     
    9798     */
    9899    public void setHoveredImage(MapillaryAbstractImage image) {
    99         hoveredImage = image;
     100        highlightedImage = image;
    100101    }
    101102
     
    106107     */
    107108    public MapillaryAbstractImage getHoveredImage() {
    108         return hoveredImage;
     109        return highlightedImage;
    109110    }
    110111
     
    237238            if (image instanceof MapillaryImage) {
    238239                MapillaryImage mapillaryImage = (MapillaryImage) image;
     240                // Donwloadins thumbnails of surrounding pictures.
    239241                if (mapillaryImage.next() != null) {
    240242                    new MapillaryCache(mapillaryImage.next().getKey(),
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31328 r31331  
    6464            "mapillary.sequence-max-jump-distance", 100);
    6565
     66    private boolean TEMP_MANUAL = false;
     67
    6668    public static MapillaryLayer INSTANCE;
    6769    public static CacheAccess<String, BufferedImageCacheEntry> CACHE;
     
    8284    private volatile TexturePaint hatched;
    8385
    84     public MapillaryLayer() {
     86    private MapillaryLayer() {
    8587        super(tr("Mapillary Images"));
    8688        bounds = new ArrayList<>();
     
    9294     */
    9395    private void init() {
    94         MapillaryLayer.INSTANCE = this;
    95         startMouseAdapter();
     96        mouseAdapter = new MapillaryMouseAdapter();
    9697        try {
    9798            CACHE = JCSCacheManager.getCache("Mapillary");
     
    115116    }
    116117
    117     private void startMouseAdapter() {
    118         mouseAdapter = new MapillaryMouseAdapter();
    119     }
    120 
    121118    public synchronized static MapillaryLayer getInstance() {
    122119        if (MapillaryLayer.INSTANCE == null)
     
    130127     */
    131128    public void download() {
    132         checkBigAreas();
    133         if (Main.pref.getBoolean("mapillary.download-manually"))
     129        checkAreaTooBig();
     130        if (Main.pref.getBoolean("mapillary.download-manually") || TEMP_MANUAL)
    134131            return;
    135132        for (Bounds bounds : Main.map.mapView.getEditLayer().data
     
    149146     * shown and you will have to download areas manually.
    150147     */
    151     private void checkBigAreas() {
     148    private void checkAreaTooBig() {
    152149        double area = 0;
    153150        for (Bounds bounds : Main.map.mapView.getEditLayer().data
     
    156153        }
    157154        if (area > MapillaryDownloadViewAction.MAX_AREA) {
    158             Main.pref.put("mapillary.download-manually", true);
     155            TEMP_MANUAL = true;
     156            MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU,
     157                    true);
    159158            JOptionPane
    160159                    .showMessageDialog(
    161160                            Main.parent,
    162                             tr("The downloaded OSM area is too big. Download mode has been change to manual. You can change this back to automatic in preferences settings."));
     161                            tr("The downloaded OSM area is too big. Download mode has been changed to manual until the layer is restarted."));
    163162        }
    164163    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java

    r31328 r31331  
    1616
    1717/**
    18  * Action that triggers the plugin.
     18 * Action that triggers the plugin. If in automatic mode, it will automatically
     19 * download the images in the areas where there is OSM data.
    1920 *
    2021 * @author nokutu
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java

    r31321 r31331  
    1515import org.openstreetmap.josm.tools.Shortcut;
    1616
     17/**
     18 * If in manual mode, downloads all the images in the current view.
     19 *
     20 * @author nokutu
     21 *
     22 */
    1723public class MapillaryDownloadViewAction extends JosmAction {
    1824
     
    3339    @Override
    3440    public void actionPerformed(ActionEvent arg0) {
    35         MapillaryLayer.getInstance();
    3641        MapillaryLayer.getInstance().bounds.add(Main.map.mapView
    3742                .getRealBounds());
     
    4146        } else {
    4247            JOptionPane.showMessageDialog(Main.parent,
    43                     tr("This area too big to be downloaded"));
     48                    tr("This area is too big to be downloaded"));
    4449        }
    4550    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java

    r31313 r31331  
    2525
    2626/**
    27  * Action that launches a MapillaryExportDialog.
     27 * Action that launches a MapillaryExportDialog and lets you export the images.
    2828 *
    2929 * @author nokutu
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java

    r31317 r31331  
    1010
    1111/**
    12  * Command created when a image's direction is changed.
     12 * Command created when an image's direction is changed.
    1313 *
    1414 * @author nokutu
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java

    r31280 r31331  
    66
    77/**
    8  * History record system in order to let you undo commands
     8 * History record system in order to let the user undo and redo commands
    99 *
    1010 * @author nokutu
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31328 r31331  
    1111
    1212/**
    13  * Class that concentrates all the ways of downloading of the plugin.
     13 * Class that concentrates all the ways of downloading of the plugin. All the
     14 * download petitions will be managed one by one.
    1415 *
    1516 * @author nokutu
     
    6263    }
    6364
     65    /**
     66     * Gets the images within the given bounds.
     67     *
     68     * @param bounds
     69     */
    6470    public void getImages(Bounds bounds) {
    6571        getImages(bounds.getMin(), bounds.getMax());
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java

    r31278 r31331  
    1919/**
    2020 * This is the thread that downloads one of the images that are going to be
    21  * exported and writes them in a {@link ArrayBlockQueue}.
     21 * exported and writes them in a {@link ArrayBlockingQueue}.
    2222 *
    2323 * @author nokutu
    2424 * @see MapillaryExportManager
    2525 */
    26 public class MapillaryExportDownloadThread implements Runnable,
     26public class MapillaryExportDownloadThread extends Thread implements
    2727        ICachedLoaderListener {
    2828
     
    4848        new MapillaryCache(image.getKey(), MapillaryCache.Type.FULL_IMAGE)
    4949                .submit(this, false);
    50 
    5150    }
    5251
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java

    r31278 r31331  
    2121/**
    2222 * Export main thread. Exportation works by creating a
    23  * {@link MapillaryWriterThread} and several
     23 * {@link MapillaryExportWriterThread} and several
    2424 * {@link MapillaryExportDownloadThread}. The second ones download every single
    2525 * image that is going to be exported and stores them in an
     
    3838    List<MapillaryAbstractImage> images;
    3939    String path;
     40   
     41    private Thread writer;
     42    private ThreadPoolExecutor ex;
    4043
    4144    public MapillaryExportManager(List<MapillaryAbstractImage> images,
     
    7275    @Override
    7376    protected void cancel() {
    74         // TODO Auto-generated method stub
     77        writer.interrupt();
     78        ex.shutdown();
    7579    }
    7680
     
    7983            OsmTransferException {
    8084        // Starts a writer thread in order to write the pictures on the disk.
    81         Thread writer = new Thread(new MapillaryExportWriterThread(path, queue,
    82                 queueImages, amount, this.getProgressMonitor()));
     85        writer = new MapillaryExportWriterThread(path, queue,
     86                queueImages, amount, this.getProgressMonitor());
    8387        writer.start();
    8488        if (path == null) {
     
    9094            return;
    9195        }
    92         ThreadPoolExecutor ex = new ThreadPoolExecutor(20, 35, 25,
     96        ex = new ThreadPoolExecutor(20, 35, 25,
    9397                TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
    9498        for (MapillaryAbstractImage image : images) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java

    r31328 r31331  
    3232 * @see MapillaryExportManager
    3333 */
    34 public class MapillaryExportWriterThread implements Runnable {
     34public class MapillaryExportWriterThread extends Thread {
    3535
    3636    private final String path;
     
    103103                os.close();
    104104            } catch (InterruptedException e) {
    105                 Main.error(e);
     105                Main.info("Mapillary export cancelled");
     106                return;
    106107            } catch (IOException e) {
    107108                Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java

    r31328 r31331  
    2222 *
    2323 * @author nokutu
    24  * @see MapillarySqueareDownloadManagerThread
     24 * @see MapillarySquareDownloadManagerThread
    2525 */
    26 public class MapillaryImageInfoDownloaderThread implements Runnable {
     26public class MapillaryImageInfoDownloaderThread extends Thread {
    2727    private final String url;
    2828    private final ExecutorService ex;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31328 r31331  
    2727 *
    2828 * @author nokutu
    29  * @see MapillarySquareDownloadManagarThread
     29 * @see MapillarySquareDownloadManagerThread
    3030 */
    31 public class MapillarySequenceDownloadThread implements Runnable {
     31public class MapillarySequenceDownloadThread extends Thread {
    3232
    3333    private final String url;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySignDownloaderThread.java

    r31328 r31331  
    1717import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1818
    19 public class MapillarySignDownloaderThread implements Runnable {
     19public class MapillarySignDownloaderThread extends Thread {
    2020
    2121    private final String url;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31328 r31331  
    2121 * @see MapillaryDownloader
    2222 */
    23 public class MapillarySquareDownloadManagerThread implements Runnable {
     23public class MapillarySquareDownloadManagerThread extends Thread {
    2424
    2525    private final String urlImages;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r31278 r31331  
    77import java.awt.event.ActionListener;
    88
     9import javax.swing.AbstractAction;
    910import javax.swing.BoxLayout;
    1011import javax.swing.ButtonGroup;
     
    1617import javax.swing.JRadioButton;
    1718
     19import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    1820import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    1921import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
     22import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2023
    2124/**
     
    4952    public MapillaryExportDialog() {
    5053        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    51 
     54       
     55        RewriteButtonAction action = new RewriteButtonAction(this);
    5256        group = new ButtonGroup();
    53         all = new JRadioButton(tr("Export all images"));
    54         sequence = new JRadioButton(tr("Export selected sequence"));
    55         selected = new JRadioButton(tr("Export selected images"));
    56         rewrite = new JRadioButton(tr("Rewrite imported images"));
     57        all = new JRadioButton(action);
     58        all.setText(tr("Export all images"));
     59        sequence = new JRadioButton(action);
     60        sequence.setText(tr("Export selected sequence"));
     61        selected = new JRadioButton(action);
     62        selected.setText(tr("Export selected images"));
     63        rewrite = new JRadioButton(action);
     64        rewrite.setText(tr("Rewrite imported images"));
    5765        group.add(all);
    5866        group.add(sequence);
     
    6876            selected.setEnabled(false);
    6977        }
     78        rewrite.setEnabled(false);
     79        for (MapillaryAbstractImage img : MapillaryData.getInstance().getImages())
     80            if (img instanceof MapillaryImportedImage)
     81                rewrite.setEnabled(true);
     82       
    7083        path = new JLabel(tr("Select a folder"));
    7184        choose = new JButton(tr("Explore"));
     
    105118        }
    106119    }
     120   
     121    public class RewriteButtonAction extends AbstractAction {
     122
     123        private String lastPath;
     124        private MapillaryExportDialog dlg;
     125       
     126        public RewriteButtonAction(MapillaryExportDialog dlg) {
     127            this.dlg = dlg;
     128        }
     129       
     130        @Override
     131        public void actionPerformed(ActionEvent arg0) {
     132           choose.setEnabled(!rewrite.isSelected());
     133           if (rewrite.isSelected()) {
     134               lastPath = dlg.path.getText();
     135               dlg.path.setText(" ");
     136           }
     137           else if (lastPath != null){
     138               dlg.path.setText(lastPath);
     139           }
     140           
     141        }
     142       
     143    }
    107144}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r31284 r31331  
    3030import javax.swing.tree.DefaultMutableTreeNode;
    3131
     32/**
     33 * Toggle dialog that shows you the latest commands done and allows the user to
     34 * revert them.
     35 *
     36 * @see MapillaryRecord
     37 * @author nokutu
     38 *
     39 */
    3240public class MapillaryHistoryDialog extends ToggleDialog implements
    3341        MapillaryRecordListener {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31278 r31331  
    2828 *
    2929 * @author Jorge
    30  * @see ImageDisplay
     30 * @see MapillaryImageDisplay
    3131 * @see MapillaryToggleDialog
    3232 */
Note: See TracChangeset for help on using the changeset viewer.