Changeset 7609 in josm


Ignore:
Timestamp:
2014-10-11T17:27:50+02:00 (5 years ago)
Author:
akks
Message:

Main.map.keyDetector was incorrectly skipping key release events,
happened when the dialog was opening on key press (i.e. in FastDraw plugin)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/AdvancedKeyPressDetector.java

    r7539 r7609  
    125125            } else if (set.add((e.getKeyCode())) && enabled) {
    126126                synchronized (this) {
    127                     for (KeyPressReleaseListener q: keyListeners) {
    128                         q.doKeyPressed(e);
     127                    if (isFocusInMainWindow()) {
     128                        for (KeyPressReleaseListener q: keyListeners) {
     129                            q.doKeyPressed(e);
     130                        }
    129131                    }
    130132                }
     
    135137                if (set.remove(e.getKeyCode()) && enabled) {
    136138                    synchronized (this) {
    137                         for (KeyPressReleaseListener q: keyListeners) {
    138                             q.doKeyReleased(e);
     139                        if (isFocusInMainWindow()) {
     140                            for (KeyPressReleaseListener q: keyListeners) {
     141                                q.doKeyReleased(e);
     142                            }
    139143                        }
    140144                    }
     
    165169        }
    166170
    167         // check if key press is done in main window, not in dialogs
    168         Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    169         if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) {
    170             processKeyEvent(ke);
    171         }
     171        processKeyEvent(ke);
    172172    }
    173173
     
    190190        this.enabled = enabled;
    191191    }
     192
     193    private boolean isFocusInMainWindow() {
     194        Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
     195        return SwingUtilities.getWindowAncestor(focused) instanceof JFrame;
     196    }
    192197}
Note: See TracChangeset for help on using the changeset viewer.