Search in sources :

Example 6 with FocusEvent

use of java.awt.event.FocusEvent in project intellij-community by JetBrains.

the class SSHCredentialsDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gb = new GridBagConstraints();
    // top label.
    gb.insets = JBUI.insets(2);
    gb.weightx = 1;
    gb.weighty = 0;
    gb.gridwidth = 3;
    gb.gridheight = 1;
    gb.gridx = 0;
    gb.gridy = 0;
    gb.anchor = GridBagConstraints.WEST;
    gb.fill = GridBagConstraints.HORIZONTAL;
    JLabel label = new JLabel(SvnBundle.message("label.ssh.authentication.realm", myRealm));
    panel.add(label, gb);
    // user name
    gb.gridy += 1;
    gb.gridwidth = 1;
    gb.weightx = 0;
    gb.fill = GridBagConstraints.NONE;
    label = new JLabel(SvnBundle.message("label.ssh.user.name"));
    panel.add(label, gb);
    // user name field
    gb.gridx = 1;
    gb.gridwidth = 2;
    gb.weightx = 1;
    gb.fill = GridBagConstraints.HORIZONTAL;
    myUserNameText = new JTextField();
    panel.add(myUserNameText, gb);
    label.setLabelFor(myUserNameText);
    if (myUserName != null) {
        myUserNameText.setText(myUserName);
    }
    myUserNameText.selectAll();
    myUserNameText.getDocument().addDocumentListener(this);
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 3;
    // ssh agent type
    mySshAgentButton = new JBRadioButton(SvnBundle.message("radio.ssh.authentication.with.agent"));
    panel.add(mySshAgentButton, gb);
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 3;
    // password type
    myPasswordButton = new JRadioButton(SvnBundle.message("radio.ssh.authentication.with.password"));
    panel.add(myPasswordButton, gb);
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 1;
    myPasswordLabel = new JLabel(SvnBundle.message("label.ssh.password"));
    panel.add(myPasswordLabel, gb);
    // passworde field
    gb.gridx = 1;
    gb.weightx = 1;
    gb.gridwidth = 2;
    gb.fill = GridBagConstraints.HORIZONTAL;
    myPasswordText = new JPasswordField();
    panel.add(myPasswordText, gb);
    myPasswordLabel.setLabelFor(myPasswordText);
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 3;
    myKeyButton = new JRadioButton(SvnBundle.message("radio.ssh.authentication.private.key"));
    panel.add(myKeyButton, gb);
    // key file.
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 1;
    myKeyFileLabel = new JLabel(SvnBundle.message("label.ssh.key.file"));
    panel.add(myKeyFileLabel, gb);
    // key field
    gb.gridx = 1;
    gb.weightx = 1;
    gb.gridwidth = 2;
    gb.fill = GridBagConstraints.HORIZONTAL;
    myKeyFileText = new TextFieldWithBrowseButton(this);
    myKeyFileText.setEditable(false);
    panel.add(myKeyFileText, gb);
    myKeyFileLabel.setLabelFor(myKeyFileText);
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 1;
    myPassphraseLabel = new JLabel(SvnBundle.message("label.ssh.passphrase"));
    panel.add(myPassphraseLabel, gb);
    // key field
    gb.gridx = 1;
    gb.weightx = 1;
    gb.gridwidth = 2;
    gb.fill = GridBagConstraints.HORIZONTAL;
    myPassphraseText = new JPasswordField(30);
    panel.add(myPassphraseText, gb);
    myPassphraseText.getDocument().addDocumentListener(this);
    myPassphraseText.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            checkKeyFile();
            updateOKButton();
        }
    });
    myPassphraseLabel.setLabelFor(myPassphraseText);
    // key file.
    gb.gridy += 1;
    gb.weightx = 0;
    gb.gridx = 0;
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.gridwidth = 1;
    myPortLabel = new JLabel(SvnBundle.message("label.ssh.port"));
    panel.add(myPortLabel, gb);
    // key field
    gb.gridx = 1;
    gb.weightx = 0;
    gb.gridwidth = 2;
    gb.fill = GridBagConstraints.NONE;
    myPortField = new JTextField();
    myPortField.setColumns(6);
    panel.add(myPortField, gb);
    myPortLabel.setLabelFor(myPortField);
    myPortField.setText("22");
    myPortField.setMinimumSize(myPortField.getPreferredSize());
    myPortField.getDocument().addDocumentListener(this);
    ButtonGroup group = new ButtonGroup();
    group.add(mySshAgentButton);
    group.add(myPasswordButton);
    group.add(myKeyButton);
    mySshAgentButton.setEnabled(myIsAgentAllowed);
    group.setSelected((myIsAgentAllowed ? mySshAgentButton : myPasswordButton).getModel(), true);
    gb.gridy += 1;
    gb.gridx = 0;
    gb.gridwidth = 3;
    gb.weightx = 1;
    gb.anchor = GridBagConstraints.WEST;
    gb.fill = GridBagConstraints.HORIZONTAL;
    myAllowSaveCheckBox = new JCheckBox(SvnBundle.message("checkbox.ssh.keep.for.current.session"));
    panel.add(myAllowSaveCheckBox, gb);
    if (!myAllowSave) {
        gb.gridy += 1;
        final JLabel cannotSaveLabel = new JLabel(SvnBundle.message("svn.cannot.save.credentials.store-auth-creds"));
        cannotSaveLabel.setForeground(UIUtil.getInactiveTextColor());
        panel.add(cannotSaveLabel, gb);
    }
    gb.gridy += 1;
    panel.add(new JSeparator(), gb);
    gb.gridy += 1;
    gb.weighty = 1;
    panel.add(new JLabel(), gb);
    myAllowSaveCheckBox.setSelected(false);
    myAllowSaveCheckBox.setEnabled(myAllowSave);
    mySshAgentButton.addActionListener(this);
    myKeyButton.addActionListener(this);
    myPasswordButton.addActionListener(this);
    updateFields();
    updateOKButton();
    return panel;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JBRadioButton(com.intellij.ui.components.JBRadioButton) FocusEvent(java.awt.event.FocusEvent) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton)

Example 7 with FocusEvent

use of java.awt.event.FocusEvent in project intellij-community by JetBrains.

the class BaseControl method initialize.

private void initialize(final Bound boundComponent) {
    myBoundComponent = createMainComponent(boundComponent);
    final JComponent highlightedComponent = getHighlightedComponent(myBoundComponent);
    myDefaultForeground = highlightedComponent.getForeground();
    myDefaultBackground = highlightedComponent.getBackground();
    final JComponent component = getComponentToListenFocusLost(myBoundComponent);
    if (component != null) {
        component.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (!e.isTemporary() && isValid()) {
                    commit();
                }
            }
        });
    }
    updateComponent();
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 8 with FocusEvent

use of java.awt.event.FocusEvent in project Botnak by Gocnak.

the class BaseTextAreaUI method installListeners.

protected void installListeners() {
    super.installListeners();
    if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
        focusListener = new FocusListener() {

            public void focusGained(FocusEvent e) {
                if (getComponent() != null) {
                    orgBorder = getComponent().getBorder();
                    LookAndFeel laf = UIManager.getLookAndFeel();
                    if (laf instanceof AbstractLookAndFeel && orgBorder instanceof UIResource) {
                        Border focusBorder = ((AbstractLookAndFeel) laf).getBorderFactory().getFocusFrameBorder();
                        getComponent().setBorder(focusBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }

            public void focusLost(FocusEvent e) {
                if (getComponent() != null) {
                    if (orgBorder instanceof UIResource) {
                        getComponent().setBorder(orgBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }
        };
        getComponent().addFocusListener(focusListener);
    }
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 9 with FocusEvent

use of java.awt.event.FocusEvent in project Botnak by Gocnak.

the class BaseFormattedTextFieldUI method installListeners.

protected void installListeners() {
    super.installListeners();
    if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
        focusListener = new FocusListener() {

            public void focusGained(FocusEvent e) {
                if (getComponent() != null) {
                    orgBorder = getComponent().getBorder();
                    LookAndFeel laf = UIManager.getLookAndFeel();
                    if (laf instanceof AbstractLookAndFeel && orgBorder instanceof UIResource) {
                        Border focusBorder = ((AbstractLookAndFeel) laf).getBorderFactory().getFocusFrameBorder();
                        getComponent().setBorder(focusBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }

            public void focusLost(FocusEvent e) {
                if (getComponent() != null) {
                    if (orgBorder instanceof UIResource) {
                        getComponent().setBorder(orgBorder);
                        getComponent().invalidate();
                        getComponent().repaint();
                    }
                }
            }
        };
        getComponent().addFocusListener(focusListener);
    }
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 10 with FocusEvent

use of java.awt.event.FocusEvent in project EnrichmentMapApp by BaderLab.

the class SliderBarPanel method getTextField.

public JFormattedTextField getTextField() {
    if (textField == null) {
        textField = new JFormattedTextField(format) {

            @Override
            public Dimension getPreferredSize() {
                final Dimension d = super.getPreferredSize();
                if (this.getGraphics() != null) {
                    // Set the preferred text field size after it gets a Graphics
                    int sw = 16 + this.getGraphics().getFontMetrics().stringWidth(format.format(max));
                    d.width = Math.max(sw, 48);
                }
                return d;
            }
        };
        textField.setHorizontalAlignment(JTextField.RIGHT);
        textField.addActionListener(evt -> {
            textFieldValueChanged();
        });
        textField.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                textFieldValueChanged();
            }
        });
    }
    return textField;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JFormattedTextField(javax.swing.JFormattedTextField) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusEvent (java.awt.event.FocusEvent)68 FocusListener (java.awt.event.FocusListener)32 FocusAdapter (java.awt.event.FocusAdapter)26 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)14 JLabel (javax.swing.JLabel)12 Dimension (java.awt.Dimension)8 KeyEvent (java.awt.event.KeyEvent)8 JButton (javax.swing.JButton)8 JPanel (javax.swing.JPanel)8 JTextField (javax.swing.JTextField)8 Border (javax.swing.border.Border)8 UIResource (javax.swing.plaf.UIResource)6 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 Insets (java.awt.Insets)5 KeyAdapter (java.awt.event.KeyAdapter)5 MouseEvent (java.awt.event.MouseEvent)5 JComboBox (javax.swing.JComboBox)5 Component (java.awt.Component)4