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;
}
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;
}
}
}
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]);
}
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);
}
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);
}
Aggregations