Changeset 6520 in josm


Ignore:
Timestamp:
2013-12-24T10:56:36+01:00 (5 years ago)
Author:
simon04
Message:

History dialog: make versions navigable with arrow keys up/down

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java

    r6084 r6520  
    1111import java.awt.event.ItemEvent;
    1212import java.awt.event.ItemListener;
     13import java.awt.event.KeyAdapter;
     14import java.awt.event.KeyEvent;
    1315import java.awt.event.MouseEvent;
    1416import java.util.Observable;
     
    5254        popupMenu = new VersionTablePopupMenu();
    5355        addMouseListener(new MouseListener());
     56        addKeyListener(new KeyAdapter() {
     57            @Override
     58            public void keyReleased(KeyEvent e) {
     59                // navigate history down/up using the corresponding arrow keys.
     60                try {
     61                    final HistoryOsmPrimitive ref = model.getReferencePointInTime();
     62                    final HistoryOsmPrimitive cur = model.getCurrentPointInTime();
     63                    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
     64                        // compute both values first and set them afterwards such that nothing is changed in case of an exception (e.g., reached top/bottom)
     65                        final HistoryOsmPrimitive refNext = model.getHistory().from(ref.getVersion()).sortAscending().get(1);
     66                        final HistoryOsmPrimitive curNext = model.getHistory().from(cur.getVersion()).sortAscending().get(1);
     67                        model.setReferencePointInTime(refNext);
     68                        model.setCurrentPointInTime(curNext);
     69                    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
     70                        // compute both values first and set them afterwards such that nothing is changed in case of an exception (e.g., reached top/bottom)
     71                        final HistoryOsmPrimitive refNext = model.getHistory().until(ref.getVersion()).sortDescending().get(1);
     72                        final HistoryOsmPrimitive curNext = model.getHistory().until(cur.getVersion()).sortDescending().get(1);
     73                        model.setReferencePointInTime(refNext);
     74                        model.setCurrentPointInTime(curNext);
     75                    }
     76                } catch (NullPointerException ignore) {
     77                } catch (IndexOutOfBoundsException ignore) {
     78                }
     79            }
     80        });
    5481        getModel().addTableModelListener(new TableModelListener() {
    5582            @Override
Note: See TracChangeset for help on using the changeset viewer.