/** * Get universal Focus listener suitable for decsription JTextFields only. * It provides screen reades support for read only enabled descriptions. */ public static synchronized FocusListener getA11YJTextFieldSupport() { if (flis == null) { flis = new java.awt.event.FocusListener() { public void focusGained(java.awt.event.FocusEvent e) { if (e.getComponent() instanceof javax.swing.JTextField) { ((javax.swing.JTextField)e.getComponent()).selectAll(); } } public void focusLost(java.awt.event.FocusEvent e) { if (e.getComponent() instanceof javax.swing.JTextField) { ((javax.swing.JTextField)e.getComponent()).select(1,1); } } }; } return flis; }
/** Delegates to the original listener. */ @Override public void focusLost(FocusEvent ev) { FocusListener l = (FocusListener) super.get(ev); if (l != null) { l.focusLost(ev); } }
private static void createAndShowGUI() { tab = new JTabbedPane(); tab.add("Tab1", new JButton("Button1")); tab.add("Tab2", new JButton("Button2")); tab.setMnemonicAt(0, KeyEvent.VK_T); tab.setMnemonicAt(1, KeyEvent.VK_B); JFrame frame = new JFrame(); frame.getContentPane().add(tab, BorderLayout.CENTER); txtField = new JTextField(); frame.getContentPane().add(txtField, BorderLayout.NORTH); listener = new bug4624207(); txtField.addFocusListener((FocusListener) listener); frame.pack(); frame.setVisible(true); }
public void use( Association<T> actualAssociation ) { actual = actualAssociation; T value = null; if( actualAssociation != null ) { value = actualAssociation.get(); } stateModel.use( value ); for( JComponent component : components ) { SwingAdapter adapter = adapters.get( component.getClass() ); adapter.fromAssociationToSwing( component, actualAssociation ); for( FocusListener listener : component.getFocusListeners() ) { if( AssociationFocusLostListener.class.isInstance( listener ) ) { ( (AssociationFocusLostListener) listener ).use( adapter, actual ); } } } }
public void use( Property<T> actualProperty ) { T value = null; if( actualProperty != null ) { value = actualProperty.get(); } stateModel.use( value ); for( JComponent component : components ) { SwingAdapter adapter = adapters.get( component.getClass() ); adapter.fromPropertyToSwing( component, actualProperty ); for( FocusListener listener : component.getFocusListeners() ) { if( PropertyFocusLostListener.class.isInstance( listener ) ) { ( (PropertyFocusLostListener) listener ).use( adapter, actualProperty ); } } } }
/** * SwingX Issue #299. */ @Test public void testUndecorateTextComponent() { JTextField textField = new JTextField(); AutoCompleteDecorator.decorate(textField, Collections.emptyList(), true); AutoCompleteDecorator.undecorate(textField); assertThat(textField.getInputMap(), is(not(instanceOf(AutoComplete.InputMap.class)))); assertThat(textField.getActionMap().get("nonstrict-backspace"), is(nullValue())); for (FocusListener l : textField.getFocusListeners()) { assertThat(l, is(not(instanceOf(AutoComplete.FocusAdapter.class)))); } assertThat(textField.getDocument(), is(not(instanceOf(AutoCompleteDocument.class)))); }
public void init() { EditorAndViewerMouseListener editorAndViewerMouseListener = new EditorAndViewerMouseListener(this); RichTextEditorKeyListener richTextEditorKeyListener = new RichTextEditorKeyListener(new EditorKeyListener(getConceptPanel(),this), this); super.init( new RichTextToHtmlTransformer(), richTextEditorKeyListener, new ViewerKeyListener(getConceptPanel(),this), new EditorFocusListener(getConceptPanel()), (FocusListener)null, editorAndViewerMouseListener, editorAndViewerMouseListener, new TextAnnotationToolbar(this)); }
/** * Removes all listeners associated with the given Component. This is useful when removing to to make sure * it does not stick around. */ public static void removeAllListeners(Component com) { for (FocusListener fl : com.getFocusListeners()) { com.removeFocusListener(fl); } for (MouseListener ml : com.getMouseListeners()) { com.removeMouseListener(ml); } for (MouseMotionListener mml : com.getMouseMotionListeners()) { com.removeMouseMotionListener(mml); } for (KeyListener kl : com.getKeyListeners()) { com.removeKeyListener(kl); } for (ComponentListener cl : com.getComponentListeners()) { com.removeComponentListener(cl); } }
/** * sets a FocusListener * * @param l * the FocusListener */ public void setFocusListener(FocusListener l) { this.titleTF.addFocusListener(l); this.artistTF.addFocusListener(l); this.albumArtistTF.addFocusListener(l); this.albumTF.addFocusListener(l); this.yearTF.addFocusListener(l); this.maxTracksTF.addFocusListener(l); this.maxCDTF.addFocusListener(l); this.commentTF.addFocusListener(l); this.composerTF.addFocusListener(l); this.origArtistTF.addFocusListener(l); this.copyrightTF.addFocusListener(l); this.urlTF.addFocusListener(l); this.encodedByTF.addFocusListener(l); this.trackTF.addFocusListener(l); this.cdTF.addFocusListener(l); this.publisherTF.addFocusListener(l); this.genreCB.addFocusListener(l); this.lyricsTA.addFocusListener(l); }
@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); }
TextComponent() { state = new State(); editable = true; dispatchToIM = true; // had been disabled by createBehavior() setFont(new Font("DialogInput", Font.PLAIN, 12)); // QUICK FIX //$NON-NLS-1$ document = new PlainDocument(); // text = new StringBuffer(); setTextKit(new TextKitImpl()); rootViewContext = createRootViewContext(); rootViewContext.getView().append(createView()); rootViewContext.getView().setSize(w, h); caret = createCaret(); setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); addAWTMouseListener(getMouseHandler()); addAWTMouseMotionListener(getMotionHandler()); addAWTFocusListener((FocusListener) caret); addAWTKeyListener(new KeyHandler()); // document handler must be added after caret's listener has been added! document.addDocumentListener(new DocumentHandler()); }
public final void testAddRemoveFocusListener() { assertEquals(0, comp.getFocusListeners().length); aComponent.addFocusListener(focusListener); FocusListener[] listeners = comp.getFocusListeners(); assertEquals(1, listeners.length); assertSame(focusListener, listeners[0]); assertNull(lastFocusEvent); comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_GAINED)); assertNotNull("focus listener called", lastFocusEvent); lastFocusEvent = null; aComponent.removeFocusListener(null); listeners = comp.getFocusListeners(); assertSame(focusListener, listeners[0]); comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_LOST)); assertNotNull("focus listener called", lastFocusEvent); lastFocusEvent = null; aComponent.removeFocusListener(focusListener); listeners = comp.getFocusListeners(); comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_LOST, true)); assertEquals(0, listeners.length); assertNull("listener not called", lastFocusEvent); }
protected boolean requestFocusInWindowForComponent(final JComponent c, int maxWaitTime) throws Exception { FocusListener listener = addFocusListener(c); RunnableResulted thread = new RunnableResulted() { @Override public void run() { result = c.requestFocusInWindow(); } }; SwingUtilities.invokeAndWait(thread); if (!thread.result) { return false; } synchronized (listener) { listener.wait(maxWaitTime); } waitForIdle(); if (!c.isFocusOwner()) { fail(); } return true; }
protected boolean requestFocusInWindowForComponent(final JComponent c, final boolean temporarily, int maxWaitTime) throws Exception { FocusListener listener = addFocusListener(c); RunnableResulted thread = new RunnableResulted() { @Override public void run() { result = c.requestFocusInWindow(temporarily); } }; SwingUtilities.invokeAndWait(thread); if (!thread.result) { return false; } synchronized (listener) { listener.wait(maxWaitTime); } waitForIdle(); if (!c.isFocusOwner()) { fail(); } return true; }
protected void requestFocusForComponent(final JComponent c, final boolean temporarily, int maxWaitTime) throws Exception { FocusListener listener = addFocusListener(c); SwingUtilities.invokeAndWait(new Runnable() { public void run() { c.requestFocus(temporarily); } }); synchronized (listener) { listener.wait(maxWaitTime); } waitForIdle(); if (!c.isFocusOwner()) { fail(); } }
public ActionsBuilder (JPanel panel, FocusListener listener) { this.focusListener = listener; panel.removeAll(); GroupLayout layout = (GroupLayout) panel.getLayout(); horizontalSeqGroup = layout.createSequentialGroup(); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(horizontalSeqGroup) ); verticalParallelGroup = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(verticalParallelGroup) ); }
public static void keepFocusedComponentVisible(Component component, JComponent container) { FocusListener listener; if(component instanceof JComponent ) { listener = getNotShowingFieldsFocusListener(container); } else { listener = getScrollingFocusListener(); // legacy fallback } keepFocusedComponentVisible(component, listener); }
private static void keepFocusedComponentVisible(Component component, FocusListener l) { component.removeFocusListener(l); // Making sure that it is not added twice component.addFocusListener(l); if (component instanceof Container) { for (Component subComponent : ((Container)component).getComponents()) { keepFocusedComponentVisible(subComponent, l); } } }
private static FocusListener getNotShowingFieldsFocusListener(JComponent container) { String key = "notShowingFieldFocusListener"; // NOI18N Object l = container.getClientProperty(key); if (l == null) { l = new NotShowingFieldsFocusListener(container); container.putClientProperty(key, l); } return (FocusListener) l; }
public void addFocusListener(FocusListener fl) { if (comp != null) { comp.addFocusListener(fl); } else { super.addFocusListener(fl); } }
public void removeFocusListener(FocusListener fl) { if (comp != null) { comp.removeFocusListener(fl); } else { super.removeFocusListener(fl); } }
/** Overridden to proxy adds to the custom editor button and the * installed component */ public void addFocusListener(FocusListener l) { if (comp != null) { button.addFocusListener(l); comp.addFocusListener(l); } }
/** Overridden to proxy removes to the custom editor button and the * installed component */ public void removeFocusListener(FocusListener l) { if (comp != null) { button.removeFocusListener(l); comp.removeFocusListener(l); } }
/** Delegates to the original listener. */ public void focusGained(FocusEvent ev) { FocusListener l = (FocusListener) super.get(ev); if (l != null) { l.focusGained(ev); } }
/** Delegates to the original listener. */ public void focusLost(FocusEvent ev) { FocusListener l = (FocusListener) super.get(ev); if (l != null) { l.focusLost(ev); } }
public synchronized void addFocusListener(FocusListener l) { super.addFocusListener(l); if (!localFocusListenerInitialized) { localFocusListenerInitialized = true; Container container = this; FocusListener focusListener = localFocusListener; addFocusListenerRecursively(container, focusListener); } }
private void addFocusListenerRecursively(Container container, FocusListener focusListener) { final Component[] components = container.getComponents(); for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component.isFocusable() && !(component instanceof JLabel)) { component.addFocusListener(focusListener); } if (component instanceof Container) { if (!(component instanceof SectionNodePanel)) { addFocusListenerRecursively((Container) component, focusListener); } } } }
private JComboBox createComboBox(CandidateDescription[] choices, CandidateDescription defaultValue, Font font, FocusListener listener ) { JComboBox combo = new JComboBox(choices); combo.setSelectedItem(defaultValue); combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N combo.setOpaque(false); combo.setFont( font ); combo.addFocusListener( listener ); combo.setEnabled( choices.length > 1 ); combo.setRenderer( new DelegatingRenderer(combo.getRenderer())); InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED ); inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N return combo; }
private void initComponentsMore() { contentPanel.setLayout(new GridBagLayout()); contentPanel.setBackground(UIManager.getColor("Table.background")); //NOI18N int row = 0; combos = new ArrayList<>(items.size()); Font monoSpaced = new Font("Monospaced", Font.PLAIN, new JLabel().getFont().getSize()); //NOI18N FocusListener focusListener = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { Component c = e.getComponent(); Rectangle r = c.getBounds(); contentPanel.scrollRectToVisible(r); } }; for (int i = 0; i < items.size(); i++) { ResolveDeclarationItem item = items.get(i); JComboBox jComboBox = createComboBox(item, monoSpaced, focusListener); combos.add(jComboBox); JLabel lblSimpleName = new JLabel(item.getName()); lblSimpleName.setOpaque(false); lblSimpleName.setFont(monoSpaced); lblSimpleName.setLabelFor(jComboBox); contentPanel.add(lblSimpleName, new GridBagConstraints(0, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 5, 2, 5), 0, 0)); contentPanel.add(jComboBox, new GridBagConstraints(1, row++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 2, 5), 0, 0)); } contentPanel.add(new JLabel(), new GridBagConstraints(2, row, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); Dimension d = contentPanel.getPreferredSize(); d.height = getRowHeight() * Math.min(combos.size(), 6); }
/** Delegates to the original listener. */ @Override public void focusGained(FocusEvent ev) { FocusListener l = (FocusListener) super.get(ev); if (l != null) { l.focusGained(ev); } }
@Override public synchronized void addFocusListener(FocusListener l) { // workaround for java bug #6433257 for (Component c : getComponents()) { c.addFocusListener(l); } }
/** * Maps {@code Component.addFocusListener(FocusListener)} through queue */ public void addFocusListener(final FocusListener focusListener) { runMapping(new MapVoidAction("addFocusListener") { @Override public void map() { getSource().addFocusListener(focusListener); } }); }
/** * Maps {@code Component.removeFocusListener(FocusListener)} through queue */ public void removeFocusListener(final FocusListener focusListener) { runMapping(new MapVoidAction("removeFocusListener") { @Override public void map() { getSource().removeFocusListener(focusListener); } }); }
/** * Adds a focus listener on the component and its descendents. * * @param c * The component. * @param focusListener * Focus Listener. */ private void installFocusListener(Component c, FocusListener focusListener) { c.addFocusListener(focusListener); if (c instanceof Container) { Container container = (Container) c; int componentCount = container.getComponentCount(); for (int i = 0; i < componentCount; i++) { Component child = container.getComponent(i); installFocusListener(child, focusListener); } } }