Changeset 33254 in osm
- Timestamp:
- 2017-04-17T02:01:34+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/imageryadjust
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imageryadjust/build.xml
r32680 r33254 2 2 <project name="imageryadjust" default="dist" basedir="."> 3 3 <property name="commit.message" value="ImageryAdjust: Adjust while holding shortcut key"/> 4 <property name="plugin.main.version" value="1 0580"/>4 <property name="plugin.main.version" value="11713"/> 5 5 6 6 <property name="plugin.author" value="Upliner"/> -
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustMapMode.java
r32329 r33254 6 6 import java.awt.Cursor; 7 7 import java.awt.GridBagLayout; 8 import java.awt.event.ActionEvent;9 8 import java.awt.event.KeyEvent; 10 9 import java.awt.event.MouseEvent; … … 35 34 import org.openstreetmap.josm.tools.Shortcut; 36 35 37 38 36 public class ImageryAdjustMapMode extends MapMode implements MouseListener, MouseMotionListener, MapFrame.MapModeChangeListener{ 39 37 boolean mouseDown; … … 41 39 private ImageryLayer adjustingLayer; 42 40 private MapMode oldMapMode; 43 44 45 public ImageryAdjustMapMode(MapFrame mapFrame) { 41 42 public ImageryAdjustMapMode() { 46 43 super(tr("Adjust imagery"), "adjustimg", 47 44 tr("Adjust the position of the selected imagery layer"), 48 45 Shortcut.registerShortcut("imageryadjust:adjustmode", tr("Mode: {0}", tr("Adjust imagery")), 49 46 KeyEvent.VK_Y, Shortcut.ALT_CTRL), 50 mapFrame,51 47 ImageProvider.getCursor("normal", "move")); 52 48 MapFrame.addMapModeChangeListener(this); … … 54 50 55 51 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)); 57 53 Iterator<? extends Layer> it = all.iterator(); 58 54 while (it.hasNext()) { … … 61 57 return all; 62 58 } 63 64 @Override65 public void actionPerformed(ActionEvent e) {66 super.actionPerformed(e);67 }68 69 59 70 60 TimedKeyReleaseListener listener; … … 93 83 protected void doKeyReleaseEvent(KeyEvent evt) { 94 84 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 } 97 89 } 98 } 90 91 @Override 92 protected void doKeyPressEvent(KeyEvent evt) { 93 // Do nothing ? 94 } 99 95 }; 100 96 } 101 97 102 @Override public void exitMode() { 98 @Override 99 public void exitMode() { 103 100 super.exitMode(); 104 101 Main.map.mapView.removeMouseListener(this); … … 108 105 } 109 106 110 @Override public void mousePressed(MouseEvent e) { 107 @Override 108 public void mousePressed(MouseEvent e) { 111 109 if (e.getButton() != MouseEvent.BUTTON1) 112 110 return; … … 124 122 EastNorth eastNorth= 125 123 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. 126 126 adjustingLayer.displace( 127 127 eastNorth.east()-prevEastNorth.east(), 128 128 eastNorth.north()-prevEastNorth.north() 129 ); 129 );*/ 130 130 prevEastNorth = eastNorth; 131 131 Main.map.mapView.repaint(); … … 182 182 */ 183 183 protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) { 184 if (adjustableLayers. size()==0) return null;184 if (adjustableLayers.isEmpty()) return null; 185 185 if (adjustableLayers.size()==1) return adjustableLayers.get(0); 186 186 JComboBox<Layer> layerList = new JComboBox<>(); … … 205 205 if (decision != 1) 206 206 return null; 207 Layer adjustLayer = (Layer) layerList.getSelectedItem(); 208 return adjustLayer; 207 return (Layer) layerList.getSelectedItem(); 209 208 } 210 209 211 210 /** 212 211 * Displays a warning message if there are no imagery layers to adjust 213 *214 212 */ 215 213 protected void warnNoImageryLayers() { … … 224 222 /** 225 223 * Replies true if there is at least one imagery layer 226 *227 224 * @return true if there is at least one imagery layer 228 225 */ … … 230 227 if (Main.map == null) return false; 231 228 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(); 234 230 } 235 231 236 232 @Override 237 233 protected void updateEnabledState() { 238 239 234 setEnabled(hasImageryLayersToAdjust()); 240 //setEnabled(hasImageryLayersToAdjust());241 235 } 242 236 } -
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustPlugin.java
r29609 r33254 15 15 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 16 16 if (oldFrame == null && newFrame != null) { 17 newFrame.addMapMode(new IconToggleButton(new ImageryAdjustMapMode(newFrame)));17 newFrame.addMapMode(new IconToggleButton(new ImageryAdjustMapMode())); 18 18 } 19 19 } -
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/TimedKeyReleaseListener.java
r31690 r33254 4 4 import java.awt.Toolkit; 5 5 import java.awt.event.AWTEventListener; 6 import java.awt.event.ActionEvent;7 import java.awt.event.ActionListener;8 6 import java.awt.event.KeyEvent; 9 7 import java.util.TreeSet; 10 8 import javax.swing.Timer; 11 9 12 public class TimedKeyReleaseListener implements AWTEventListener { 10 import org.openstreetmap.josm.Main; 11 12 public abstract class TimedKeyReleaseListener implements AWTEventListener { 13 13 private final TreeSet<Integer> set = new TreeSet<>(); 14 14 private Timer timer; … … 16 16 17 17 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 } 26 23 }); 27 24 … … 30 27 AWTEvent.KEY_EVENT_MASK); 31 28 } catch (SecurityException ex) { 29 Main.error(ex); 32 30 } 33 31 } … … 59 57 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 60 58 } catch (SecurityException ex) { 59 Main.error(ex); 61 60 } 62 61 } 63 62 64 protected void doKeyReleaseEvent(KeyEvent evt) { 65 } 63 protected abstract void doKeyReleaseEvent(KeyEvent evt); 66 64 67 protected void doKeyPressEvent(KeyEvent evt) { 68 } 65 protected abstract void doKeyPressEvent(KeyEvent evt); 69 66 }
Note:
See TracChangeset
for help on using the changeset viewer.