Changeset 3722 in josm for trunk/src/org
- Timestamp:
- 2010-12-14T12:19:38+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r3720 r3722 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.AWTEvent; 6 7 import java.awt.Cursor; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.Insets; 10 import java.awt.Toolkit; 11 import java.awt.event.AWTEventListener; 9 12 import java.awt.event.ActionEvent; 13 import java.awt.event.KeyEvent; 10 14 import java.awt.event.MouseEvent; 11 15 import java.awt.event.MouseListener; … … 25 29 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 26 30 import org.openstreetmap.josm.gui.ExtendedDialog; 31 import org.openstreetmap.josm.gui.JMultilineLabel; 27 32 import org.openstreetmap.josm.gui.layer.ImageryLayer; 28 33 import org.openstreetmap.josm.tools.GBC; … … 30 35 31 36 32 public class ImageryAdjustAction extends MapMode implements MouseListener, MouseMotionListener {37 public class ImageryAdjustAction extends MapMode implements MouseListener, MouseMotionListener, AWTEventListener{ 33 38 static ImageryOffsetDialog offsetDialog; 34 39 static Cursor cursor = ImageProvider.getCursor("normal", "move"); … … 58 63 oldDx = layer.getDx(); 59 64 oldDy = layer.getDy(); 65 try { 66 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 67 } catch (SecurityException ex) { 68 } 60 69 offsetDialog = new ImageryOffsetDialog(); 61 70 offsetDialog.setVisible(true); … … 69 78 offsetDialog = null; 70 79 } 80 try { 81 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 82 } catch (SecurityException ex) { 83 } 71 84 Main.map.mapView.removeMouseListener(this); 72 85 Main.map.mapView.removeMouseMotionListener(this); 86 } 87 88 @Override 89 public void eventDispatched(AWTEvent event) { 90 if (!(event instanceof KeyEvent)) return; 91 if (event.getID() != KeyEvent.KEY_PRESSED) return; 92 if (layer == null) return; 93 KeyEvent kev = (KeyEvent)event; 94 double dx = 0, dy = 0; 95 switch (kev.getKeyCode()) { 96 case KeyEvent.VK_UP : dy = +1; break; 97 case KeyEvent.VK_DOWN : dy = -1; break; 98 case KeyEvent.VK_LEFT : dx = -1; break; 99 case KeyEvent.VK_RIGHT : dx = +1; break; 100 } 101 if (dx != 0 || dy != 0) { 102 double ppd = layer.getPPD(); 103 layer.displace(dx / ppd, dy / ppd); 104 if (offsetDialog != null) { 105 offsetDialog.updateOffset(); 106 } 107 kev.consume(); 108 Main.map.repaint(); 109 } 73 110 } 74 111 … … 111 148 super.actionPerformed(e); 112 149 } 113 114 150 115 151 class ImageryOffsetDialog extends ExtendedDialog implements PropertyChangeListener { … … 124 160 false); 125 161 setButtonIcons(new String[] { "ok", "cancel" }); 126 contentInsets = new Insets(15, 15, 5, 15); 127 JPanel pnl = new JPanel(); 128 pnl.setLayout(new GridBagLayout()); 162 contentInsets = new Insets(10, 15, 5, 15); 163 JPanel pnl = new JPanel(new GridBagLayout()); 164 pnl.add(new JMultilineLabel(tr("Use arrow keys or drag the imagery layer with mouse to adjust the imagery offset.\n" + 165 "You can also enter east and north offset in the {0} coordinates.\n" + 166 "If you want to save the offset as bookmark, enter the bookmark name below",Main.proj.toString())), GBC.eop()); 129 167 pnl.add(new JLabel(tr("Easting") + ": "),GBC.std()); 130 168 pnl.add(easting,GBC.std().fill(GBC.HORIZONTAL).insets(0, 0, 5, 0)); 131 169 pnl.add(new JLabel(tr("Northing") + ": "),GBC.std()); 132 pnl.add(northing,GBC.eol() );170 pnl.add(northing,GBC.eol().fill(GBC.HORIZONTAL)); 133 171 pnl.add(new JLabel(tr("Bookmark name: ")),GBC.eol().insets(0,5,0,0)); 134 172 pnl.add(tBookmarkName,GBC.eol().fill(GBC.HORIZONTAL));
Note:
See TracChangeset
for help on using the changeset viewer.