Mercurial > hg > ltpda
view src/ConnectionManager/src/connectionmanager/CredentialsDialog.java @ 28:01b86b780ba7 database-connection-manager
Remove LTPDARepositoryManager implementation. Java code
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 960fe1aa1c10 |
children | 6def6533cb16 |
line wrap: on
line source
package connectionmanager; public class CredentialsDialog extends javax.swing.JDialog { public boolean cancelled = true; public boolean cache = true; public String username = null; public String password = null; public CredentialsDialog(javax.swing.JDialog parent, String hostname, String[] usernames) { super(parent, true); initComponents(); super.setLocationRelativeTo(parent); this.cacheCheckBox.setVisible(false); titleLabel.setText(String.format("Credentials for mysql://%s/", hostname)); if ((usernames != null) && (usernames.length > 0)) { usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames)); passwordField.requestFocus(); } super.getRootPane().setDefaultButton(okButton); } public CredentialsDialog(java.awt.Frame parent, String hostname, String database, String[] usernames, int cache) { super(parent, true); initComponents(); super.setLocationRelativeTo(parent); switch (cache) { case 0: this.cache = false; this.cacheCheckBox.setVisible(false); break; case 1: this.cache = true; this.cacheCheckBox.setVisible(false); break; case 2: this.cache = true; this.cacheCheckBox.setVisible(true); break; } titleLabel.setText(String.format("Credentials for mysql://%s/%s/", hostname, database)); if ((usernames != null) && (usernames.length > 0)) { usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames)); passwordField.requestFocus(); } super.getRootPane().setDefaultButton(okButton); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); titleLabel = new javax.swing.JLabel(); passwordField = new javax.swing.JPasswordField(); cacheCheckBox = new javax.swing.JCheckBox(); usernameField = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); setTitle("Database connection"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); okButton.setText("Connect"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); titleLabel.setText("Credentials for mysql://%s/%s/"); cacheCheckBox.setText("Remember this password"); usernameField.setEditable(true); usernameField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { usernameFieldActionPerformed(evt); } }); jLabel2.setText("Password:"); jLabel1.setText("Username:"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(titleLabel) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jLabel2)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) .add(usernameField, 0, 240, Short.MAX_VALUE))) .add(layout.createSequentialGroup() .add(cacheCheckBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 190, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE) .add(cancelButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(okButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(titleLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(usernameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel1)) .add(12, 12, 12) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel2)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false) .add(cacheCheckBox) .add(okButton) .add(cancelButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed cancelled = false; username = (String) usernameField.getSelectedItem(); password = new String(passwordField.getPassword()); cache = cacheCheckBox.isSelected(); doClose(); }//GEN-LAST:event_okButtonActionPerformed private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed cancelled = true; doClose(); }//GEN-LAST:event_cancelButtonActionPerformed private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog cancelled = true; doClose(); }//GEN-LAST:event_closeDialog private void usernameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameFieldActionPerformed }//GEN-LAST:event_usernameFieldActionPerformed private void doClose() { setVisible(false); dispose(); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox cacheCheckBox; private javax.swing.JButton cancelButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JButton okButton; private javax.swing.JPasswordField passwordField; private javax.swing.JLabel titleLabel; private javax.swing.JComboBox usernameField; // End of variables declaration//GEN-END:variables }