Ignore:
Timestamp:
2015-06-09T18:27:24+02:00 (9 years ago)
Author:
nokutu
Message:

Started with history dialog and code cleaned

Location:
applications/editors/josm/plugins/mapillary
Files:
2 added
19 edited

Legend:

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

    r31255 r31256  
    103103                return tempCa;
    104104        }
    105        
    106         @Override
    107         public boolean equals(Object object) {
    108                 if (object instanceof MapillaryAbstractImage)
    109                         return this.getLatLon().equalsEpsilon(((MapillaryAbstractImage) object).getLatLon());
    110                 return false;
    111         }
    112        
    113         @Override
    114         public int hashCode() {
    115                 return this.getLatLon().hashCode();
    116         }
    117105}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31255 r31256  
    11package org.openstreetmap.josm.plugins.mapillary;
    2 
    32
    43/**
     
    8887                return this.getSequence().previous(this);
    8988        }
     89
     90        @Override
     91        public boolean equals(Object object) {
     92                if (object instanceof MapillaryImage)
     93                        return this.key.equals(((MapillaryImage) object).getKey());
     94                return false;
     95        }
     96
     97        @Override
     98        public int hashCode() {
     99                return this.key.hashCode();
     100        }
    90101}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31254 r31256  
    99public class MapillaryImportedImage extends MapillaryAbstractImage {
    1010
    11         private File file;
    12        
     11        protected File file;
     12
    1313        public MapillaryImportedImage(double lat, double lon, double ca, File file) {
    1414                super(lat, lon, ca);
    1515                this.file = file;
    1616        }
    17        
     17
    1818        public BufferedImage getImage() throws IOException {
    1919                return ImageIO.read(file);
    2020        }
     21
     22        @Override
     23        public boolean equals(Object object) {
     24                if (object instanceof MapillaryImportedImage)
     25                        return this.file.equals(((MapillaryImportedImage) object).file);
     26                return false;
     27        }
     28
     29        @Override
     30        public int hashCode() {
     31                return this.file.hashCode();
     32        }
    2133}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31255 r31256  
    300300                LatLon selectedCoords = mapillaryData.getSelectedImage().getLatLon();
    301301                for (MapillaryAbstractImage imagePrev : mapillaryData.getImages()) {
    302                         if (!(imagePrev instanceof MapillaryImportedImage))
     302                        if (!(imagePrev instanceof MapillaryImage))
    303303                                continue;
    304304                        MapillaryImage image = (MapillaryImage) imagePrev;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31219 r31256  
    2222        }
    2323
    24 
    2524        /**
    2625         * Returns all MapillaryImages objects contained by this object.
     
    3130                return this.images;
    3231        }
    33        
    3432
    3533        public int getCreatedAt() {
     
    4543                this.images.add(image);
    4644        }
    47        
     45
    4846        public String getKey() {
    4947                return this.key;
     
    5654         */
    5755        public synchronized void add(List<MapillaryImage> images) {
    58                 for (MapillaryImage image : images) {
     56                for (MapillaryImage image : images)
    5957                        add(image);
    60                 }
    6158        }
    6259
     
    8077                        throw new IllegalArgumentException();
    8178                int i = images.indexOf(image);
    82                 if (i == images.size() - 1) {
     79                if (i == images.size() - 1)
    8380                        return null;
    84                 } else
     81                else
    8582                        return images.get(i + 1);
    8683        }
     
    9693                        throw new IllegalArgumentException();
    9794                int i = images.indexOf(image);
    98                 if (i == 0) {
     95                if (i == 0)
    9996                        return null;
    100                 } else
     97                else
    10198                        return images.get(i - 1);
    10299        }
     
    116113                                - this.images.indexOf(image2));
    117114        }
    118        
     115
    119116        @Override
    120117        public boolean equals(Object obj) {
     
    123120                return false;
    124121        }
    125        
     122
    126123        @Override
    127124        public int hashCode() {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31255 r31256  
    3030
    3131        public JFileChooser chooser;
     32
     33        private int noTagsPics = 0;
    3234
    3335        public MapillaryImportAction() {
     
    6971                                                        Main.error(ex);
    7072                                                }
    71                                         }
    72                                         else if (file.getPath().substring(file.getPath().length() - 4)
     73                                        } else if (file.getPath()
     74                                                        .substring(file.getPath().length() - 4)
    7375                                                        .equals(".png")) {
    7476                                                readPNG(file);
     
    9799                        double lonValue = 0;
    98100                        double caValue = 0;
    99                         if (lat.getValue() instanceof RationalNumber[])
     101                        if (lat != null && lat.getValue() instanceof RationalNumber[])
    100102                                latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(),
    101103                                                lat_ref.getValue().toString());
    102                         if (lon.getValue() instanceof RationalNumber[])
     104                        if (lon != null && lon.getValue() instanceof RationalNumber[])
    103105                                lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(),
    104106                                                lon_ref.getValue().toString());
    105                         if (ca.getValue() instanceof RationalNumber)
     107                        if (ca != null && ca.getValue() instanceof RationalNumber)
    106108                                caValue = ((RationalNumber) ca.getValue()).doubleValue();
    107109                        if (lat_ref.getValue().toString().equals("S"))
     
    114116                                                                file));
    115117                        } else {
    116                                 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
    117                                                 Main.map.mapView.getCenter());
    118                                 MapillaryData.getInstance().add(
    119                                                 new MapillaryImportedImage(pos.lat(), pos.lon(), 0,
    120                                                                 file));
     118                                readNoTags(file);
    121119                        }
    122120                }
    123121        }
    124        
    125         private void readPNG(File file) {
     122
     123        private void readNoTags(File file) {
     124                double HORIZONTAL_DISTANCE = 0.0001;
     125                double horDev;
     126                if (noTagsPics % 2 == 0)
     127                        horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;
     128                else
     129                        horDev = -HORIZONTAL_DISTANCE * (noTagsPics + 1) / 2;
    126130                LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
    127131                                Main.map.mapView.getCenter());
    128132                MapillaryData.getInstance().add(
    129                                 new MapillaryImportedImage(pos.lat(), pos.lon(), 0,
    130                                                 file));
     133                                new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
     134                noTagsPics++;
     135        }
     136
     137        private void readPNG(File file) {
     138                readNoTags(file);
    131139        }
    132140
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java

    r31252 r31256  
    11package org.openstreetmap.josm.plugins.mapillary.commands;
    22
     3import static org.openstreetmap.josm.tools.I18n.trn;
    34import java.util.ArrayList;
    45import java.util.List;
     
    4142                Main.map.repaint();
    4243        }
     44       
     45        public String toString() {
     46                return trn("Moved {0} node", "Moved {0} nodes", images.size(), images.size());
     47        }
    4348}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java

    r31252 r31256  
    11package org.openstreetmap.josm.plugins.mapillary.commands;
     2
     3import static org.openstreetmap.josm.tools.I18n.trn;
    24
    35import java.util.ArrayList;
     
    4042        }
    4143
     44        public String toString() {
     45                return trn("Turned {0} node", "Moved {0} nodes", images.size(), images.size());
     46        }
    4247}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java

    r31252 r31256  
    1616import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    1717import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
     18import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1819import org.xml.sax.SAXException;
    1920
     
    3738        String path;
    3839
    39         public MapillaryExportManager(List<MapillaryAbstractImage> images, String path) {
     40        public MapillaryExportManager(List<MapillaryAbstractImage> images,
     41                        String path) {
    4042                super(tr("Downloading") + "...", new PleaseWaitProgressMonitor(
    4143                                "Exporting Mapillary Images"), true);
     
    6466                        if (image instanceof MapillaryImage) {
    6567                                try {
    66                                         ex.execute(new MapillaryExportDownloadThread((MapillaryImage) image, queue,
    67                                                         queueImages));
     68                                        ex.execute(new MapillaryExportDownloadThread(
     69                                                        (MapillaryImage) image, queue, queueImages));
    6870                                } catch (Exception e) {
    6971                                        Main.error(e);
    7072                                }
     73                        } else if (image instanceof MapillaryImportedImage) {
    7174                                try {
    72                                         // If the queue is full, waits for it to have more space
    73                                         // available before executing anything else.
    74                                         while (ex.getQueue().remainingCapacity() == 0)
    75                                                 Thread.sleep(100);
    76                                 } catch (Exception e) {
     75                                        queue.put(((MapillaryImportedImage) image).getImage());
     76                                        queueImages.put((MapillaryImportedImage) image);
     77                                } catch (InterruptedException e) {
    7778                                        Main.error(e);
    7879                                }
    7980                        }
    80                         else {
    81                                 //TODO
     81                        try {
     82                                // If the queue is full, waits for it to have more space
     83                                // available before executing anything else.
     84                                while (ex.getQueue().remainingCapacity() == 0)
     85                                        Thread.sleep(100);
     86                        } catch (Exception e) {
     87                                Main.error(e);
    8288                        }
    8389                }
    8490                try {
    8591                        writer.join();
    86                 } catch (Exception e) {
     92                } catch (InterruptedException e) {
    8793                        Main.error(e);
    8894                }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java

    r31252 r31256  
    9191                                Main.error(e);
    9292                        } catch (ImageWriteException e) {
    93                                 // TODO Auto-generated catch block
    94                                 e.printStackTrace();
     93                                Main.error(e);
    9594                        } catch (ImageReadException e) {
    96                                 // TODO Auto-generated catch block
    97                                 e.printStackTrace();
     95                                Main.error(e);
    9896                        }
    9997
     
    103101                }
    104102        }
    105 
    106103}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31252 r31256  
    4949                        JsonObject jsonall = Json.createReader(br).readObject();
    5050
    51                         if (!jsonall.getBoolean("more") && !ex.isShutdown()) {
     51                        if (!jsonall.getBoolean("more") && !ex.isShutdown())
    5252                                ex.shutdown();
    53                         }
    5453                        JsonArray jsonseq = jsonall.getJsonArray("ss");
    5554                        // At the moment there is a bug with some sequences at Mapillay API,
     
    7271                                                Main.warn("Mapillary bug at " + url);
    7372                                                isSequenceWrong = true;
    74                                         } catch (Exception e) {
    75                                                 Main.error(e);
    7673                                        }
    7774                                }
    7875                                if (isSequenceWrong)
    7976                                        break;
    80                                 MapillarySequence sequence = new MapillarySequence(jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at").intValue());
    81                                 for (MapillaryAbstractImage mimage : MapillaryData.getInstance().getImages())
     77                                MapillarySequence sequence = new MapillarySequence(
     78                                                jsonobj.getString("key"), jsonobj.getJsonNumber(
     79                                                                "captured_at").intValue());
     80                                for (MapillaryAbstractImage mimage : MapillaryData
     81                                                .getInstance().getImages())
    8282                                        if (mimage instanceof MapillaryImage
    83                                                         && ((MapillaryImage) mimage).getSequence().getKey().equals(sequence.getKey()))
     83                                                        && ((MapillaryImage) mimage).getSequence().getKey()
     84                                                                        .equals(sequence.getKey()))
    8485                                                break;
    8586                                int first = -1;
     
    108109                                        img.setSequence(sequence);
    109110                                }
    110                                 MapillaryData.getInstance().addWithoutUpdate(new ArrayList<MapillaryAbstractImage>(finalImages));
     111                                MapillaryData.getInstance().addWithoutUpdate(
     112                                                new ArrayList<MapillaryAbstractImage>(finalImages));
    111113                                sequence.add(finalImages);
    112114                        }
    113115                } catch (IOException e) {
    114                         Main.error("Error reading the url " + url + " might be a Mapillary problem.");
     116                        Main.error("Error reading the url " + url
     117                                        + " might be a Mapillary problem.");
    115118                }
    116119        }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31252 r31256  
    2727        private final Bounds bounds;
    2828
    29         public MapillarySquareDownloadManagerThread(String urlImages, String urlSequences, Bounds bounds) {
     29        public MapillarySquareDownloadManagerThread(String urlImages,
     30                        String urlSequences, Bounds bounds) {
    3031                this.urlImages = urlImages;
    3132                this.urlSequences = urlSequences;
     
    3536        public void run() {
    3637                Main.map.statusLine.setHelpText("Downloading images from Mapillary");
    37                 downloadSequences();
     38                try {
     39                        downloadSequences();
     40                } catch (InterruptedException e) {
     41                        Main.error(e);
     42                }
    3843                if (MapillaryData.getInstance().getImages().size() > 0)
    3944                        Main.map.statusLine.setHelpText(tr("Total images: ")
     
    4348        }
    4449
    45         public void downloadSequences() {
     50        public void downloadSequences() throws InterruptedException {
    4651                ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25,
    4752                                TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
    4853                int page = 0;
    4954                while (!ex.isShutdown()) {
    50                         ex.execute(new MapillarySequenceDownloadThread(ex,
    51                                         urlSequences + "&page=" + page + "&limit=1", bounds));
    52                         try {
    53                                 while (ex.getQueue().remainingCapacity() == 0)
    54                                         Thread.sleep(100);
    55                         } catch (Exception e) {
    56                                 Main.error(e);
    57                         }
     55                        ex.execute(new MapillarySequenceDownloadThread(ex, urlSequences
     56                                        + "&page=" + page + "&limit=1", bounds));
     57                        while (ex.getQueue().remainingCapacity() == 0)
     58                                Thread.sleep(100);
    5859                        page++;
    5960                }
    60                 try {
    61                         while (!ex.awaitTermination(15, TimeUnit.SECONDS)) {
    62                         }
    63                 } catch (Exception e) {
    64                         Main.error(e);
    65                 }
     61                ex.awaitTermination(15, TimeUnit.SECONDS);
    6662                MapillaryData.getInstance().dataUpdated();
    6763        }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadThread.java

    r31252 r31256  
    22
    33import java.io.BufferedReader;
     4import java.io.IOException;
     5import java.net.MalformedURLException;
    46import java.net.URL;
    57import java.io.InputStreamReader;
     
    3537        public void run() {
    3638                try {
    37                         BufferedReader br;
    38                         br = new BufferedReader(new InputStreamReader(
     39                        BufferedReader br = new BufferedReader(new InputStreamReader(
    3940                                        new URL(url).openStream()));
    4041                        JsonObject jsonobj = Json.createReader(br).readObject();
    41                         if (!jsonobj.getBoolean("more")) {
     42                        if (!jsonobj.getBoolean("more"))
    4243                                ex.shutdownNow();
    43                         }
    4444                        JsonArray jsonarr = jsonobj.getJsonArray("ims");
    4545                        ArrayList<MapillaryAbstractImage> images = new ArrayList<>();
     
    5757                        }
    5858                        MapillaryData.getInstance().add(images);
    59                 } catch (Exception e) {
     59                } catch (MalformedURLException e) {
     60                        Main.error(e);
     61                } catch (IOException e) {
    6062                        Main.error(e);
    6163                }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31251 r31256  
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     4
    45import java.awt.Cursor;
    56import java.awt.event.ActionEvent;
     
    1415import javax.swing.SwingUtilities;
    1516
     17import org.openstreetmap.josm.Main;
     18
    1619import java.awt.Desktop;
    1720
    1821public class HyperlinkLabel extends JLabel implements ActionListener {
    1922
    20         /**
    21          * The normal text set by the user.
    22          */
    2323        private String text;
    24 
    2524        private URL url;
    2625
     
    4443        }
    4544
     45        /**
     46         * Sets a new URL, just pass the key of the image or null if there is none.
     47         *
     48         * @param key
     49         */
    4650        public void setURL(String key) {
     51                if (key == null) {
     52                        this.url = null;
     53                        return;
     54                }
    4755                try {
    4856                        this.url = new URL("http://www.mapillary.com/map/im/" + key);
    4957                } catch (MalformedURLException e) {
    50                         // TODO Auto-generated catch block
    51                         e.printStackTrace();
     58                        Main.error(e);
    5259                }
    5360        }
     
    5663         * Returns the text set by the user.
    5764         */
    58 
    5965        public String getNormalText() {
    6066                return text;
     
    6470         * Processes mouse events and responds to clicks.
    6571         */
    66 
    6772        protected void processMouseEvent(MouseEvent evt) {
    6873                super.processMouseEvent(evt);
     
    7681         * when the label is clicked.
    7782         */
    78 
    7983        public void addActionListener(ActionListener listener) {
    8084                listenerList.add(ActionListener.class, listener);
     
    8589         * notifications when the label is clicked.
    8690         */
    87 
    8891        public void removeActionListener(ActionListener listener) {
    8992                listenerList.remove(ActionListener.class, listener);
     
    9396         * Fires an ActionEvent to all interested listeners.
    9497         */
    95 
    9698        protected void fireActionPerformed(ActionEvent evt) {
    9799                Object[] listeners = listenerList.getListenerList();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r31252 r31256  
    2828
    2929        protected JOptionPane optionPane;
    30         // Button to export all downloaded images.
     30        /** Button to export all downloaded images. */
    3131        public JRadioButton all;
    32         // Button to export all images in the sequence of the selected
    33         // MapillaryImage.
     32        /**
     33         * Button to export all images in the sequence of the selected
     34         * MapillaryImage.
     35         */
    3436        public JRadioButton sequence;
    35         // Button to export all images belonging to the selected MapillaryImage
    36         // objects.
     37        /**
     38         * Button to export all images belonging to the selected MapillaryImage
     39         * objects.
     40         */
    3741        public JRadioButton selected;
    3842        public ButtonGroup group;
     
    7882                add(path);
    7983                add(choose);
    80 
    8184        }
    8285
     
    98101                }
    99102        }
    100 
    101103}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31249 r31256  
    4242         */
    4343        private Rectangle visibleRect = null;
     44
    4445        /**
    4546         * When a selection is done, the rectangle of the selection (in image
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31251 r31256  
    2323        @Override
    2424        public void addGui(PreferenceTabbedPane gui) {
    25                 // TODO Auto-generated method stub
    2625                JPanel panel = new JPanel();
    2726               
     
    4241        @Override
    4342        public boolean isExpert() {
    44                 // TODO Auto-generated method stub
    4543                return false;
    4644        }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java

    r31255 r31256  
    6565                mapillaryImageDisplay = new MapillaryImageDisplay();
    6666
    67                 // this.add(mapillaryImageDisplay);
    6867                blueButton.setForeground(Color.BLUE);
    6968                redButton.setForeground(Color.RED);
     
    8281
    8382        public static MapillaryToggleDialog getInstance() {
    84                 if (INSTANCE == null) {
     83                if (INSTANCE == null)
    8584                        INSTANCE = new MapillaryToggleDialog();
    86                 }
    8785                return INSTANCE;
    8886        }
     
    142140                                        Main.error(e);
    143141                                }
     142                                mapillaryImageDisplay.hyperlink.setURL(null);
    144143                        }
    145144                }
     
    281280                                }
    282281                        } catch (IOException e) {
    283                                 e.printStackTrace();
     282                                Main.error(e);
    284283                        }
    285284                }
     
    306305                                        FlowLayout.LEFT) : new GridLayout(1, buttons.size()));
    307306                        buttonsPanel.add(buttonRowPanel);
    308                         for (SideButton button : buttons) {
     307                        for (SideButton button : buttons)
    309308                                buttonRowPanel.add(button);
    310                         }
    311309                        if (reverse)
    312310                                top.add(buttonsPanel, BorderLayout.SOUTH);
Note: See TracChangeset for help on using the changeset viewer.