Search in sources :

Example 61 with KeyEvent

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

the class UIManager method initialize.

/*
     * Only called by maybeInitialize().
     */
private static void initialize() {
    Properties swingProps = loadSwingProperties();
    initializeSystemDefaults(swingProps);
    initializeDefaultLAF(swingProps);
    initializeAuxiliaryLAFs(swingProps);
    initializeInstalledLAFs(swingProps);
    // Install Swing's PaintEventDispatcher
    if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
        sun.awt.PaintEventDispatcher.setPaintEventDispatcher(new SwingPaintEventDispatcher());
    }
    // Install a hook that will be invoked if no one consumes the
    // KeyEvent.  If the source isn't a JComponent this will process
    // key bindings, if the source is a JComponent it implies that
    // processKeyEvent was already invoked and thus no need to process
    // the bindings again, unless the Component is disabled, in which
    // case KeyEvents will no longer be dispatched to it so that we
    // handle it here.
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor() {

        public boolean postProcessKeyEvent(KeyEvent e) {
            Component c = e.getComponent();
            if ((!(c instanceof JComponent) || (c != null && !c.isEnabled())) && JComponent.KeyboardState.shouldProcess(e) && SwingUtilities.processKeyBindings(e)) {
                e.consume();
                return true;
            }
            return false;
        }
    });
    AWTAccessor.getComponentAccessor().setRequestFocusController(JComponent.focusController);
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyEventPostProcessor(java.awt.KeyEventPostProcessor) Properties(java.util.Properties) Component(java.awt.Component)

Example 62 with KeyEvent

use of java.awt.event.KeyEvent 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 63 with KeyEvent

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

the class KeyboardFocusManager method retargetFocusEvent.

static AWTEvent retargetFocusEvent(AWTEvent event) {
    if (clearingCurrentLightweightRequests) {
        return event;
    }
    KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        if (event instanceof FocusEvent || event instanceof WindowEvent) {
            focusLog.finer(">>> {0}", String.valueOf(event));
        }
        if (focusLog.isLoggable(PlatformLogger.Level.FINER) && event instanceof KeyEvent) {
            focusLog.finer("    focus owner is {0}", String.valueOf(manager.getGlobalFocusOwner()));
            focusLog.finer(">>> {0}", String.valueOf(event));
        }
    }
    synchronized (heavyweightRequests) {
        /*
             * This code handles FOCUS_LOST event which is generated by
             * DefaultKeyboardFocusManager for FOCUS_GAINED.
             *
             * This code based on knowledge of DefaultKeyboardFocusManager's
             * implementation and might be not applicable for another
             * KeyboardFocusManager.
             *
             * Fix for 4472032
             */
        if (newFocusOwner != null && event.getID() == FocusEvent.FOCUS_LOST) {
            FocusEvent fe = (FocusEvent) event;
            if (manager.getGlobalFocusOwner() == fe.getComponent() && fe.getOppositeComponent() == newFocusOwner) {
                newFocusOwner = null;
                return event;
            }
        }
    }
    processCurrentLightweightRequests();
    switch(event.getID()) {
        case FocusEvent.FOCUS_GAINED:
            {
                event = retargetFocusGained((FocusEvent) event);
                break;
            }
        case FocusEvent.FOCUS_LOST:
            {
                event = retargetFocusLost((FocusEvent) event);
                break;
            }
        default:
    }
    return event;
}
Also used : KeyEvent(java.awt.event.KeyEvent) WindowEvent(java.awt.event.WindowEvent) CausedFocusEvent(sun.awt.CausedFocusEvent) FocusEvent(java.awt.event.FocusEvent)

Example 64 with KeyEvent

use of java.awt.event.KeyEvent in project intellij-plugins by JetBrains.

the class ChooseBuildConfigurationDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    List<Module> modules = new ArrayList<>(myTreeItems.keySet());
    Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    for (Module module : modules) {
        DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
        root.add(moduleNode);
        List<FlexBCConfigurable> bcs = myTreeItems.get(module);
        Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
        for (FlexBCConfigurable bc : bcs) {
            DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
            moduleNode.add(bcNode);
        }
    }
    myTree.setModel(new DefaultTreeModel(root));
    myTree.setRootVisible(false);
    new TreeSpeedSearch(myTree, o -> {
        Object lastPathComponent = o.getLastPathComponent();
        return getText((DefaultMutableTreeNode) lastPathComponent);
    }, true).setComparator(new SpeedSearchComparator(false));
    TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateOnSelectionChange();
        }
    });
    myTree.setCellRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
            Object object = treeNode.getUserObject();
            if (object instanceof Module) {
                Module module = (Module) object;
                setIcon(ModuleType.get(module).getIcon());
                append(module.getName());
            } else if (object instanceof FlexBCConfigurable) {
                FlexBCConfigurable configurable = (FlexBCConfigurable) object;
                setIcon(configurable.getIcon());
                BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
            }
        }
    });
    TreeUtil.expandAll(myTree);
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (mySelection != null) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                doOKAction();
            }
        }
    });
    updateOnSelectionChange();
    return myContentPane;
}
Also used : FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) HashMap(com.intellij.util.containers.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) ModuleStructureConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) KeyEvent(java.awt.event.KeyEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module)

Example 65 with KeyEvent

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

the class DefaultKeyboardFocusManager method purgeStampedEvents.

// Notes:
//   * must be called inside a synchronized block
//   * if 'start' is < 0, then this function does nothing
//   * if 'end' is < 0, then all KeyEvents from 'start' to the end of the
//     queue will be removed
private void purgeStampedEvents(long start, long end) {
    if (start < 0) {
        return;
    }
    for (Iterator<KeyEvent> iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
        KeyEvent ke = iter.next();
        long time = ke.getWhen();
        if (start < time && (end < 0 || time <= end)) {
            iter.remove();
        }
        if (end >= 0 && time > end) {
            break;
        }
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent)

Aggregations

KeyEvent (java.awt.event.KeyEvent)301 KeyAdapter (java.awt.event.KeyAdapter)159 MouseEvent (java.awt.event.MouseEvent)79 ActionEvent (java.awt.event.ActionEvent)74 JPanel (javax.swing.JPanel)69 ActionListener (java.awt.event.ActionListener)61 MouseAdapter (java.awt.event.MouseAdapter)59 KeyListener (java.awt.event.KeyListener)54 Dimension (java.awt.Dimension)50 JLabel (javax.swing.JLabel)48 JTextField (javax.swing.JTextField)44 BorderLayout (java.awt.BorderLayout)40 JButton (javax.swing.JButton)40 JScrollPane (javax.swing.JScrollPane)35 Insets (java.awt.Insets)33 Point (java.awt.Point)33 FocusEvent (java.awt.event.FocusEvent)31 GridBagConstraints (java.awt.GridBagConstraints)23 BoxLayout (javax.swing.BoxLayout)22 GridBagLayout (java.awt.GridBagLayout)20