Example usage for javax.swing JPasswordField JPasswordField

List of usage examples for javax.swing JPasswordField JPasswordField

Introduction

In this page you can find the example usage for javax.swing JPasswordField JPasswordField.

Prototype

public JPasswordField(int columns) 

Source Link

Document

Constructs a new empty JPasswordField with the specified number of columns.

Usage

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

/**
 * This will parse a document./*from w w  w  .  j a v a2  s .  co m*/
 *
 * @param file The file addressing the document.
 * @throws IOException If there is an error parsing the document.
 */
private void parseDocument(File file, String password) throws IOException {
    while (true) {
        try {
            document = PDDocument.load(file, password);
        } catch (InvalidPasswordException ipe) {
            // https://stackoverflow.com/questions/8881213/joptionpane-to-get-password
            JPanel panel = new JPanel();
            JLabel label = new JLabel("Password:");
            JPasswordField pass = new JPasswordField(10);
            panel.add(label);
            panel.add(pass);
            String[] options = new String[] { "OK", "Cancel" };
            int option = JOptionPane.showOptionDialog(null, panel, "Enter password", JOptionPane.NO_OPTION,
                    JOptionPane.PLAIN_MESSAGE, null, options, "");
            if (option == 0) {
                password = new String(pass.getPassword());
                continue;
            }
            throw ipe;
        }
        break;
    }
    printMenuItem.setEnabled(true);
    reopenMenuItem.setEnabled(true);
}

From source file:org.kse.gui.dialogs.importexport.DImportKeyPairOpenSsl.java

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;//  www.j av a 2 s  .c o m
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;

    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;

    jlEncrypted = new JLabel(res.getString("DImportKeyPairOpenSsl.jlEncrypted.text"));
    GridBagConstraints gbc_jlEncrypted = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypted.gridy = 0;

    jcbEncrypted = new JCheckBox();
    jcbEncrypted.setSelected(true);
    jcbEncrypted.setToolTipText(res.getString("DImportKeyPairOpenSsl.jcbEncrypted.tooltip"));
    GridBagConstraints gbc_jcbEncrypted = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypted.gridy = 0;

    jlPassword = new JLabel(res.getString("DImportKeyPairOpenSsl.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 1;

    jpfPassword = new JPasswordField(15);
    jpfPassword.setToolTipText(res.getString("DImportKeyPairOpenSsl.jpfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 1;

    jlPrivateKey = new JLabel(res.getString("DImportKeyPairOpenSsl.jlPrivateKey.text"));
    GridBagConstraints gbc_jlPrivateKey = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPrivateKey.gridy = 2;

    jtfPrivateKeyPath = new JTextField(30);
    jtfPrivateKeyPath.setToolTipText(res.getString("DImportKeyPairOpenSsl.jtfPrivateKeyPath.tooltip"));
    GridBagConstraints gbc_jtfPrivateKeyPath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfPrivateKeyPath.gridy = 2;
    gbc_jtfPrivateKeyPath.gridwidth = 6;

    jbPrivateKeyBrowse = new JButton(res.getString("DImportKeyPairOpenSsl.jbPrivateKeyBrowse.text"));
    PlatformUtil.setMnemonic(jbPrivateKeyBrowse,
            res.getString("DImportKeyPairOpenSsl.jbPrivateKeyBrowse.mnemonic").charAt(0));
    jbPrivateKeyBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairOpenSsl.this);
                privateKeyBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairOpenSsl.this);
            }
        }
    });
    jbPrivateKeyBrowse.setToolTipText(res.getString("DImportKeyPairOpenSsl.jbPrivateKeyBrowse.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyBrowse.gridy = 2;
    gbc_jbPrivateKeyBrowse.gridx = 9;

    jbPrivateKeyDetails = new JButton(res.getString("DImportKeyPairOpenSsl.jbPrivateKeyDetails.text"));
    jbPrivateKeyDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairOpenSsl.this);
                privateKeyDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairOpenSsl.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbPrivateKeyDetails,
            res.getString("DImportKeyPairOpenSsl.jbPrivateKeyDetails.mnemonic").charAt(0));
    jbPrivateKeyDetails.setToolTipText(res.getString("DImportKeyPairOpenSsl.jbPrivateKeyDetails.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyDetails.gridy = 2;
    gbc_jbPrivateKeyDetails.gridx = 12;

    jlCertificate = new JLabel(res.getString("DImportKeyPairOpenSsl.jlCertificate.text"));
    GridBagConstraints gbc_jlCertificate = (GridBagConstraints) gbcLbl.clone();
    gbc_jlCertificate.gridy = 3;

    jtfCertificatePath = new JTextField(30);
    jtfCertificatePath.setToolTipText(res.getString("DImportKeyPairOpenSsl.jtfCertificatePath.tooltip"));
    GridBagConstraints gbc_jtfCertificatePath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfCertificatePath.gridy = 3;
    gbc_jtfCertificatePath.gridwidth = 6;

    jbCertificateBrowse = new JButton(res.getString("DImportKeyPairOpenSsl.jbCertificateBrowse.text"));
    jbCertificateBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairOpenSsl.this);
                certificateBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairOpenSsl.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateBrowse,
            res.getString("DImportKeyPairOpenSsl.jbCertificateBrowse.mnemonic").charAt(0));
    jbCertificateBrowse.setToolTipText(res.getString("DImportKeyPairOpenSsl.jbCertificateBrowse.tooltip"));
    GridBagConstraints gbc_jbCertificateBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateBrowse.gridy = 3;
    gbc_jbCertificateBrowse.gridx = 9;

    jbCertificateDetails = new JButton(res.getString("DImportKeyPairOpenSsl.jbCertificateDetails.text"));
    jbCertificateDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairOpenSsl.this);
                certificateDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairOpenSsl.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateDetails,
            res.getString("DImportKeyPairOpenSsl.jbCertificateDetails.mnemonic").charAt(0));
    jbCertificateDetails.setToolTipText(res.getString("DImportKeyPairOpenSsl.jbCertificateDetails.tooltip"));
    GridBagConstraints gbc_jbCertificateDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateDetails.gridy = 3;
    gbc_jbCertificateDetails.gridx = 12;

    jpKeyPair = new JPanel(new GridBagLayout());
    jpKeyPair.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()),
            new EmptyBorder(5, 5, 5, 5)));

    jpKeyPair.add(jlEncrypted, gbc_jlEncrypted);
    jpKeyPair.add(jcbEncrypted, gbc_jcbEncrypted);
    jpKeyPair.add(jlPassword, gbc_jlPassword);
    jpKeyPair.add(jpfPassword, gbc_jpfPassword);
    jpKeyPair.add(jlPrivateKey, gbc_jlPrivateKey);
    jpKeyPair.add(jtfPrivateKeyPath, gbc_jtfPrivateKeyPath);
    jpKeyPair.add(jbPrivateKeyBrowse, gbc_jbPrivateKeyBrowse);
    jpKeyPair.add(jbPrivateKeyDetails, gbc_jbPrivateKeyDetails);
    jpKeyPair.add(jlCertificate, gbc_jlCertificate);
    jpKeyPair.add(jtfCertificatePath, gbc_jtfCertificatePath);
    jpKeyPair.add(jbCertificateBrowse, gbc_jbCertificateBrowse);
    jpKeyPair.add(jbCertificateDetails, gbc_jbCertificateDetails);

    jcbEncrypted.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypted.isSelected()) {
                jpfPassword.setEnabled(true);
            } else {
                jpfPassword.setEnabled(false);
                jpfPassword.setText("");
            }
        }
    });

    jbImport = new JButton(res.getString("DImportKeyPairOpenSsl.jbImport.text"));
    PlatformUtil.setMnemonic(jbImport, res.getString("DImportKeyPairOpenSsl.jbImport.mnemonic").charAt(0));
    jbImport.setToolTipText(res.getString("DImportKeyPairOpenSsl.jbImport.tooltip"));
    jbImport.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairOpenSsl.this);
                importPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairOpenSsl.this);
            }
        }
    });

    jbCancel = new JButton(res.getString("DImportKeyPairOpenSsl.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });

    jpButtons = PlatformUtil.createDialogButtonPanel(jbImport, jbCancel);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpKeyPair, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    setTitle(res.getString("DImportKeyPairOpenSsl.Title"));
    setResizable(false);

    getRootPane().setDefaultButton(jbImport);

    pack();
}

From source file:org.kse.gui.dialogs.importexport.DImportKeyPairPkcs8.java

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;//from  w w w  .ja  va  2s. c o  m
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;

    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;

    jlEncrypted = new JLabel(res.getString("DImportKeyPairPkcs8.jlEncrypted.text"));
    GridBagConstraints gbc_jlEncrypted = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypted.gridy = 0;

    jcbEncrypted = new JCheckBox();
    jcbEncrypted.setSelected(true);
    jcbEncrypted.setToolTipText(res.getString("DImportKeyPairPkcs8.jcbEncrypted.tooltip"));
    GridBagConstraints gbc_jcbEncrypted = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypted.gridy = 0;

    jlPassword = new JLabel(res.getString("DImportKeyPairPkcs8.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 1;

    jpfPassword = new JPasswordField(15);
    jpfPassword.setToolTipText(res.getString("DImportKeyPairPkcs8.jpfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 1;

    jlPrivateKey = new JLabel(res.getString("DImportKeyPairPkcs8.jlPrivateKey.text"));
    GridBagConstraints gbc_jlPrivateKey = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPrivateKey.gridy = 2;

    jtfPrivateKeyPath = new JTextField(30);
    jtfPrivateKeyPath.setToolTipText(res.getString("DImportKeyPairPkcs8.jtfPrivateKeyPath.tooltip"));
    GridBagConstraints gbc_jtfPrivateKeyPath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfPrivateKeyPath.gridy = 2;
    gbc_jtfPrivateKeyPath.gridwidth = 6;

    jbPrivateKeyBrowse = new JButton(res.getString("DImportKeyPairPkcs8.jbPrivateKeyBrowse.text"));
    PlatformUtil.setMnemonic(jbPrivateKeyBrowse,
            res.getString("DImportKeyPairPkcs8.jbPrivateKeyBrowse.mnemonic").charAt(0));
    jbPrivateKeyBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPkcs8.this);
                privateKeyBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPkcs8.this);
            }
        }
    });
    jbPrivateKeyBrowse.setToolTipText(res.getString("DImportKeyPairPkcs8.jbPrivateKeyBrowse.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyBrowse.gridy = 2;
    gbc_jbPrivateKeyBrowse.gridx = 9;

    jbPrivateKeyDetails = new JButton(res.getString("DImportKeyPairPkcs8.jbPrivateKeyDetails.text"));
    jbPrivateKeyDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPkcs8.this);
                privateKeyDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPkcs8.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbPrivateKeyDetails,
            res.getString("DImportKeyPairPkcs8.jbPrivateKeyDetails.mnemonic").charAt(0));
    jbPrivateKeyDetails.setToolTipText(res.getString("DImportKeyPairPkcs8.jbPrivateKeyDetails.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyDetails.gridy = 2;
    gbc_jbPrivateKeyDetails.gridx = 12;

    jlCertificate = new JLabel(res.getString("DImportKeyPairPkcs8.jlCertificate.text"));
    GridBagConstraints gbc_jlCertificate = (GridBagConstraints) gbcLbl.clone();
    gbc_jlCertificate.gridy = 3;

    jtfCertificatePath = new JTextField(30);
    jtfCertificatePath.setToolTipText(res.getString("DImportKeyPairPkcs8.jtfCertificatePath.tooltip"));
    GridBagConstraints gbc_jtfCertificatePath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfCertificatePath.gridy = 3;
    gbc_jtfCertificatePath.gridwidth = 6;

    jbCertificateBrowse = new JButton(res.getString("DImportKeyPairPkcs8.jbCertificateBrowse.text"));
    jbCertificateBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPkcs8.this);
                certificateBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPkcs8.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateBrowse,
            res.getString("DImportKeyPairPkcs8.jbCertificateBrowse.mnemonic").charAt(0));
    jbCertificateBrowse.setToolTipText(res.getString("DImportKeyPairPkcs8.jbCertificateBrowse.tooltip"));
    GridBagConstraints gbc_jbCertificateBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateBrowse.gridy = 3;
    gbc_jbCertificateBrowse.gridx = 9;

    jbCertificateDetails = new JButton(res.getString("DImportKeyPairPkcs8.jbCertificateDetails.text"));
    jbCertificateDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPkcs8.this);
                certificateDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPkcs8.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateDetails,
            res.getString("DImportKeyPairPkcs8.jbCertificateDetails.mnemonic").charAt(0));
    jbCertificateDetails.setToolTipText(res.getString("DImportKeyPairPkcs8.jbCertificateDetails.tooltip"));
    GridBagConstraints gbc_jbCertificateDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateDetails.gridy = 3;
    gbc_jbCertificateDetails.gridx = 12;

    jpKeyPair = new JPanel(new GridBagLayout());
    jpKeyPair.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()),
            new EmptyBorder(5, 5, 5, 5)));

    jpKeyPair.add(jlEncrypted, gbc_jlEncrypted);
    jpKeyPair.add(jcbEncrypted, gbc_jcbEncrypted);
    jpKeyPair.add(jlPassword, gbc_jlPassword);
    jpKeyPair.add(jpfPassword, gbc_jpfPassword);
    jpKeyPair.add(jlPrivateKey, gbc_jlPrivateKey);
    jpKeyPair.add(jtfPrivateKeyPath, gbc_jtfPrivateKeyPath);
    jpKeyPair.add(jbPrivateKeyBrowse, gbc_jbPrivateKeyBrowse);
    jpKeyPair.add(jbPrivateKeyDetails, gbc_jbPrivateKeyDetails);
    jpKeyPair.add(jlCertificate, gbc_jlCertificate);
    jpKeyPair.add(jtfCertificatePath, gbc_jtfCertificatePath);
    jpKeyPair.add(jbCertificateBrowse, gbc_jbCertificateBrowse);
    jpKeyPair.add(jbCertificateDetails, gbc_jbCertificateDetails);

    jcbEncrypted.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypted.isSelected()) {
                jpfPassword.setEnabled(true);
            } else {
                jpfPassword.setEnabled(false);
                jpfPassword.setText("");
            }
        }
    });

    jbImport = new JButton(res.getString("DImportKeyPairPkcs8.jbImport.text"));
    PlatformUtil.setMnemonic(jbImport, res.getString("DImportKeyPairPkcs8.jbImport.mnemonic").charAt(0));
    jbImport.setToolTipText(res.getString("DImportKeyPairPkcs8.jbImport.tooltip"));
    jbImport.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPkcs8.this);
                importPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPkcs8.this);
            }
        }
    });

    jbCancel = new JButton(res.getString("DImportKeyPairPkcs8.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });

    jpButtons = PlatformUtil.createDialogButtonPanel(jbImport, jbCancel);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpKeyPair, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    setTitle(res.getString("DImportKeyPairPkcs8.Title"));
    setResizable(false);

    getRootPane().setDefaultButton(jbImport);

    pack();
}

From source file:org.kse.gui.dialogs.importexport.DImportKeyPairPvk.java

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;//from ww w.  j a  va 2  s.  c o  m
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;

    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;

    jlEncrypted = new JLabel(res.getString("DImportKeyPairPvk.jlEncrypted.text"));
    GridBagConstraints gbc_jlEncrypted = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypted.gridy = 0;

    jcbEncrypted = new JCheckBox();
    jcbEncrypted.setSelected(true);
    jcbEncrypted.setToolTipText(res.getString("DImportKeyPairPvk.jcbEncrypted.tooltip"));
    GridBagConstraints gbc_jcbEncrypted = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypted.gridy = 0;

    jlPassword = new JLabel(res.getString("DImportKeyPairPvk.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 1;

    jpfPassword = new JPasswordField(15);
    jpfPassword.setToolTipText(res.getString("DImportKeyPairPvk.jpfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 1;

    jlPrivateKey = new JLabel(res.getString("DImportKeyPairPvk.jlPrivateKey.text"));
    GridBagConstraints gbc_jlPrivateKey = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPrivateKey.gridy = 2;

    jtfPrivateKeyPath = new JTextField(30);
    jtfPrivateKeyPath.setToolTipText(res.getString("DImportKeyPairPvk.jtfPrivateKeyPath.tooltip"));
    GridBagConstraints gbc_jtfPrivateKeyPath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfPrivateKeyPath.gridy = 2;
    gbc_jtfPrivateKeyPath.gridwidth = 6;

    jbPrivateKeyBrowse = new JButton(res.getString("DImportKeyPairPvk.jbPrivateKeyBrowse.text"));
    PlatformUtil.setMnemonic(jbPrivateKeyBrowse,
            res.getString("DImportKeyPairPvk.jbPrivateKeyBrowse.mnemonic").charAt(0));
    jbPrivateKeyBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPvk.this);
                privateKeyBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPvk.this);
            }
        }
    });
    jbPrivateKeyBrowse.setToolTipText(res.getString("DImportKeyPairPvk.jbPrivateKeyBrowse.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyBrowse.gridy = 2;
    gbc_jbPrivateKeyBrowse.gridx = 9;

    jbPrivateKeyDetails = new JButton(res.getString("DImportKeyPairPvk.jbPrivateKeyDetails.text"));
    jbPrivateKeyDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPvk.this);
                privateKeyDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPvk.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbPrivateKeyDetails,
            res.getString("DImportKeyPairPvk.jbPrivateKeyDetails.mnemonic").charAt(0));
    jbPrivateKeyDetails.setToolTipText(res.getString("DImportKeyPairPvk.jbPrivateKeyDetails.tooltip"));
    GridBagConstraints gbc_jbPrivateKeyDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbPrivateKeyDetails.gridy = 2;
    gbc_jbPrivateKeyDetails.gridx = 12;

    jlCertificate = new JLabel(res.getString("DImportKeyPairPvk.jlCertificate.text"));
    GridBagConstraints gbc_jlCertificate = (GridBagConstraints) gbcLbl.clone();
    gbc_jlCertificate.gridy = 3;

    jtfCertificatePath = new JTextField(30);
    jtfCertificatePath.setToolTipText(res.getString("DImportKeyPairPvk.jtfCertificatePath.tooltip"));
    GridBagConstraints gbc_jtfCertificatePath = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfCertificatePath.gridy = 3;
    gbc_jtfCertificatePath.gridwidth = 6;

    jbCertificateBrowse = new JButton(res.getString("DImportKeyPairPvk.jbCertificateBrowse.text"));
    jbCertificateBrowse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPvk.this);
                certificateBrowsePressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPvk.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateBrowse,
            res.getString("DImportKeyPairPvk.jbCertificateBrowse.mnemonic").charAt(0));
    jbCertificateBrowse.setToolTipText(res.getString("DImportKeyPairPvk.jbCertificateBrowse.tooltip"));
    GridBagConstraints gbc_jbCertificateBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateBrowse.gridy = 3;
    gbc_jbCertificateBrowse.gridx = 9;

    jbCertificateDetails = new JButton(res.getString("DImportKeyPairPvk.jbCertificateDetails.text"));
    jbCertificateDetails.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPvk.this);
                certificateDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPvk.this);
            }
        }
    });
    PlatformUtil.setMnemonic(jbCertificateDetails,
            res.getString("DImportKeyPairPvk.jbCertificateDetails.mnemonic").charAt(0));
    jbCertificateDetails.setToolTipText(res.getString("DImportKeyPairPvk.jbCertificateDetails.tooltip"));
    GridBagConstraints gbc_jbCertificateDetails = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbCertificateDetails.gridy = 3;
    gbc_jbCertificateDetails.gridx = 12;

    jpKeyPair = new JPanel(new GridBagLayout());
    jpKeyPair.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()),
            new EmptyBorder(5, 5, 5, 5)));

    jpKeyPair.add(jlEncrypted, gbc_jlEncrypted);
    jpKeyPair.add(jcbEncrypted, gbc_jcbEncrypted);
    jpKeyPair.add(jlPassword, gbc_jlPassword);
    jpKeyPair.add(jpfPassword, gbc_jpfPassword);
    jpKeyPair.add(jlPrivateKey, gbc_jlPrivateKey);
    jpKeyPair.add(jtfPrivateKeyPath, gbc_jtfPrivateKeyPath);
    jpKeyPair.add(jbPrivateKeyBrowse, gbc_jbPrivateKeyBrowse);
    jpKeyPair.add(jbPrivateKeyDetails, gbc_jbPrivateKeyDetails);
    jpKeyPair.add(jlCertificate, gbc_jlCertificate);
    jpKeyPair.add(jtfCertificatePath, gbc_jtfCertificatePath);
    jpKeyPair.add(jbCertificateBrowse, gbc_jbCertificateBrowse);
    jpKeyPair.add(jbCertificateDetails, gbc_jbCertificateDetails);

    jcbEncrypted.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypted.isSelected()) {
                jpfPassword.setEnabled(true);
            } else {
                jpfPassword.setEnabled(false);
                jpfPassword.setText("");
            }
        }
    });

    jbImport = new JButton(res.getString("DImportKeyPairPvk.jbImport.text"));
    PlatformUtil.setMnemonic(jbImport, res.getString("DImportKeyPairPvk.jbImport.mnemonic").charAt(0));
    jbImport.setToolTipText(res.getString("DImportKeyPairPvk.jbImport.tooltip"));
    jbImport.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DImportKeyPairPvk.this);
                importPressed();
            } finally {
                CursorUtil.setCursorFree(DImportKeyPairPvk.this);
            }
        }
    });

    jbCancel = new JButton(res.getString("DImportKeyPairPvk.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });

    jpButtons = PlatformUtil.createDialogButtonPanel(jbImport, jbCancel);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpKeyPair, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    setTitle(res.getString("DImportKeyPairPvk.Title"));
    setResizable(false);

    getRootPane().setDefaultButton(jbImport);

    pack();
}

From source file:org.kuali.test.ui.components.dialogs.UpdateTestLoginDlg.java

private void initComponents() {
    String[] labels = { "Target Host", "Username Parameter", "Password Parameter", "New Username",
            "New Password", };

    targetHost = new JTextField(20);
    usernameParameter = new JTextField("username", 20);
    passwordParameter = new JTextField("password", 20);
    newUsername = new JTextField(20);
    newPassword = new JPasswordField(20);
    JComponent[] components = { targetHost, usernameParameter, passwordParameter, newUsername, newPassword };

    getContentPane().add(UIUtils.buildEntryPanel(labels, components), BorderLayout.CENTER);

    addStandardButtons();/* ww w .j  a  v  a  2s . co m*/
    setDefaultBehavior();
}

From source file:org.nuxeo.launcher.sync.NuxeoSyncFrame.java

protected Component buildSyncPanel() {
    syncPanel = new JPanel();
    syncPanel.setBackground(new Color(55, 55, 55));
    syncPanel.setForeground(Color.WHITE);
    syncPanel.setLayout(new GridBagLayout());

    JLabel l = new JLabel("Server IP", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1.0;/*ww  w.  java2  s. c o m*/
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.insets = new Insets(0, 0, 0, 0);
    syncPanel.add(l, c);
    syncServerIpTextField = new JTextField(10);
    l.setLabelFor(syncServerIpTextField);
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.WEST;

    syncPanel.add(syncServerIpTextField, c);

    l = new JLabel("Port", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncPortTextField = new JTextField(10);
    l.setLabelFor(syncPortTextField);
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.WEST;
    syncPanel.add(syncPortTextField, c);

    l = new JLabel("Login", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncLoginTextField = new JTextField(10);
    l.setLabelFor(syncLoginTextField);
    c.gridx = 1;
    c.gridy = 3;
    c.anchor = GridBagConstraints.WEST;

    syncPanel.add(syncLoginTextField, c);

    l = new JLabel("Password", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncPasswordField = new JPasswordField(10);
    l.setLabelFor(syncPasswordField);
    c.gridx = 1;
    c.gridy = 4;
    c.anchor = GridBagConstraints.WEST;
    syncPanel.add(syncPasswordField, c);

    syncButton = new JButton();
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    c.insets = new Insets(10, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    // set the action to the button
    synchronizeAction = createSyncAction();
    syncButton.setAction(synchronizeAction);
    syncButton.setText("Synchronize");

    updateSyncButton();

    syncPanel.add(syncButton, c);

    errorMessageLabel = new JLabel("", SwingConstants.TRAILING);
    errorMessageLabel.setForeground(Color.RED);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(10, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    syncPanel.add(errorMessageLabel, c);
    return syncPanel;
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private JPanel createLocationsPanel() {
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0.5;//from w w  w .  j av a 2s .  c  o m

    JPanel folderPanel = new JPanel();
    folderPanel.setLayout(new BoxLayout(folderPanel, BoxLayout.X_AXIS));
    folderPanel.setBorder(BorderFactory.createTitledBorder("Working folder"));
    folderField = new JTextField();
    folderField.setText((new File("").getAbsolutePath()));
    folderField.setToolTipText("The folder where all output will be written");
    folderPanel.add(folderField);
    JButton pickButton = new JButton("Pick folder");
    pickButton.setToolTipText("Pick a different working folder");
    folderPanel.add(pickButton);
    pickButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pickFolder();
        }
    });
    componentsToDisableWhenRunning.add(pickButton);
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    panel.add(folderPanel, c);

    JPanel sourcePanel = new JPanel();
    sourcePanel.setLayout(new GridLayout(0, 2));
    sourcePanel.setBorder(BorderFactory.createTitledBorder("Source data location"));
    sourcePanel.add(new JLabel("Data type"));
    sourceType = new JComboBox<String>(new String[] { "Delimited text files", "MySQL", "Oracle", "SQL Server",
            "PostgreSQL", "MS Access", "PDW", "Redshift", "Teradata" });
    sourceType.setToolTipText("Select the type of source data available");
    sourceType.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent arg0) {
            sourceIsFiles = arg0.getItem().toString().equals("Delimited text files");
            sourceServerField.setEnabled(!sourceIsFiles);
            sourceUserField.setEnabled(!sourceIsFiles);
            sourcePasswordField.setEnabled(!sourceIsFiles);
            sourceDatabaseField.setEnabled(!sourceIsFiles);
            sourceDelimiterField.setEnabled(sourceIsFiles);
            addAllButton.setEnabled(!sourceIsFiles);

            if (!sourceIsFiles && arg0.getItem().toString().equals("Oracle")) {
                sourceServerField.setToolTipText(
                        "For Oracle servers this field contains the SID, servicename, and optionally the port: '<host>/<sid>', '<host>:<port>/<sid>', '<host>/<service name>', or '<host>:<port>/<service name>'");
                sourceUserField.setToolTipText(
                        "For Oracle servers this field contains the name of the user used to log in");
                sourcePasswordField.setToolTipText(
                        "For Oracle servers this field contains the password corresponding to the user");
                sourceDatabaseField.setToolTipText(
                        "For Oracle servers this field contains the schema (i.e. 'user' in Oracle terms) containing the source tables");
            } else if (!sourceIsFiles && arg0.getItem().toString().equals("PostgreSQL")) {
                sourceServerField.setToolTipText(
                        "For PostgreSQL servers this field contains the host name and database name (<host>/<database>)");
                sourceUserField.setToolTipText("The user used to log in to the server");
                sourcePasswordField.setToolTipText("The password used to log in to the server");
                sourceDatabaseField.setToolTipText(
                        "For PostgreSQL servers this field contains the schema containing the source tables");
            } else if (!sourceIsFiles) {
                sourceServerField
                        .setToolTipText("This field contains the name or IP address of the database server");
                if (arg0.getItem().toString().equals("SQL Server"))
                    sourceUserField.setToolTipText(
                            "The user used to log in to the server. Optionally, the domain can be specified as <domain>/<user> (e.g. 'MyDomain/Joe')");
                else
                    sourceUserField.setToolTipText("The user used to log in to the server");
                sourcePasswordField.setToolTipText("The password used to log in to the server");
                sourceDatabaseField.setToolTipText("The name of the database containing the source tables");
            }
        }
    });
    sourcePanel.add(sourceType);

    sourcePanel.add(new JLabel("Server location"));
    sourceServerField = new JTextField("127.0.0.1");
    sourceServerField.setEnabled(false);
    sourcePanel.add(sourceServerField);
    sourcePanel.add(new JLabel("User name"));
    sourceUserField = new JTextField("");
    sourceUserField.setEnabled(false);
    sourcePanel.add(sourceUserField);
    sourcePanel.add(new JLabel("Password"));
    sourcePasswordField = new JPasswordField("");
    sourcePasswordField.setEnabled(false);
    sourcePanel.add(sourcePasswordField);
    sourcePanel.add(new JLabel("Database name"));
    sourceDatabaseField = new JTextField("");
    sourceDatabaseField.setEnabled(false);
    sourcePanel.add(sourceDatabaseField);

    sourcePanel.add(new JLabel("Delimiter"));
    sourceDelimiterField = new JTextField(",");
    sourceDelimiterField.setToolTipText("The delimiter that separates values. Enter 'tab' for tab.");
    sourcePanel.add(sourceDelimiterField);

    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    panel.add(sourcePanel, c);

    JPanel testConnectionButtonPanel = new JPanel();
    testConnectionButtonPanel.setLayout(new BoxLayout(testConnectionButtonPanel, BoxLayout.X_AXIS));
    testConnectionButtonPanel.add(Box.createHorizontalGlue());

    JButton testConnectionButton = new JButton("Test connection");
    testConnectionButton.setBackground(new Color(151, 220, 141));
    testConnectionButton.setToolTipText("Test the connection");
    testConnectionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            testConnection(getSourceDbSettings());
        }
    });
    componentsToDisableWhenRunning.add(testConnectionButton);
    testConnectionButtonPanel.add(testConnectionButton);

    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    panel.add(testConnectionButtonPanel, c);

    return panel;
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private JPanel createFakeDataPanel() {
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0.5;/*from   ww  w. ja v a  2s .  c o  m*/

    JPanel folderPanel = new JPanel();
    folderPanel.setLayout(new BoxLayout(folderPanel, BoxLayout.X_AXIS));
    folderPanel.setBorder(BorderFactory.createTitledBorder("Scan report file"));
    scanReportFileField = new JTextField();
    scanReportFileField.setText((new File("ScanReport.xlsx").getAbsolutePath()));
    scanReportFileField.setToolTipText(
            "The path to the scan report that will be used as a template to generate the fake data");
    folderPanel.add(scanReportFileField);
    JButton pickButton = new JButton("Pick file");
    pickButton.setToolTipText("Pick a scan report file");
    folderPanel.add(pickButton);
    pickButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pickScanReportFile();
        }
    });
    componentsToDisableWhenRunning.add(pickButton);
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    panel.add(folderPanel, c);

    JPanel targetPanel = new JPanel();
    targetPanel.setLayout(new GridLayout(0, 2));
    targetPanel.setBorder(BorderFactory.createTitledBorder("Target data location"));
    targetPanel.add(new JLabel("Data type"));
    targetType = new JComboBox<String>(
            new String[] { "Delimited text files", "MySQL", "Oracle", "SQL Server", "PostgreSQL" });
    // targetType = new JComboBox(new String[] { "Delimited text files", "MySQL" });
    targetType.setToolTipText("Select the type of source data available");
    targetType.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent arg0) {
            targetIsFiles = arg0.getItem().toString().equals("Delimited text files");
            targetServerField.setEnabled(!targetIsFiles);
            targetUserField.setEnabled(!targetIsFiles);
            targetPasswordField.setEnabled(!targetIsFiles);
            targetDatabaseField.setEnabled(!targetIsFiles);
            targetCSVFormat.setEnabled(targetIsFiles);

            if (!targetIsFiles && arg0.getItem().toString().equals("Oracle")) {
                targetServerField.setToolTipText(
                        "For Oracle servers this field contains the SID, servicename, and optionally the port: '<host>/<sid>', '<host>:<port>/<sid>', '<host>/<service name>', or '<host>:<port>/<service name>'");
                targetUserField.setToolTipText(
                        "For Oracle servers this field contains the name of the user used to log in");
                targetPasswordField.setToolTipText(
                        "For Oracle servers this field contains the password corresponding to the user");
                targetDatabaseField.setToolTipText(
                        "For Oracle servers this field contains the schema (i.e. 'user' in Oracle terms) containing the source tables");
            } else if (!targetIsFiles && arg0.getItem().toString().equals("PostgreSQL")) {
                targetServerField.setToolTipText(
                        "For PostgreSQL servers this field contains the host name and database name (<host>/<database>)");
                targetUserField.setToolTipText("The user used to log in to the server");
                targetPasswordField.setToolTipText("The password used to log in to the server");
                targetDatabaseField.setToolTipText(
                        "For PostgreSQL servers this field contains the schema containing the source tables");
            } else if (!targetIsFiles) {
                targetServerField
                        .setToolTipText("This field contains the name or IP address of the database server");
                if (arg0.getItem().toString().equals("SQL Server"))
                    targetUserField.setToolTipText(
                            "The user used to log in to the server. Optionally, the domain can be specified as <domain>/<user> (e.g. 'MyDomain/Joe')");
                else
                    targetUserField.setToolTipText("The user used to log in to the server");
                targetPasswordField.setToolTipText("The password used to log in to the server");
                targetDatabaseField.setToolTipText("The name of the database containing the source tables");
            }
        }
    });
    targetPanel.add(targetType);

    targetPanel.add(new JLabel("Server location"));
    targetServerField = new JTextField("127.0.0.1");
    targetServerField.setEnabled(false);
    targetPanel.add(targetServerField);
    targetPanel.add(new JLabel("User name"));
    targetUserField = new JTextField("");
    targetUserField.setEnabled(false);
    targetPanel.add(targetUserField);
    targetPanel.add(new JLabel("Password"));
    targetPasswordField = new JPasswordField("");
    targetPasswordField.setEnabled(false);
    targetPanel.add(targetPasswordField);
    targetPanel.add(new JLabel("Database name"));
    targetDatabaseField = new JTextField("");
    targetDatabaseField.setEnabled(false);
    targetPanel.add(targetDatabaseField);

    targetPanel.add(new JLabel("CSV Format"));
    targetCSVFormat = new JComboBox<>(new String[] { "Default (comma, CRLF)", "TDF (tab, CRLF)",
            "MySQL (tab, LF)", "RFC4180", "Excel CSV" });
    targetCSVFormat.setToolTipText("The format of the output");
    targetCSVFormat.setEnabled(true);
    targetPanel.add(targetCSVFormat);

    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    panel.add(targetPanel, c);

    JPanel fakeDataButtonPanel = new JPanel();
    fakeDataButtonPanel.setLayout(new BoxLayout(fakeDataButtonPanel, BoxLayout.X_AXIS));

    fakeDataButtonPanel.add(new JLabel("Max rows per table"));
    generateRowCount = new JSpinner();
    generateRowCount.setValue(10000);
    fakeDataButtonPanel.add(generateRowCount);
    fakeDataButtonPanel.add(Box.createHorizontalGlue());

    JButton testConnectionButton = new JButton("Test connection");
    testConnectionButton.setBackground(new Color(151, 220, 141));
    testConnectionButton.setToolTipText("Test the connection");
    testConnectionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            testConnection(getTargetDbSettings());
        }
    });
    componentsToDisableWhenRunning.add(testConnectionButton);
    fakeDataButtonPanel.add(testConnectionButton);

    JButton fakeDataButton = new JButton("Generate fake data");
    fakeDataButton.setBackground(new Color(151, 220, 141));
    fakeDataButton.setToolTipText("Generate fake data based on the scan report");
    fakeDataButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            fakeDataRun();
        }
    });
    componentsToDisableWhenRunning.add(fakeDataButton);
    fakeDataButtonPanel.add(fakeDataButton);

    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    panel.add(fakeDataButtonPanel, c);

    return panel;
}

From source file:org.openmrs.test.BaseContextSensitiveTest.java

/**
 * 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>
 * //from   w  ww  .j  a  va  2  s . c  o  m
 * @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) {
                frame.toFront(); // bring the dialog's window to the
                // 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;

    // response of 2 is the cancel button, response of -1 is the little red
    // X in the top right
    return (response == 2 || response == -1 ? null
            : new String[] { usernameField.getText(), String.valueOf(passwordField.getPassword()) });
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTextbox.java

@Override
public Object getManagedObject() {
    if (super.getManagedObject() == null) {
        switch (this.type) {
        case PASSWORD:
            JPasswordField pass = new JPasswordField((value != null) ? value : "");
            pass.setPreferredSize(new Dimension(getWidth(), 20));
            pass.setMinimumSize(new Dimension(pass.getPreferredSize().width, pass.getPreferredSize().height));
            pass.setEditable(!readonly);
            textComp = pass;//  w  ww . j  a v a  2s  .co m
            setManagedObject(pass);
            break;
        case NUMERIC:
        default: // regular text
            if (this.multiline) {
                textArea = new JTextArea((value != null) ? value : "");
                scrollPane = new JScrollPane(textArea);
                textComp = textArea;
                setManagedObject(scrollPane);
                textArea.setEditable(!readonly);
                this.scrollPane.setMinimumSize(new Dimension(getWidth(), this.height));
                // this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            } else {
                textField = new JTextField((value != null) ? value : "");
                textField.setPreferredSize(new Dimension(getWidth(), textField.getPreferredSize().height));
                textField.setMinimumSize(
                        new Dimension(textField.getPreferredSize().width, textField.getPreferredSize().height));
                textField.setEditable(!readonly);
                setManagedObject(textField);
                textComp = textField;
            }

            // constrin Numeric only here
            if (this.type == TextType.NUMERIC) {
                textComp.setDocument(new NumericDocument(min, max));
            }
            textComp.setEnabled(!disabled);
            break;
        }

        textComp.addKeyListener(new KeyListener() {
            public void keyPressed(KeyEvent e) {
                oldValue = textComp.getText();
            }

            public void keyReleased(KeyEvent e) {
                if (oldValue != null && !oldValue.equals(textComp.getText())) {
                    SwingTextbox.this.changeSupport.firePropertyChange("value", oldValue,
                            SwingTextbox.this.getValue());
                    oldValue = textComp.getText();
                } else if (oldValue == null) {
                    // AWT error where sometimes the keyReleased is fired before keyPressed.
                    oldValue = textComp.getText();
                } else {
                    logger.debug("Special key pressed, ignoring");
                }
            }

            public void keyTyped(KeyEvent e) {
            }

        });

        textComp.setToolTipText(this.getTooltiptext());

        // Why do we need this here if we setup oninput in the setOninput
        // textComp.addKeyListener(new KeyAdapter() {
        //
        // public void keyReleased(KeyEvent e) {
        // invoke(onInput);
        // }
        // });
    }

    return super.getManagedObject();

}