Search in sources :

Example 1 with InputMethodEvent

use of java.awt.event.InputMethodEvent in project intellij-community by JetBrains.

the class AddRepositoryLocationDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JLabel selectText = new JLabel(message("repository.browser.add.location.prompt"));
    selectText.setUI(new MultiLineLabelUI());
    JPanel mainPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, NORTHWEST, NONE, insets(5), 0, 0);
    mainPanel.add(selectText, gb);
    ++gb.gridy;
    myCombo = new ComboBox<>(new CollectionComboBoxModel<>(myPreviousLocations));
    myCombo.setEditable(true);
    myCombo.setMinimumSize(size(250, 20));
    gb.fill = HORIZONTAL;
    mainPanel.add(myCombo, gb);
    gb.fill = NONE;
    myComboField = (JTextField) myCombo.getEditor().getEditorComponent();
    myComboField.addInputMethodListener(new InputMethodListener() {

        public void inputMethodTextChanged(InputMethodEvent event) {
            validateMe();
        }

        public void caretPositionChanged(InputMethodEvent event) {
            validateMe();
        }
    });
    myComboField.addKeyListener(new KeyListener() {

        public void keyTyped(KeyEvent e) {
            validateMe();
        }

        public void keyPressed(KeyEvent e) {
            validateMe();
        }

        public void keyReleased(KeyEvent e) {
            validateMe();
        }
    });
    myCombo.addActionListener(e -> validateMe());
    validateMe();
    JPanel wrapper = new JPanel(new GridBagLayout());
    wrapper.add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, NORTHWEST, HORIZONTAL, emptyInsets(), 0, 0));
    wrapper.setPreferredSize(size(400, 70));
    return wrapper;
}
Also used : MultiLineLabelUI(com.intellij.openapi.ui.MultiLineLabelUI) KeyEvent(java.awt.event.KeyEvent) GridBagConstraints(java.awt.GridBagConstraints) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) InputMethodListener(java.awt.event.InputMethodListener) KeyListener(java.awt.event.KeyListener) InputMethodEvent(java.awt.event.InputMethodEvent)

Example 2 with InputMethodEvent

use of java.awt.event.InputMethodEvent in project jdk8u_jdk by JetBrains.

the class X11InputMethod method postInputMethodEvent.

/**
     * Creates an input method event from the arguments given
     * and posts it on the AWT event queue. For arguments,
     * see InputMethodEvent. Called by input method.
     *
     * @see java.awt.event.InputMethodEvent#InputMethodEvent
     */
private void postInputMethodEvent(int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition, long when) {
    Component source = getClientComponent();
    if (source != null) {
        InputMethodEvent event = new InputMethodEvent(source, id, when, text, committedCharacterCount, caret, visiblePosition);
        SunToolkit.postEvent(SunToolkit.targetToAppContext(source), (AWTEvent) event);
    }
}
Also used : InputMethodEvent(java.awt.event.InputMethodEvent) Component(java.awt.Component)

Example 3 with InputMethodEvent

use of java.awt.event.InputMethodEvent in project jdk8u_jdk by JetBrains.

the class InputMethodContext method dispatchCommittedText.

/**
     * Dispatches committed text to a client component.
     * Called by composition window.
     *
     * @param client The component that the text should get dispatched to.
     * @param text The iterator providing access to the committed
     *        (and possible composed) text.
     * @param committedCharacterCount The number of committed characters in the text.
     */
synchronized void dispatchCommittedText(Component client, AttributedCharacterIterator text, int committedCharacterCount) {
    // the event was in the queue.
    if (committedCharacterCount == 0 || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted = (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();
            InputMethodEvent inputEvent = new InputMethodEvent(client, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, toBeCommitted, committedCharacterCount, null, null);
            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED, time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) AttributedString(java.text.AttributedString) InputMethodRequests(java.awt.im.InputMethodRequests) InputMethodEvent(java.awt.event.InputMethodEvent) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 4 with InputMethodEvent

use of java.awt.event.InputMethodEvent in project jdk8u_jdk by JetBrains.

the class bug8041990 method main.

public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();
        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();
        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component, InputMethodEvent.CARET_POSITION_CHANGED, TextHitInfo.leading(0), TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();
        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) AtomicReference(java.util.concurrent.atomic.AtomicReference) InputMethodEvent(java.awt.event.InputMethodEvent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with InputMethodEvent

use of java.awt.event.InputMethodEvent in project jdk8u_jdk by JetBrains.

the class bug6636983 method sendInputMethodEvent.

void sendInputMethodEvent() {
    InputMethodEvent ime = new InputMethodEvent(ep, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, Hiragana_A.getIterator(), 0, null, null);
    ep.dispatchEvent(ime);
}
Also used : InputMethodEvent(java.awt.event.InputMethodEvent)

Aggregations

InputMethodEvent (java.awt.event.InputMethodEvent)7 Component (java.awt.Component)3 KeyEvent (java.awt.event.KeyEvent)2 MultiLineLabelUI (com.intellij.openapi.ui.MultiLineLabelUI)1 CollectionComboBoxModel (com.intellij.ui.CollectionComboBoxModel)1 GridBagConstraints (java.awt.GridBagConstraints)1 FocusEvent (java.awt.event.FocusEvent)1 InputEvent (java.awt.event.InputEvent)1 InputMethodListener (java.awt.event.InputMethodListener)1 KeyListener (java.awt.event.KeyListener)1 InputMethodRequests (java.awt.im.InputMethodRequests)1 InputMethod (java.awt.im.spi.InputMethod)1 AttributedCharacterIterator (java.text.AttributedCharacterIterator)1 AttributedString (java.text.AttributedString)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SunToolkit (sun.awt.SunToolkit)1