de8b6554bb65f912d3fabd1fae7418a96e15738c
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / EditProfile.java
1 package uk.ac.ntu.n0521366.wsyd.client;
2
3 import java.util.TreeSet;
4 /*
5  * To change this license header, choose License Headers in Project Properties.
6  * To change this template file, choose Tools | Templates
7  * and open the template in the editor.
8  */
9
10 /**
11  *
12  * @author Eddie Berrisford-Lynch
13  */
14 public class EditProfile extends javax.swing.JDialog {
15
16     /**
17      * Creates new form WSYD_RegiProfile
18      */
19     public EditProfile(java.awt.Frame parent, boolean modal) {
20         super(parent, modal);
21         initComponents();
22     }
23
24     /**
25      * This method is called from within the constructor to initialize the form.
26      * WARNING: Do NOT modify this code. The content of this method is always
27      * regenerated by the Form Editor.
28      */
29     @SuppressWarnings("unchecked")
30     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
31     private void initComponents() {
32         java.awt.GridBagConstraints gridBagConstraints;
33
34         gLabelUsername = new javax.swing.JLabel();
35         gFieldUsername = new javax.swing.JTextField();
36         gButtonConfirmation = new javax.swing.JButton();
37         gLabelPassword = new javax.swing.JLabel();
38         gPFieldPassword = new javax.swing.JPasswordField();
39         gLabelPConfirmation = new javax.swing.JLabel();
40         gPFieldPConfirmation = new javax.swing.JPasswordField();
41         gLabelPWarning = new javax.swing.JLabel();
42         gLabelBirthplace = new javax.swing.JLabel();
43         gFieldBirthplace = new javax.swing.JTextField();
44         gLabelCurrLocation = new javax.swing.JLabel();
45         gFieldCurrLocation = new javax.swing.JTextField();
46         gLabelInterests = new javax.swing.JLabel();
47         jScrollPane1 = new javax.swing.JScrollPane();
48         gListInterests = new javax.swing.JList();
49         gLabelBio = new javax.swing.JLabel();
50         jScrollPane2 = new javax.swing.JScrollPane();
51         gTAreaBio = new javax.swing.JTextArea();
52
53         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
54         setTitle("Your Profile");
55         setMinimumSize(new java.awt.Dimension(600, 600));
56         java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
57         layout.columnWidths = new int[] {0, 5, 0, 5, 0};
58         layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0};
59         getContentPane().setLayout(layout);
60
61         gLabelUsername.setText("Username:");
62         gridBagConstraints = new java.awt.GridBagConstraints();
63         gridBagConstraints.gridx = 0;
64         gridBagConstraints.gridy = 0;
65         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
66         getContentPane().add(gLabelUsername, gridBagConstraints);
67
68         gFieldUsername.setMinimumSize(new java.awt.Dimension(70, 25));
69         gFieldUsername.setPreferredSize(new java.awt.Dimension(150, 25));
70         gridBagConstraints = new java.awt.GridBagConstraints();
71         gridBagConstraints.gridx = 2;
72         gridBagConstraints.gridy = 0;
73         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
74         getContentPane().add(gFieldUsername, gridBagConstraints);
75
76         gButtonConfirmation.setText("Register");
77         gButtonConfirmation.addMouseListener(new java.awt.event.MouseAdapter() {
78             public void mouseClicked(java.awt.event.MouseEvent evt) {
79                 gButtonConfirmationMouseClicked(evt);
80             }
81         });
82         gridBagConstraints = new java.awt.GridBagConstraints();
83         gridBagConstraints.gridx = 4;
84         gridBagConstraints.gridy = 0;
85         getContentPane().add(gButtonConfirmation, gridBagConstraints);
86
87         gLabelPassword.setText("Password:");
88         gridBagConstraints = new java.awt.GridBagConstraints();
89         gridBagConstraints.gridx = 0;
90         gridBagConstraints.gridy = 2;
91         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
92         getContentPane().add(gLabelPassword, gridBagConstraints);
93
94         gPFieldPassword.setMinimumSize(new java.awt.Dimension(70, 25));
95         gPFieldPassword.setPreferredSize(new java.awt.Dimension(120, 25));
96         gridBagConstraints = new java.awt.GridBagConstraints();
97         gridBagConstraints.gridx = 2;
98         gridBagConstraints.gridy = 2;
99         gridBagConstraints.gridwidth = 3;
100         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
101         getContentPane().add(gPFieldPassword, gridBagConstraints);
102
103         gLabelPConfirmation.setText("Confirm:");
104         gridBagConstraints = new java.awt.GridBagConstraints();
105         gridBagConstraints.gridx = 0;
106         gridBagConstraints.gridy = 4;
107         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
108         getContentPane().add(gLabelPConfirmation, gridBagConstraints);
109
110         gPFieldPConfirmation.setMinimumSize(new java.awt.Dimension(70, 25));
111         gPFieldPConfirmation.setPreferredSize(new java.awt.Dimension(120, 25));
112         gridBagConstraints = new java.awt.GridBagConstraints();
113         gridBagConstraints.gridx = 2;
114         gridBagConstraints.gridy = 4;
115         gridBagConstraints.gridwidth = 3;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117         getContentPane().add(gPFieldPConfirmation, gridBagConstraints);
118         gridBagConstraints = new java.awt.GridBagConstraints();
119         gridBagConstraints.gridx = 4;
120         gridBagConstraints.gridy = 4;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
122         getContentPane().add(gLabelPWarning, gridBagConstraints);
123
124         gLabelBirthplace.setText("Birthplace:");
125         gridBagConstraints = new java.awt.GridBagConstraints();
126         gridBagConstraints.gridx = 0;
127         gridBagConstraints.gridy = 6;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
129         getContentPane().add(gLabelBirthplace, gridBagConstraints);
130
131         gFieldBirthplace.setMinimumSize(new java.awt.Dimension(100, 25));
132         gFieldBirthplace.setPreferredSize(new java.awt.Dimension(200, 25));
133         gFieldBirthplace.addActionListener(new java.awt.event.ActionListener() {
134             public void actionPerformed(java.awt.event.ActionEvent evt) {
135                 gFieldBirthplaceActionPerformed(evt);
136             }
137         });
138         gridBagConstraints = new java.awt.GridBagConstraints();
139         gridBagConstraints.gridx = 2;
140         gridBagConstraints.gridy = 6;
141         getContentPane().add(gFieldBirthplace, gridBagConstraints);
142
143         gLabelCurrLocation.setText("Current City/Town:");
144         gridBagConstraints = new java.awt.GridBagConstraints();
145         gridBagConstraints.gridx = 0;
146         gridBagConstraints.gridy = 8;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
148         getContentPane().add(gLabelCurrLocation, gridBagConstraints);
149
150         gFieldCurrLocation.setMinimumSize(new java.awt.Dimension(100, 25));
151         gFieldCurrLocation.setPreferredSize(new java.awt.Dimension(200, 25));
152         gridBagConstraints = new java.awt.GridBagConstraints();
153         gridBagConstraints.gridx = 2;
154         gridBagConstraints.gridy = 8;
155         getContentPane().add(gFieldCurrLocation, gridBagConstraints);
156
157         gLabelInterests.setText("Interests:");
158         gridBagConstraints = new java.awt.GridBagConstraints();
159         gridBagConstraints.gridx = 0;
160         gridBagConstraints.gridy = 10;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
162         getContentPane().add(gLabelInterests, gridBagConstraints);
163
164         gListInterests.setModel(new javax.swing.AbstractListModel() {
165             String[] strings = { "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8" };
166             public int getSize() { return strings.length; }
167             public Object getElementAt(int i) { return strings[i]; }
168         });
169         gListInterests.setToolTipText("Select the interests you have, they will be displayed (Hold CTRL + Click)");
170         jScrollPane1.setViewportView(gListInterests);
171
172         gridBagConstraints = new java.awt.GridBagConstraints();
173         gridBagConstraints.gridx = 2;
174         gridBagConstraints.gridy = 10;
175         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176         getContentPane().add(jScrollPane1, gridBagConstraints);
177
178         gLabelBio.setText("Bio:");
179         gridBagConstraints = new java.awt.GridBagConstraints();
180         gridBagConstraints.gridx = 0;
181         gridBagConstraints.gridy = 12;
182         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
183         getContentPane().add(gLabelBio, gridBagConstraints);
184
185         gTAreaBio.setColumns(35);
186         gTAreaBio.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
187         gTAreaBio.setLineWrap(true);
188         gTAreaBio.setRows(12);
189         gTAreaBio.setTabSize(4);
190         gTAreaBio.setMinimumSize(new java.awt.Dimension(100, 50));
191         jScrollPane2.setViewportView(gTAreaBio);
192
193         gridBagConstraints = new java.awt.GridBagConstraints();
194         gridBagConstraints.gridx = 2;
195         gridBagConstraints.gridy = 12;
196         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
197         gridBagConstraints.gridheight = 5;
198         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
199         getContentPane().add(jScrollPane2, gridBagConstraints);
200
201         pack();
202     }// </editor-fold>//GEN-END:initComponents
203
204     private void gFieldBirthplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthplaceActionPerformed
205         // TODO add your handling code here:
206     }//GEN-LAST:event_gFieldBirthplaceActionPerformed
207
208     private void gButtonConfirmationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonConfirmationMouseClicked
209         // TODO add your handling code here:
210         TreeSet<String> interests = null;
211         /*
212         for (int i = 0; i < gListInterests.getModel().getSize(); i++)
213         {
214             interests.add(((String)gListInterests.getModel().getElementAt(i)));
215         }*/
216         if (((ClientGUI)this.getOwner()).confirmRegistration(gFieldUsername.getText(),
217                 new String(gPFieldPassword.getPassword()),
218                 gFieldBirthplace.getText(),
219                 gFieldCurrLocation.getText(),
220                 interests,
221                 gTAreaBio.getText())) this.dispose();
222         else gLabelPWarning.setText("Server failed to register. Retry.");
223     }//GEN-LAST:event_gButtonConfirmationMouseClicked
224
225     /**
226      * @param args the command line arguments
227      */
228     public static void main(String args[]) {
229         /* Set the Nimbus look and feel */
230         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
231         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
232          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
233          */
234         try {
235             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
236                 if ("Nimbus".equals(info.getName())) {
237                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
238                     break;
239                 }
240             }
241         } catch (ClassNotFoundException ex) {
242             java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
243         } catch (InstantiationException ex) {
244             java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
245         } catch (IllegalAccessException ex) {
246             java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
247         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
248             java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
249         }
250         //</editor-fold>
251         //</editor-fold>
252
253         /* Create and display the dialog */
254         java.awt.EventQueue.invokeLater(new Runnable() {
255             public void run() {
256                 EditProfile dialog = new EditProfile(new javax.swing.JFrame(), true);
257                 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
258                     @Override
259                     public void windowClosing(java.awt.event.WindowEvent e) {
260                         System.exit(0);
261                     }
262                 });
263                 dialog.setVisible(true);
264             }
265         });
266     }
267
268     // Variables declaration - do not modify//GEN-BEGIN:variables
269     private javax.swing.JButton gButtonConfirmation;
270     private javax.swing.JTextField gFieldBirthplace;
271     private javax.swing.JTextField gFieldCurrLocation;
272     private javax.swing.JTextField gFieldUsername;
273     private javax.swing.JLabel gLabelBio;
274     private javax.swing.JLabel gLabelBirthplace;
275     private javax.swing.JLabel gLabelCurrLocation;
276     private javax.swing.JLabel gLabelInterests;
277     private javax.swing.JLabel gLabelPConfirmation;
278     private javax.swing.JLabel gLabelPWarning;
279     private javax.swing.JLabel gLabelPassword;
280     private javax.swing.JLabel gLabelUsername;
281     private javax.swing.JList gListInterests;
282     private javax.swing.JPasswordField gPFieldPConfirmation;
283     private javax.swing.JPasswordField gPFieldPassword;
284     private javax.swing.JTextArea gTAreaBio;
285     private javax.swing.JScrollPane jScrollPane1;
286     private javax.swing.JScrollPane jScrollPane2;
287     // End of variables declaration//GEN-END:variables
288 }