use of javax.swing.JPasswordField in project zaproxy by zaproxy.
the class StandardFieldsDialog method addPasswordField.
/**
* Adds a {@link JPasswordField} field, with the given label and, optionally, the given value.
*
* @param fieldLabel the label of the field
* @param value the value of the field, might be {@code null}
* @throws IllegalArgumentException if the dialogue is a tabbed dialogue
* @since TODO add version
* @see #addPasswordField(int, String, String)
* @see #getPasswordValue(String)
*/
public void addPasswordField(String fieldLabel, String value) {
if (isTabbed()) {
throw new IllegalArgumentException("Initialised as a tabbed dialog - must use method with tab parameters");
}
JPasswordField field = new JPasswordField();
if (value != null) {
field.setText(value);
}
this.addField(fieldLabel, field, field, 0.0D);
}
use of javax.swing.JPasswordField in project zaproxy by zaproxy.
the class StandardFieldsDialog method addPasswordField.
/**
* Adds a {@link JPasswordField} field to the tab with the given index, with the given label and, optionally, the given
* value.
*
* @param tabIndex the index of the tab
* @param fieldLabel the label of the field
* @param value the value of the field, might be {@code null}
* @throws IllegalArgumentException if the dialogue is not a tabbed dialogue or if the index does not correspond to an
* existing tab
* @since TODO add version
* @see #addPasswordField(String, String)
* @see #getPasswordValue(String)
*/
public void addPasswordField(int tabIndex, String fieldLabel, String value) {
if (!isTabbed()) {
throw new IllegalArgumentException("Not initialised as a tabbed dialog - must use method without tab parameters");
}
if (tabIndex < 0 || tabIndex >= this.tabPanels.size()) {
throw new IllegalArgumentException("Invalid tab index: " + tabIndex);
}
JPasswordField field = new JPasswordField();
if (value != null) {
field.setText(value);
}
this.addField(this.tabPanels.get(tabIndex), this.tabOffsets.get(tabIndex), fieldLabel, field, field, 0.0D);
incTabOffset(tabIndex);
}
use of javax.swing.JPasswordField in project nhin-d by DirectProject.
the class ComponentCreation method createComponent.
/**
* Process the container pane to create different swing component as per the identifier given as parameter
* @param type This decide which component should be created
* @param labelData This is the value of a component/or can be used as title of the component
* @param flag This is used to make any check box or radio button selected
* @param c is a object of GridBagConstarins, and used to set any grid layout
* @param pane Container object to add component into this pane
* @param myButtonGroup used for radio or check boxes to group together
* @param gridx This is the x index integer value for the component inside the grid
* @param gridy This is the y index integer value for the component inside the grid
* @return void
*/
public void createComponent(String type, String lableData, boolean flag, GridBagConstraints c, Container pane, ButtonGroup myButtonGroup, int gridx, int gridy) {
if (type.equalsIgnoreCase("RADIO")) {
JRadioButton aButton = new JRadioButton(lableData, flag);
c.gridx = gridx;
c.gridy = gridy;
pane.add(aButton, c);
/*
* Button group to make the dynamic movement of screens
*/
TrustBundlePublisher ex = new TrustBundlePublisher();
if (myButtonGroup != null) {
myButtonGroup.add(aButton);
if (lableData.equalsIgnoreCase(" Create Unsigned Trust Bundle")) {
//UnSignedTrustBundle ex = new UnSignedTrustBundle();
aButton.addActionListener(ex);
} else if (lableData.equalsIgnoreCase(" Create Signed Trust Bundle")) {
//SignedTrustBundle ex = new SignedTrustBundle();
aButton.addActionListener(ex);
} else {
//ViewTrustBundle ex = new ViewTrustBundle();
aButton.addActionListener(ex);
}
}
} else if (type.equalsIgnoreCase("LABEL")) {
JLabel label1 = new JLabel(lableData);
c.gridx = gridx;
c.gridy = gridy;
pane.add(label1, c);
} else if (type.equalsIgnoreCase("TEXT")) {
JTextField field = new JTextField();
c.gridx = gridx;
c.gridy = gridy;
pane.add(field, c);
} else if (type.equalsIgnoreCase("PASSWORD")) {
//JTextField field = new JTextField();
JPasswordField passwordField = new JPasswordField(10);
//passwordField.setActionCommand(OK);
//passwordField.addActionListener(this);
c.gridx = gridx;
c.gridy = gridy;
pane.add(passwordField, c);
} else if (type.equalsIgnoreCase("BUTTON")) {
JButton button = new JButton(lableData);
c.gridx = gridx;
c.gridy = gridy;
pane.add(button, c);
ButtonSelector create = new ButtonSelector(pane);
button.addActionListener(create);
} else if (type.equalsIgnoreCase("TEXTPANE")) {
JTextPane jTextPane = new JTextPane();
jTextPane.setEditable(false);
jTextPane.setBackground(new Color(238, 238, 238));
;
//jTextPane.setSize(55, 10);
c.gridx = gridx;
c.gridy = gridy;
pane.add(jTextPane, c);
} else if (type.equalsIgnoreCase("TEXTAREA")) {
JTextArea jTextPane = new JTextArea(lableData);
jTextPane.setEditable(false);
jTextPane.setBackground(new Color(238, 238, 238));
;
c.gridx = gridx;
c.gridy = gridy;
pane.add(jTextPane, c);
}
}
use of javax.swing.JPasswordField in project jdk8u_jdk by JetBrains.
the class DialogCallbackHandler method handle.
/**
* Handles the specified set of callbacks.
*
* @param callbacks the callbacks to handle
* @throws UnsupportedCallbackException if the callback is not an
* instance of NameCallback or PasswordCallback
*/
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
/* Collect messages to display in the dialog */
final List<Object> messages = new ArrayList<>(3);
/* Collection actions to perform if the user clicks OK */
final List<Action> okActions = new ArrayList<>(2);
ConfirmationInfo confirmation = new ConfirmationInfo();
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof TextOutputCallback) {
TextOutputCallback tc = (TextOutputCallback) callbacks[i];
switch(tc.getMessageType()) {
case TextOutputCallback.INFORMATION:
confirmation.messageType = JOptionPane.INFORMATION_MESSAGE;
break;
case TextOutputCallback.WARNING:
confirmation.messageType = JOptionPane.WARNING_MESSAGE;
break;
case TextOutputCallback.ERROR:
confirmation.messageType = JOptionPane.ERROR_MESSAGE;
break;
default:
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized message type");
}
messages.add(tc.getMessage());
} else if (callbacks[i] instanceof NameCallback) {
final NameCallback nc = (NameCallback) callbacks[i];
JLabel prompt = new JLabel(nc.getPrompt());
final JTextField name = new JTextField(JTextFieldLen);
String defaultName = nc.getDefaultName();
if (defaultName != null) {
name.setText(defaultName);
}
/*
* Put the prompt and name in a horizontal box,
* and add that to the set of messages.
*/
Box namePanel = Box.createHorizontalBox();
namePanel.add(prompt);
namePanel.add(name);
messages.add(namePanel);
/* Store the name back into the callback if OK */
okActions.add(new Action() {
public void perform() {
nc.setName(name.getText());
}
});
} else if (callbacks[i] instanceof PasswordCallback) {
final PasswordCallback pc = (PasswordCallback) callbacks[i];
JLabel prompt = new JLabel(pc.getPrompt());
final JPasswordField password = new JPasswordField(JPasswordFieldLen);
if (!pc.isEchoOn()) {
password.setEchoChar('*');
}
Box passwordPanel = Box.createHorizontalBox();
passwordPanel.add(prompt);
passwordPanel.add(password);
messages.add(passwordPanel);
okActions.add(new Action() {
public void perform() {
pc.setPassword(password.getPassword());
}
});
} else if (callbacks[i] instanceof ConfirmationCallback) {
ConfirmationCallback cc = (ConfirmationCallback) callbacks[i];
confirmation.setCallback(cc);
if (cc.getPrompt() != null) {
messages.add(cc.getPrompt());
}
} else {
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
/* Display the dialog */
int result = JOptionPane.showOptionDialog(parentComponent, messages.toArray(), "Confirmation", /* title */
confirmation.optionType, confirmation.messageType, null, /* icon */
confirmation.options, /* options */
confirmation.initialValue);
/* Perform the OK actions */
if (result == JOptionPane.OK_OPTION || result == JOptionPane.YES_OPTION) {
Iterator<Action> iterator = okActions.iterator();
while (iterator.hasNext()) {
iterator.next().perform();
}
}
confirmation.handleResult(result);
}
use of javax.swing.JPasswordField in project jdk8u_jdk by JetBrains.
the class PasswordView method drawSelectedText.
/**
* Renders the given range in the model as selected text. This
* is implemented to render the text in the color specified in
* the hosting component. It assumes the highlighter will render
* the selected background. Uses the result of getEchoChar() to
* display the characters.
*
* @param g the graphics context
* @param x the starting X coordinate >= 0
* @param y the starting Y coordinate >= 0
* @param p0 the starting offset in the model >= 0
* @param p1 the ending offset in the model >= p0
* @return the X location of the end of the range >= 0
* @exception BadLocationException if p0 or p1 are out of range
*/
protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
g.setColor(selected);
Container c = getContainer();
if (c instanceof JPasswordField) {
JPasswordField f = (JPasswordField) c;
if (!f.echoCharIsSet()) {
return super.drawSelectedText(g, x, y, p0, p1);
}
char echoChar = f.getEchoChar();
int n = p1 - p0;
for (int i = 0; i < n; i++) {
x = drawEchoCharacter(g, x, y, echoChar);
}
}
return x;
}
Aggregations