Java Code Examples for java.awt.AWTEvent#getID()

The following examples show how to use java.awt.AWTEvent#getID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DitherTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
Example 2
Source File: DitherTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
Example 3
Source File: DitherTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
Example 4
Source File: RComponent.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void handleRawRecording(IJSONRecorder recorder, AWTEvent event) {
    if (event instanceof MouseEvent && event.getID() == MouseEvent.MOUSE_PRESSED) {
        recorder.recordRawMouseEvent(this, (MouseEvent) event);
    }
    if (event instanceof KeyEvent && event.getID() != KeyEvent.KEY_RELEASED) {
        recorder.recordRawKeyEvent(this, (KeyEvent) event);
    }
}
 
Example 5
Source File: TracedEventQueue.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void postEvent(AWTEvent theEvent) {
    boolean printEvent = true;
    int id = theEvent.getID();
    for (int i = 0; i < suppressedIDs.length; i++) {
        if (id == suppressedIDs[i]) {
            printEvent = false;
            break;
        }
    }
    if (printEvent) {
        System.out.println(Thread.currentThread().getName() +
                           ": " + theEvent);
    }
    super.postEvent(theEvent);
}
 
Example 6
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
void handleJavaFocusEvent(AWTEvent e) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer(e.toString());
    }
    if (e.getID() == FocusEvent.FOCUS_GAINED) {
        focusGained((FocusEvent)e);
    } else {
        focusLost((FocusEvent)e);
    }
}
 
Example 7
Source File: TracedEventQueue.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void postEvent(AWTEvent theEvent) {
    boolean printEvent = true;
    int id = theEvent.getID();
    for (int i = 0; i < suppressedIDs.length; i++) {
        if (id == suppressedIDs[i]) {
            printEvent = false;
            break;
        }
    }
    if (printEvent) {
        System.out.println(Thread.currentThread().getName() +
                           ": " + theEvent);
    }
    super.postEvent(theEvent);
}
 
Example 8
Source File: DropdownButton.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void processEventImpl(AWTEvent e) {
    super.processEvent(e);
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        if (isFocusable()) requestFocus();
        else button.requestFocus();
    }
}
 
Example 9
Source File: ContainerFocusAutoTransferTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean dispatchEvent(AWTEvent e) {
    if (e.getID() == FocusEvent.FOCUS_GAINED) {
        System.out.println(e);
        Component src = (Component)e.getSource();
        if (src == frame.b1 || src == frame.b2) {
            throw new TestFailedException("wrong focus transfer on removal!");
        }
    }
    return super.dispatchEvent(e);
}
 
Example 10
Source File: TracedEventQueue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void postEvent(AWTEvent theEvent) {
    boolean printEvent = true;
    int id = theEvent.getID();
    for (int i = 0; i < suppressedIDs.length; i++) {
        if (id == suppressedIDs[i]) {
            printEvent = false;
            break;
        }
    }
    if (printEvent) {
        System.out.println(Thread.currentThread().getName() +
                           ": " + theEvent);
    }
    super.postEvent(theEvent);
}
 
Example 11
Source File: AppletFrame.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void processEvent(AWTEvent e) {
    // Window Destroy event
    if (e.getID() == Event.WINDOW_DESTROY) {
        // exit the program
        System.exit(0);
    }
}
 
Example 12
Source File: XComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void handleJavaFocusEvent(AWTEvent e) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer(e.toString());
    }
    if (e.getID() == FocusEvent.FOCUS_GAINED) {
        focusGained((FocusEvent)e);
    } else {
        focusLost((FocusEvent)e);
    }
}
 
Example 13
Source File: NbClipboard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void eventDispatched(AWTEvent ev) {
    if (!(ev instanceof WindowEvent))
        return;

    if (ev.getID() == WindowEvent.WINDOW_DEACTIVATED) {
        lastWindowDeactivated = System.currentTimeMillis();
        lastWindowDeactivatedSource = new WeakReference<Object>(ev.getSource());
        anyWindowIsActivated = false;
        if( Utilities.isWindows() ) {
            //#247585 - even listening to clipboard changes when the window isn't active 
            //may throw a MS Windows error as the 'clipboard copy' action doesn't have enough time to finish
            systemClipboard.removeFlavorListener(this);
        }
    }
    if (ev.getID() == WindowEvent.WINDOW_ACTIVATED) {
        if( Utilities.isWindows() ) {
            systemClipboard.addFlavorListener(this);
        }
        anyWindowIsActivated = true;
        if (System.currentTimeMillis() - lastWindowDeactivated < 100 &&
            ev.getSource() == lastWindowDeactivatedSource.get()) {
            activateWindowHack (false);
        }
        if (log.isLoggable (Level.FINE)) {
            log.log (Level.FINE, "window activated scheduling update"); // NOI18N
        }
        scheduleGetFromSystemClipboard(true);
    }
}
 
Example 14
Source File: ContainerFocusAutoTransferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean dispatchEvent(AWTEvent e) {
    if (e.getID() == FocusEvent.FOCUS_GAINED) {
        System.out.println(e);
        Component src = (Component)e.getSource();
        if (src == frame.b1 || src == frame.b2) {
            throw new TestFailedException("wrong focus transfer on removal!");
        }
    }
    return super.dispatchEvent(e);
}
 
Example 15
Source File: InputContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.im.InputContext#dispatchEvent
 */
@SuppressWarnings("fallthrough")
public void dispatchEvent(AWTEvent event) {

    if (event instanceof InputMethodEvent) {
        return;
    }

    // Ignore focus events that relate to the InputMethodWindow of this context.
    // This is a workaround.  Should be removed after 4452384 is fixed.
    if (event instanceof FocusEvent) {
        Component opposite = ((FocusEvent)event).getOppositeComponent();
        if ((opposite != null) &&
            (getComponentWindow(opposite) instanceof InputMethodWindow) &&
            (opposite.getInputContext() == this)) {
            return;
        }
    }

    InputMethod inputMethod = getInputMethod();
    int id = event.getID();

    switch (id) {
    case FocusEvent.FOCUS_GAINED:
        focusGained((Component) event.getSource());
        break;

    case FocusEvent.FOCUS_LOST:
        focusLost((Component) event.getSource(), ((FocusEvent) event).isTemporary());
        break;

    case KeyEvent.KEY_PRESSED:
        if (checkInputMethodSelectionKey((KeyEvent)event)) {
            // pop up the input method selection menu
            InputMethodManager.getInstance().notifyChangeRequestByHotKey((Component)event.getSource());
            break;
        }

        // fall through

    default:
        if ((inputMethod != null) && (event instanceof InputEvent)) {
            inputMethod.dispatchEvent(event);
        }
    }
}
 
Example 16
Source File: CodePointInputMethod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This is the input method's main routine.  The composed text is stored
 * in buffer.
 */
public void dispatchEvent(AWTEvent event) {
    // This input method handles KeyEvent only.
    if (!(event instanceof KeyEvent)) {
        return;
    }

    KeyEvent e = (KeyEvent) event;
    int eventID = event.getID();
    boolean notInCompositionMode = buffer.length() == 0;

    if (eventID == KeyEvent.KEY_PRESSED) {
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }

        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                moveCaretLeft();
                break;
            case KeyEvent.VK_RIGHT:
                moveCaretRight();
                break;
        }
    } else if (eventID == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();

        // If we are not in composition mode, wait a back slash
        if (notInCompositionMode) {
            // If the type character is not a back slash, pass through
            if (c != '\\') {
                return;
            }

            startComposition();     // Enter to composition mode
        } else {
            switch (c) {
                case ' ':       // Exit from composition mode
                    finishComposition();
                    break;
                case '\u007f':  // Delete
                    deleteCharacter();
                    break;
                case '\b':      // BackSpace
                    deletePreviousCharacter();
                    break;
                case '\u001b':  // Escape
                    cancelComposition();
                    break;
                case '\n':      // Return
                case '\t':      // Tab
                    sendCommittedText();
                    break;
                default:
                    composeUnicodeEscape(c);
                    break;
            }
        }
    } else {  // KeyEvent.KEY_RELEASED
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }
    }

    e.consume();
}
 
Example 17
Source File: InputContext.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.im.InputContext#dispatchEvent
 */
@SuppressWarnings("fallthrough")
public void dispatchEvent(AWTEvent event) {

    if (event instanceof InputMethodEvent) {
        return;
    }

    // Ignore focus events that relate to the InputMethodWindow of this context.
    // This is a workaround.  Should be removed after 4452384 is fixed.
    if (event instanceof FocusEvent) {
        Component opposite = ((FocusEvent)event).getOppositeComponent();
        if ((opposite != null) &&
            (getComponentWindow(opposite) instanceof InputMethodWindow) &&
            (opposite.getInputContext() == this)) {
            return;
        }
    }

    InputMethod inputMethod = getInputMethod();
    int id = event.getID();

    switch (id) {
    case FocusEvent.FOCUS_GAINED:
        focusGained((Component) event.getSource());
        break;

    case FocusEvent.FOCUS_LOST:
        focusLost((Component) event.getSource(), ((FocusEvent) event).isTemporary());
        break;

    case KeyEvent.KEY_PRESSED:
        if (checkInputMethodSelectionKey((KeyEvent)event)) {
            // pop up the input method selection menu
            InputMethodManager.getInstance().notifyChangeRequestByHotKey((Component)event.getSource());
            break;
        }

        // fall through

    default:
        if ((inputMethod != null) && (event instanceof InputEvent)) {
            inputMethod.dispatchEvent(event);
        }
    }
}
 
Example 18
Source File: InputContext.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.im.InputContext#dispatchEvent
 */
@SuppressWarnings("fallthrough")
public void dispatchEvent(AWTEvent event) {

    if (event instanceof InputMethodEvent) {
        return;
    }

    // Ignore focus events that relate to the InputMethodWindow of this context.
    // This is a workaround.  Should be removed after 4452384 is fixed.
    if (event instanceof FocusEvent) {
        Component opposite = ((FocusEvent)event).getOppositeComponent();
        if ((opposite != null) &&
            (getComponentWindow(opposite) instanceof InputMethodWindow) &&
            (opposite.getInputContext() == this)) {
            return;
        }
    }

    InputMethod inputMethod = getInputMethod();
    int id = event.getID();

    switch (id) {
    case FocusEvent.FOCUS_GAINED:
        focusGained((Component) event.getSource());
        break;

    case FocusEvent.FOCUS_LOST:
        focusLost((Component) event.getSource(), ((FocusEvent) event).isTemporary());
        break;

    case KeyEvent.KEY_PRESSED:
        if (checkInputMethodSelectionKey((KeyEvent)event)) {
            // pop up the input method selection menu
            InputMethodManager.getInstance().notifyChangeRequestByHotKey((Component)event.getSource());
            break;
        }

        // fall through

    default:
        if ((inputMethod != null) && (event instanceof InputEvent)) {
            inputMethod.dispatchEvent(event);
        }
    }
}
 
Example 19
Source File: CodePointInputMethod.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This is the input method's main routine.  The composed text is stored
 * in buffer.
 */
public void dispatchEvent(AWTEvent event) {
    // This input method handles KeyEvent only.
    if (!(event instanceof KeyEvent)) {
        return;
    }

    KeyEvent e = (KeyEvent) event;
    int eventID = event.getID();
    boolean notInCompositionMode = buffer.length() == 0;

    if (eventID == KeyEvent.KEY_PRESSED) {
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }

        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                moveCaretLeft();
                break;
            case KeyEvent.VK_RIGHT:
                moveCaretRight();
                break;
        }
    } else if (eventID == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();

        // If we are not in composition mode, wait a back slash
        if (notInCompositionMode) {
            // If the type character is not a back slash, pass through
            if (c != '\\') {
                return;
            }

            startComposition();     // Enter to composition mode
        } else {
            switch (c) {
                case ' ':       // Exit from composition mode
                    finishComposition();
                    break;
                case '\u007f':  // Delete
                    deleteCharacter();
                    break;
                case '\b':      // BackSpace
                    deletePreviousCharacter();
                    break;
                case '\u001b':  // Escape
                    cancelComposition();
                    break;
                case '\n':      // Return
                case '\t':      // Tab
                    sendCommittedText();
                    break;
                default:
                    composeUnicodeEscape(c);
                    break;
            }
        }
    } else {  // KeyEvent.KEY_RELEASED
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }
    }

    e.consume();
}
 
Example 20
Source File: CodePointInputMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This is the input method's main routine.  The composed text is stored
 * in buffer.
 */
public void dispatchEvent(AWTEvent event) {
    // This input method handles KeyEvent only.
    if (!(event instanceof KeyEvent)) {
        return;
    }

    KeyEvent e = (KeyEvent) event;
    int eventID = event.getID();
    boolean notInCompositionMode = buffer.length() == 0;

    if (eventID == KeyEvent.KEY_PRESSED) {
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }

        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                moveCaretLeft();
                break;
            case KeyEvent.VK_RIGHT:
                moveCaretRight();
                break;
        }
    } else if (eventID == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();

        // If we are not in composition mode, wait a back slash
        if (notInCompositionMode) {
            // If the type character is not a back slash, pass through
            if (c != '\\') {
                return;
            }

            startComposition();     // Enter to composition mode
        } else {
            switch (c) {
                case ' ':       // Exit from composition mode
                    finishComposition();
                    break;
                case '\u007f':  // Delete
                    deleteCharacter();
                    break;
                case '\b':      // BackSpace
                    deletePreviousCharacter();
                    break;
                case '\u001b':  // Escape
                    cancelComposition();
                    break;
                case '\n':      // Return
                case '\t':      // Tab
                    sendCommittedText();
                    break;
                default:
                    composeUnicodeEscape(c);
                    break;
            }
        }
    } else {  // KeyEvent.KEY_RELEASED
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }
    }

    e.consume();
}