Search in sources :

Example 41 with JPasswordField

use of javax.swing.JPasswordField in project protege-client by protegeproject.

the class LoginDialog method dialogInit.

/**
 * Called by constructors to initialize the dialog.
 *
 * @since ostermillerutils 1.00.00
 */
@Override
protected void dialogInit() {
    name = new JTextField("", 20);
    pass = new JPasswordField("", 20);
    okButton = new JButton("OK");
    cancelButton = new JButton("Cancel");
    nameLabel = new JLabel("Username: ");
    passLabel = new JLabel("Password: ");
    super.dialogInit();
    KeyListener keyListener = (new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE || (e.getSource() == cancelButton && e.getKeyCode() == KeyEvent.VK_ENTER)) {
                pressed_OK = false;
                LoginDialog.this.setVisible(false);
            }
            if (e.getSource() == okButton && e.getKeyCode() == KeyEvent.VK_ENTER) {
                pressed_OK = true;
                LoginDialog.this.setVisible(false);
            }
        }
    });
    addKeyListener(keyListener);
    ActionListener actionListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            if (source == name) {
                // the user pressed enter in the name field.
                name.transferFocus();
            } else {
                // other actions close the dialog.
                pressed_OK = (source == pass || source == okButton);
                LoginDialog.this.setVisible(false);
            }
        }
    };
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.insets.top = 5;
    c.insets.bottom = 5;
    JPanel pane = new JPanel(gridbag);
    pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20));
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(nameLabel, c);
    pane.add(nameLabel);
    gridbag.setConstraints(name, c);
    name.addActionListener(actionListener);
    name.addKeyListener(keyListener);
    pane.add(name);
    c.gridy = 1;
    gridbag.setConstraints(passLabel, c);
    pane.add(passLabel);
    gridbag.setConstraints(pass, c);
    pass.addActionListener(actionListener);
    pass.addKeyListener(keyListener);
    pane.add(pass);
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.CENTER;
    JPanel panel = new JPanel();
    okButton.addActionListener(actionListener);
    okButton.addKeyListener(keyListener);
    panel.add(okButton);
    cancelButton.addActionListener(actionListener);
    cancelButton.addKeyListener(keyListener);
    panel.add(cancelButton);
    gridbag.setConstraints(panel, c);
    pane.add(panel);
    getContentPane().add(pane);
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) JPasswordField(javax.swing.JPasswordField) KeyListener(java.awt.event.KeyListener)

Example 42 with JPasswordField

use of javax.swing.JPasswordField in project CCDD by nasa.

the class CcddServerPropertyDialog method initialize.

/**
 ********************************************************************************************
 * Create the server properties dialog
 ********************************************************************************************
 */
private void initialize() {
    // Create a border for the input fields
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
    // Create a panel to hold the components of the dialog
    JPanel selectPnl = new JPanel(new GridBagLayout());
    selectPnl.setBorder(BorderFactory.createEmptyBorder());
    // Create dialog based on supplied dialog type
    switch(dialogType) {
        case LOGIN:
            // Initialize the flags that indicates if a user name is available and if the
            // dialog should be resizable
            boolean isUsers = false;
            boolean allowResize = false;
            // Add the server host to the dialog so that the user knows what credentials are
            // required
            JPanel serverPnl = new JPanel();
            JLabel serverLbl1 = new JLabel("Enter credentials for server: ");
            serverLbl1.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            serverLbl1.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
            serverPnl.add(serverLbl1);
            JLabel serverLbl2 = new JLabel(dbControl.getHost());
            serverLbl2.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            serverLbl2.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
            serverPnl.add(serverLbl2);
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.insets.bottom = 0;
            selectPnl.add(serverPnl, gbc);
            gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
            gbc.weightx = 1.0;
            gbc.gridwidth = 1;
            gbc.gridy++;
            // Check if a connection exists to the server
            if (dbControl.isServerConnected()) {
                // Get the array containing the users
                String[] users = dbControl.queryUserList(CcddServerPropertyDialog.this);
                String[][] userInfo = new String[users.length][2];
                int userIndex = -1;
                // Step through each user
                for (int index = 0; index < users.length; index++) {
                    // Store the user name
                    userInfo[index][0] = users[index];
                    // Check if this is the current user
                    if (users[index].equals(dbControl.getUser())) {
                        // Store the index for the current user
                        userIndex = index;
                    }
                }
                // Add radio buttons for the users
                isUsers = addRadioButtons(dbControl.getUser(), false, userInfo, Arrays.asList(userIndex), "Select user", selectPnl, gbc);
                // Allow resizing the dialog if the number of users to choose from exceeds the
                // initial number of viewable rows (i.e., the scroll bar is displayed)
                allowResize = users.length > ModifiableSizeInfo.INIT_VIEWABLE_LIST_ROWS.getSize();
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() * 2;
            } else // No server connection exists; the user must enter a user name
            {
                // Add the user label and field
                JLabel userLbl = new JLabel("User");
                userLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.weightx = 0.0;
                gbc.gridx = 0;
                selectPnl.add(userLbl, gbc);
                userFld = new JTextField(dbControl.getUser(), 15);
                userFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                userFld.setEditable(true);
                userFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                userFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                userFld.setBorder(border);
                gbc.weightx = 1.0;
                gbc.gridx++;
                selectPnl.add(userFld, gbc);
                isUsers = true;
            }
            // Check if any users exist
            if (isUsers) {
                // Add the password label and field
                JLabel passwordLbl = new JLabel("Password");
                passwordLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.weightx = 0.0;
                gbc.gridx = 0;
                gbc.gridy++;
                gbc.insets.bottom = 0;
                selectPnl.add(passwordLbl, gbc);
                passwordFld = new JPasswordField("", 15);
                passwordFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                passwordFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                passwordFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                passwordFld.setBorder(border);
                passwordFld.setEditable(true);
                gbc.weightx = 1.0;
                gbc.gridx++;
                selectPnl.add(passwordFld, gbc);
                // Check if a user is selected
                if (!dbControl.getUser().isEmpty()) {
                    // Set the password field to initially have the focus
                    setInitialFocusComponent(passwordFld);
                }
                // Display the user & password dialog
                if (showOptionsDialog(ccddMain.getMainFrame(), selectPnl, "Select User", DialogOption.OK_CANCEL_OPTION, allowResize) == OK_BUTTON) {
                    // Check if a connection exists to the server
                    if (dbControl.isServerConnected()) {
                        // Store the user name from the selected radio button
                        dbControl.setUser(getRadioButtonSelected());
                    } else // No server connection exists
                    {
                        // Store the user name from the user field
                        dbControl.setUser(userFld.getText());
                    }
                    // Store the password
                    dbControl.setPassword(String.valueOf(passwordFld.getPassword()));
                    // Open the specified database as the new user; use the flag to determine
                    // if the active or default database should be opened
                    dbControl.openDatabaseInBackground(useActiveDatabase ? dbControl.getProjectName() : DEFAULT_DATABASE);
                }
            } else // No other user exists to choose
            {
                // Inform the user that no other user exists on the server
                new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>No other user exists", "Server Login", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
            }
            break;
        case DB_SERVER:
            // Create the database server host, using the list of remembered servers from the
            // program preferences, the port dialog labels and fields, and the check box for
            // enabling an SSL connection
            JLabel hostLbl = new JLabel("Host");
            hostLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            gbc.weightx = 0.0;
            selectPnl.add(hostLbl, gbc);
            List<String> servers = new ArrayList<String>(ModifiableSizeInfo.NUM_REMEMBERED_SERVERS.getSize());
            servers.addAll(Arrays.asList(ccddMain.getProgPrefs().get(SERVER_STRINGS, "").split(AUTO_COMPLETE_TEXT_SEPARATOR)));
            hostFld = new AutoCompleteTextField(servers, ModifiableSizeInfo.NUM_REMEMBERED_SERVERS.getSize());
            hostFld.setText(dbControl.getHost());
            hostFld.setColumns(15);
            hostFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
            hostFld.setEditable(true);
            hostFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
            hostFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
            hostFld.setBorder(border);
            gbc.weightx = 1.0;
            gbc.gridx++;
            selectPnl.add(hostFld, gbc);
            portLbl = new JLabel("Port");
            portLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            gbc.weightx = 0.0;
            gbc.gridx = 0;
            gbc.gridy++;
            selectPnl.add(portLbl, gbc);
            portFld = new JTextField(dbControl.getPort(), 4);
            portFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
            portFld.setEditable(true);
            portFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
            portFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
            portFld.setBorder(border);
            gbc.weightx = 1.0;
            gbc.gridx++;
            selectPnl.add(portFld, gbc);
            JCheckBox enableSSLCbox = new JCheckBox("Enable SSL", dbControl.isSSL());
            enableSSLCbox.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            enableSSLCbox.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
            enableSSLCbox.setBorder(BorderFactory.createEmptyBorder());
            gbc.insets.bottom = 0;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.weightx = 0.0;
            gbc.gridx = 0;
            gbc.gridy++;
            selectPnl.add(enableSSLCbox, gbc);
            // Display the server properties parameter dialog
            if (showOptionsDialog(ccddMain.getMainFrame(), selectPnl, "Database Server", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                // Update the host list and store it in the program preferences
                hostFld.updateList(hostFld.getText());
                ccddMain.getProgPrefs().put(SERVER_STRINGS, hostFld.getListAsString());
                // Open the default database using the new server properties
                dbControl.openDatabaseInBackground(DEFAULT_DATABASE, hostFld.getText(), portFld.getText(), enableSSLCbox.isSelected());
            }
            break;
        case WEB_SERVER:
            // Create the web server port dialog label and field
            portLbl = new JLabel("Port");
            portLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            gbc.weightx = 0.0;
            gbc.insets.bottom = 0;
            selectPnl.add(portLbl, gbc);
            portFld = new JTextField(ccddMain.getProgPrefs().get(WEB_SERVER_PORT, DEFAULT_WEB_SERVER_PORT), 4);
            portFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
            portFld.setEditable(true);
            portFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
            portFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
            portFld.setBorder(border);
            gbc.weightx = 1.0;
            gbc.gridx++;
            selectPnl.add(portFld, gbc);
            // Display the server properties parameter dialog
            if (showOptionsDialog(ccddMain.getMainFrame(), selectPnl, "Web Server", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                // Store the web server port
                ccddMain.getProgPrefs().put(WEB_SERVER_PORT, portFld.getText());
                // Check if the web server exists
                if (ccddMain.getWebServer() != null) {
                    // Store the web server port and restart the web server
                    ccddMain.getWebServer().startServer();
                }
            }
            break;
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) AutoCompleteTextField(CCDD.CcddClassesComponent.AutoCompleteTextField) JPasswordField(javax.swing.JPasswordField) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder)

Example 43 with JPasswordField

use of javax.swing.JPasswordField in project fql by CategoricalData.

the class DatabaseOptions method getOptions.

/**
 * @return
 */
@Override
public List<Option> getOptions() {
    final List<Option> opts = new LinkedList<>();
    final Map<String, String> saved = _theFrame.getMModel().getConnectionParams();
    if (!_skipConnSettings) {
        final String username = saved.get("username");
        String hostname = saved.get("hostname");
        final String port = saved.get("port");
        if (hostname == null) {
            // A reasonable hostname default
            hostname = "localhost";
        }
        opts.add(new Option(new JLabel("Username"), _username = JUtils.textField(username)));
        opts.add(new Option(new JLabel("Password"), _password = (JPasswordField) JUtils.fixHeight(new JPasswordField())));
        opts.add(new Option(new JLabel("Database hostname"), _hostname = JUtils.textField(hostname)));
        opts.add(new Option(new JLabel("Database port"), _port = JUtils.textField(port)));
    }
    String defaultDBName = saved.get("database");
    if (defaultDBName == null) {
        defaultDBName = _theFrame.getMModel().getDocInfo().getName().replaceAll("\\W+", "_").replaceFirst("^_+", "").replaceFirst("_+$", "");
    }
    opts.add(new Option(new JLabel("Database name"), _database = JUtils.textField(defaultDBName)));
    if ("PostgreSQL".equals(_dialect)) {
        String schema = saved.get("schema");
        if (schema == null) {
            schema = "";
        }
        opts.add(new Option(new JLabel("Schema name"), _schema = JUtils.textField(schema)));
    }
    final boolean quoting;
    String quoteSetting = saved.get("quoteIdentifiers");
    if (quoteSetting == null) {
        quoteSetting = Easik.getInstance().getSettings().getProperty("sql_quoting");
    }
    quoting = (quoteSetting != null) && "true".equals(quoteSetting);
    _quoteIdentifiers = new JCheckBox("Quote table and column names");
    _quoteIdentifiers.setSelected(quoting);
    opts.add(new Option(new JLabel("Identifier quoting"), _quoteIdentifiers));
    // describe these in more detail
    if (_dbd != null) {
        // current settings:
        if (_dbd.hasOption("hostname")) {
            _hostname.setText((String) _dbd.getOption("hostname"));
        }
        if (_dbd.hasOption("port")) {
            _port.setText((String) _dbd.getOption("port"));
        }
        if (_dbd.hasOption("username")) {
            _username.setText((String) _dbd.getOption("username"));
        }
        if (_dbd.hasOption("database")) {
            _database.setText((String) _dbd.getOption("database"));
        }
        if ("PostgreSQL".equals(_dialect) && _dbd.hasOption("schema")) {
            _schema.setText((String) _dbd.getOption("schema"));
        }
        if (_dbd.hasOption("quoteIdentifiers")) {
            _quoteIdentifiers.setSelected(Boolean.parseBoolean((String) _dbd.getOption("quoteIdentifiers")));
        }
    }
    return opts;
}
Also used : JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField) JLabel(javax.swing.JLabel) Option(easik.ui.Option) LinkedList(java.util.LinkedList)

Example 44 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 45 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 : JComponent(javax.swing.JComponent) ArrayList(java.util.ArrayList) 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)

Aggregations

JPasswordField (javax.swing.JPasswordField)102 JLabel (javax.swing.JLabel)61 JPanel (javax.swing.JPanel)47 JTextField (javax.swing.JTextField)46 BorderLayout (java.awt.BorderLayout)30 JButton (javax.swing.JButton)24 JCheckBox (javax.swing.JCheckBox)24 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 JTextArea (javax.swing.JTextArea)8