Changeset 3722 in josm for trunk/src/org


Ignore:
Timestamp:
2010-12-14T12:19:38+01:00 (14 years ago)
Author:
Upliner
Message:

Allow to adjust imagery offset with arrow keys, add explaination to the adjust dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java

    r3720 r3722  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.AWTEvent;
    67import java.awt.Cursor;
    78import java.awt.GridBagLayout;
    89import java.awt.Insets;
     10import java.awt.Toolkit;
     11import java.awt.event.AWTEventListener;
    912import java.awt.event.ActionEvent;
     13import java.awt.event.KeyEvent;
    1014import java.awt.event.MouseEvent;
    1115import java.awt.event.MouseListener;
     
    2529import org.openstreetmap.josm.data.imagery.OffsetBookmark;
    2630import org.openstreetmap.josm.gui.ExtendedDialog;
     31import org.openstreetmap.josm.gui.JMultilineLabel;
    2732import org.openstreetmap.josm.gui.layer.ImageryLayer;
    2833import org.openstreetmap.josm.tools.GBC;
     
    3035
    3136
    32 public class ImageryAdjustAction extends MapMode implements MouseListener, MouseMotionListener{
     37public class ImageryAdjustAction extends MapMode implements MouseListener, MouseMotionListener, AWTEventListener{
    3338    static ImageryOffsetDialog offsetDialog;
    3439    static Cursor cursor = ImageProvider.getCursor("normal", "move");
     
    5863        oldDx = layer.getDx();
    5964        oldDy = layer.getDy();
     65        try {
     66            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
     67        } catch (SecurityException ex) {
     68        }
    6069        offsetDialog = new ImageryOffsetDialog();
    6170        offsetDialog.setVisible(true);
     
    6978            offsetDialog = null;
    7079        }
     80        try {
     81            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     82        } catch (SecurityException ex) {
     83        }
    7184        Main.map.mapView.removeMouseListener(this);
    7285        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        }
    73110    }
    74111
     
    111148        super.actionPerformed(e);
    112149    }
    113 
    114150
    115151    class ImageryOffsetDialog extends ExtendedDialog implements PropertyChangeListener {
     
    124160                    false);
    125161            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());
    129167            pnl.add(new JLabel(tr("Easting") + ": "),GBC.std());
    130168            pnl.add(easting,GBC.std().fill(GBC.HORIZONTAL).insets(0, 0, 5, 0));
    131169            pnl.add(new JLabel(tr("Northing") + ": "),GBC.std());
    132             pnl.add(northing,GBC.eol());
     170            pnl.add(northing,GBC.eol().fill(GBC.HORIZONTAL));
    133171            pnl.add(new JLabel(tr("Bookmark name: ")),GBC.eol().insets(0,5,0,0));
    134172            pnl.add(tBookmarkName,GBC.eol().fill(GBC.HORIZONTAL));
Note: See TracChangeset for help on using the changeset viewer.