Changeset 2601 in josm for trunk


Ignore:
Timestamp:
2009-12-10T12:12:49+01:00 (15 years ago)
Author:
bastiK
Message:

fixed #3722 - add shortcut for "next photo" and "previous photo" (PG-UP and PG-DOWN)
Some components consume these shortcuts if focused. This can be resolved on an individual basis if it is a problem for certain work flows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r2577 r2601  
    1515import java.awt.event.KeyEvent;
    1616
     17import javax.swing.AbstractAction;
     18import javax.swing.ImageIcon;
    1719import javax.swing.JButton;
     20import javax.swing.JComponent;
    1821import javax.swing.JPanel;
    1922import javax.swing.JToggleButton;
    2023
    2124import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.gui.SideButton;
    2226import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    2327import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
     
    2630import org.openstreetmap.josm.tools.Shortcut;
    2731
    28 public class ImageViewerDialog extends ToggleDialog implements ActionListener {
     32public class ImageViewerDialog extends ToggleDialog {
    2933
    3034    private static final String COMMAND_ZOOM = "zoom";
     
    5357        super(tr("Geotagged Images"), "geoimage", tr("Display geotagged images"), Shortcut.registerShortcut("tools:geotagged", tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.GROUP_EDIT), 200);
    5458
     59        if (INSTANCE != null) {
     60            throw new IllegalStateException("Image viewer dialog should not be instanciated twice !");
     61        }
     62
    5563        /* Don't show a detached dialog right from the start. */
    5664        if (isShowing && !isDocked) {
     
    5866        }
    5967
    60         if (INSTANCE != null) {
    61             throw new IllegalStateException("Image viewer dialog should not be instanciated twice !");
    62         }
    63 
    6468        INSTANCE = this;
    6569
     
    7276        buttons.setLayout(new FlowLayout());
    7377
    74         JButton button;
    75 
    7678        Dimension buttonDim = new Dimension(26,26);
    77         button = new JButton();
    78         button.setIcon(ImageProvider.get("dialogs", "previous"));
    79         button.setActionCommand(COMMAND_PREVIOUS);
    80         button.setToolTipText(tr("Previous"));
    81         button.addActionListener(this);
    82         button.setPreferredSize(buttonDim);
    83         buttons.add(button);
    84         btnPrevious = button; //FIX
    85 
    86         button = new JButton();
    87         button.setIcon(ImageProvider.get("dialogs", "delete"));
    88         button.setActionCommand(COMMAND_REMOVE);
    89         button.setToolTipText(tr("Remove photo from layer"));
    90         button.addActionListener(this);
    91         button.setPreferredSize(buttonDim);
    92         buttons.add(button);
    93 
    94         button = new JButton();
    95         button.setIcon(ImageProvider.get("dialogs", "next"));
    96         button.setActionCommand(COMMAND_NEXT);
    97         button.setToolTipText(tr("Next"));
    98         button.addActionListener(this);
    99         button.setPreferredSize(buttonDim);
    100         buttons.add(button);
    101         btnNext = button;
    102 
    103         JToggleButton tb = new JToggleButton();
    104         tb.setIcon(ImageProvider.get("dialogs", "centreview"));
    105         tb.setActionCommand(COMMAND_CENTERVIEW);
    106         tb.setToolTipText(tr("Center view"));
    107         tb.addActionListener(this);
    108         tb.setPreferredSize(buttonDim);
    109         buttons.add(tb);
    110 
    111         button = new JButton();
    112         button.setIcon(ImageProvider.get("dialogs", "zoom-best-fit"));
    113         button.setActionCommand(COMMAND_ZOOM);
    114         button.setToolTipText(tr("Zoom best fit and 1:1"));
    115         button.addActionListener(this);
    116         button.setPreferredSize(buttonDim);
    117         buttons.add(button);
     79       
     80        ImageAction prevAction = new ImageAction(COMMAND_PREVIOUS, ImageProvider.get("dialogs", "previous"), tr("Previous"));
     81        btnPrevious = new JButton(prevAction);
     82        btnPrevious.setPreferredSize(buttonDim);
     83        buttons.add(btnPrevious);
     84        Shortcut scPrev = Shortcut.registerShortcut(
     85            "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.GROUP_DIRECT);
     86        final String APREVIOUS = "Previous Image";
     87        Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scPrev.getKeyStroke(), APREVIOUS);
     88        Main.contentPane.getActionMap().put(APREVIOUS, prevAction);
     89        btnPrevious.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scPrev.getKeyStroke(), APREVIOUS);
     90        btnPrevious.getActionMap().put(APREVIOUS, prevAction);
     91
     92        JButton btnDelete = new JButton(new ImageAction(COMMAND_REMOVE, ImageProvider.get("dialogs", "delete"), tr("Remove photo from layer")));
     93        btnDelete.setPreferredSize(buttonDim);
     94        buttons.add(btnDelete);
     95     
     96        ImageAction nextAction = new ImageAction(COMMAND_NEXT, ImageProvider.get("dialogs", "next"), tr("Next"));
     97        btnNext = new JButton(nextAction);
     98        btnNext.setPreferredSize(buttonDim);
     99        buttons.add(btnNext);
     100        Shortcut scNext = Shortcut.registerShortcut(
     101            "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.GROUP_DIRECT);
     102        final String ANEXT = "Next Image";
     103        Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scNext.getKeyStroke(), ANEXT);
     104        Main.contentPane.getActionMap().put(ANEXT, nextAction);
     105        btnNext.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scNext.getKeyStroke(), ANEXT);
     106        btnNext.getActionMap().put(ANEXT, nextAction);
     107
     108        JToggleButton tbCentre = new JToggleButton(new ImageAction(COMMAND_CENTERVIEW, ImageProvider.get("dialogs", "centreview"), tr("Center view")));
     109        tbCentre.setPreferredSize(buttonDim);
     110        buttons.add(tbCentre);
     111       
     112        JButton btnZoomBestFit = new JButton(new ImageAction(COMMAND_ZOOM, ImageProvider.get("dialogs", "zoom-best-fit"), tr("Zoom best fit and 1:1")));
     113        btnZoomBestFit.setPreferredSize(buttonDim);
     114        buttons.add(btnZoomBestFit);
    118115
    119116        content.add(buttons, BorderLayout.SOUTH);
    120117
    121118        add(content, BorderLayout.CENTER);
    122 
    123     }
    124 
    125     public void actionPerformed(ActionEvent e) {
    126         if (COMMAND_NEXT.equals(e.getActionCommand())) {
    127             if (currentLayer != null) {
    128                 currentLayer.showNextPhoto();
    129             }
    130         } else if (COMMAND_PREVIOUS.equals(e.getActionCommand())) {
    131             if (currentLayer != null) {
    132                 currentLayer.showPreviousPhoto();
    133             }
    134 
    135         } else if (COMMAND_CENTERVIEW.equals(e.getActionCommand())) {
    136             centerView = ((JToggleButton) e.getSource()).isSelected();
    137             if (centerView && currentEntry != null && currentEntry.pos != null) {
    138                 Main.map.mapView.zoomTo(currentEntry.pos);
    139             }
    140 
    141         } else if (COMMAND_ZOOM.equals(e.getActionCommand())) {
    142             imgDisplay.zoomBestFitOrOne();
    143 
    144         } else if (COMMAND_REMOVE.equals(e.getActionCommand())) {
    145             if (currentLayer != null) {
    146                currentLayer.removeCurrentPhoto();
    147             }
    148         }
    149 
     119    }
     120
     121    class ImageAction extends AbstractAction {
     122        private final String action;
     123        public ImageAction(String action, ImageIcon icon, String toolTipText) {
     124            this.action = action;
     125            putValue(SHORT_DESCRIPTION, toolTipText);
     126            putValue(SMALL_ICON, icon);
     127        }
     128
     129        public void actionPerformed(ActionEvent e) {
     130            if (COMMAND_NEXT.equals(action)) {
     131                if (currentLayer != null) {
     132                    currentLayer.showNextPhoto();
     133                }
     134            } else if (COMMAND_PREVIOUS.equals(action)) {
     135                if (currentLayer != null) {
     136                    currentLayer.showPreviousPhoto();
     137                }
     138
     139            } else if (COMMAND_CENTERVIEW.equals(action)) {
     140                centerView = ((JToggleButton) e.getSource()).isSelected();
     141                if (centerView && currentEntry != null && currentEntry.pos != null) {
     142                    Main.map.mapView.zoomTo(currentEntry.pos);
     143                }
     144
     145            } else if (COMMAND_ZOOM.equals(action)) {
     146                imgDisplay.zoomBestFitOrOne();
     147
     148            } else if (COMMAND_REMOVE.equals(action)) {
     149                if (currentLayer != null) {
     150                   currentLayer.removeCurrentPhoto();
     151                }
     152            }
     153        }
    150154    }
    151155
Note: See TracChangeset for help on using the changeset viewer.