Changeset 33745 in osm


Ignore:
Timestamp:
2017-10-30T19:13:43+01:00 (7 years ago)
Author:
holgermappt
Message:

Update for JOSM deprecated API.

Location:
applications/editors/josm/plugins/photoadjust
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/photoadjust/build.xml

    r33303 r33745  
    55    <property name="commit.message" value="Commit message"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    7     <property name="plugin.main.version" value="11713"/>
     7    <property name="plugin.main.version" value="12792"/>
    88
    99    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java

    r33303 r33745  
    1212import java.util.List;
    1313
    14 import org.openstreetmap.josm.Main;
    1514import org.openstreetmap.josm.actions.mapmode.MapMode;
    1615import org.openstreetmap.josm.gui.IconToggleButton;
     16import org.openstreetmap.josm.gui.MainApplication;
    1717import org.openstreetmap.josm.gui.MapFrame;
    1818import org.openstreetmap.josm.gui.layer.Layer;
     
    2121import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    2222import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     23import org.openstreetmap.josm.gui.layer.MainLayerManager;
    2324import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    2425import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
     
    5758        initAdapters();
    5859        this.worker = worker;
    59         Main.getLayerManager().addLayerChangeListener(this);
    60         Main.getLayerManager().addActiveLayerChangeListener(this);
     60        MainApplication.getLayerManager().addLayerChangeListener(this);
     61        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
    6162    }
    6263
     
    115116    private void activateMode() {
    116117        if (modeSelected && !modeActive) {
    117             Main.map.mapView.addMouseListener(mouseAdapter);
    118             Main.map.mapView.addMouseMotionListener(mouseMotionAdapter);
     118            MainApplication.getMap().mapView.addMouseListener(mouseAdapter);
     119            MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter);
    119120            modeActive = true;
    120121            updateStatusLine();
     
    127128    private void deactivateMode() {
    128129        if (modeActive) {
    129             Main.map.mapView.removeMouseListener(mouseAdapter);
    130             Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
     130            MainApplication.getMap().mapView.removeMouseListener(mouseAdapter);
     131            MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter);
    131132            modeActive = false;
    132133        }
     
    139140        // Activate the mode only if the current layer is not a GeoImageLayer.
    140141        // GeoImageLayer's are handled by the plug-in directly.
    141         if (!(Main.getLayerManager().getActiveLayer() instanceof GeoImageLayer)) {
     142        if (!(MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer)) {
    142143            activateMode();
    143144        }
     
    154155    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    155156        // The main part of the plugin takes care of all operations if a GeoImageLayer is active.
    156         if (Main.getLayerManager().getActiveLayer() instanceof GeoImageLayer) {
     157        if (MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer) {
    157158            deactivateMode();
    158159        } else {
     
    219220     */
    220221    private boolean hasLayersToAdjust() {
    221         if (Main.map == null || Main.map.mapView == null) return false;
    222         int giLayerNum = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).size();
     222        final MainLayerManager layerManager = MainApplication.getLayerManager();
     223        if (layerManager == null) return false;
     224        int giLayerNum = layerManager.getLayersOfType(GeoImageLayer.class).size();
    223225        if (ignoreOneGILayer) {
    224226            giLayerNum--;
     
    233235     */
    234236    private List<GeoImageLayer> getVisibleGeoImageLayers() {
    235         List<GeoImageLayer> all = new ArrayList<>(Main.getLayerManager().getLayersOfType(GeoImageLayer.class));
     237        List<GeoImageLayer> all = new ArrayList<>(MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class));
    236238        Iterator<GeoImageLayer> it = all.iterator();
    237239        while (it.hasNext()) {
     
    245247    public void destroy() {
    246248        super.destroy();
    247         Main.getLayerManager().removeActiveLayerChangeListener(this);
    248         Main.getLayerManager().removeLayerChangeListener(this);
     249        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
     250        MainApplication.getLayerManager().removeLayerChangeListener(this);
    249251    }
    250252
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustPlugin.java

    r33303 r33745  
    77import java.util.List;
    88
    9 import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.gui.MainApplication;
    1010import org.openstreetmap.josm.gui.MapFrame;
    1111import org.openstreetmap.josm.gui.layer.Layer;
     
    7777    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    7878        if (oldFrame == null && newFrame != null) {
    79             Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
     79            MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
    8080            PhotoAdjustMapMode adjustMode = new PhotoAdjustMapMode(worker);
    8181            adjustMode.installMapMode(newFrame);
    8282        } else {
    83             Main.getLayerManager().removeActiveLayerChangeListener(this);
     83            MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
    8484        }
    8585    }
     
    8989        worker.reset();
    9090        Layer oldLayer = e.getPreviousActiveLayer();
    91         Layer newLayer = Main.getLayerManager().getActiveLayer();
     91        Layer newLayer = MainApplication.getLayerManager().getActiveLayer();
    9292        if ( oldLayer instanceof GeoImageLayer
    9393             && newLayer instanceof GeoImageLayer) {
     
    9696        else {
    9797            if (oldLayer instanceof GeoImageLayer) {
    98                 Main.map.mapView.removeMouseListener(mouseAdapter);
    99                 Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
     98                MainApplication.getMap().mapView.removeMouseListener(mouseAdapter);
     99                MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter);
    100100                imageLayer = null;
    101101            }
    102102            if (newLayer instanceof GeoImageLayer) {
    103103                imageLayer = (GeoImageLayer)newLayer;
    104                 Main.map.mapView.addMouseListener(mouseAdapter);
    105                 Main.map.mapView.addMouseMotionListener(mouseMotionAdapter);
     104                MainApplication.getMap().mapView.addMouseListener(mouseAdapter);
     105                MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter);
    106106            }
    107107        }
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java

    r32015 r33745  
    66import java.util.List;
    77
    8 import org.openstreetmap.josm.Main;
    98import org.openstreetmap.josm.data.coor.LatLon;
     9import org.openstreetmap.josm.gui.MainApplication;
    1010import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
    1111import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry;
     
    139139    public void doMouseReleased(MouseEvent evt) {
    140140        restoreCenterView();
     141        //if (dragLayer != null && dragPhoto != null) {
     142        //    // Re-display the photo to update the OSD.
     143        //    ImageViewerDialog.showImage(dragLayer, dragPhoto);
     144        //}
    141145    }
    142146
     
    166170     */
    167171    private void setDragOffset(ImageEntry photo, MouseEvent evt) {
    168         final Point2D centerPoint = Main.map.mapView.getPoint2D(photo.getPos());
     172        final Point2D centerPoint = MainApplication.getMap().mapView.getPoint2D(photo.getPos());
    169173        dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(),
    170174                                        centerPoint.getY() - evt.getY());
     
    182186        LatLon newPos;
    183187        if (dragOffset != null) {
    184             newPos = Main.map.mapView.getLatLon(dragOffset.getX() + evt.getX(),
    185                                                 dragOffset.getY() + evt.getY());
     188            newPos = MainApplication.getMap().mapView.getLatLon(
     189                dragOffset.getX() + evt.getX(),
     190                dragOffset.getY() + evt.getY());
    186191        }
    187192        else {
    188             newPos = Main.map.mapView.getLatLon(evt.getX(), evt.getY());
     193            newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY());
    189194        }
    190195        photo.setPos(newPos);
    191196        photo.flagNewGpsData();
    192197        layer.updateBufferAndRepaint();
    193         // Need to re-display the photo because the OSD data might change (new
    194         // coordinates).
    195         ImageViewerDialog.showImage(layer, photo);
     198        // Re-display the photo because the OSD data might change (new
     199        // coordinates).  Or do that in doMouseReleased().
     200        //ImageViewerDialog.showImage(layer, photo);
    196201    }
    197202
     
    210215            return;
    211216        }
    212         final LatLon mouseLL = Main.map.mapView.getLatLon(evt.getX(), evt.getY());
     217        final LatLon mouseLL = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY());
    213218        // The projection doesn't matter here.
    214         double direction = 360.0 - photoLL.heading(mouseLL) * 360.0 / 2.0 / Math.PI;
     219        double direction = photoLL.bearing(mouseLL) * 360.0 / 2.0 / Math.PI;
    215220        if (direction < 0.0) {
    216221            direction += 360.0;
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java

    r33303 r33745  
    2424import org.openstreetmap.josm.actions.JosmAction;
    2525import org.openstreetmap.josm.data.coor.LatLon;
     26import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
     27import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
    2628import org.openstreetmap.josm.gui.ExtendedDialog;
     29import org.openstreetmap.josm.gui.MainApplication;
    2730import org.openstreetmap.josm.gui.MainMenu;
    2831import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
     
    4043
    4144    public PhotoPropertyEditor() {
    42         MainMenu.add(Main.main.menu.editMenu, new PropertyEditorAction());
     45        MainMenu.add(MainApplication.getMenu().editMenu, new PropertyEditorAction());
    4346    }
    4447
     
    8891                if (dialog.getValue() == 1) {
    8992                    dialog.updateImageTmp();
     93                    // FIXME: Remove next line, see below.
     94                    boolean isNewGpsData = photo.getTmp().hasNewGpsData();
     95                    // There are cases where isNewGpsData is not set but there
     96                    // is still new data, e.g. if the EXIF data was re-read
     97                    // from the image file.
    9098                    photo.applyTmp();
     99                    // FIXME: Remove the next lines once the patch in ticket
     100                    // #15502 is active.
     101                    if (isNewGpsData) {
     102                        photo.flagNewGpsData();
     103                    }
    91104                } else {
    92105                    photo.discardTmp();
     
    135148        private final ImageEntry image;
    136149        private final GeoImageLayer layer;
     150        // Image as it was when the dialog was opened.
     151        private final ImageEntry imgOrig;
    137152        private static final Color BG_COLOR_ERROR = new Color(255, 224, 224);
    138153
     
    142157            this.image = image;
    143158            this.layer = layer;
     159            imgOrig = image.clone();
    144160            setButtonIcons(new String[] {"ok", "cancel"});
    145161            final JPanel content = new JPanel(new GridBagLayout());
     
    174190            Action editCoordAction = new AbstractAction(tr("Edit")) {
    175191                @Override public void actionPerformed(ActionEvent evt) {
    176                     final LatLonDialog dialog
     192                    final LatLonDialog llDialog
    177193                        = new LatLonDialog(Main.parent,
    178194                                           tr("Edit Image Coordinates"), null);
    179                     dialog.setCoordinates(getLatLon());
    180                     dialog.showDialog();
    181                     if (dialog.getValue() == 1) {
    182                         LatLon coordinates = dialog.getCoordinates();
     195                    llDialog.setCoordinates(getLatLon());
     196                    llDialog.showDialog();
     197                    if (llDialog.getValue() == 1) {
     198                        final LatLon coordinates = llDialog.getCoordinates();
    183199                        if (coordinates != null) {
    184                             coords.setText(coordinates.toStringCSV(" "));
     200                            coords.setText(posToText(coordinates));
    185201                        }
    186202                    }
     
    302318        }
    303319
     320        /**
     321         * Convert an image position into a display string.
     322         *
     323         * @param pos Coordinates of image position.
     324         * @return Image position as text.
     325         */
     326        private String posToText(LatLon pos) {
     327            // See josm.gui.dialogs.LatLonDialog.setCoordinates().
     328            String posStr =
     329                pos == null ? "" :
     330                CoordinateFormatManager.getDefaultFormat().latToString(pos) +
     331                ' ' +
     332                CoordinateFormatManager.getDefaultFormat().lonToString(pos);
     333            return posStr;
     334        }
    304335
    305336        /**
     
    311342            if (image.getPos() != null) {
    312343                //coords.setText(image.getPos().toDisplayString());
    313                 coords.setText(image.getPos().toStringCSV(" "));
     344                coords.setText(posToText(image.getPos()));
    314345            } else {
    315346                coords.setText(null);
     
    382413        public void updateImageTmp() {
    383414            ImageEntry imgTmp = image.getTmp();
     415
    384416            String text = coords.getText();
     417            // The position of imgTmp is set in any case because it was
     418            // modified while the dialog was open.
    385419            if (text == null || text.isEmpty()) {
    386                 if (imgTmp.getPos() != null) {
     420                imgTmp.setPos(null);
     421                if (imgOrig.getPos() != null) {
    387422                    imgTmp.flagNewGpsData();
    388                     imgTmp.setPos(null);
    389                 }
    390             } else {
    391                 if ( imgTmp.getPos() == null
    392                      || !text.equals(imgTmp.getPos().toStringCSV(" "))) {
     423                }
     424            } else {
     425                // Coordinates field is not empty.
     426                imgTmp.setPos(getLatLon());
     427                // Flag new GPS data if the temporary image is at a different
     428                // position as the original image.  It doesn't work to compare
     429                // against the coords text field as that might contain data
     430                // (e.g. trailing zeros) that do not change the value.  It
     431                // doesn't work to compare imgTmp.getPos() with getLatLon()
     432                // because the dialog will round the initial position.
     433                if ( imgOrig.getPos() == null
     434                     || !posToText(imgOrig.getPos()).equals(posToText(imgTmp.getPos()))
     435                     ) {
    393436                    imgTmp.flagNewGpsData();
    394                     imgTmp.setPos(getLatLon());
    395437                }
    396438            }
     
    431473            LatLon latLon;
    432474            try {
    433                 latLon = LatLon.parse(coords.getText());
     475                latLon = LatLonParser.parse(coords.getText());
    434476                if (!latLon.isValid()) {
    435477                    latLon = null;
     
    453495            final String coordsText = coords.getText();
    454496            try {
    455                 latLon = LatLon.parse(coordsText);
     497                latLon = LatLonParser.parse(coordsText);
    456498            } catch (IllegalArgumentException exn) {
    457499                latLon = null;
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java

    r32451 r33745  
    1111import javax.swing.JMenuItem;
    1212
    13 import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.gui.MainApplication;
    1414import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    1515import org.openstreetmap.josm.gui.layer.Layer;
     
    5353                }
    5454            }
    55             Main.getLayerManager().addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(),
    56                                                  tr("Untagged Images"),
    57                                                  layer.isUseThumbs()));
     55            MainApplication.getLayerManager()
     56                .addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(),
     57                                            tr("Untagged Images"),
     58                                            layer.isUseThumbs()));
    5859        }
    5960    }
Note: See TracChangeset for help on using the changeset viewer.