Search in sources :

Example 1 with InputContext

use of java.awt.im.InputContext in project processing by processing.

the class FileTextFieldTransferHandler method importData.

@Override
public boolean importData(JComponent comp, Transferable t) {
    JTextComponent c = (JTextComponent) comp;
    // knows not to remove any data
    if (c == exportComp && c.getCaretPosition() >= p0 && c.getCaretPosition() <= p1) {
        shouldRemove = false;
        return true;
    }
    boolean imported = false;
    if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        InputContext ic = c.getInputContext();
        if (ic != null) {
            ic.endComposition();
        }
        try {
            List<?> list = (List<?>) t.getTransferData(DataFlavor.javaFileListFlavor);
            if (list.size() > 0) {
                File file = (File) list.get(0);
                switch(fileSelectionMode) {
                    case JFileChooser.FILES_AND_DIRECTORIES:
                        break;
                    case JFileChooser.FILES_ONLY:
                        if (file.isDirectory()) {
                            return false;
                        }
                        break;
                    case JFileChooser.DIRECTORIES_ONLY:
                        if (!file.isDirectory()) {
                            return false;
                        }
                        break;
                }
                if (fileFilter != null && !fileFilter.accept(file)) {
                    return false;
                }
                c.setText(file.getPath());
            }
            imported = true;
        } catch (UnsupportedFlavorException ex) {
        //   ex.printStackTrace();
        } catch (IOException ex) {
        //   ex.printStackTrace();
        }
    }
    if (!imported) {
        DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
        if (importFlavor != null) {
            InputContext ic = c.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                //                    String text = (String) t.getTransferData(DataFlavor.stringFlavor);
                Reader r = importFlavor.getReaderForText(t);
                boolean useRead = false;
                handleReaderImport(r, c, useRead);
                imported = true;
            } catch (UnsupportedFlavorException ex) {
            //   ex.printStackTrace();
            } catch (BadLocationException ex) {
            //   ex.printStackTrace();
            } catch (IOException ex) {
            //   ex.printStackTrace();
            }
        }
    }
    return imported;
}
Also used : InputContext(java.awt.im.InputContext)

Example 2 with InputContext

use of java.awt.im.InputContext in project jdk8u_jdk by JetBrains.

the class InputContextTest method main.

public static void main(String[] args) throws Exception {
    Frame frame = new Frame();
    InputContext ic = frame.getInputContext();
    // 4151222
    try {
        ic.removeNotify(null);
        throw new Exception("InputContext.removeNotify(null) doesn't throw NullPointerException");
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            throw new Exception("InputContext.removeNotify(null) throws " + e + " instead of NullPointerException.");
        }
    }
    // 4150206
    try {
        ic.selectInputMethod(null);
        throw new Exception("InputContext.selectInputMethod(null) doesn't throw NullPointerException");
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            throw new Exception("InputContext.selectInputMethod(null) throws " + e + " instead of NullPointerException.");
        }
    }
    // 4243948
    try {
        ic.selectInputMethod(Locale.JAPANESE);
    } catch (Exception e) {
        throw new Exception("InputContext.selectInputMethod(Locale) throws " + e);
    }
}
Also used : Frame(java.awt.Frame) InputContext(java.awt.im.InputContext)

Example 3 with InputContext

use of java.awt.im.InputContext in project jdk8u_jdk by JetBrains.

the class Component method enableInputMethods.

/**
     * Enables or disables input method support for this component. If input
     * method support is enabled and the component also processes key events,
     * incoming events are offered to
     * the current input method and will only be processed by the component or
     * dispatched to its listeners if the input method does not consume them.
     * By default, input method support is enabled.
     *
     * @param enable true to enable, false to disable
     * @see #processKeyEvent
     * @since 1.2
     */
public void enableInputMethods(boolean enable) {
    if (enable) {
        if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
            return;
        // event.
        if (isFocusOwner()) {
            InputContext inputContext = getInputContext();
            if (inputContext != null) {
                FocusEvent focusGainedEvent = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
                inputContext.dispatchEvent(focusGainedEvent);
            }
        }
        eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
    } else {
        if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
            InputContext inputContext = getInputContext();
            if (inputContext != null) {
                inputContext.endComposition();
                inputContext.removeNotify(this);
            }
        }
        eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
    }
}
Also used : InputContext(java.awt.im.InputContext) CausedFocusEvent(sun.awt.CausedFocusEvent)

Example 4 with InputContext

use of java.awt.im.InputContext in project jdk8u_jdk by JetBrains.

the class JFormattedTextField method processFocusEvent.

/**
     * Processes any focus events, such as
     * <code>FocusEvent.FOCUS_GAINED</code> or
     * <code>FocusEvent.FOCUS_LOST</code>.
     *
     * @param e the <code>FocusEvent</code>
     * @see FocusEvent
     */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);
    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }
    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }
        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    } else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
Also used : InputContext(java.awt.im.InputContext)

Example 5 with InputContext

use of java.awt.im.InputContext in project intellij-community by JetBrains.

the class IdeKeyEventDispatcher method inInitState.

private boolean inInitState() {
    Component focusOwner = myContext.getFocusOwner();
    boolean isModalContext = myContext.isModalContext();
    DataContext dataContext = myContext.getDataContext();
    KeyEvent e = myContext.getInputEvent();
    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (myLeftCtrlPressed && myRightAltPressed && focusOwner != null && e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) {
        if (Registry.is("actionSystem.force.alt.gr")) {
            return false;
        }
        final InputContext inputContext = focusOwner.getInputContext();
        if (inputContext != null) {
            Locale locale = inputContext.getLocale();
            if (locale != null) {
                @NonNls final String language = locale.getLanguage();
                if (ALT_GR_LAYOUTS.contains(language)) {
                    // don't search for shortcuts
                    return false;
                }
            }
        }
    }
    KeyStroke originalKeyStroke = KeyStrokeAdapter.getDefaultKeyStroke(e);
    if (originalKeyStroke == null) {
        return false;
    }
    KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke);
    if (myKeyGestureProcessor.processInitState()) {
        return true;
    }
    if (SystemInfo.isMac) {
        boolean keyTyped = e.getID() == KeyEvent.KEY_TYPED;
        boolean hasMnemonicsInWindow = e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode()) || keyTyped && hasMnemonicInWindow(focusOwner, e.getKeyChar());
        boolean imEnabled = IdeEventQueue.getInstance().isInputMethodEnabled();
        if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK && (hasMnemonicsInWindow || !imEnabled && keyTyped)) {
            setPressedWasProcessed(true);
            setState(KeyState.STATE_PROCESSED);
            return false;
        }
    }
    updateCurrentContext(focusOwner, new KeyboardShortcut(keyStroke, null), isModalContext);
    if (myContext.getActions().isEmpty()) {
        // there's nothing mapped for this stroke
        return false;
    }
    if (myContext.isHasSecondStroke()) {
        myFirstKeyStroke = keyStroke;
        final ArrayList<Pair<AnAction, KeyStroke>> secondKeyStrokes = getSecondKeystrokeActions();
        final Project project = CommonDataKeys.PROJECT.getData(dataContext);
        StringBuilder message = new StringBuilder();
        message.append(KeyMapBundle.message("prefix.key.pressed.message"));
        message.append(' ');
        for (int i = 0; i < secondKeyStrokes.size(); i++) {
            Pair<AnAction, KeyStroke> pair = secondKeyStrokes.get(i);
            if (i > 0)
                message.append(", ");
            message.append(pair.getFirst().getTemplatePresentation().getText());
            message.append(" (");
            message.append(KeymapUtil.getKeystrokeText(pair.getSecond()));
            message.append(")");
        }
        StatusBar.Info.set(message.toString(), project);
        mySecondStrokeTimeout.cancelAllRequests();
        mySecondStrokeTimeout.addRequest(mySecondStrokeTimeoutRunnable, Registry.intValue("actionSystem.secondKeystrokeTimeout"));
        if (Registry.is("actionSystem.secondKeystrokeAutoPopupEnabled")) {
            mySecondKeystrokePopupTimeout.cancelAllRequests();
            if (secondKeyStrokes.size() > 1) {
                final DataContext oldContext = myContext.getDataContext();
                mySecondKeystrokePopupTimeout.addRequest(() -> {
                    if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
                        StatusBar.Info.set(null, CommonDataKeys.PROJECT.getData(oldContext));
                        new SecondaryKeystrokePopup(myFirstKeyStroke, secondKeyStrokes, oldContext).showInBestPositionFor(oldContext);
                    }
                }, Registry.intValue("actionSystem.secondKeystrokePopupTimeout"));
            }
        }
        setState(KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE);
        return true;
    } else {
        return processAction(e, myActionProcessor);
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) InputContext(java.awt.im.InputContext) KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) JTextComponent(javax.swing.text.JTextComponent) Pair(com.intellij.openapi.util.Pair)

Aggregations

InputContext (java.awt.im.InputContext)8 ComponentPeer (java.awt.peer.ComponentPeer)2 CausedFocusEvent (sun.awt.CausedFocusEvent)2 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 Frame (java.awt.Frame)1 KeyEvent (java.awt.event.KeyEvent)1 LightweightPeer (java.awt.peer.LightweightPeer)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JTextComponent (javax.swing.text.JTextComponent)1 NonNls (org.jetbrains.annotations.NonNls)1 Nullable (org.jetbrains.annotations.Nullable)1 AppContext (sun.awt.AppContext)1 SunToolkit (sun.awt.SunToolkit)1 WindowClosingListener (sun.awt.WindowClosingListener)1 SunDropTargetEvent (sun.awt.dnd.SunDropTargetEvent)1 CompositionArea (sun.awt.im.CompositionArea)1