Merge branch 'feature_client'
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / Login.java
diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/Login.java b/src/uk/ac/ntu/n0521366/wsyd/client/Login.java
new file mode 100644 (file)
index 0000000..db417c1
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ * 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.
+ */
+package uk.ac.ntu.n0521366.wsyd.client;
+
+import javax.swing.JFrame;
+/**
+ *
+ * @author Eddie Berrisford-Lynch
+ */
+public class Login extends javax.swing.JDialog {
+
+    /**
+     * Creates new form WSYD_Login
+     */
+    public Login(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;
+
+        gLabelWSYD = new javax.swing.JLabel();
+        gLabelName = new javax.swing.JLabel();
+        gFieldName = new javax.swing.JTextField();
+        gLabelPassword = new javax.swing.JLabel();
+        gFieldPassword = new javax.swing.JPasswordField();
+        gButtonLogin = new javax.swing.JButton();
+        gButtonRegister = new javax.swing.JButton();
+        gLabelRegister = new javax.swing.JLabel();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+        setMinimumSize(new java.awt.Dimension(400, 300));
+        addWindowListener(new java.awt.event.WindowAdapter() {
+            public void windowClosing(java.awt.event.WindowEvent evt) {
+                formWindowClosing(evt);
+            }
+            public void windowClosed(java.awt.event.WindowEvent evt) {
+                formWindowClosed(evt);
+            }
+        });
+        java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
+        layout.columnWidths = new int[] {0, 5, 0};
+        layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0};
+        getContentPane().setLayout(layout);
+
+        gLabelWSYD.setText("Welcome to We Stealz Your Dataz!");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
+        gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
+        getContentPane().add(gLabelWSYD, gridBagConstraints);
+
+        gLabelName.setText("Name:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 2;
+        getContentPane().add(gLabelName, gridBagConstraints);
+
+        gFieldName.setText("Enter Username...");
+        gFieldName.setMinimumSize(new java.awt.Dimension(70, 25));
+        gFieldName.setPreferredSize(new java.awt.Dimension(150, 25));
+        gFieldName.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                gFieldNameActionPerformed(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 2;
+        getContentPane().add(gFieldName, gridBagConstraints);
+
+        gLabelPassword.setText("Password:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 4;
+        getContentPane().add(gLabelPassword, gridBagConstraints);
+
+        gFieldPassword.setMinimumSize(new java.awt.Dimension(70, 19));
+        gFieldPassword.setPreferredSize(new java.awt.Dimension(150, 25));
+        gFieldPassword.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                gFieldPasswordActionPerformed(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 4;
+        getContentPane().add(gFieldPassword, gridBagConstraints);
+
+        gButtonLogin.setText("Login");
+        gButtonLogin.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
+        gButtonLogin.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
+                gButtonLoginMouseClicked(evt);
+            }
+        });
+        gButtonLogin.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                gButtonLoginActionPerformed(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 6;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
+        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
+        getContentPane().add(gButtonLogin, gridBagConstraints);
+
+        gButtonRegister.setText("Register");
+        gButtonRegister.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
+                gButtonRegisterMouseClicked(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 8;
+        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
+        getContentPane().add(gButtonRegister, gridBagConstraints);
+
+        gLabelRegister.setText("Not already registered?");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 8;
+        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
+        getContentPane().add(gLabelRegister, gridBagConstraints);
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void gFieldNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldNameActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gFieldNameActionPerformed
+
+    private void gButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gButtonLoginActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gButtonLoginActionPerformed
+
+    private void gFieldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldPasswordActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gFieldPasswordActionPerformed
+
+    private void gButtonLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonLoginMouseClicked
+        // TODO add your handling code here:
+        if (((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()))); //this.dispose();
+        else gFieldName.setText("Invalid Login...");
+    }//GEN-LAST:event_gButtonLoginMouseClicked
+
+    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_formWindowClosed
+
+    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
+        // TODO add your handling code here:
+        ((ClientGUI)this.getOwner()).loginAbort();
+    }//GEN-LAST:event_formWindowClosing
+
+    private void gButtonRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonRegisterMouseClicked
+        // TODO add your handling code here:
+        ((ClientGUI)this.getOwner()).regiProfileDialog();
+    }//GEN-LAST:event_gButtonRegisterMouseClicked
+
+    /**
+     * @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(Login.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() {
+                Login dialog = new Login(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 gButtonLogin;
+    private javax.swing.JButton gButtonRegister;
+    private javax.swing.JTextField gFieldName;
+    private javax.swing.JPasswordField gFieldPassword;
+    private javax.swing.JLabel gLabelName;
+    private javax.swing.JLabel gLabelPassword;
+    private javax.swing.JLabel gLabelRegister;
+    private javax.swing.JLabel gLabelWSYD;
+    // End of variables declaration//GEN-END:variables
+}