client: send and receive network messages
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / ClientGUI.java
diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.java b/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.java
new file mode 100644 (file)
index 0000000..06daa9c
--- /dev/null
@@ -0,0 +1,585 @@
+/*
+ * 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 java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.SortedMap;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.JProgressBar;
+import javax.swing.Timer;
+import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
+import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogin;
+import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessageEvent;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessageEventListener;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerTCP;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerUDP;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerUDPMulticast;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkStream;
+import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkStreamManager;
+import uk.ac.ntu.n0521366.wsyd.libs.net.ServiceAddressMap;
+import uk.ac.ntu.n0521366.wsyd.libs.net.WSYD_SocketAddress;
+
+/**
+ *
+ * @author Eddie Berrisford-Lynch
+ */
+public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEventListener {
+    
+    private boolean loginSuccessful = false;
+    
+    private boolean regiSuccessful = false;
+    
+    private Login login = new Login(this, true);
+    
+    Socket socialSocket;
+    
+    /**
+     * Readable/displayable name of this application
+     * 
+     * Will be assigned userID when SocialServer connection established
+     */
+    private String _title = null;
+    
+    /**
+     * Network services to address map.
+     */
+    ServiceAddressMap _serviceToAddressMap;
+    
+    /**
+     * Handles display and sending of log messages.
+     */
+    @SuppressWarnings("NonConstantLogger")
+    private static Logger LOGGER;
+    
+    /**
+     * SortedMap wraps a TreeMap that has been made thread-safe by
+     * Collections.synchronizedSortedMap() in readMembers().
+     *
+     * Long key, the userID
+     * WSYD_Member member record
+     */
+    SortedMap<Long, WSYD_Member> _members;
+    
+    /**
+     * userIDs of members currently logged in
+     */
+    ArrayList<Long> _membersOnline;
+    
+    Timer _regularTasks;
+    
+    WSYD_SocketAddress _multicastAdvertiserSA;
+    
+    NetworkServerUDPMulticast _multicastService;
+    
+    WSYD_SocketAddress _udpNotificationServiceSA;
+    
+    NetworkServerUDP _udpNotificationService;
+    
+    WSYD_SocketAddress _tcpChatServiceSA;
+    
+    NetworkServerTCP _tcpChatService;
+    
+    NetworkStreamManager _tcpStreamManager;
+    
+    /**
+     * Creates new form ClientGUI
+     */
+    public ClientGUI() {
+        initComponents();
+        _serviceToAddressMap = new ServiceAddressMap(_title, LOGGER);
+        _tcpStreamManager = new NetworkStreamManager();
+    }
+
+    /**
+     * 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() {
+
+        gSplitPane1 = new javax.swing.JSplitPane();
+        gDetails = new javax.swing.JTabbedPane();
+        gPersonalProfile = new javax.swing.JPanel();
+        gPersonalName = new javax.swing.JLabel();
+        gPersonalStatus = new javax.swing.JTextField();
+        gScrollPane1 = new javax.swing.JScrollPane();
+        gPersonalNewsFeed = new javax.swing.JList();
+        gFriendProfile = new javax.swing.JPanel();
+        gLabelFriendName = new javax.swing.JLabel();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        gTAreaFriendBio = new javax.swing.JTextArea();
+        jScrollPane2 = new javax.swing.JScrollPane();
+        gListFriendInterests = new javax.swing.JList();
+        gLabelFriendBirthplace = new javax.swing.JLabel();
+        gLabelFriendBirthplaceData = new javax.swing.JLabel();
+        gLabelFriendLocation = new javax.swing.JLabel();
+        gLabelFriendLocationData = new javax.swing.JLabel();
+        jScrollPane3 = new javax.swing.JScrollPane();
+        gTAreaFriendStatuses = new javax.swing.JTextArea();
+        gLabelFriendInterests = new javax.swing.JLabel();
+        gButtonAddFriendChat = new javax.swing.JButton();
+        gOnlineList = new javax.swing.JScrollPane();
+        jList1 = new javax.swing.JList();
+        gStatusPanel = new javax.swing.JPanel();
+        gLabelFriendsOnlineQty = new javax.swing.JLabel();
+        gLabelFriendRequestsQty = new javax.swing.JLabel();
+        gLabelOnlineQty = new javax.swing.JLabel();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setTitle("We Stealz Your Dataz");
+        addWindowListener(new java.awt.event.WindowAdapter() {
+            public void windowActivated(java.awt.event.WindowEvent evt) {
+                formWindowActivated(evt);
+            }
+        });
+
+        gSplitPane1.setDividerLocation(this.getWidth() - 200);
+        gSplitPane1.setResizeWeight(0.5);
+        gSplitPane1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
+            public void propertyChange(java.beans.PropertyChangeEvent evt) {
+                gSplitPane1PropertyChange(evt);
+            }
+        });
+
+        gPersonalName.setText("Your Name");
+        gPersonalName.setToolTipText("Click to edit your profile");
+        gPersonalName.setMinimumSize(new java.awt.Dimension(64, 15));
+
+        gPersonalStatus.setText("My current status");
+        gPersonalStatus.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                gPersonalStatusActionPerformed(evt);
+            }
+        });
+
+        gPersonalNewsFeed.setModel(new javax.swing.AbstractListModel() {
+            String[] strings = { "Server uptime: 1 hour" };
+            public int getSize() { return strings.length; }
+            public Object getElementAt(int i) { return strings[i]; }
+        });
+        gPersonalNewsFeed.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        gPersonalNewsFeed.setToolTipText("WSYD News Feed");
+        gPersonalNewsFeed.setMinimumSize(new java.awt.Dimension(64, 17));
+        gPersonalNewsFeed.setNextFocusableComponent(gPersonalName);
+        gScrollPane1.setViewportView(gPersonalNewsFeed);
+
+        javax.swing.GroupLayout gPersonalProfileLayout = new javax.swing.GroupLayout(gPersonalProfile);
+        gPersonalProfile.setLayout(gPersonalProfileLayout);
+        gPersonalProfileLayout.setHorizontalGroup(
+            gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gPersonalProfileLayout.createSequentialGroup()
+                .addGap(30, 30, 30)
+                .addGroup(gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+                    .addComponent(gScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
+                    .addComponent(gPersonalName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .addComponent(gPersonalStatus))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+        );
+        gPersonalProfileLayout.setVerticalGroup(
+            gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gPersonalProfileLayout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(gPersonalName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(18, 18, 18)
+                .addComponent(gPersonalStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(gScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+        );
+
+        gDetails.addTab("News and Status", gPersonalProfile);
+
+        gLabelFriendName.setText("Friend's Name");
+
+        gTAreaFriendBio.setEditable(false);
+        gTAreaFriendBio.setColumns(35);
+        gTAreaFriendBio.setLineWrap(true);
+        gTAreaFriendBio.setRows(12);
+        gTAreaFriendBio.setTabSize(4);
+        gTAreaFriendBio.setText("Friend's Bio");
+        gTAreaFriendBio.setMinimumSize(new java.awt.Dimension(100, 50));
+        gTAreaFriendBio.setPreferredSize(new java.awt.Dimension(350, 156));
+        jScrollPane1.setViewportView(gTAreaFriendBio);
+
+        gListFriendInterests.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
+        gListFriendInterests.setModel(new javax.swing.AbstractListModel() {
+            String[] strings = { "Interest1", "Interest2", "Interest3", "..." };
+            public int getSize() { return strings.length; }
+            public Object getElementAt(int i) { return strings[i]; }
+        });
+        gListFriendInterests.setMinimumSize(new java.awt.Dimension(85, 85));
+        gListFriendInterests.setPreferredSize(new java.awt.Dimension(100, 85));
+        jScrollPane2.setViewportView(gListFriendInterests);
+
+        gLabelFriendBirthplace.setText("Birthplace:");
+
+        gLabelFriendBirthplaceData.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
+        gLabelFriendBirthplaceData.setText("Their Birthplace");
+
+        gLabelFriendLocation.setText("Current City/Town:");
+
+        gLabelFriendLocationData.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
+        gLabelFriendLocationData.setText("Their City/Town");
+
+        gTAreaFriendStatuses.setEditable(false);
+        gTAreaFriendStatuses.setColumns(20);
+        gTAreaFriendStatuses.setRows(5);
+        gTAreaFriendStatuses.setText("Friend's Three statuses");
+        jScrollPane3.setViewportView(gTAreaFriendStatuses);
+
+        gLabelFriendInterests.setText("Interests:");
+
+        gButtonAddFriendChat.setText("Add");
+
+        javax.swing.GroupLayout gFriendProfileLayout = new javax.swing.GroupLayout(gFriendProfile);
+        gFriendProfile.setLayout(gFriendProfileLayout);
+        gFriendProfileLayout.setHorizontalGroup(
+            gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gFriendProfileLayout.createSequentialGroup()
+                .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addGroup(gFriendProfileLayout.createSequentialGroup()
+                        .addGap(24, 24, 24)
+                        .addComponent(gLabelFriendLocation))
+                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gFriendProfileLayout.createSequentialGroup()
+                        .addContainerGap()
+                        .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addComponent(gLabelFriendInterests, javax.swing.GroupLayout.Alignment.TRAILING)
+                            .addComponent(gLabelFriendName, javax.swing.GroupLayout.Alignment.TRAILING)
+                            .addComponent(gLabelFriendBirthplace, javax.swing.GroupLayout.Alignment.TRAILING))))
+                .addGap(32, 32, 32)
+                .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(gLabelFriendLocationData)
+                    .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+                        .addComponent(gButtonAddFriendChat)
+                        .addComponent(gLabelFriendBirthplaceData)))
+                .addGap(90, 90, 90)
+                .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+                    .addComponent(jScrollPane1)
+                    .addComponent(jScrollPane3))
+                .addGap(21, 21, 21))
+        );
+        gFriendProfileLayout.setVerticalGroup(
+            gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gFriendProfileLayout.createSequentialGroup()
+                .addContainerGap()
+                .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addGroup(gFriendProfileLayout.createSequentialGroup()
+                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addGap(18, 18, 18)
+                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
+                    .addGroup(gFriendProfileLayout.createSequentialGroup()
+                        .addComponent(gLabelFriendName)
+                        .addGap(39, 39, 39)
+                        .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                            .addComponent(gLabelFriendBirthplaceData)
+                            .addComponent(gLabelFriendBirthplace))
+                        .addGap(38, 38, 38)
+                        .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                            .addComponent(gLabelFriendLocation)
+                            .addComponent(gLabelFriendLocationData))
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                        .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addComponent(gLabelFriendInterests)
+                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
+                    .addGroup(gFriendProfileLayout.createSequentialGroup()
+                        .addComponent(gButtonAddFriendChat)
+                        .addGap(0, 0, Short.MAX_VALUE)))
+                .addContainerGap())
+        );
+
+        gDetails.addTab("Friend Profile", gFriendProfile);
+
+        gSplitPane1.setLeftComponent(gDetails);
+
+        jList1.setModel(new javax.swing.AbstractListModel() {
+            String[] strings = { "Eddie Berrisford-Lynch", "Tom Thumb", "Peter Pan", "Freddy Mercury", "Sam Smith" };
+            public int getSize() { return strings.length; }
+            public Object getElementAt(int i) { return strings[i]; }
+        });
+        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        jList1.setMaximumSize(new java.awt.Dimension(200, 119));
+        jList1.setMinimumSize(new java.awt.Dimension(100, 119));
+        jList1.setVisibleRowCount(30);
+        gOnlineList.setViewportView(jList1);
+
+        gSplitPane1.setRightComponent(gOnlineList);
+
+        getContentPane().add(gSplitPane1, java.awt.BorderLayout.CENTER);
+
+        gLabelFriendsOnlineQty.setText("Friends: 000");
+
+        gLabelFriendRequestsQty.setText("Requests Pending: 000");
+
+        gLabelOnlineQty.setText("Online: 000");
+
+        javax.swing.GroupLayout gStatusPanelLayout = new javax.swing.GroupLayout(gStatusPanel);
+        gStatusPanel.setLayout(gStatusPanelLayout);
+        gStatusPanelLayout.setHorizontalGroup(
+            gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gStatusPanelLayout.createSequentialGroup()
+                .addComponent(gLabelOnlineQty)
+                .addGap(18, 18, 18)
+                .addComponent(gLabelFriendsOnlineQty)
+                .addGap(18, 18, 18)
+                .addComponent(gLabelFriendRequestsQty)
+                .addContainerGap(651, Short.MAX_VALUE))
+        );
+        gStatusPanelLayout.setVerticalGroup(
+            gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                .addComponent(gLabelFriendsOnlineQty)
+                .addComponent(gLabelFriendRequestsQty)
+                .addComponent(gLabelOnlineQty))
+        );
+
+        getContentPane().add(gStatusPanel, java.awt.BorderLayout.SOUTH);
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void gPersonalStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gPersonalStatusActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gPersonalStatusActionPerformed
+
+    private void gSplitPane1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_gSplitPane1PropertyChange
+        // TODO add your handling code here:
+    }//GEN-LAST:event_gSplitPane1PropertyChange
+
+    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
+        // TODO add your handling code here:
+    }//GEN-LAST:event_formWindowActivated
+
+    private ClientGUI initNeighbourListener() {
+        _multicastAdvertiserSA = new WSYD_SocketAddress(Network.MULTICAST_IP, Network.PORTS_MULTICAST_DISCOVERY, WSYD_SocketAddress.Protocol.UDP);
+        _multicastService = new NetworkServerUDPMulticast(_multicastAdvertiserSA, _title + "MC", _serviceToAddressMap, LOGGER);
+        _multicastService.getEventManager().addNetworkMessageEventListener(this, "Neighbour");
+        _multicastService.execute();
+        _serviceToAddressMap.put("all", new ServiceAddressMap.LastSeenHost(new InetSocketAddress(Network.MULTICAST_IP, Network.PORTS_MULTICAST_DISCOVERY), ServiceAddressMap.LastSeenHost.STATE.STATIC));
+               
+        return this;
+    }
+    
+    private void initListeners() {
+        
+        _udpNotificationServiceSA = new WSYD_SocketAddress(Network.IPv4_WILDCARD, Network.PORTS_EPHEMERAL, WSYD_SocketAddress.Protocol.UDP);
+        _udpNotificationService = new NetworkServerUDP(_udpNotificationServiceSA, _title + "_Notifier", _serviceToAddressMap, LOGGER);
+        _udpNotificationService.getEventManager().addNetworkMessageEventListener(this, "Notification");
+        _udpNotificationService.execute();
+        
+        _tcpChatServiceSA = new WSYD_SocketAddress(Network.IPv4_WILDCARD, Network.PORTS_EPHEMERAL, WSYD_SocketAddress.Protocol.TCP);
+        _tcpChatService = new NetworkServerTCP(_tcpChatServiceSA, _title + "_Chat", _serviceToAddressMap, _tcpStreamManager, LOGGER);
+        _tcpChatService.getEventManager().addNetworkMessageEventListener(this, "ChatRequest");
+        _tcpChatService.execute();
+        
+        ActionListener servicesAnnounceActionListener = new ActionListener() {
+            /**
+             * Perform regular house-keeping tasks.
+             * @param e 
+             */
+            @Override
+            public void actionPerformed(ActionEvent e) {   
+                // clean up the known hosts map
+                ArrayList<String> servicesRemoved = _serviceToAddressMap.cleanServiceAddressMap(5000);
+                for (String service: servicesRemoved) {
+                    // FIXME: does the process care if hosts have been removed? if not, remove this array iteration
+                    switch (service) {
+                    }
+                }
+                
+                // TODO: PING server
+
+            }
+        };
+        
+        _regularTasks = new Timer(1000, servicesAnnounceActionListener);
+        _regularTasks.setInitialDelay(100);
+        _regularTasks.start();
+        
+    }
+    
+    private void connectionDialog() {
+        JProgressBar progressBar = new JProgressBar(0,100);
+        progressBar.setValue(0);
+        progressBar.setIndeterminate(true);
+        progressBar.setString("Waiting for Server...");
+        progressBar.setStringPainted(true);
+        System.err.println("Progress Bar created");
+        
+        while (!_serviceToAddressMap.containsService("ServerSocialMC")) { 
+        }
+        
+        try {
+            socialSocket = new Socket(_serviceToAddressMap.getServiceAddress("ServerSocialMC").getAddress(), Network.PORTS_SERVER_SOCIAL);
+            NetworkStream newStream = new NetworkStream(socialSocket, _tcpStreamManager);
+            _tcpStreamManager.addStream(NetworkStreamManager.SERVERSOCIAL, newStream);
+        } catch (IOException ex) {
+            //Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
+            System.err.println("IOException in connectionDialog()");
+        }
+        //progressBar.setIndeterminate(false);
+        //progressBar.setValue(100);
+        loginDialog();
+    }
+    
+    private void loginDialog()
+    {
+        //WSYD_Login login = new Login(this, true);
+        login.setLocationRelativeTo(null);
+        login.setVisible(true);
+        if (loginSuccessful)
+        {
+            this.setLocationRelativeTo(null);
+            this.setVisible(true);
+        }
+    }
+    
+    public void loginAbort()
+    {
+        this.dispose();
+    }
+    
+    public boolean validateLogin(String uName, String pWord)
+    {
+        boolean result = false;
+        System.out.println(uName + pWord + "<");
+        
+        if (uName.equals("admin") && pWord.equals("admin"))
+        {
+            System.out.println("True");
+            loginSuccessful = true;
+            result = true;
+        }
+        else {
+            // TODO: wrap a login message with credentials
+            NetworkMessage message = new NetworkMessage("Login", null, new MessageLogin(uName, pWord));
+            _tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL).write(message);
+            // TODO: send login credentials to server for verification
+            result = true;
+        }
+        return result;
+    }
+    
+    public void regiProfileDialog()
+    {
+        EditProfile registration = new EditProfile(this, true);
+        registration.setLocationRelativeTo(null);
+        registration.setVisible(true);
+        if (regiSuccessful)
+        {
+            login.dispose();
+            this.setLocationRelativeTo(null);
+            this.setVisible(true);
+        }
+    }
+    
+    public boolean confirmRegistration(String uName, String pWord, String bPlace, String cLocation, TreeSet interests, String bio)
+    {
+        System.out.println(uName);
+        System.out.println(pWord);
+        System.out.println(bPlace);
+        System.out.println(cLocation);
+        
+        System.out.println(bio);
+        //TO DO: If server accepts registration return true
+        regiSuccessful = true;
+        return true;
+        //return false;
+    }
+    
+    
+    /**
+     * @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(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+        //</editor-fold>
+        //</editor-fold>
+        //</editor-fold>
+
+        /* Create and display the form */
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                new ClientGUI().initNeighbourListener().connectionDialog();
+            }
+        });
+    }
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JButton gButtonAddFriendChat;
+    private javax.swing.JTabbedPane gDetails;
+    private javax.swing.JPanel gFriendProfile;
+    private javax.swing.JLabel gLabelFriendBirthplace;
+    private javax.swing.JLabel gLabelFriendBirthplaceData;
+    private javax.swing.JLabel gLabelFriendInterests;
+    private javax.swing.JLabel gLabelFriendLocation;
+    private javax.swing.JLabel gLabelFriendLocationData;
+    private javax.swing.JLabel gLabelFriendName;
+    private javax.swing.JLabel gLabelFriendRequestsQty;
+    private javax.swing.JLabel gLabelFriendsOnlineQty;
+    private javax.swing.JLabel gLabelOnlineQty;
+    private javax.swing.JList gListFriendInterests;
+    private javax.swing.JScrollPane gOnlineList;
+    private javax.swing.JLabel gPersonalName;
+    private javax.swing.JList gPersonalNewsFeed;
+    private javax.swing.JPanel gPersonalProfile;
+    private javax.swing.JTextField gPersonalStatus;
+    private javax.swing.JScrollPane gScrollPane1;
+    private javax.swing.JSplitPane gSplitPane1;
+    private javax.swing.JPanel gStatusPanel;
+    private javax.swing.JTextArea gTAreaFriendBio;
+    private javax.swing.JTextArea gTAreaFriendStatuses;
+    private javax.swing.JList jList1;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JScrollPane jScrollPane2;
+    private javax.swing.JScrollPane jScrollPane3;
+    // End of variables declaration//GEN-END:variables
+
+    @Override
+    public void NetworkMessageReceived(NetworkMessageEvent event) {
+        NetworkMessage nm = event.getNetworkMessage();
+        if (nm == null)
+            return;
+        
+        System.err.println(MessageFormat.format("Network Message received with intent {0} from sender {1}", nm.getIntent(), nm.getSender()));
+    }
+}