Changeset 33254 in osm


Ignore:
Timestamp:
2017-04-17T02:01:34+02:00 (8 years ago)
Author:
donvip
Message:

update to JOSM 11713 + code cleanup

Location:
applications/editors/josm/plugins/imageryadjust
Files:
4 edited

Legend:

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

    r32680 r33254  
    22<project name="imageryadjust" default="dist" basedir=".">
    33    <property name="commit.message" value="ImageryAdjust: Adjust while holding shortcut key"/>
    4     <property name="plugin.main.version" value="10580"/>
     4    <property name="plugin.main.version" value="11713"/>
    55
    66    <property name="plugin.author" value="Upliner"/>
  • applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustMapMode.java

    r32329 r33254  
    66import java.awt.Cursor;
    77import java.awt.GridBagLayout;
    8 import java.awt.event.ActionEvent;
    98import java.awt.event.KeyEvent;
    109import java.awt.event.MouseEvent;
     
    3534import org.openstreetmap.josm.tools.Shortcut;
    3635
    37 
    3836public class ImageryAdjustMapMode extends MapMode implements MouseListener, MouseMotionListener, MapFrame.MapModeChangeListener{
    3937    boolean mouseDown;
     
    4139    private ImageryLayer adjustingLayer;
    4240    private MapMode oldMapMode;
    43 
    44    
    45     public ImageryAdjustMapMode(MapFrame mapFrame) {
     41   
     42    public ImageryAdjustMapMode() {
    4643        super(tr("Adjust imagery"), "adjustimg",
    4744                tr("Adjust the position of the selected imagery layer"),
    4845                Shortcut.registerShortcut("imageryadjust:adjustmode", tr("Mode: {0}", tr("Adjust imagery")),
    4946                KeyEvent.VK_Y, Shortcut.ALT_CTRL),
    50                 mapFrame,
    5147                ImageProvider.getCursor("normal", "move"));
    5248        MapFrame.addMapModeChangeListener(this);
     
    5450   
    5551    private List<? extends Layer> getVisibleLayers() {
    56         List<? extends Layer> all = new ArrayList<Layer>(Main.getLayerManager().getLayersOfType(ImageryLayer.class));
     52        List<? extends Layer> all = new ArrayList<>(Main.getLayerManager().getLayersOfType(ImageryLayer.class));
    5753        Iterator<? extends Layer> it = all.iterator();
    5854        while (it.hasNext()) {
     
    6157        return all;
    6258    }
    63 
    64     @Override
    65     public void actionPerformed(ActionEvent e) {
    66         super.actionPerformed(e);
    67     }
    68    
    6959   
    7060    TimedKeyReleaseListener listener;
     
    9383                protected void doKeyReleaseEvent(KeyEvent evt) {
    9484                    if (releaseEvent.getKeyCode() == getShortcut().getKeyStroke().getKeyCode()) {
    95                     if (oldMapMode!=null && !(oldMapMode instanceof ImageryAdjustMapMode))
    96                     Main.map.selectMapMode(oldMapMode);
     85                        if (oldMapMode!=null && !(oldMapMode instanceof ImageryAdjustMapMode)) {
     86                            Main.map.selectMapMode(oldMapMode);
     87                        }
     88                    }
    9789                }
    98             }
     90
     91                @Override
     92                protected void doKeyPressEvent(KeyEvent evt) {
     93                    // Do nothing ?
     94                }
    9995        };
    10096    }
    10197
    102     @Override public void exitMode() {
     98    @Override
     99    public void exitMode() {
    103100        super.exitMode();
    104101        Main.map.mapView.removeMouseListener(this);
     
    108105    }
    109106
    110     @Override public void mousePressed(MouseEvent e) {
     107    @Override
     108    public void mousePressed(MouseEvent e) {
    111109        if (e.getButton() != MouseEvent.BUTTON1)
    112110            return;
     
    124122        EastNorth eastNorth=
    125123            Main.map.mapView.getEastNorth(e.getX(),e.getY());
     124        /* FIXME if this is needed. Comment from JOSM core when displace method has been deprecated:
     125        // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate.
    126126        adjustingLayer.displace(
    127127                eastNorth.east()-prevEastNorth.east(),
    128128                eastNorth.north()-prevEastNorth.north()
    129         );
     129        );*/
    130130        prevEastNorth = eastNorth;
    131131        Main.map.mapView.repaint();
     
    182182     */
    183183    protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) {
    184         if (adjustableLayers.size()==0) return null;
     184        if (adjustableLayers.isEmpty()) return null;
    185185        if (adjustableLayers.size()==1) return adjustableLayers.get(0);
    186186        JComboBox<Layer> layerList = new JComboBox<>();
     
    205205        if (decision != 1)
    206206            return null;
    207         Layer adjustLayer = (Layer) layerList.getSelectedItem();
    208         return adjustLayer;
     207        return (Layer) layerList.getSelectedItem();
    209208    }
    210209
    211210    /**
    212211     * Displays a warning message if there are no imagery layers to adjust
    213      *
    214212     */
    215213    protected void warnNoImageryLayers() {
     
    224222    /**
    225223     * Replies true if there is at least one imagery layer
    226      *
    227224     * @return true if there is at least one imagery layer
    228225     */
     
    230227        if (Main.map == null) return false;
    231228        if (Main.map.mapView == null) return false;
    232         boolean b = ! Main.getLayerManager().getLayersOfType(ImageryLayer.class).isEmpty();
    233         return b;
     229        return ! Main.getLayerManager().getLayersOfType(ImageryLayer.class).isEmpty();
    234230    }
    235231
    236232    @Override
    237233    protected void updateEnabledState() {
    238        
    239234        setEnabled(hasImageryLayersToAdjust());
    240         //setEnabled(hasImageryLayersToAdjust());
    241235    }
    242236}
  • applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustPlugin.java

    r29609 r33254  
    1515    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    1616        if (oldFrame == null && newFrame != null) {
    17         newFrame.addMapMode(new IconToggleButton(new ImageryAdjustMapMode(newFrame)));
     17            newFrame.addMapMode(new IconToggleButton(new ImageryAdjustMapMode()));
    1818        }
    1919    }
  • applications/editors/josm/plugins/imageryadjust/src/imageryadjust/TimedKeyReleaseListener.java

    r31690 r33254  
    44import java.awt.Toolkit;
    55import java.awt.event.AWTEventListener;
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    86import java.awt.event.KeyEvent;
    97import java.util.TreeSet;
    108import javax.swing.Timer;
    119
    12 public class TimedKeyReleaseListener implements AWTEventListener {
     10import org.openstreetmap.josm.Main;
     11
     12public abstract class TimedKeyReleaseListener implements AWTEventListener {
    1313    private final TreeSet<Integer> set = new TreeSet<>();
    1414    private Timer timer;
     
    1616   
    1717    public TimedKeyReleaseListener() {
    18         timer = new Timer(0, new ActionListener() {
    19             @Override
    20             public void actionPerformed(ActionEvent ae) {
    21                  timer.stop();
    22                  if (set.remove(releaseEvent.getKeyCode())) {
    23                   doKeyReleaseEvent(releaseEvent);
    24                  }
    25             }
     18        timer = new Timer(0, ae -> {
     19             timer.stop();
     20             if (set.remove(releaseEvent.getKeyCode())) {
     21                 doKeyReleaseEvent(releaseEvent);
     22             }
    2623        });
    2724       
     
    3027                    AWTEvent.KEY_EVENT_MASK);
    3128        } catch (SecurityException ex) {
     29            Main.error(ex);
    3230        }
    3331    }
     
    5957            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    6058        } catch (SecurityException ex) {
     59            Main.error(ex);
    6160        }
    6261    }
    6362   
    64     protected void doKeyReleaseEvent(KeyEvent evt) {
    65     }
     63    protected abstract void doKeyReleaseEvent(KeyEvent evt);
    6664
    67     protected void doKeyPressEvent(KeyEvent evt) {
    68     }
     65    protected abstract void doKeyPressEvent(KeyEvent evt);
    6966}
Note: See TracChangeset for help on using the changeset viewer.