Example usage for java.awt.event FocusEvent getSource

List of usage examples for java.awt.event FocusEvent getSource

Introduction

In this page you can find the example usage for java.awt.event FocusEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

/**
 * Installs a workaround for bug #4699955 in a JSpinner.
 * /*  w  w  w.  j ava 2 s .c  o m*/
 * @param spinner
 *            The spinner to fix
 */
public static void installSpinnerBugWorkaround(final JSpinner spinner) {
    ((DefaultEditor) spinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(final FocusEvent e) {
            if (e.getSource() instanceof JTextComponent) {
                final JTextComponent text = ((JTextComponent) e.getSource());
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        text.selectAll();
                    }
                });
            }
        }
    });
    spinner.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(final FocusEvent e) {
            if (e.getSource() instanceof JSpinner) {
                final JTextComponent text = ((DefaultEditor) ((JSpinner) e.getSource()).getEditor())
                        .getTextField();
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        text.requestFocus();
                    }
                });
            }
        }
    });
}

From source file:Main.java

/**
 * Installs a workaround for bug #4699955 in a JSpinner.
 *
 * @param spinner/*from   w  ww.j a  v  a2s  . c o m*/
 *            The spinner to fix
 */

public static void installSpinnerBugWorkaround(final JSpinner spinner) {
    ((DefaultEditor) spinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(final FocusEvent e) {
            if (e.getSource() instanceof JTextComponent) {
                final JTextComponent text = (JTextComponent) e.getSource();
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        text.selectAll();
                    }
                });
            }
        }
    });
    spinner.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(final FocusEvent e) {
            if (e.getSource() instanceof JSpinner) {
                final JTextComponent text = ((DefaultEditor) ((JSpinner) e.getSource()).getEditor())
                        .getTextField();
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        text.requestFocus();
                    }
                });
            }
        }
    });
}

From source file:Main.java

public void focusGained(FocusEvent evt) {
    final JTextComponent c = (JTextComponent) evt.getSource();
    String s = c.getText();//ww  w. j  ava 2  s.  c o  m

    for (int i = 0; i < s.length(); i++) {
        if (!Character.isDigit(s.charAt(i))) {
            c.setSelectionStart(i);
            c.setSelectionEnd(i);
            break;
        }
    }
}

From source file:Main.java

public void focusLost(FocusEvent evt) {
    final JTextComponent c = (JTextComponent) evt.getSource();
    String s = c.getText();/*from w  w  w.  j  av a 2s . c o  m*/

    if (evt.isTemporary()) {
        return;
    }
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isDigit(s.charAt(i))) {
            System.out.println("must only contain digits");
            c.requestFocus();
            break;
        }
    }
}

From source file:MenuItemChooser.java

public void focusLost(FocusEvent e) {
    if (e.getSource() == qty) {
        updateQtyOrdered();
    }
}

From source file:ru.codemine.pos.ui.salespanel.QuantitySetupWindow.java

public void showWindow() {
    if (!actionListenersInit)
        setupActionListeners();//from w  ww. ja  v  a 2  s.  co m
    mainWindow.blockBarcodeInput();

    Product product = salesPanel.getChequeSetupPanel().getSelectedProduct();
    if (product == null) {
        mainWindow.unblockBarcodeInput();
        return;
    }

    int maxQuantity = storeService.getAvaibleStocksOnRetail(product);
    onStoresLabel.setText("?: " + String.valueOf(maxQuantity) + " .");
    setTitle("? - " + product.getName());
    spinner.setModel(new SpinnerNumberModel(1, 1, maxQuantity, 1));

    JTextField ft = ((WebSpinner.DefaultEditor) spinner.getEditor()).getTextField();
    ft.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            final JTextComponent txtcomp = (JTextComponent) e.getSource();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    txtcomp.selectAll();
                }
            });
        }
    });
    ft.requestFocus();

    setVisible(true);
}

From source file:ch.zhaw.simulation.diagram.charteditor.DefaultNumberAxisEditor.java

/**
 * Revalidates minimum/maximum range./*www .j av  a 2s.co  m*/
 * 
 * @param event
 *            the event.
 */
public void focusLost(FocusEvent event) {
    if (event.getSource() == this.minimumRangeValue) {
        validateMinimum();
    } else if (event.getSource() == this.maximumRangeValue) {
        validateMaximum();
    }
}

From source file:com.t3.macro.api.functions.input.ColumnPanel.java

/** Adjusts the runtime behavior of controls. Called when displayed. */
public void runtimeFixup() {
    // When first displayed, the focus will go to the first field.
    lastFocus = findFirstFocusable();/*from   ww w. j  av  a2s  .c o m*/

    // When a field gains the focus, save it in lastFocus.
    FocusListener listener = new FocusListener() {
        @Override
        public void focusGained(FocusEvent fe) {
            JComponent src = (JComponent) fe.getSource();
            lastFocus = src;
            if (src instanceof JTextField)
                ((JTextField) src).selectAll();
            //               // debugging
            //               String s = (src instanceof JTextField) ?
            //                  " (" + ((JTextField)src).getText() + ")" : "";
            //               System.out.println("  Got focus " + src.getClass().getName() + s);
        }

        @Override
        public void focusLost(FocusEvent arg0) {
        }
    };

    for (JComponent c : inputFields) {
        // Each control saves itself to lastFocus when it gains focus.
        c.addFocusListener(listener);

        // Implement control-specific adjustments
        if (c instanceof ColumnPanel) {
            ColumnPanel cp = (ColumnPanel) c;
            cp.runtimeFixup();
        }
    }
    if (lastFocus != null)
        scrollRectToVisible(lastFocus.getBounds());
}

From source file:net.sf.jabref.gui.AutoCompleteListener.java

@Override
public void focusLost(FocusEvent event) {
    if (toSetIn != null) {
        JTextComponent comp = (JTextComponent) event.getSource();
        clearCurrentSuggestion(comp);// w  w  w  .java  2  s .  com
    }
    if (nextFocusListener != null) {
        nextFocusListener.focusLost(event);
    }
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void focusGained(FocusEvent e) {
    if (e.getSource() == table) {
        // Propagate the event
        final FocusListener[] listeners = getListeners(FocusListener.class);

        if (listeners != null) {
            final FocusEvent event = new FocusEvent(this, e.getID(), e.isTemporary(), e.getOppositeComponent());

            for (FocusListener listener : listeners) {
                listener.focusGained(event);
            }/*from   w  ww  .j  av a  2 s .  c  om*/
        }
    }
}