Example usage for java.awt.event FocusAdapter FocusAdapter

List of usage examples for java.awt.event FocusAdapter FocusAdapter

Introduction

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

Prototype

FocusAdapter

Source Link

Usage

From source file:com.aw.swing.mvp.cmp.pick.PickManager.java

/**
 * @param attrName La caja de texto txt<attrName> debe existir
 * @param pick//from w  w  w. j  a  v  a2  s  .co m
 * @return
 */
public Pick registerPick(String attrName, final Pick pick) {
    final String pickName = getPickName(attrName);
    getPicksInfo().add(new PickInfo(pick, attrName, pickName));
    picks.add(pick);
    if (pick instanceof PickImpl) {
        ((PickImpl) pick).setPresenter(presenter);
        pick.setMainAttribute(attrName);
        final JTextComponent jTextComponent = (JTextComponent) presenter.getIpView()
                .getComponent(getTxtPick(attrName));
        jTextComponent.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent e) {

                if (e.isTemporary()) {
                    return;
                }

                // if the pick action is currently executing
                Boolean executingPick = (Boolean) jTextComponent
                        .getClientProperty(BindingComponent.ATTR_EXECUTING_PICK_ACTION);
                if ((executingPick != null) && (executingPick)) {
                    jTextComponent.putClientProperty(BindingComponent.ATTR_EXECUTING_PICK_ACTION, null);
                    //                        return;
                }
                System.out.println("XXX    Focus LOST   2");
                // if the focus will be directed to the pick Button
                Component cmp = e.getOppositeComponent();
                if (cmp instanceof JComponent) {
                    JComponent jComponent = (JComponent) cmp;
                    String actionName = (String) jComponent.getClientProperty(BindingComponent.ATTR_ACTION);
                    if (pickName.equals(actionName)) {
                        return;
                    }
                }

                if (!pick.isPickFilled()) {

                    jTextComponent.setText("");
                }
            }
        });
        jTextComponent.addKeyListener(new PickKeyListener(pick));
        jTextComponent.putClientProperty(PICK_NAME, pickName);
        jTextComponent.putClientProperty(PICK, pick);
        //            JButton jButton = (JButton) presenter.getIpView().getComponent(getBtnPick(attrName));
    }
    return pick;
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboComponentName.java

private void init() {

    final JTextField tfComponentName = (JTextField) this.getEditor().getEditorComponent();

    tfComponentName.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();
            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && ch != KeyEvent.VK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;

            if (ch == KeyEvent.VK_ENTER) {

                JComboComponentName.this.hidePopup();
                return;
            }/*  w w w  .j  a v a 2 s.  c  o m*/
            // 1. save string
            String keyword = tfComponentName.getText();//.trim();
            updateComboBoxList(keyword);

        }
    });

    tfComponentName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (tfComponentName.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });

}

From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java

@Override
public void setEditor(final JFormattedTextField editor) {
    final int ENTER_CODE = 10;

    editor.addKeyListener(new KeyAdapter() {
        @Override/*  w  w w.jav  a  2 s.  co  m*/
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == '\u007F' && editor.getCaretPosition() < format.length()) {
                editor.setCaretPosition(editor.getCaretPosition() + 1);
            }
        }

        @Override
        public void keyPressed(KeyEvent event) {
            if (ENTER_CODE == event.getKeyCode())
                try {
                    editor.commitEdit();
                } catch (ParseException e) {
                    //
                }
        }
    });

    editor.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            editor.setCaretPosition(0);
        }
    });

    super.setEditor(editor);

    if (format == null) {
        setFormats(
                Datatypes.getFormatStrings(AppBeans.get(UserSessionSource.class).getLocale()).getDateFormat());
    } else
        setFormats(format);
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

public RegexAttachmentDialog(AttachmentHandlerProperties properties) {
    super(PlatformUI.MIRTH_FRAME, true);
    this.parent = PlatformUI.MIRTH_FRAME;

    setTitle("Set Attachment Properties");
    getContentPane().setBackground(UIConstants.BACKGROUND_COLOR);
    setLayout(new MigLayout("novisualpadding, hidemode 3, insets 12", "[fill, grow]"));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setPreferredSize(new Dimension(650, 550));

    initComponents();//  www  . ja va  2 s  .c  om
    initLayout();
    initInboundReplacementTable();
    initOutboundReplacementTable();

    attachmentHandlerProperties = properties;

    regexTextField.setText(
            StringUtils.defaultIfEmpty(attachmentHandlerProperties.getProperties().get("regex.pattern"), ""));
    regexTextField.requestFocus();
    regexTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            if (initialFocus) {
                regexTextField.setCaretPosition(0);
                initialFocus = false;
            }
        }

    });
    mimeTypeField.setText(
            StringUtils.defaultIfEmpty(attachmentHandlerProperties.getProperties().get("regex.mimetype"), ""));

    int count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) inboundReplacementTable.getModel();
        tableModel.addRow(
                new Object[] { attachmentHandlerProperties.getProperties().get("regex.replaceKey" + count),
                        attachmentHandlerProperties.getProperties().get("regex.replaceValue" + count) });
        count++;
    }

    count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("outbound.regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) outboundReplacementTable.getModel();
        tableModel.addRow(new Object[] {
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceKey" + count),
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceValue" + count) });
        count++;
    }

    setLocationRelativeTo(parent);
    setVisible(true);
}

From source file:org.jspresso.framework.binding.swing.JActionFieldConnector.java

/**
 * {@inheritDoc}/*from   ww  w.  j  a  va 2s.c  o m*/
 */
@Override
protected void bindJComponent() {

    getConnectedJComponent().addTextFieldFocusListener(new FocusAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                performActionIfNeeded();
            }
        }
    });
}

From source file:se.trixon.mapollage.ui.config.ModuleSourcePanel.java

private void init() {
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override/*  ww  w .java 2 s .c o m*/
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveSourcePath();
        }
    });

    patternTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mSource.setFilePattern(patternTextField.getText());
        }
    });

    excludeTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mSource.setExcludePattern(excludeTextField.getText());
        }
    });
}

From source file:se.trixon.toolbox.photokml.config.ModuleSourcePanel.java

private void init() {
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override/*from w  w w  . ja  v  a2s  .  c o m*/
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveSourcePath();
        }
    });

    patternTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mOptions.setSourcePattern(patternTextField.getText());
        }
    });
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java

public GenericServerConfigForm(final Project project, final UserCfg defaultUser, final Connector tester) {
    this.project = project;
    $$$setupUI$$$();//from  w  w w. j  ava2 s  . co m
    testConnection.addActionListener(
            new TestConnectionListener(project, tester, new TestConnectionListener.ServerDataProvider() {
                public ServerData getServer() {
                    synchronized (GenericServerConfigForm.this) {
                        saveData();
                        ServerData.Builder builder = new ServerData.Builder(serverCfg);
                        builder.defaultUser(defaultUser);
                        return builder.build();
                    }
                }
            }, this));
    serverUrl.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            adjustUrl();
        }
    });

    listener = new DocumentListener() {

        public void insertUpdate(DocumentEvent e) {
            setServerState();
        }

        public void removeUpdate(DocumentEvent e) {
            setServerState();
        }

        public void changedUpdate(DocumentEvent e) {
            setServerState();
        }
    };

    useDefault.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            enableDisableUserPassword();
        }
    });

    cbEnabled.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeEvent) {

        }
    });

    urlDocumentListener = new DocumentAdapter() {
        protected void textChanged(DocumentEvent documentEvent) {
            enableDisableSever(false);
        }
    };

    serverName.addFocusListener(new FocusAdapter() {
        public void focusLost(final FocusEvent e) {
            if (StringUtils.stripToEmpty(serverName.getText()).length() == 0) {
                serverName.setText(originalServerName);
            }
        }
    });

    enableDisableSever(true);
    enableDisableUserPassword();
}

From source file:edu.ku.brc.af.ui.forms.validation.ValTextArea.java

public void init() {
    bgColor = getBackground();/*from w  w w.  j  ava2s  .  co m*/
    if (valTextColor == null || requiredFieldColor == null) {
        valTextColor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor");
        requiredFieldColor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor");
    }
    AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this);

    initDocument();

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            isNew = false;
            repaint();
        }
    });

    // Enable being able to TAB out of TextArea
    getInputMap().put(KeyStroke.getKeyStroke("TAB"), "none");
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.VK_TAB) {
                if (event.isShiftDown()) {
                    transferFocusBackward();
                } else {
                    transferFocus();
                }
            }
        }
    });

}

From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel.java

public GroovyScriptStepDesktopPanel(WsdlGroovyScriptTestStep groovyStep) {
    super(groovyStep);
    this.groovyStep = groovyStep;
    componentEnabler = new TestRunComponentEnabler(groovyStep.getTestCase());

    buildUI();//from w w w  .j a  v  a 2 s  .co  m
    setPreferredSize(new Dimension(600, 440));

    logger = Logger.getLogger(groovyStep.getName() + "#" + hashCode());

    addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            editor.requestFocusInWindow();
        }
    });

    groovyStep.addPropertyChangeListener(this);
}