use of javax.swing.JPasswordField in project triplea by triplea-game.
the class LobbyGamePanel method stopGameHeadlessHostBot.
private void stopGameHeadlessHostBot() {
final int selectedIndex = gameTable.getSelectedRow();
if (selectedIndex == -1) {
return;
}
final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to perform a remote stop game on this host?", "Remote Stopgame Headless Host Bot", JOptionPane.OK_CANCEL_OPTION);
if (result != JOptionPane.OK_OPTION) {
return;
}
final INode lobbyWatcherNode = getLobbyWatcherNodeForTableRow(selectedIndex);
final IModeratorController controller = (IModeratorController) messengers.getRemoteMessenger().getRemote(AbstractModeratorController.getModeratorControllerName());
final JLabel label = new JLabel("Enter Host Remote Access Password, (Leave blank for no password).");
final JPasswordField passwordField = new JPasswordField();
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(passwordField, BorderLayout.CENTER);
final int selectedOption = JOptionPane.showOptionDialog(getTopLevelAncestor(), panel, "Host Remote Access Password?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
if (selectedOption != JOptionPane.OK_OPTION || passwordField.getPassword() == null) {
return;
}
final String password = new String(passwordField.getPassword());
final String salt = controller.getHeadlessHostBotSalt(lobbyWatcherNode);
final String hashedPassword = hashPassword(password, salt);
final String response = controller.stopGameHeadlessHostBot(lobbyWatcherNode, hashedPassword, salt);
JOptionPane.showMessageDialog(null, (response == null ? "Successfully attempted stop of current game on host" : "Failed: " + response));
}
use of javax.swing.JPasswordField in project jmulticard by ctt-gob-es.
the class UIPasswordCallback method getPassword.
@Override
public char[] getPassword() {
final JPasswordField pwd = new JPasswordField(10);
final JLabel lbText = new JLabel(this.message);
lbText.setMinimumSize(new Dimension(lbText.getFontMetrics(lbText.getFont()).stringWidth(this.message), lbText.getSize().height));
lbText.setLabelFor(pwd);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(lbText);
panel.add(pwd);
final JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, new ImageIcon(this.getClass().getResource(DNI_LOGO))) {
private static final long serialVersionUID = -3012522768561175760L;
@Override
public void selectInitialValue() {
pwd.requestFocusInWindow();
}
};
final JDialog dialog = pane.createDialog(this.parent, this.title);
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
final Object selectedValue = pane.getValue();
if (selectedValue == null) {
return new char[0];
}
if (((Integer) selectedValue).intValue() == JOptionPane.OK_OPTION) {
return pwd.getPassword();
}
throw new CancelledOperationException(// $NON-NLS-1$
"La insercion de contrasena ha sido cancelada por el usuario");
}
use of javax.swing.JPasswordField in project tetrad by cmu-phil.
the class HpcAccountEditor method initiateUI.
private void initiateUI() {
setLayout(new BorderLayout());
// Header
JPanel headerPanel = new JPanel(new BorderLayout());
JLabel headerLabel = new JLabel("High-Performance Computing Account");
headerLabel.setFont(new Font(headerLabel.getFont().getName(), Font.BOLD, 20));
headerPanel.add(headerLabel, BorderLayout.CENTER);
JPanel spacePanel = new JPanel();
spacePanel.setSize(300, 100);
headerPanel.add(spacePanel, BorderLayout.SOUTH);
add(headerPanel, BorderLayout.NORTH);
// Content
Box contentBox = Box.createVerticalBox();
// Connection Name
Box connBox = Box.createHorizontalBox();
JLabel connLabel = new JLabel("Connection", JLabel.TRAILING);
connLabel.setPreferredSize(new Dimension(100, 5));
connBox.add(connLabel);
final JTextField connField = new JTextField(20);
connField.setText(hpcAccount.getConnectionName());
connField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setConnectionName(connField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
connLabel.setLabelFor(connField);
connBox.add(connField);
contentBox.add(connBox);
// Username
Box userBox = Box.createHorizontalBox();
JLabel userLabel = new JLabel("Username", JLabel.TRAILING);
userLabel.setPreferredSize(new Dimension(100, 5));
userBox.add(userLabel);
final JTextField userField = new JTextField(20);
userField.setText(hpcAccount.getUsername());
userField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setUsername(userField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
userLabel.setLabelFor(userField);
userBox.add(userField);
contentBox.add(userBox);
// Password
Box passBox = Box.createHorizontalBox();
JLabel passLabel = new JLabel("Password", JLabel.TRAILING);
passLabel.setPreferredSize(new Dimension(100, 5));
passBox.add(passLabel);
final JPasswordField passField = new JPasswordField(20);
passField.setText(hpcAccount.getPassword());
passField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setPassword(new String(passField.getPassword()));
}
@Override
public void keyPressed(KeyEvent e) {
}
});
passLabel.setLabelFor(passField);
passBox.add(passField);
contentBox.add(passBox);
// Scheme
JPanel schemePanel = new JPanel(new BorderLayout());
JLabel schemeLabel = new JLabel("Scheme", JLabel.TRAILING);
schemeLabel.setPreferredSize(new Dimension(100, 5));
schemePanel.add(schemeLabel, BorderLayout.WEST);
final JRadioButton httpRadioButton = new JRadioButton("http");
final JRadioButton httpsRadioButton = new JRadioButton("https");
if (hpcAccount.getScheme().equalsIgnoreCase("https")) {
httpsRadioButton.setSelected(true);
} else {
httpRadioButton.setSelected(true);
}
ButtonGroup schemeGroup = new ButtonGroup();
schemeGroup.add(httpRadioButton);
schemeGroup.add(httpsRadioButton);
Box schemeRadioBox = Box.createHorizontalBox();
schemeRadioBox.add(httpRadioButton);
schemeRadioBox.add(httpsRadioButton);
schemeLabel.setLabelFor(schemeRadioBox);
ActionListener schemeActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (httpRadioButton.isSelected()) {
hpcAccount.setScheme("http");
} else {
hpcAccount.setScheme("https");
}
}
};
httpRadioButton.addActionListener(schemeActionListener);
httpsRadioButton.addActionListener(schemeActionListener);
schemePanel.add(schemeRadioBox, BorderLayout.CENTER);
contentBox.add(schemePanel);
// Host
Box hostBox = Box.createHorizontalBox();
JLabel hostLabel = new JLabel("Host Name", JLabel.TRAILING);
hostLabel.setPreferredSize(new Dimension(100, 5));
hostBox.add(hostLabel);
final JTextField hostField = new JTextField(20);
hostField.setText(hpcAccount.getHostname());
hostField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setHostname(hostField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
hostLabel.setLabelFor(hostField);
hostBox.add(hostField);
contentBox.add(hostBox);
// Port number
Box portBox = Box.createHorizontalBox();
JLabel portLabel = new JLabel("Port Number", JLabel.TRAILING);
portLabel.setPreferredSize(new Dimension(100, 5));
portBox.add(portLabel);
final JTextField portField = new JTextField(20);
portField.setText(String.valueOf(hpcAccount.getPort()));
portField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
try {
int port = Integer.parseInt(portField.getText());
hpcAccount.setPort(port);
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
if (portField.getText().trim().length() > 0) {
JOptionPane.showMessageDialog(portField, "Port number is decimal number only!");
}
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
portLabel.setLabelFor(portField);
portBox.add(portField);
contentBox.add(portBox);
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.add(contentBox, BorderLayout.NORTH);
add(contentPanel, BorderLayout.CENTER);
// Footer -> Test and Save buttons
JPanel footerPanel = new JPanel(new BorderLayout());
final JButton testConnButton = new JButton("Test Connection");
testConnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
button.setText("Testing...");
parentComponent.updateUI();
button.setEnabled(false);
boolean success = HpcAccountUtils.testConnection(hpcAccountManager, hpcAccount);
// Pop-up the test result
JOptionPane.showMessageDialog(null, "" + hpcAccount + " Connection " + (success ? "Successful" : "Failed"), "HPC Account Setting", JOptionPane.INFORMATION_MESSAGE);
button.setEnabled(true);
button.setText("Test Connection");
hpcAccount.setLastLoginDate(new Date());
hpcAccountManager.saveAccount(hpcAccount);
}
});
JButton saveButton = new JButton("Save");
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
button.setText("Saving...");
parentComponent.updateUI();
button.setEnabled(false);
hpcAccountManager.saveAccount(hpcAccount);
if (listModel.indexOf(hpcAccount) == -1) {
listModel.addElement(hpcAccount);
}
button.setEnabled(true);
button.setText("Save");
parentComponent.updateUI();
}
});
footerPanel.add(testConnButton, BorderLayout.WEST);
footerPanel.add(saveButton, BorderLayout.EAST);
add(footerPanel, BorderLayout.SOUTH);
}
use of javax.swing.JPasswordField in project open-ecard by ecsec.
the class SettingsGroup method addInputItem.
/**
* Adds an input field to the group.
* The specified property is bound to the input and updates when the value changes.
*
* @param name Name displayed on the label besides the input element.
* @param description Optional tooltip description visible when hovering the label.
* @param property Property entry this element is bound to.
* @param isPassword If {@code true} the input field's text is masked and thus usable for passwords.
* @return The input element which has been created and added to the entry.
*/
protected JTextField addInputItem(@Nonnull String name, @Nullable String description, @Nonnull final String property, boolean isPassword) {
JLabel label = addLabel(name, description);
String value = properties.getProperty(property);
value = value == null ? "" : value;
final JTextField input;
if (isPassword) {
input = new JPasswordField(value) {
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = 100;
return dim;
}
};
} else {
input = new JTextField(value) {
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = 100;
return dim;
}
};
}
fieldLabels.put(input, label);
// add listener for value changes
input.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
properties.setProperty(property, input.getText());
}
@Override
public void removeUpdate(DocumentEvent e) {
properties.setProperty(property, input.getText());
}
@Override
public void changedUpdate(DocumentEvent e) {
// ignore
}
});
addComponent(input);
itemIdx++;
return input;
}
use of javax.swing.JPasswordField in project opt4j by felixreimann.
the class Query method addPassword.
/**
* Create a single-line password box with the specified name, label, and
* default value. To control the width of the box, call setTextWidth()
* first. To get the value, call getCharArrayValue(). Calling
* getStringValue() on a password entry will result in an error because it
* is less secure to pass around passwords as Strings than as arrays of
* characters.
* <p>
* The underlying class that is used to implement the password facility is
* javax.swing.JPasswordField. For details about how to use JPasswordField,
* see the <a href=
* "http://java.sun.com/docs/books/tutorial/uiswing/components/passwordfield.html"
* target="_top">Java Tutorial</a>
*
* @param name
* The name used to identify the entry (when accessing the
* entry).
* @param label
* The label to attach to the entry.
* @param defaultValue
* Default value to appear in the entry box.
* @param background
* The background color.
* @param foreground
* The foreground color.
* @since Ptolemy II 3.1
*/
public void addPassword(String name, String label, String defaultValue, Color background, Color foreground) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
JPasswordField entryBox = new JPasswordField(defaultValue, _width);
entryBox.setBackground(background);
entryBox.setForeground(foreground);
_addPair(name, lbl, entryBox, entryBox);
// Add the listener last so that there is no notification
// of the first value.
entryBox.addActionListener(new QueryActionListener(name));
// Add a listener for loss of focus. When the entry gains
// and then loses focus, listeners are notified of an update,
// but only if the value has changed since the last notification.
// FIXME: Unfortunately, Java calls this listener some random
// time after the window has been closed. It is not even a
// a queued event when the window is closed. Thus, we have
// a subtle bug where if you enter a value in a line, do not
// hit return, and then click on the X to close the window,
// the value is restored to the original, and then sometime
// later, the focus is lost and the entered value becomes
// the value of the parameter. I don't know of any workaround.
entryBox.addFocusListener(new QueryFocusListener(name));
}
Aggregations