diff ConnectionManager/src/connectionmanager/CredentialsDialog.java @ 5:35f1cfcaa5a9

Add crude Java GUI.
author Daniele Nicolodi <daniele@science.unitn.it>
date Wed, 02 Jun 2010 17:29:18 +0200
parents
children 670905eb688a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConnectionManager/src/connectionmanager/CredentialsDialog.java	Wed Jun 02 17:29:18 2010 +0200
@@ -0,0 +1,174 @@
+package connectionmanager;
+
+public class CredentialsDialog extends javax.swing.JDialog {
+
+    private String[] usernames;
+    private String[] passwords;
+
+    public boolean cancelled = true;
+    public boolean cache = false;
+    public String username = null;
+    public String password = null;
+
+    public CredentialsDialog(java.awt.Frame parent, boolean modal) {
+        super(parent, modal);
+        initComponents();
+    }
+
+    public CredentialsDialog() {
+        super(new javax.swing.JFrame(), true);
+        initComponents();
+    }
+
+    public CredentialsDialog(String[] usernames, String[] passwords) {
+        super(new javax.swing.JFrame(), true);
+        this.usernames = usernames;
+        this.passwords = passwords;
+        initComponents();
+
+        if (usernames != null) {
+            this.usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames));
+        }
+    }
+
+    @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();
+        jLabel3 = 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();
+
+        addWindowListener(new java.awt.event.WindowAdapter() {
+            public void windowClosing(java.awt.event.WindowEvent evt) {
+                closeDialog(evt);
+            }
+        });
+
+        okButton.setText("Connect");
+        okButton.setSelected(true);
+        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);
+            }
+        });
+
+        jLabel3.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(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(251, Short.MAX_VALUE)
+                .add(cancelButton)
+                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
+                .add(okButton)
+                .addContainerGap())
+            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                .add(layout.createSequentialGroup()
+                    .add(36, 36, 36)
+                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                        .add(cacheCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
+                        .add(layout.createSequentialGroup()
+                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                .add(jLabel1)
+                                .add(jLabel2))
+                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
+                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                                .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
+                                .add(usernameField, 0, 271, Short.MAX_VALUE)))
+                        .add(jLabel3))
+                    .add(36, 36, 36)))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(266, Short.MAX_VALUE)
+                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+                    .add(okButton)
+                    .add(cancelButton))
+                .addContainerGap())
+            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                .add(layout.createSequentialGroup()
+                    .add(81, 81, 81)
+                    .add(jLabel3)
+                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+                        .add(jLabel1)
+                        .add(usernameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
+                    .add(14, 14, 14)
+                    .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))
+                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
+                    .add(cacheCheckBox)
+                    .add(116, 116, 116)))
+        );
+
+        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.JLabel jLabel3;
+    private javax.swing.JButton okButton;
+    private javax.swing.JPasswordField passwordField;
+    private javax.swing.JComboBox usernameField;
+    // End of variables declaration//GEN-END:variables
+}