Example usage for java.awt Component addInputMethodListener

List of usage examples for java.awt Component addInputMethodListener

Introduction

In this page you can find the example usage for java.awt Component addInputMethodListener.

Prototype

public synchronized void addInputMethodListener(InputMethodListener l) 

Source Link

Document

Adds the specified input method listener to receive input method events from this component.

Usage

From source file:Main.java

private static void addComponentListeners(Component c, Object... objs) {
    if (c == null)
        return;//  w  ww  . ja va  2s.  co  m
    ComponentListener componentListener = search(objs, ComponentListener.class);
    FocusListener focusListener = search(objs, FocusListener.class);
    HierarchyBoundsListener hierarchyBoundsListener = search(objs, HierarchyBoundsListener.class);
    HierarchyListener hierarchyListener = search(objs, HierarchyListener.class);
    InputMethodListener inputMethodListener = search(objs, InputMethodListener.class);
    KeyListener keyListener = search(objs, KeyListener.class);
    MouseListener mouseListener = search(objs, MouseListener.class);
    MouseMotionListener mouseMotionListener = search(objs, MouseMotionListener.class);
    MouseWheelListener mouseWheelListener = search(objs, MouseWheelListener.class);
    if (componentListener != null)
        c.addComponentListener(componentListener);
    if (focusListener != null)
        c.addFocusListener(focusListener);
    if (hierarchyBoundsListener != null)
        c.addHierarchyBoundsListener(hierarchyBoundsListener);
    if (hierarchyListener != null)
        c.addHierarchyListener(hierarchyListener);
    if (inputMethodListener != null)
        c.addInputMethodListener(inputMethodListener);
    if (keyListener != null)
        c.addKeyListener(keyListener);
    if (mouseListener != null)
        c.addMouseListener(mouseListener);
    if (mouseMotionListener != null)
        c.addMouseMotionListener(mouseMotionListener);
    if (mouseWheelListener != null)
        c.addMouseWheelListener(mouseWheelListener);
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Registers common component changes/*from w  ww . j  a  va  2  s  .co  m*/
 * @param function receives an instance of javaQuery with the changed view selected, as well as the
 * following arguments:
 * <ol>
 * <li>{@link changeEvent} to define the type of event that was triggered
 * <li>The associated event
 * </ol>
 * @return
 * @see changeEvent
 */
public $ change(final Function function) {
    for (final Component component : views) {
        component.addInputMethodListener(new InputMethodListener() {

            @Override
            public void caretPositionChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_CARET_POSITION_CHANGED, event);
            }

            @Override
            public void inputMethodTextChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_METHOD_TEXT_CHANGED, event);
            }

        });

        component.addHierarchyBoundsListener(new HierarchyBoundsListener() {

            @Override
            public void ancestorMoved(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCESTOR_MOVED, event);
            }

            @Override
            public void ancestorResized(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCENSTOR_RESIZED, event);
            }

        });

        component.addHierarchyListener(new HierarchyListener() {

            @Override
            public void hierarchyChanged(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_CHANGED, event);
            }

        });

        component.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                function.invoke($.with(component), ChangeEvent.PROPERTY_CHANGED, event);
            }
        });

        component.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_HIDDEN, event);
            }

            @Override
            public void componentMoved(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_MOVED, event);
            }

            @Override
            public void componentResized(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_RESIZED, event);
            }

            @Override
            public void componentShown(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_SHOWN, event);
            }

        });

        if (component instanceof Container) {
            ((Container) component).addContainerListener(new ContainerListener() {

                @Override
                public void componentAdded(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_ADDED, event);
                }

                @Override
                public void componentRemoved(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_REMOVED, event);
                }

            });
        }
    }
    return this;
}