/** * Adds a new listener to the list of text listeners for this * component. * * @param listener The listener to be added. */ public synchronized void addTextListener(TextListener listener) { textListener = AWTEventMulticaster.add(textListener, listener); enableEvents(AWTEvent.TEXT_EVENT_MASK); }
protected void processTextEvent(TextEvent e) { for (TextListener listener : textListeners.getUserListeners()) { switch (e.getID()) { case TextEvent.TEXT_VALUE_CHANGED: listener.textValueChanged(e); break; } } }
public void testAddRemoveTextListener() { textComp.addTextListener(listener); assertSame(listener, textComp.textListener); TextListener newListener = new MyTextListener(); textComp.addTextListener(newListener); assertTrue("if there are several listeners multicaster is used", textComp.textListener instanceof AWTEventMulticaster); AWTEventMulticaster aem = (AWTEventMulticaster) textComp.textListener; assertSame(listener, aem.a); textComp.removeTextListener(listener); assertTrue("if there is only one listener then it is used", textComp.textListener instanceof MyTextListener); assertSame(newListener, textComp.textListener); textComp.removeTextListener(newListener); assertNull(textComp.textListener); }
protected void addListeners( final GenericDialog gd, final TextField tf, final Label label1, final Label label2 ) { final GenericLoadParseQueryXML< ?,?,?,?,?,? > lpq = this; // using TextListener instead tf.addTextListener( new TextListener() { @Override public void textValueChanged( final TextEvent t ) { if ( t.getID() == TextEvent.TEXT_VALUE_CHANGED ) { final String xmlFilename = tf.getText(); // try parsing if it ends with XML tryParsing( xmlFilename, false ); label1.setText( lpq.message1 ); label2.setText( lpq.message2 ); label1.setForeground( lpq.color ); label2.setForeground( lpq.color ); } } }); }
/** * Maps {@code TextComponent.addTextListener(TextListener)} through queue */ public void addTextListener(final TextListener textListener) { runMapping(new MapVoidAction("addTextListener") { @Override public void map() { ((TextComponent) getSource()).addTextListener(textListener); } }); }
/** * Maps {@code TextComponent.removeTextListener(TextListener)} through queue */ public void removeTextListener(final TextListener textListener) { runMapping(new MapVoidAction("removeTextListener") { @Override public void map() { ((TextComponent) getSource()).removeTextListener(textListener); } }); }
private static void fireTextEvent() { EventListener[] lstrs = EVENT_LISTENER_LIST.getListeners(TextListener.class); if (lstrs != null && lstrs.length > 0) { TextEvent te = new TextEvent(FIND_REPLACE_DIALOG, TextEvent.TEXT_VALUE_CHANGED); for (int i = 0; i < lstrs.length; i++) { ((TextListener) lstrs[i]).textValueChanged(te); } } }
private JPanel createViewOne(MenuController menuController) { JPanel pnl = createFormularPanel(); // TextListener textActionListener = new TextListener() { public void textValueChanged(TextEvent e) { enableButtons(); } }; namesInputForm = new NamesFormularPanel(menuController.trans, textActionListener); namesInputForm.setLocation(2, 10); pnl.add(namesInputForm); // return pnl; }
public NamesFormularPanel(Translator trans, TextListener al) { super(); // setLayout(null); setSize(new Dimension(224, 90)); setBackground(Color.WHITE); setForeground(Color.BLACK); // // text input fields nameOfPlayerTxtField = new TextField(); nameOfPlayerTxtField.addTextListener(al); nameOfPlayerTxtField.setFont(systemFont); nameOfPlayerTxtField.setBounds(5, 5, 210, 22); add(nameOfPlayerTxtField); // nameOfPartyTxtField = new TextField(); nameOfPartyTxtField.addTextListener(al); nameOfPartyTxtField.setFont(systemFont); nameOfPartyTxtField.setBounds(5, 50, 210, 22); add(nameOfPartyTxtField); // // ... and their labels JLabel lbl = new JLabel(trans.word("menu.settings.namePlayer")); lbl.setBounds(5, 25, 210, 20); lbl.setFont(SettingsPanel.cursiveFont); add(lbl); // lbl = new JLabel(trans.word("menu.settings.nameParty")); lbl.setBounds(5, 70, 210, 20); lbl.setFont(SettingsPanel.cursiveFont); add(lbl); }
public void textValueChanged(TextEvent e) { if ((a != null) && (a instanceof TextListener)) { ((TextListener) a).textValueChanged(e); } if ((b != null) && (b instanceof TextListener)) { ((TextListener) b).textValueChanged(e); } }
@SuppressWarnings("unchecked") @Override public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (TextListener.class.isAssignableFrom(listenerType)) { return (T[]) getTextListeners(); } return super.getListeners(listenerType); }
public void testGetListeners() { Class<TextListener> cls = TextListener.class; EventListener[] listeners = textComp.getListeners(cls); assertEquals(0, listeners.length); textComp.addTextListener(listener); assertEquals(1, (listeners = textComp.getListeners(cls)).length); assertSame(listener, listeners[0]); }
public void testGetTextListeners() { TextListener[] listeners = textComp.getTextListeners(); assertEquals(0, listeners.length); textComp.addTextListener(listener); assertEquals(1, (listeners = textComp.getTextListeners()).length); assertSame(listener, listeners[0]); }
/** * Adds a TextListener event listener. * * @param listener The listener to add. * * @see #removeTextListener */ public void addTextListener(TextListener listener) { // is there anything to do? if (listener == null) return; if (textListeners == null) textListeners = new Vector(); // add listener textListeners.addElement(listener); }
/** * Removes a TextListener event listener. * * @param listener The listener to remove. * * @see #addTextListener */ public void removeTextListener(TextListener listener) { // is there anything to do? if (listener == null || textListeners == null) return; // add listener textListeners.removeElement(listener); }
/** * This function delivers TextListener events, when the ok * button is clicked. * * @param evt The event to deliver. */ protected void deliverEvent(EventObject evt) { if (evt instanceof TextEvent) { TextEvent event = (TextEvent)evt; Vector l; synchronized (textListeners) { l = (Vector)textListeners.clone(); } int size = l.size(); for (int i = 0; i < size; i++) ((TextListener)l.elementAt(i)).textValueChanged(event); } }
protected void addListeners( final GenericDialog gd, final Vector<?> tf, final Label label, final long[] dim ) { final TextField downsample = (TextField)tf.get( 2 ); downsample.addTextListener( new TextListener() { @Override public void textValueChanged(TextEvent arg0) { int downsampling = Integer.parseInt( downsample.getText() ); final long numPixels = numPixels( dim, downsampling ); final long megabytes = (numPixels * 4) / (1024*1024); label.setText( "Image size for segmentation: " + (dim[ 0 ])/downsampling + " x " + (dim[ 1 ])/downsampling + " x " + (dim[ 2 ])/downsampling + " pixels, " + megabytes + " MB" ); label.setForeground( GUIHelper.good ); } } ); }
/** * Returns all text listeners registered to this object. */ public TextListener[] getTextListeners() { return (TextListener[]) getListeners(TextListener.class); }
public static void addTextListener(TextListener tl) { EVENT_LISTENER_LIST.add(TextListener.class, tl); }
public static void removeTextListener(TextListener tl) { EVENT_LISTENER_LIST.remove(TextListener.class, tl); }
public static TextListener add(TextListener a, TextListener b) { return (TextListener) addInternal(a, b); }
public static TextListener remove(TextListener l, TextListener oldl) { return (TextListener) removeInternal(l, oldl); }