comparison 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
comparison
equal deleted inserted replaced
4:c706c10a76bd 5:35f1cfcaa5a9
1 package connectionmanager;
2
3 public class CredentialsDialog extends javax.swing.JDialog {
4
5 private String[] usernames;
6 private String[] passwords;
7
8 public boolean cancelled = true;
9 public boolean cache = false;
10 public String username = null;
11 public String password = null;
12
13 public CredentialsDialog(java.awt.Frame parent, boolean modal) {
14 super(parent, modal);
15 initComponents();
16 }
17
18 public CredentialsDialog() {
19 super(new javax.swing.JFrame(), true);
20 initComponents();
21 }
22
23 public CredentialsDialog(String[] usernames, String[] passwords) {
24 super(new javax.swing.JFrame(), true);
25 this.usernames = usernames;
26 this.passwords = passwords;
27 initComponents();
28
29 if (usernames != null) {
30 this.usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames));
31 }
32 }
33
34 @SuppressWarnings("unchecked")
35 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
36 private void initComponents() {
37
38 okButton = new javax.swing.JButton();
39 cancelButton = new javax.swing.JButton();
40 jLabel3 = new javax.swing.JLabel();
41 passwordField = new javax.swing.JPasswordField();
42 cacheCheckBox = new javax.swing.JCheckBox();
43 usernameField = new javax.swing.JComboBox();
44 jLabel2 = new javax.swing.JLabel();
45 jLabel1 = new javax.swing.JLabel();
46
47 addWindowListener(new java.awt.event.WindowAdapter() {
48 public void windowClosing(java.awt.event.WindowEvent evt) {
49 closeDialog(evt);
50 }
51 });
52
53 okButton.setText("Connect");
54 okButton.setSelected(true);
55 okButton.addActionListener(new java.awt.event.ActionListener() {
56 public void actionPerformed(java.awt.event.ActionEvent evt) {
57 okButtonActionPerformed(evt);
58 }
59 });
60
61 cancelButton.setText("Cancel");
62 cancelButton.addActionListener(new java.awt.event.ActionListener() {
63 public void actionPerformed(java.awt.event.ActionEvent evt) {
64 cancelButtonActionPerformed(evt);
65 }
66 });
67
68 jLabel3.setText("Credentials for mysql://%s/%s/");
69
70 cacheCheckBox.setText("Remember this password");
71
72 usernameField.setEditable(true);
73 usernameField.addActionListener(new java.awt.event.ActionListener() {
74 public void actionPerformed(java.awt.event.ActionEvent evt) {
75 usernameFieldActionPerformed(evt);
76 }
77 });
78
79 jLabel2.setText("Password:");
80
81 jLabel1.setText("Username:");
82
83 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
84 getContentPane().setLayout(layout);
85 layout.setHorizontalGroup(
86 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
87 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
88 .addContainerGap(251, Short.MAX_VALUE)
89 .add(cancelButton)
90 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
91 .add(okButton)
92 .addContainerGap())
93 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
94 .add(layout.createSequentialGroup()
95 .add(36, 36, 36)
96 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
97 .add(cacheCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
98 .add(layout.createSequentialGroup()
99 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
100 .add(jLabel1)
101 .add(jLabel2))
102 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
103 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
104 .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
105 .add(usernameField, 0, 271, Short.MAX_VALUE)))
106 .add(jLabel3))
107 .add(36, 36, 36)))
108 );
109 layout.setVerticalGroup(
110 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
111 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
112 .addContainerGap(266, Short.MAX_VALUE)
113 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
114 .add(okButton)
115 .add(cancelButton))
116 .addContainerGap())
117 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
118 .add(layout.createSequentialGroup()
119 .add(81, 81, 81)
120 .add(jLabel3)
121 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
122 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
123 .add(jLabel1)
124 .add(usernameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
125 .add(14, 14, 14)
126 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
127 .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
128 .add(jLabel2))
129 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
130 .add(cacheCheckBox)
131 .add(116, 116, 116)))
132 );
133
134 pack();
135 }// </editor-fold>//GEN-END:initComponents
136
137 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
138 cancelled = false;
139 username = (String)usernameField.getSelectedItem();
140 password = new String(passwordField.getPassword());
141 cache = cacheCheckBox.isSelected();
142 doClose();
143 }//GEN-LAST:event_okButtonActionPerformed
144
145 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
146 cancelled = true;
147 doClose();
148 }//GEN-LAST:event_cancelButtonActionPerformed
149
150 private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
151 cancelled = true;
152 doClose();
153 }//GEN-LAST:event_closeDialog
154
155 private void usernameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameFieldActionPerformed
156
157 }//GEN-LAST:event_usernameFieldActionPerformed
158
159 private void doClose() {
160 setVisible(false);
161 dispose();
162 }
163
164 // Variables declaration - do not modify//GEN-BEGIN:variables
165 private javax.swing.JCheckBox cacheCheckBox;
166 private javax.swing.JButton cancelButton;
167 private javax.swing.JLabel jLabel1;
168 private javax.swing.JLabel jLabel2;
169 private javax.swing.JLabel jLabel3;
170 private javax.swing.JButton okButton;
171 private javax.swing.JPasswordField passwordField;
172 private javax.swing.JComboBox usernameField;
173 // End of variables declaration//GEN-END:variables
174 }