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;
}
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);
}
}
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;
}
}
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();
}
}
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);
}
Aggregations