Changeset 27744 in osm for applications/editors
- Timestamp:
- 2012-02-10T20:08:20+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/imageryadjust
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imageryadjust/build.xml
r27540 r27744 30 30 <project name="imageryadjust" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="ImageryAdjust: adjust single visible layer"/>32 <property name="commit.message" value="ImageryAdjust: Adjust while holding Y"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4667"/> -
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustMapMode.java
r27540 r27744 1 1 package imageryadjust; 2 2 3 import java.awt.*; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 5 import java.awt.Component; 6 import java.awt.Cursor; 7 import java.awt.GridBagLayout; 8 import java.awt.event.MouseEvent; 9 import java.awt.event.MouseListener; 10 import java.awt.event.MouseMotionListener; 11 import java.util.ArrayList; 12 import java.util.Iterator; 6 import java.awt.event.*; 13 7 import java.util.List; 14 15 import javax.swing.DefaultComboBoxModel; 16 import javax.swing.DefaultListCellRenderer; 17 import javax.swing.Icon; 18 import javax.swing.JComboBox; 19 import javax.swing.JLabel; 20 import javax.swing.JList; 21 import javax.swing.JOptionPane; 22 import javax.swing.JPanel; 8 import java.util.*; 9 10 import javax.swing.*; 11 import javax.swing.Timer; 23 12 24 13 import org.openstreetmap.josm.Main; … … 31 20 import org.openstreetmap.josm.tools.GBC; 32 21 import org.openstreetmap.josm.tools.ImageProvider; 33 34 public class ImageryAdjustMapMode extends MapMode implements MouseListener, MouseMotionListener{ 22 import org.openstreetmap.josm.tools.Shortcut; 23 24 25 public class ImageryAdjustMapMode extends MapMode implements MouseListener, MouseMotionListener, AWTEventListener, MapFrame.MapModeChangeListener{ 35 26 boolean mouseDown; 36 27 EastNorth prevEastNorth; 37 28 private ImageryLayer adjustingLayer; 38 29 private MapMode oldMapMode; 30 31 private final TreeSet<Integer> set = new TreeSet<Integer>(); 32 private Timer timer; 33 private KeyEvent releaseEvent; 34 39 35 public ImageryAdjustMapMode(MapFrame mapFrame) { 40 36 super(tr("Adjust imagery"), "adjustimg", 41 tr("Adjust the position of the selected imagery layer"), mapFrame, 37 tr("Adjust the position of the selected imagery layer"), 38 Shortcut.registerShortcut("imageryadjust:adjustmode", tr("imageryadjust"), KeyEvent.VK_Y, Shortcut.GROUP_EDIT), 39 mapFrame, 42 40 ImageProvider.getCursor("normal", "move")); 41 MapFrame.addMapModeChangeListener(this); 43 42 } 44 43 … … 51 50 return all; 52 51 } 52 53 @Override 54 public void actionPerformed(ActionEvent e) { 55 super.actionPerformed(e); 56 } 57 58 53 59 54 60 @Override public void enterMode() { … … 71 77 Main.map.mapView.addMouseListener(this); 72 78 Main.map.mapView.addMouseMotionListener(this); 79 timer = new Timer(0, new ActionListener() { 80 @Override 81 public void actionPerformed(ActionEvent ae) { 82 timer.stop(); 83 if (set.remove(releaseEvent.getKeyCode())) { 84 doKeyReleaseEvent(releaseEvent); 85 } 86 } 87 88 }); 89 90 try { 91 Toolkit.getDefaultToolkit().addAWTEventListener(this, 92 AWTEvent.KEY_EVENT_MASK); 93 } catch (SecurityException ex) { 94 } 95 96 73 97 } 74 98 … … 78 102 Main.map.mapView.removeMouseMotionListener(this); 79 103 adjustingLayer = null; 104 try { 105 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 106 } catch (SecurityException ex) { 107 } 80 108 } 81 109 … … 107 135 prevEastNorth = null; 108 136 } 137 138 private void doKeyEvent(KeyEvent keyEvent) { 139 } 140 141 private void doKeyReleaseEvent(KeyEvent releaseEvent) { 142 if (releaseEvent.getKeyCode() == getShortcut().getKeyStroke().getKeyCode()) { 143 if (oldMapMode!=null && !(oldMapMode instanceof ImageryAdjustMapMode)) 144 Main.map.selectMapMode(oldMapMode); 145 } 146 } 109 147 110 148 @Override public boolean layerIsSupported(Layer l) { 111 return hasImageryLayersToAdjust(); 112 } 149 //return hasImageryLayersToAdjust(); 150 return true; 151 } 152 153 @Override 154 public void eventDispatched(AWTEvent event) { 155 if (event instanceof KeyEvent) { 156 KeyEvent e=(KeyEvent) event; 157 158 if (event.getID() == KeyEvent.KEY_PRESSED) { 159 if (timer.isRunning()) { 160 timer.stop(); 161 } else { 162 if (set.add((e.getKeyCode()))) doKeyEvent((KeyEvent) event); 163 } 164 } 165 if (event.getID() == KeyEvent.KEY_RELEASED) { 166 if (timer.isRunning()) { 167 timer.stop(); 168 if (set.remove(e.getKeyCode())) doKeyReleaseEvent(e); 169 } else { 170 releaseEvent = e; 171 timer.restart(); 172 } 173 } 174 } 175 } 176 177 @Override 178 public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) { 179 this.oldMapMode = oldMapMode; 180 } 181 113 182 114 183 /** … … 194 263 if (Main.map == null) return false; 195 264 if (Main.map.mapView == null) return false; 196 return ! Main.map.mapView.getLayersOfType(ImageryLayer.class).isEmpty(); 265 boolean b = ! Main.map.mapView.getLayersOfType(ImageryLayer.class).isEmpty(); 266 return b; 197 267 } 198 268 199 269 @Override 200 270 protected void updateEnabledState() { 271 201 272 setEnabled(hasImageryLayersToAdjust()); 273 //setEnabled(hasImageryLayersToAdjust()); 202 274 } 203 275 } -
applications/editors/josm/plugins/imageryadjust/src/imageryadjust/ImageryAdjustPlugin.java
r24812 r27744 1 1 package imageryadjust; 2 2 3 import javax.swing.Action; 3 4 import org.openstreetmap.josm.gui.IconToggleButton; 4 5 import org.openstreetmap.josm.gui.MapFrame; … … 14 15 @Override 15 16 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 16 if ( newFrame == null) return;17 if (oldFrame == null && newFrame != null) { 17 18 newFrame.addMapMode(new IconToggleButton(new ImageryAdjustMapMode(newFrame))); 19 } 18 20 } 19 21 }
Note:
See TracChangeset
for help on using the changeset viewer.