Changeset 4751 in josm for trunk/src


Ignore:
Timestamp:
2011-12-30T17:31:00+01:00 (8 years ago)
Author:
jttt
Message:

Extend Jump to next/previous marker to georefimage layer and made it easily possible to add jumping to any layer where it makes sense

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r4711 r4751  
    5959import org.openstreetmap.josm.gui.help.HelpUtil;
    6060import org.openstreetmap.josm.gui.io.SaveLayersDialog;
     61import org.openstreetmap.josm.gui.layer.JumpToMarkerActions;
    6162import org.openstreetmap.josm.gui.layer.Layer;
    6263import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
     
    9293        MultikeyActionsHandler.getInstance().addAction(instance.new ShowHideLayerAction(false));
    9394        MultikeyActionsHandler.getInstance().addAction(instance.new ActivateLayerAction());
     95        JumpToMarkerActions.initialize();
    9496    }
    9597
     
    15551557    }
    15561558
    1557     public static List<MultikeyInfo> getLayerInfoByClass(Class<? extends Layer> layerClass) {
     1559    // This is not Class<? extends Layer> on purpose, to allow asking for layers implementing some interface
     1560    public static List<MultikeyInfo> getLayerInfoByClass(Class<?> layerClass) {
    15581561
    15591562        List<MultikeyInfo> result = new ArrayList<MultikeyShortcutAction.MultikeyInfo>();
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r4627 r4751  
    5555import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    5656import org.openstreetmap.josm.gui.layer.GpxLayer;
     57import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer;
     58import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker;
     59import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
    5760import org.openstreetmap.josm.gui.layer.Layer;
    5861import org.openstreetmap.josm.tools.ExifReader;
     
    6871import com.drew.metadata.exif.GpsDirectory;
    6972
    70 public class GeoImageLayer extends Layer implements PropertyChangeListener {
     73public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {
    7174
    7275    List<ImageEntry> data;
     
    230233                        tr("Error"),
    231234                        JOptionPane.ERROR_MESSAGE
    232                 );
     235                        );
    233236            }
    234237            if (layer != null) {
     
    299302        }
    300303        entries.add(SeparatorLayerAction.INSTANCE);
     304        entries.add(new JumpToNextMarker(this));
     305        entries.add(new JumpToPreviousMarker(this));
     306        entries.add(SeparatorLayerAction.INSTANCE);
    301307        entries.add(new LayerListPopup.InfoAction(this));
    302308
     
    312318            }
    313319        return trn("{0} image loaded.", "{0} images loaded.", data.size(), data.size())
    314         + " " + trn("{0} was found to be GPS tagged.", "{0} were found to be GPS tagged.", i, i);
     320                + " " + trn("{0} was found to be GPS tagged.", "{0} were found to be GPS tagged.", i, i);
    315321    }
    316322
     
    529535        } catch (MetadataException ex) {
    530536        }
    531        
     537
    532538        try {
    533539            // longitude
     
    694700                            tr("Error"),
    695701                            JOptionPane.ERROR_MESSAGE
    696                     );
     702                            );
    697703                }
    698704
     
    818824        return copy;
    819825    }
     826
     827    public void jumpToNextMarker() {
     828        showNextPhoto();
     829    }
     830
     831    public void jumpToPreviousMarker() {
     832        showPreviousPhoto();
     833    }
    820834}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r4710 r4751  
    1212import java.awt.Point;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.KeyEvent;
    1514import java.awt.event.MouseAdapter;
    1615import java.awt.event.MouseEvent;
    1716import java.io.File;
    18 import java.lang.ref.WeakReference;
    1917import java.net.URL;
    2018import java.util.ArrayList;
     
    4139import org.openstreetmap.josm.gui.layer.CustomizeColor;
    4240import org.openstreetmap.josm.gui.layer.GpxLayer;
     41import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer;
     42import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker;
     43import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
    4344import org.openstreetmap.josm.gui.layer.Layer;
    4445import org.openstreetmap.josm.tools.AudioPlayer;
    4546import org.openstreetmap.josm.tools.ImageProvider;
    46 import org.openstreetmap.josm.tools.MultikeyActionsHandler;
    47 import org.openstreetmap.josm.tools.MultikeyShortcutAction;
    48 import org.openstreetmap.josm.tools.Shortcut;
    4947
    5048/**
     
    5957 * The data is read only.
    6058 */
    61 public class MarkerLayer extends Layer {
     59public class MarkerLayer extends Layer implements JumpToMarkerLayer {
    6260
    6361    /**
     
    138136        });
    139137    }
    140 
    141     static {
    142         MultikeyActionsHandler.getInstance().addAction(new JumpToNextMarker(null));
    143         MultikeyActionsHandler.getInstance().addAction(new JumpToPreviousMarker(null));
    144     }
    145 
    146138
    147139    /**
     
    450442    }
    451443
    452     public static final class JumpToNextMarker extends AbstractAction implements MultikeyShortcutAction {
    453 
    454         private final MarkerLayer layer;
    455         private WeakReference<MarkerLayer> lastLayer;
    456 
    457         public JumpToNextMarker(MarkerLayer layer) {
    458             putValue(ACCELERATOR_KEY, Shortcut.registerShortcut("core_multikey:nextMarker", "", 'J', Shortcut.GROUP_DIRECT, KeyEvent.ALT_DOWN_MASK + KeyEvent.CTRL_DOWN_MASK).getKeyStroke());
    459             putValue(SHORT_DESCRIPTION, tr("Jump to next marker"));
    460             putValue(NAME, tr("Jump to next marker"));
    461 
    462             this.layer = layer;
    463         }
    464 
    465         @Override
    466         public void actionPerformed(ActionEvent e) {
    467             execute(layer);
    468         }
    469 
    470         @Override
    471         public void executeMultikeyAction(int index, boolean repeat) {
    472             Layer l = LayerListDialog.getLayerForIndex(index);
    473             if (l != null) {
    474                 if (l instanceof MarkerLayer) {
    475                     execute((MarkerLayer) l);
    476                 }
    477             } else if (repeat && lastLayer != null) {
    478                 l = lastLayer.get();
    479                 if (LayerListDialog.isLayerValid(l)) {
    480                     execute((MarkerLayer) l);
    481                 }
    482             }
    483         }
    484 
    485 
    486         private void execute(MarkerLayer l) {
    487             l.jumpToNextMarker();
    488             lastLayer = new WeakReference<MarkerLayer>(l);
    489         }
    490 
    491         @Override
    492         public List<MultikeyInfo> getMultikeyCombinations() {
    493             return LayerListDialog.getLayerInfoByClass(MarkerLayer.class);
    494         }
    495 
    496         @Override
    497         public MultikeyInfo getLastMultikeyAction() {
    498             if (lastLayer != null)
    499                 return LayerListDialog.getLayerInfo(lastLayer.get());
    500             else
    501                 return null;
    502         }
    503 
    504     }
    505 
    506     public static final class JumpToPreviousMarker extends AbstractAction implements MultikeyShortcutAction {
    507 
    508         private WeakReference<MarkerLayer> lastLayer;
    509         private final MarkerLayer layer;
    510 
    511         public JumpToPreviousMarker(MarkerLayer layer) {
    512             this.layer = layer;
    513 
    514             putValue(ACCELERATOR_KEY, Shortcut.registerShortcut("core_multikey:previousMarker", "", 'P', Shortcut.GROUP_DIRECT, KeyEvent.ALT_DOWN_MASK + KeyEvent.CTRL_DOWN_MASK).getKeyStroke());
    515             putValue(SHORT_DESCRIPTION, tr("Jump to previous marker"));
    516             putValue(NAME, tr("Jump to previous marker"));
    517         }
    518 
    519         @Override
    520         public void actionPerformed(ActionEvent e) {
    521             execute(layer);
    522         }
    523 
    524         @Override
    525         public void executeMultikeyAction(int index, boolean repeat) {
    526             Layer l = LayerListDialog.getLayerForIndex(index);
    527             if (l != null) {
    528                 if (l instanceof MarkerLayer) {
    529                     execute((MarkerLayer) l);
    530                 }
    531             } else if (repeat && lastLayer != null) {
    532                 l = lastLayer.get();
    533                 if (LayerListDialog.isLayerValid(l)) {
    534                     execute((MarkerLayer) l);
    535                 }
    536             }
    537         }
    538 
    539         private void execute(MarkerLayer l) {
    540             l.jumpToPreviousMarker();
    541             lastLayer = new WeakReference<MarkerLayer>(l);
    542         }
    543 
    544         @Override
    545         public List<MultikeyInfo> getMultikeyCombinations() {
    546             return LayerListDialog.getLayerInfoByClass(MarkerLayer.class);
    547         }
    548 
    549         @Override
    550         public MultikeyInfo getLastMultikeyAction() {
    551             if (lastLayer != null)
    552                 return LayerListDialog.getLayerInfo(lastLayer.get());
    553             else
    554                 return null;
    555         }
    556 
    557     }
    558444
    559445    private class SynchronizeAudio extends AbstractAction {
Note: See TracChangeset for help on using the changeset viewer.