Changeset 9660 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-01-28T00:23:22+01:00 (9 years ago)
Author:
Don-vip
Message:

GeoImageLayer: add unit test, fix sonar issues, add javadoc

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r9078 r9660  
    1111import java.awt.FlowLayout;
    1212import java.awt.Graphics;
     13import java.awt.GraphicsEnvironment;
    1314import java.awt.GridBagLayout;
    1415import java.awt.GridLayout;
     
    382383        this.setVisible(true);
    383384        titleBar.setVisible(false);
    384         detachedDialog = new DetachedDialog();
    385         detachedDialog.setVisible(true);
     385        if (!GraphicsEnvironment.isHeadless()) {
     386            detachedDialog = new DetachedDialog();
     387            detachedDialog.setVisible(true);
     388        }
    386389        setIsShowing(true);
    387390        setIsDocked(false);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r9543 r9660  
    99import java.awt.Dimension;
    1010import java.awt.FlowLayout;
     11import java.awt.GraphicsEnvironment;
    1112import java.awt.GridBagConstraints;
    1213import java.awt.GridBagLayout;
     
    750751        outerPanel.add(statusBar, BorderLayout.PAGE_END);
    751752
    752         syncDialog = new ExtendedDialog(
    753                 Main.parent,
    754                 tr("Correlate images with GPX track"),
    755                 new String[] {tr("Correlate"), tr("Cancel")},
    756                 false
    757         );
    758         syncDialog.setContent(panelTf, false);
    759         syncDialog.setButtonIcons(new String[] {"ok", "cancel"});
    760         syncDialog.setupDialog();
    761         outerPanel.add(syncDialog.getContentPane(), BorderLayout.PAGE_START);
    762         syncDialog.setContentPane(outerPanel);
    763         syncDialog.pack();
    764         syncDialog.addWindowListener(new SyncDialogWindowListener());
    765         syncDialog.showDialog();
     753        if (!GraphicsEnvironment.isHeadless()) {
     754            syncDialog = new ExtendedDialog(
     755                    Main.parent,
     756                    tr("Correlate images with GPX track"),
     757                    new String[] {tr("Correlate"), tr("Cancel")},
     758                    false
     759            );
     760            syncDialog.setContent(panelTf, false);
     761            syncDialog.setButtonIcons(new String[] {"ok", "cancel"});
     762            syncDialog.setupDialog();
     763            outerPanel.add(syncDialog.getContentPane(), BorderLayout.PAGE_START);
     764            syncDialog.setContentPane(outerPanel);
     765            syncDialog.pack();
     766            syncDialog.addWindowListener(new SyncDialogWindowListener());
     767            syncDialog.showDialog();
     768        }
    766769    }
    767770
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r9296 r9660  
    7171public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {
    7272
     73    private static List<Action> menuAdditions = new LinkedList<>();
     74
     75    private static volatile List<MapMode> supportedMapModes;
     76
    7377    List<ImageEntry> data;
    7478    GpxLayer gpxLayer;
     
    8892    boolean updateOffscreenBuffer = true;
    8993
    90     /** Loads a set of images, while displaying a dialog that indicates what the plugin is currently doing.
     94    private MouseAdapter mouseAdapter;
     95    private MapModeChangeListener mapModeListener;
     96
     97    /**
     98     * Constructs a new {@code GeoImageLayer}.
     99     * @param data The list of images to display
     100     * @param gpxLayer The associated GPX layer
     101     */
     102    public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer) {
     103        this(data, gpxLayer, null, false);
     104    }
     105
     106    /**
     107     * Constructs a new {@code GeoImageLayer}.
     108     * @param data The list of images to display
     109     * @param gpxLayer The associated GPX layer
     110     * @param name Layer name
     111     * @since 6392
     112     */
     113    public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name) {
     114        this(data, gpxLayer, name, false);
     115    }
     116
     117    /**
     118     * Constructs a new {@code GeoImageLayer}.
     119     * @param data The list of images to display
     120     * @param gpxLayer The associated GPX layer
     121     * @param useThumbs Thumbnail display flag
     122     * @since 6392
     123     */
     124    public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, boolean useThumbs) {
     125        this(data, gpxLayer, null, useThumbs);
     126    }
     127
     128    /**
     129     * Constructs a new {@code GeoImageLayer}.
     130     * @param data The list of images to display
     131     * @param gpxLayer The associated GPX layer
     132     * @param name Layer name
     133     * @param useThumbs Thumbnail display flag
     134     * @since 6392
     135     */
     136    public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name, boolean useThumbs) {
     137        super(name != null ? name : tr("Geotagged Images"));
     138        if (data != null) {
     139            Collections.sort(data);
     140        }
     141        this.data = data;
     142        this.gpxLayer = gpxLayer;
     143        this.useThumbs = useThumbs;
     144    }
     145
     146    /**
     147     * Loads a set of images, while displaying a dialog that indicates what the plugin is currently doing.
    91148     * In facts, this object is instantiated with a list of files. These files may be JPEG files or
    92149     * directories. In case of directories, they are scanned to find all the images they contain.
    93150     * Then all the images that have be found are loaded as ImageEntry instances.
    94151     */
    95     private static final class Loader extends PleaseWaitRunnable {
     152    static final class Loader extends PleaseWaitRunnable {
    96153
    97154        private boolean canceled;
     
    102159        private final GpxLayer gpxLayer;
    103160
    104         protected void rememberError(String message) {
    105             this.errorMessages.add(message);
    106         }
    107 
    108161        Loader(Collection<File> selection, GpxLayer gpxLayer) {
    109162            super(tr("Extracting GPS locations from EXIF"));
     
    111164            this.gpxLayer = gpxLayer;
    112165            errorMessages = new LinkedHashSet<>();
     166        }
     167
     168        protected void rememberError(String message) {
     169            this.errorMessages.add(message);
    113170        }
    114171
     
    133190
    134191            // read the image files
    135             List<ImageEntry> data = new ArrayList<>(files.size());
     192            List<ImageEntry> entries = new ArrayList<>(files.size());
    136193
    137194            for (File f : files) {
     
    146203                ImageEntry e = new ImageEntry(f);
    147204                e.extractExif();
    148                 data.add(e);
    149             }
    150             layer = new GeoImageLayer(data, gpxLayer);
     205                entries.add(e);
     206            }
     207            layer = new GeoImageLayer(entries, gpxLayer);
    151208            files.clear();
    152209        }
     
    242299
    243300    public static void create(Collection<File> files, GpxLayer gpxLayer) {
    244         Loader loader = new Loader(files, gpxLayer);
    245         Main.worker.execute(loader);
    246     }
    247 
    248     /**
    249      * Constructs a new {@code GeoImageLayer}.
    250      * @param data The list of images to display
    251      * @param gpxLayer The associated GPX layer
    252      */
    253     public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer) {
    254         this(data, gpxLayer, null, false);
    255     }
    256 
    257     /**
    258      * Constructs a new {@code GeoImageLayer}.
    259      * @param data The list of images to display
    260      * @param gpxLayer The associated GPX layer
    261      * @param name Layer name
    262      * @since 6392
    263      */
    264     public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name) {
    265         this(data, gpxLayer, name, false);
    266     }
    267 
    268     /**
    269      * Constructs a new {@code GeoImageLayer}.
    270      * @param data The list of images to display
    271      * @param gpxLayer The associated GPX layer
    272      * @param useThumbs Thumbnail display flag
    273      * @since 6392
    274      */
    275     public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, boolean useThumbs) {
    276         this(data, gpxLayer, null, useThumbs);
    277     }
    278 
    279     /**
    280      * Constructs a new {@code GeoImageLayer}.
    281      * @param data The list of images to display
    282      * @param gpxLayer The associated GPX layer
    283      * @param name Layer name
    284      * @param useThumbs Thumbnail display flag
    285      * @since 6392
    286      */
    287     public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name, boolean useThumbs) {
    288         super(name != null ? name : tr("Geotagged Images"));
    289         if (data != null) {
    290             Collections.sort(data);
    291         }
    292         this.data = data;
    293         this.gpxLayer = gpxLayer;
    294         this.useThumbs = useThumbs;
     301        Main.worker.execute(new Loader(files, gpxLayer));
    295302    }
    296303
     
    299306        return ImageProvider.get("dialogs/geoimage");
    300307    }
    301 
    302     private static List<Action> menuAdditions = new LinkedList<>();
    303308
    304309    public static void registerMenuAddition(Action addition) {
     
    509514                Point p = mv.getPoint(e.getPos());
    510515
    511                 int imgWidth = 100;
    512                 int imgHeight = 100;
     516                int imgWidth;
     517                int imgHeight;
    513518                if (useThumbs && e.hasThumbnail()) {
    514519                    Dimension d = scaledDimension(e.getThumbnail());
     
    570575    }
    571576
     577    /**
     578     * Shows next photo.
     579     */
    572580    public void showNextPhoto() {
    573581        if (data != null && !data.isEmpty()) {
     
    583591    }
    584592
     593    /**
     594     * Shows previous photo.
     595     */
    585596    public void showPreviousPhoto() {
    586597        if (data != null && !data.isEmpty()) {
     
    596607    }
    597608
     609    /**
     610     * Shows first photo.
     611     */
    598612    public void showFirstPhoto() {
    599613        if (data != null && !data.isEmpty()) {
     
    606620    }
    607621
     622    /**
     623     * Shows last photo.
     624     */
    608625    public void showLastPhoto() {
    609626        if (data != null && !data.isEmpty()) {
     
    638655
    639656    public void removeCurrentPhotoFromDisk() {
    640         ImageEntry toDelete = null;
     657        ImageEntry toDelete;
    641658        if (data != null && !data.isEmpty() && currentPhoto >= 0 && currentPhoto < data.size()) {
    642659            toDelete = data.get(currentPhoto);
     
    684701
    685702    public void copyCurrentPhotoPath() {
    686         ImageEntry toCopy = null;
    687703        if (data != null && !data.isEmpty() && currentPhoto >= 0 && currentPhoto < data.size()) {
    688             toCopy = data.get(currentPhoto);
    689             String copyString = toCopy.getFile().toString();
    690             Utils.copyToClipboard(copyString);
     704            Utils.copyToClipboard(data.get(currentPhoto).getFile().toString());
    691705        }
    692706    }
     
    759773    }
    760774
    761     private static volatile List<MapMode> supportedMapModes;
    762 
    763775    /**
    764776     * Registers a map mode for which the functionality of this layer should be available.
     
    794806        return false;
    795807    }
    796 
    797     private MouseAdapter mouseAdapter;
    798     private MapModeChangeListener mapModeListener;
    799808
    800809    @Override
Note: See TracChangeset for help on using the changeset viewer.