Search in sources :

Example 11 with JPasswordField

use of javax.swing.JPasswordField in project jdk8u_jdk by JetBrains.

the class PasswordView method viewToModel.

/**
     * Provides a mapping from the view coordinate space to the logical
     * coordinate space of the model.
     *
     * @param fx the X coordinate >= 0.0f
     * @param fy the Y coordinate >= 0.0f
     * @param a the allocated region to render into
     * @return the location within the model that best represents the
     *  given point in the view
     * @see View#viewToModel
     */
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
    bias[0] = Position.Bias.Forward;
    int n = 0;
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (!f.echoCharIsSet()) {
            return super.viewToModel(fx, fy, a, bias);
        }
        char echoChar = f.getEchoChar();
        int charWidth = f.getFontMetrics(f.getFont()).charWidth(echoChar);
        a = adjustAllocation(a);
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
        n = (charWidth > 0 ? ((int) fx - alloc.x) / charWidth : Integer.MAX_VALUE);
        if (n < 0) {
            n = 0;
        } else if (n > (getStartOffset() + getDocument().getLength())) {
            n = getDocument().getLength() - getStartOffset();
        }
    }
    return getStartOffset() + n;
}
Also used : JPasswordField(javax.swing.JPasswordField)

Example 12 with JPasswordField

use of javax.swing.JPasswordField in project bndtools by bndtools.

the class GitCredentialsProvider method updateCredentialItems.

private static void updateCredentialItems(JComponent[] components) {
    for (JComponent component : components) {
        CredentialItem item = (CredentialItem) component.getClientProperty(CRED_ITEM);
        if (item == null) {
            continue;
        }
        if (item instanceof CredentialItem.Username) {
            JTextField field = (JTextField) component;
            ((CredentialItem.Username) item).setValue(field.getText());
            continue;
        }
        if (item instanceof CredentialItem.Password) {
            JPasswordField field = (JPasswordField) component;
            ((CredentialItem.Password) item).setValue(field.getPassword());
            continue;
        }
        if (item instanceof CredentialItem.StringType) {
            if (item.isValueSecure()) {
                JPasswordField field = (JPasswordField) component;
                ((CredentialItem.StringType) item).setValue(new String(field.getPassword()));
                continue;
            }
            JTextField field = (JTextField) component;
            ((CredentialItem.Username) item).setValue(field.getText());
            continue;
        }
        if (item instanceof CredentialItem.YesNoType) {
            JCheckBox field = (JCheckBox) component;
            ((CredentialItem.YesNoType) item).setValue(field.isSelected());
            continue;
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField) JComponent(javax.swing.JComponent) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) JTextField(javax.swing.JTextField)

Example 13 with JPasswordField

use of javax.swing.JPasswordField in project bndtools by bndtools.

the class GitCredentialsProvider method getSwingUI.

private static JComponent[] getSwingUI(CredentialItem... items) {
    List<JComponent> components = new ArrayList<JComponent>();
    for (CredentialItem item : items) {
        if (item instanceof CredentialItem.Username) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field = new JTextField();
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.Password) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field = new JPasswordField();
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.StringType) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field;
            if (item.isValueSecure()) {
                field = new JPasswordField();
            } else {
                field = new JTextField();
            }
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.InformationalMessage) {
            components.add(new JLabel(item.getPromptText()));
            continue;
        }
        if (item instanceof CredentialItem.YesNoType) {
            JCheckBox field = new JCheckBox(item.getPromptText(), ((CredentialItem.YesNoType) item).getValue());
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
    }
    return components.toArray(new JComponent[0]);
}
Also used : ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField)

Example 14 with JPasswordField

use of javax.swing.JPasswordField in project jgnash by ccavanaugh.

the class NetworkAuthenticator method getPasswordAuthentication.

@Override
protected PasswordAuthentication getPasswordAuthentication() {
    Preferences auth = Preferences.userRoot().node(NODEHTTP);
    char[] pass = null;
    String user;
    // get the password
    String _pass = auth.get(HTTPPASS, null);
    if (_pass != null) {
        if (!_pass.isEmpty()) {
            pass = _pass.toCharArray();
        }
    }
    // get the user
    user = auth.get(HTTPUSER, null);
    if (user != null) {
        if (user.length() <= 0) {
            user = null;
        }
    }
    // if either returns null, pop a dialog
    if (user == null || pass == null) {
        JTextField username = new JTextField();
        JPasswordField password = new JPasswordField();
        JPanel panel = new JPanel(new GridLayout(2, 2));
        panel.add(new JLabel(ResourceUtils.getString("Label.UserName")));
        panel.add(username);
        panel.add(new JLabel(ResourceUtils.getString("Label.Password")));
        panel.add(password);
        int option = JOptionPane.showConfirmDialog(null, new Object[] { "Site: " + getRequestingHost(), "Realm: " + getRequestingPrompt(), panel }, "Enter Network Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (option == JOptionPane.OK_OPTION) {
            user = username.getText();
            pass = password.getPassword();
        } else {
            return null;
        }
    }
    return new PasswordAuthentication(user, pass);
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JPasswordField(javax.swing.JPasswordField) JLabel(javax.swing.JLabel) Preferences(java.util.prefs.Preferences) JTextField(javax.swing.JTextField) PasswordAuthentication(java.net.PasswordAuthentication)

Example 15 with JPasswordField

use of javax.swing.JPasswordField in project jgnash by ccavanaugh.

the class NetworkOptions method initComponents.

private void initComponents() {
    proxyCheckBox = new JCheckBox(rb.getString("Button.UseProxy"));
    hostField = new JTextFieldEx();
    portField = new JIntegerField();
    authCheckBox = new JCheckBox(rb.getString("Button.HTTPAuth"));
    nameField = new JTextFieldEx();
    passwordField = new JPasswordField();
    SpinnerNumberModel model = new SpinnerNumberModel(ConnectionFactory.getConnectionTimeout(), ConnectionFactory.MIN_TIMEOUT, ConnectionFactory.MAX_TIMEOUT, 1);
    connectionTimeout = new JSpinner(model);
}
Also used : JCheckBox(javax.swing.JCheckBox) JIntegerField(jgnash.ui.components.JIntegerField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPasswordField(javax.swing.JPasswordField) JSpinner(javax.swing.JSpinner) JTextFieldEx(jgnash.ui.components.JTextFieldEx)

Aggregations

JPasswordField (javax.swing.JPasswordField)33 JTextField (javax.swing.JTextField)19 JLabel (javax.swing.JLabel)17 JPanel (javax.swing.JPanel)13 JCheckBox (javax.swing.JCheckBox)10 BorderLayout (java.awt.BorderLayout)9 JButton (javax.swing.JButton)8 JRadioButton (javax.swing.JRadioButton)5 JTextArea (javax.swing.JTextArea)5 Dimension (java.awt.Dimension)4 JComponent (javax.swing.JComponent)4 JTextPane (javax.swing.JTextPane)4 Component (java.awt.Component)3 GridBagLayout (java.awt.GridBagLayout)3 ArrayList (java.util.ArrayList)3 Font (java.awt.Font)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridLayout (java.awt.GridLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2