@SuppressWarnings("unchecked") public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (ComponentListener.class.isAssignableFrom(listenerType)) { return (T[]) getComponentListeners(); } else if (FocusListener.class.isAssignableFrom(listenerType)) { return (T[]) getFocusListeners(); } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyBoundsListeners(); } else if (HierarchyListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyListeners(); } else if (InputMethodListener.class.isAssignableFrom(listenerType)) { return (T[]) getInputMethodListeners(); } else if (KeyListener.class.isAssignableFrom(listenerType)) { return (T[]) getKeyListeners(); } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseWheelListeners(); } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseMotionListeners(); } else if (MouseListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseListeners(); } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) { return (T[]) getPropertyChangeListeners(); } return (T[]) Array.newInstance(listenerType, 0); }
/** * Maps {@code Component.addInputMethodListener(InputMethodListener)} * through queue */ public void addInputMethodListener(final InputMethodListener inputMethodListener) { runMapping(new MapVoidAction("addInputMethodListener") { @Override public void map() { getSource().addInputMethodListener(inputMethodListener); } }); }
/** * Maps * {@code Component.removeInputMethodListener(InputMethodListener)} * through queue */ public void removeInputMethodListener(final InputMethodListener inputMethodListener) { runMapping(new MapVoidAction("removeInputMethodListener") { @Override public void map() { getSource().removeInputMethodListener(inputMethodListener); } }); }
@Override public void addInputMethodListener(InputMethodListener listener) { if (this.ipFields != null) { for (JIPV4Field field : this.ipFields) { field.addInputMethodListener(listener); } } }
@Override public void removeInputMethodListener(InputMethodListener listener) { if (this.ipFields != null) { for (JIPV4Field field : this.ipFields) { field.removeInputMethodListener(listener); } } }
/** * Deserializes this component. This regenerates all serializable listeners * which were registered originally. * * @param s the stream to read from * @throws ClassNotFoundException if deserialization fails * @throws IOException if the stream fails */ private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { s.defaultReadObject(); String key = (String) s.readObject(); while (key != null) { Object listener = s.readObject(); if ("componentL".equals(key)) addComponentListener((ComponentListener) listener); else if ("focusL".equals(key)) addFocusListener((FocusListener) listener); else if ("keyL".equals(key)) addKeyListener((KeyListener) listener); else if ("mouseL".equals(key)) addMouseListener((MouseListener) listener); else if ("mouseMotionL".equals(key)) addMouseMotionListener((MouseMotionListener) listener); else if ("inputMethodL".equals(key)) addInputMethodListener((InputMethodListener) listener); else if ("hierarchyL".equals(key)) addHierarchyListener((HierarchyListener) listener); else if ("hierarchyBoundsL".equals(key)) addHierarchyBoundsListener((HierarchyBoundsListener) listener); else if ("mouseWheelL".equals(key)) addMouseWheelListener((MouseWheelListener) listener); key = (String) s.readObject(); } }
/** * This method is called when the text is changed. * * @param event the <code>InputMethodEvent</code> indicating the text change */ public void inputMethodTextChanged(InputMethodEvent event) { if (applet != null) { InputMethodListener[] l = applet.getInputMethodListeners(); for (int i = 0; i < l.length; i++) l[i].inputMethodTextChanged(event); } }
/** * This method is called when the cursor position within the text is changed. * * @param event the <code>InputMethodEvent</code> indicating the change */ public void caretPositionChanged(InputMethodEvent event) { if (applet != null) { InputMethodListener[] l = applet.getInputMethodListeners(); for (int i = 0; i < l.length; i++) l[i].caretPositionChanged(event); } }
@Override public void wireComponent(final ComponentContext context) { super.wireComponent(context); final JTextComponent component = (JTextComponent) context .getComponent(); final MethodListenerProxy<InputMethodListener> inputMethodListenerProxy = new MethodListenerProxy<InputMethodListener>( InputMethodListener.class, context.getActionListeners()); if (inputMethodListenerProxy.hasListeningMethod()) { component.addInputMethodListener(inputMethodListenerProxy .getProxy()); } }
public void caretPositionChanged(InputMethodEvent e) { if ((a != null) && (a instanceof InputMethodListener)) { ((InputMethodListener) a).caretPositionChanged(e); } if ((b != null) && (b instanceof InputMethodListener)) { ((InputMethodListener) b).caretPositionChanged(e); } }
public void inputMethodTextChanged(InputMethodEvent e) { if ((a != null) && (a instanceof InputMethodListener)) { ((InputMethodListener) a).inputMethodTextChanged(e); } if ((b != null) && (b instanceof InputMethodListener)) { ((InputMethodListener) b).inputMethodTextChanged(e); } }
private void processInputMethodEventImpl(InputMethodEvent e, Collection<InputMethodListener> c) { for (InputMethodListener listener : c) { switch (e.getID()) { case InputMethodEvent.CARET_POSITION_CHANGED: listener.caretPositionChanged(e); break; case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: listener.inputMethodTextChanged(e); break; } } }
public static void processIMEvent(final InputMethodListener listener, final InputMethodEvent e) { if (e.getID() == InputMethodEvent.CARET_POSITION_CHANGED) { listener.caretPositionChanged(e); } if (e.getID() == InputMethodEvent.INPUT_METHOD_TEXT_CHANGED) { listener.inputMethodTextChanged(e); } }
public void testAddInputMethodListener() { SimpleInputMethodListener listener1 = new SimpleInputMethodListener("1"); SimpleInputMethodListener listener2 = new SimpleInputMethodListener("2"); SimpleInputMethodListener listener3 = new SimpleInputMethodListener("3"); jtc.addInputMethodListener(listener1); jtc.addInputMethodListener(listener2); jtc.addInputMethodListener(listener3); InputMethodListener listeners[] = jtc.getInputMethodListeners(); assertEquals(listener1, listeners[0]); assertEquals(listener2, listeners[1]); assertEquals(listener3, listeners[2]); assertEquals(3, listeners.length); }