client: send and receive network messages
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / EditProfile.java
diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.java b/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.java
new file mode 100644 (file)
index 0000000..de8b655
--- /dev/null
@@ -0,0 +1,288 @@
+package uk.ac.ntu.n0521366.wsyd.client;
+
+import java.util.TreeSet;
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author Eddie Berrisford-Lynch
+ */
+public class EditProfile extends javax.swing.JDialog {
+
+    /**
+     * Creates new form WSYD_RegiProfile
+     */
+    public EditProfile(java.awt.Frame parent, boolean modal) {
+        super(parent, modal);
+        initComponents();
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+        java.awt.GridBagConstraints gridBagConstraints;
+
+        gLabelUsername = new javax.swing.JLabel();
+        gFieldUsername = new javax.swing.JTextField();
+        gButtonConfirmation = new javax.swing.JButton();
+        gLabelPassword = new javax.swing.JLabel();
+        gPFieldPassword = new javax.swing.JPasswordField();
+        gLabelPConfirmation = new javax.swing.JLabel();
+        gPFieldPConfirmation = new javax.swing.JPasswordField();
+        gLabelPWarning = new javax.swing.JLabel();
+        gLabelBirthplace = new javax.swing.JLabel();
+        gFieldBirthplace = new javax.swing.JTextField();
+        gLabelCurrLocation = new javax.swing.JLabel();
+        gFieldCurrLocation = new javax.swing.JTextField();
+        gLabelInterests = new javax.swing.JLabel();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        gListInterests = new javax.swing.JList();
+        gLabelBio = new javax.swing.JLabel();
+        jScrollPane2 = new javax.swing.JScrollPane();
+        gTAreaBio = new javax.swing.JTextArea();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+        setTitle("Your Profile");
+        setMinimumSize(new java.awt.Dimension(600, 600));
+        java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
+        layout.columnWidths = new int[] {0, 5, 0, 5, 0};
+        layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0};
+        getContentPane().setLayout(layout);
+
+        gLabelUsername.setText("Username:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelUsername, gridBagConstraints);
+
+        gFieldUsername.setMinimumSize(new java.awt.Dimension(70, 25));
+        gFieldUsername.setPreferredSize(new java.awt.Dimension(150, 25));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        getContentPane().add(gFieldUsername, gridBagConstraints);
+
+        gButtonConfirmation.setText("Register");
+        gButtonConfirmation.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
+                gButtonConfirmationMouseClicked(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 4;
+        gridBagConstraints.gridy = 0;
+        getContentPane().add(gButtonConfirmation, gridBagConstraints);
+
+        gLabelPassword.setText("Password:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelPassword, gridBagConstraints);
+
+        gPFieldPassword.setMinimumSize(new java.awt.Dimension(70, 25));
+        gPFieldPassword.setPreferredSize(new java.awt.Dimension(120, 25));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.gridwidth = 3;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        getContentPane().add(gPFieldPassword, gridBagConstraints);
+
+        gLabelPConfirmation.setText("Confirm:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 4;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelPConfirmation, gridBagConstraints);
+
+        gPFieldPConfirmation.setMinimumSize(new java.awt.Dimension(70, 25));
+        gPFieldPConfirmation.setPreferredSize(new java.awt.Dimension(120, 25));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 4;
+        gridBagConstraints.gridwidth = 3;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        getContentPane().add(gPFieldPConfirmation, gridBagConstraints);
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 4;
+        gridBagConstraints.gridy = 4;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
+        getContentPane().add(gLabelPWarning, gridBagConstraints);
+
+        gLabelBirthplace.setText("Birthplace:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 6;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelBirthplace, gridBagConstraints);
+
+        gFieldBirthplace.setMinimumSize(new java.awt.Dimension(100, 25));
+        gFieldBirthplace.setPreferredSize(new java.awt.Dimension(200, 25));
+        gFieldBirthplace.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                gFieldBirthplaceActionPerformed(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 6;
+        getContentPane().add(gFieldBirthplace, gridBagConstraints);
+
+        gLabelCurrLocation.setText("Current City/Town:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 8;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelCurrLocation, gridBagConstraints);
+
+        gFieldCurrLocation.setMinimumSize(new java.awt.Dimension(100, 25));
+        gFieldCurrLocation.setPreferredSize(new java.awt.Dimension(200, 25));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 8;
+        getContentPane().add(gFieldCurrLocation, gridBagConstraints);
+
+        gLabelInterests.setText("Interests:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 10;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelInterests, gridBagConstraints);
+
+        gListInterests.setModel(new javax.swing.AbstractListModel() {
+            String[] strings = { "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8" };
+            public int getSize() { return strings.length; }
+            public Object getElementAt(int i) { return strings[i]; }
+        });
+        gListInterests.setToolTipText("Select the interests you have, they will be displayed (Hold CTRL + Click)");
+        jScrollPane1.setViewportView(gListInterests);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 10;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        getContentPane().add(jScrollPane1, gridBagConstraints);
+
+        gLabelBio.setText("Bio:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 12;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
+        getContentPane().add(gLabelBio, gridBagConstraints);
+
+        gTAreaBio.setColumns(35);
+        gTAreaBio.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
+        gTAreaBio.setLineWrap(true);
+        gTAreaBio.setRows(12);
+        gTAreaBio.setTabSize(4);
+        gTAreaBio.setMinimumSize(new java.awt.Dimension(100, 50));
+        jScrollPane2.setViewportView(gTAreaBio);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 12;
+        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
+        gridBagConstraints.gridheight = 5;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        getContentPane().add(jScrollPane2, gridBagConstraints);
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void gFieldBirthplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthplaceActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gFieldBirthplaceActionPerformed
+
+    private void gButtonConfirmationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonConfirmationMouseClicked
+        // TODO add your handling code here:
+        TreeSet<String> interests = null;
+        /*
+        for (int i = 0; i < gListInterests.getModel().getSize(); i++)
+        {
+            interests.add(((String)gListInterests.getModel().getElementAt(i)));
+        }*/
+        if (((ClientGUI)this.getOwner()).confirmRegistration(gFieldUsername.getText(),
+                new String(gPFieldPassword.getPassword()),
+                gFieldBirthplace.getText(),
+                gFieldCurrLocation.getText(),
+                interests,
+                gTAreaBio.getText())) this.dispose();
+        else gLabelPWarning.setText("Server failed to register. Retry.");
+    }//GEN-LAST:event_gButtonConfirmationMouseClicked
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String args[]) {
+        /* Set the Nimbus look and feel */
+        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
+         */
+        try {
+            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+                if ("Nimbus".equals(info.getName())) {
+                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
+                    break;
+                }
+            }
+        } catch (ClassNotFoundException ex) {
+            java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(EditProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+        //</editor-fold>
+
+        /* Create and display the dialog */
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                EditProfile dialog = new EditProfile(new javax.swing.JFrame(), true);
+                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
+                    @Override
+                    public void windowClosing(java.awt.event.WindowEvent e) {
+                        System.exit(0);
+                    }
+                });
+                dialog.setVisible(true);
+            }
+        });
+    }
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JButton gButtonConfirmation;
+    private javax.swing.JTextField gFieldBirthplace;
+    private javax.swing.JTextField gFieldCurrLocation;
+    private javax.swing.JTextField gFieldUsername;
+    private javax.swing.JLabel gLabelBio;
+    private javax.swing.JLabel gLabelBirthplace;
+    private javax.swing.JLabel gLabelCurrLocation;
+    private javax.swing.JLabel gLabelInterests;
+    private javax.swing.JLabel gLabelPConfirmation;
+    private javax.swing.JLabel gLabelPWarning;
+    private javax.swing.JLabel gLabelPassword;
+    private javax.swing.JLabel gLabelUsername;
+    private javax.swing.JList gListInterests;
+    private javax.swing.JPasswordField gPFieldPConfirmation;
+    private javax.swing.JPasswordField gPFieldPassword;
+    private javax.swing.JTextArea gTAreaBio;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JScrollPane jScrollPane2;
+    // End of variables declaration//GEN-END:variables
+}