Search in sources :

Example 71 with JPasswordField

use of javax.swing.JPasswordField in project compss by bsc-wdc.

the class SubmitRemoteJob method getPassphrase.

private static String getPassphrase() {
    JPasswordField pwd = new JPasswordField();
    Object[] message = { "grid-proxy-init\nPlease enter your passphrase.", pwd };
    JOptionPane.showMessageDialog(null, message, "Grid-Proxy-Init", JOptionPane.QUESTION_MESSAGE);
    return new String(pwd.getPassword());
}
Also used : JPasswordField(javax.swing.JPasswordField)

Example 72 with JPasswordField

use of javax.swing.JPasswordField in project openmrs-core by openmrs.

the class BaseContextSensitiveTest method askForUsernameAndPassword.

/**
 * Utility method for obtaining username and password through Swing interface for tests. Any
 * tests extending the org.openmrs.BaseTest class may simply invoke this method by name.
 * Username and password are returned in a two-member String array. If the user aborts, null is
 * returned. <b> <em>Do not call for non-interactive tests, since this method will try to
 * render an interactive dialog box for authentication!</em></b>
 *
 * @param message string to display above username field
 * @return Two-member String array containing username and password, respectively, or
 *         <code>null</code> if user aborts dialog
 */
public static synchronized String[] askForUsernameAndPassword(String message) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    if (message == null || "".equals(message))
        message = "Enter username/password to authenticate to OpenMRS...";
    JPanel panel = new JPanel(new GridBagLayout());
    JLabel usernameLabel = new JLabel("Username");
    usernameLabel.setFont(font);
    usernameField = new JTextField(20);
    usernameField.setFont(font);
    JLabel passwordLabel = new JLabel("Password");
    passwordLabel.setFont(font);
    JPasswordField passwordField = new JPasswordField(20);
    passwordField.setFont(font);
    panel.add(usernameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0));
    panel.add(usernameField, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    panel.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0));
    panel.add(passwordField, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    frame = new JFrame();
    Window window = new Window(frame);
    frame.setVisible(true);
    frame.setTitle("JUnit Test Credentials");
    // We use a TimerTask to force focus on username, but still use
    // JOptionPane for model dialog
    TimerTask later = new TimerTask() {

        @Override
        public void run() {
            if (frame != null) {
                // bring the dialog's window to the front
                frame.toFront();
                usernameField.grabFocus();
            }
        }
    };
    // try setting focus half a second from now
    new Timer().schedule(later, 500);
    // attention grabber for those people that aren't as observant
    TimerTask laterStill = new TimerTask() {

        @Override
        public void run() {
            if (frame != null) {
                // bring the dialog's window to the
                frame.toFront();
                // front
                usernameField.grabFocus();
            }
        }
    };
    // if the user hasn't done anything in 10 seconds, tell them the window
    // is there
    new Timer().schedule(laterStill, 10000);
    // show the dialog box
    int response = JOptionPane.showConfirmDialog(window, panel, message, JOptionPane.OK_CANCEL_OPTION);
    // clear out the window so the timer doesn't screw up
    laterStill.cancel();
    frame.setVisible(false);
    window.setVisible(false);
    frame = null;
    // X in the top right
    return (response == 2 || response == -1 ? null : new String[] { usernameField.getText(), String.valueOf(passwordField.getPassword()) });
}
Also used : Window(java.awt.Window) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) DatabaseUnitRuntimeException(org.dbunit.DatabaseUnitRuntimeException) ContextAuthenticationException(org.openmrs.api.context.ContextAuthenticationException) FileNotFoundException(java.io.FileNotFoundException) DataSetException(org.dbunit.dataset.DataSetException) SQLException(java.sql.SQLException) DatabaseUnitException(org.dbunit.DatabaseUnitException) IOException(java.io.IOException) TimerTask(java.util.TimerTask) Timer(java.util.Timer) JPasswordField(javax.swing.JPasswordField) JFrame(javax.swing.JFrame)

Example 73 with JPasswordField

use of javax.swing.JPasswordField in project ili2db by claeis.

the class GpkgDbPanel method getDbpwdUi.

/**
 * This method initializes dbpwdUi
 *
 * @return javax.swing.JPasswordField
 */
private JPasswordField getDbpwdUi() {
    if (dbpwdUi == null) {
        dbpwdUi = new JPasswordField();
        dbpwdUi.setColumns(40);
    }
    return dbpwdUi;
}
Also used : JPasswordField(javax.swing.JPasswordField)

Example 74 with JPasswordField

use of javax.swing.JPasswordField in project ili2db by claeis.

the class PgDbPanel method getDbpwdUi.

/**
 * This method initializes dbpwdUi
 *
 * @return javax.swing.JPasswordField
 */
private JPasswordField getDbpwdUi() {
    if (dbpwdUi == null) {
        dbpwdUi = new JPasswordField();
        dbpwdUi.setColumns(40);
    }
    return dbpwdUi;
}
Also used : JPasswordField(javax.swing.JPasswordField)

Example 75 with JPasswordField

use of javax.swing.JPasswordField in project ili2db by claeis.

the class GeodbDbPanel method getDbpwdUi.

/**
 * This method initializes dbpwdUi
 *
 * @return javax.swing.JPasswordField
 */
private JPasswordField getDbpwdUi() {
    if (dbpwdUi == null) {
        dbpwdUi = new JPasswordField();
        dbpwdUi.setColumns(40);
    }
    return dbpwdUi;
}
Also used : JPasswordField(javax.swing.JPasswordField)

Aggregations

JPasswordField (javax.swing.JPasswordField)100 JLabel (javax.swing.JLabel)60 JPanel (javax.swing.JPanel)47 JTextField (javax.swing.JTextField)44 BorderLayout (java.awt.BorderLayout)30 JButton (javax.swing.JButton)24 JCheckBox (javax.swing.JCheckBox)23 GridBagLayout (java.awt.GridBagLayout)22 GridBagConstraints (java.awt.GridBagConstraints)19 ActionEvent (java.awt.event.ActionEvent)19 ActionListener (java.awt.event.ActionListener)19 Insets (java.awt.Insets)18 Dimension (java.awt.Dimension)15 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 EmptyBorder (javax.swing.border.EmptyBorder)12 EtchedBorder (javax.swing.border.EtchedBorder)12 AbstractAction (javax.swing.AbstractAction)11 CompoundBorder (javax.swing.border.CompoundBorder)11 ItemEvent (java.awt.event.ItemEvent)7