06daa9c258c0a2590ee83fb81d308db9ce74a376
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / ClientGUI.java
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package uk.ac.ntu.n0521366.wsyd.client;
7
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.io.IOException;
11 import java.net.InetSocketAddress;
12 import java.net.Socket;
13 import java.text.MessageFormat;
14 import java.util.ArrayList;
15 import java.util.SortedMap;
16 import javax.swing.JDialog;
17 import javax.swing.JFrame;
18 import javax.swing.JTextField;
19 import java.util.TreeSet;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import javax.swing.JProgressBar;
23 import javax.swing.Timer;
24 import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
25 import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogin;
26 import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
27 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage;
28 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessageEvent;
29 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessageEventListener;
30 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerTCP;
31 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerUDP;
32 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkServerUDPMulticast;
33 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkStream;
34 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkStreamManager;
35 import uk.ac.ntu.n0521366.wsyd.libs.net.ServiceAddressMap;
36 import uk.ac.ntu.n0521366.wsyd.libs.net.WSYD_SocketAddress;
37
38 /**
39  *
40  * @author Eddie Berrisford-Lynch
41  */
42 public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEventListener {
43     
44     private boolean loginSuccessful = false;
45     
46     private boolean regiSuccessful = false;
47     
48     private Login login = new Login(this, true);
49     
50     Socket socialSocket;
51     
52     /**
53      * Readable/displayable name of this application
54      * 
55      * Will be assigned userID when SocialServer connection established
56      */
57     private String _title = null;
58     
59     /**
60      * Network services to address map.
61      */
62     ServiceAddressMap _serviceToAddressMap;
63     
64     /**
65      * Handles display and sending of log messages.
66      */
67     @SuppressWarnings("NonConstantLogger")
68     private static Logger LOGGER;
69     
70     /**
71      * SortedMap wraps a TreeMap that has been made thread-safe by
72      * Collections.synchronizedSortedMap() in readMembers().
73      *
74      * Long key, the userID
75      * WSYD_Member member record
76      */
77     SortedMap<Long, WSYD_Member> _members;
78     
79     /**
80      * userIDs of members currently logged in
81      */
82     ArrayList<Long> _membersOnline;
83     
84     Timer _regularTasks;
85     
86     WSYD_SocketAddress _multicastAdvertiserSA;
87     
88     NetworkServerUDPMulticast _multicastService;
89     
90     WSYD_SocketAddress _udpNotificationServiceSA;
91     
92     NetworkServerUDP _udpNotificationService;
93     
94     WSYD_SocketAddress _tcpChatServiceSA;
95     
96     NetworkServerTCP _tcpChatService;
97     
98     NetworkStreamManager _tcpStreamManager;
99     
100     /**
101      * Creates new form ClientGUI
102      */
103     public ClientGUI() {
104         initComponents();
105         _serviceToAddressMap = new ServiceAddressMap(_title, LOGGER);
106         _tcpStreamManager = new NetworkStreamManager();
107     }
108
109     /**
110      * This method is called from within the constructor to initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is always
112      * regenerated by the Form Editor.
113      */
114     @SuppressWarnings("unchecked")
115     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
116     private void initComponents() {
117
118         gSplitPane1 = new javax.swing.JSplitPane();
119         gDetails = new javax.swing.JTabbedPane();
120         gPersonalProfile = new javax.swing.JPanel();
121         gPersonalName = new javax.swing.JLabel();
122         gPersonalStatus = new javax.swing.JTextField();
123         gScrollPane1 = new javax.swing.JScrollPane();
124         gPersonalNewsFeed = new javax.swing.JList();
125         gFriendProfile = new javax.swing.JPanel();
126         gLabelFriendName = new javax.swing.JLabel();
127         jScrollPane1 = new javax.swing.JScrollPane();
128         gTAreaFriendBio = new javax.swing.JTextArea();
129         jScrollPane2 = new javax.swing.JScrollPane();
130         gListFriendInterests = new javax.swing.JList();
131         gLabelFriendBirthplace = new javax.swing.JLabel();
132         gLabelFriendBirthplaceData = new javax.swing.JLabel();
133         gLabelFriendLocation = new javax.swing.JLabel();
134         gLabelFriendLocationData = new javax.swing.JLabel();
135         jScrollPane3 = new javax.swing.JScrollPane();
136         gTAreaFriendStatuses = new javax.swing.JTextArea();
137         gLabelFriendInterests = new javax.swing.JLabel();
138         gButtonAddFriendChat = new javax.swing.JButton();
139         gOnlineList = new javax.swing.JScrollPane();
140         jList1 = new javax.swing.JList();
141         gStatusPanel = new javax.swing.JPanel();
142         gLabelFriendsOnlineQty = new javax.swing.JLabel();
143         gLabelFriendRequestsQty = new javax.swing.JLabel();
144         gLabelOnlineQty = new javax.swing.JLabel();
145
146         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
147         setTitle("We Stealz Your Dataz");
148         addWindowListener(new java.awt.event.WindowAdapter() {
149             public void windowActivated(java.awt.event.WindowEvent evt) {
150                 formWindowActivated(evt);
151             }
152         });
153
154         gSplitPane1.setDividerLocation(this.getWidth() - 200);
155         gSplitPane1.setResizeWeight(0.5);
156         gSplitPane1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
157             public void propertyChange(java.beans.PropertyChangeEvent evt) {
158                 gSplitPane1PropertyChange(evt);
159             }
160         });
161
162         gPersonalName.setText("Your Name");
163         gPersonalName.setToolTipText("Click to edit your profile");
164         gPersonalName.setMinimumSize(new java.awt.Dimension(64, 15));
165
166         gPersonalStatus.setText("My current status");
167         gPersonalStatus.addActionListener(new java.awt.event.ActionListener() {
168             public void actionPerformed(java.awt.event.ActionEvent evt) {
169                 gPersonalStatusActionPerformed(evt);
170             }
171         });
172
173         gPersonalNewsFeed.setModel(new javax.swing.AbstractListModel() {
174             String[] strings = { "Server uptime: 1 hour" };
175             public int getSize() { return strings.length; }
176             public Object getElementAt(int i) { return strings[i]; }
177         });
178         gPersonalNewsFeed.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
179         gPersonalNewsFeed.setToolTipText("WSYD News Feed");
180         gPersonalNewsFeed.setMinimumSize(new java.awt.Dimension(64, 17));
181         gPersonalNewsFeed.setNextFocusableComponent(gPersonalName);
182         gScrollPane1.setViewportView(gPersonalNewsFeed);
183
184         javax.swing.GroupLayout gPersonalProfileLayout = new javax.swing.GroupLayout(gPersonalProfile);
185         gPersonalProfile.setLayout(gPersonalProfileLayout);
186         gPersonalProfileLayout.setHorizontalGroup(
187             gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188             .addGroup(gPersonalProfileLayout.createSequentialGroup()
189                 .addGap(30, 30, 30)
190                 .addGroup(gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
191                     .addComponent(gScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
192                     .addComponent(gPersonalName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193                     .addComponent(gPersonalStatus))
194                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
195         );
196         gPersonalProfileLayout.setVerticalGroup(
197             gPersonalProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198             .addGroup(gPersonalProfileLayout.createSequentialGroup()
199                 .addContainerGap()
200                 .addComponent(gPersonalName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
201                 .addGap(18, 18, 18)
202                 .addComponent(gPersonalStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
203                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204                 .addComponent(gScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
205                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
206         );
207
208         gDetails.addTab("News and Status", gPersonalProfile);
209
210         gLabelFriendName.setText("Friend's Name");
211
212         gTAreaFriendBio.setEditable(false);
213         gTAreaFriendBio.setColumns(35);
214         gTAreaFriendBio.setLineWrap(true);
215         gTAreaFriendBio.setRows(12);
216         gTAreaFriendBio.setTabSize(4);
217         gTAreaFriendBio.setText("Friend's Bio");
218         gTAreaFriendBio.setMinimumSize(new java.awt.Dimension(100, 50));
219         gTAreaFriendBio.setPreferredSize(new java.awt.Dimension(350, 156));
220         jScrollPane1.setViewportView(gTAreaFriendBio);
221
222         gListFriendInterests.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
223         gListFriendInterests.setModel(new javax.swing.AbstractListModel() {
224             String[] strings = { "Interest1", "Interest2", "Interest3", "..." };
225             public int getSize() { return strings.length; }
226             public Object getElementAt(int i) { return strings[i]; }
227         });
228         gListFriendInterests.setMinimumSize(new java.awt.Dimension(85, 85));
229         gListFriendInterests.setPreferredSize(new java.awt.Dimension(100, 85));
230         jScrollPane2.setViewportView(gListFriendInterests);
231
232         gLabelFriendBirthplace.setText("Birthplace:");
233
234         gLabelFriendBirthplaceData.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
235         gLabelFriendBirthplaceData.setText("Their Birthplace");
236
237         gLabelFriendLocation.setText("Current City/Town:");
238
239         gLabelFriendLocationData.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
240         gLabelFriendLocationData.setText("Their City/Town");
241
242         gTAreaFriendStatuses.setEditable(false);
243         gTAreaFriendStatuses.setColumns(20);
244         gTAreaFriendStatuses.setRows(5);
245         gTAreaFriendStatuses.setText("Friend's Three statuses");
246         jScrollPane3.setViewportView(gTAreaFriendStatuses);
247
248         gLabelFriendInterests.setText("Interests:");
249
250         gButtonAddFriendChat.setText("Add");
251
252         javax.swing.GroupLayout gFriendProfileLayout = new javax.swing.GroupLayout(gFriendProfile);
253         gFriendProfile.setLayout(gFriendProfileLayout);
254         gFriendProfileLayout.setHorizontalGroup(
255             gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256             .addGroup(gFriendProfileLayout.createSequentialGroup()
257                 .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258                     .addGroup(gFriendProfileLayout.createSequentialGroup()
259                         .addGap(24, 24, 24)
260                         .addComponent(gLabelFriendLocation))
261                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gFriendProfileLayout.createSequentialGroup()
262                         .addContainerGap()
263                         .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264                             .addComponent(gLabelFriendInterests, javax.swing.GroupLayout.Alignment.TRAILING)
265                             .addComponent(gLabelFriendName, javax.swing.GroupLayout.Alignment.TRAILING)
266                             .addComponent(gLabelFriendBirthplace, javax.swing.GroupLayout.Alignment.TRAILING))))
267                 .addGap(32, 32, 32)
268                 .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
270                     .addComponent(gLabelFriendLocationData)
271                     .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
272                         .addComponent(gButtonAddFriendChat)
273                         .addComponent(gLabelFriendBirthplaceData)))
274                 .addGap(90, 90, 90)
275                 .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
276                     .addComponent(jScrollPane1)
277                     .addComponent(jScrollPane3))
278                 .addGap(21, 21, 21))
279         );
280         gFriendProfileLayout.setVerticalGroup(
281             gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282             .addGroup(gFriendProfileLayout.createSequentialGroup()
283                 .addContainerGap()
284                 .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
285                     .addGroup(gFriendProfileLayout.createSequentialGroup()
286                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
287                         .addGap(18, 18, 18)
288                         .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
289                     .addGroup(gFriendProfileLayout.createSequentialGroup()
290                         .addComponent(gLabelFriendName)
291                         .addGap(39, 39, 39)
292                         .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
293                             .addComponent(gLabelFriendBirthplaceData)
294                             .addComponent(gLabelFriendBirthplace))
295                         .addGap(38, 38, 38)
296                         .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
297                             .addComponent(gLabelFriendLocation)
298                             .addComponent(gLabelFriendLocationData))
299                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
300                         .addGroup(gFriendProfileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301                             .addComponent(gLabelFriendInterests)
302                             .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
303                     .addGroup(gFriendProfileLayout.createSequentialGroup()
304                         .addComponent(gButtonAddFriendChat)
305                         .addGap(0, 0, Short.MAX_VALUE)))
306                 .addContainerGap())
307         );
308
309         gDetails.addTab("Friend Profile", gFriendProfile);
310
311         gSplitPane1.setLeftComponent(gDetails);
312
313         jList1.setModel(new javax.swing.AbstractListModel() {
314             String[] strings = { "Eddie Berrisford-Lynch", "Tom Thumb", "Peter Pan", "Freddy Mercury", "Sam Smith" };
315             public int getSize() { return strings.length; }
316             public Object getElementAt(int i) { return strings[i]; }
317         });
318         jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
319         jList1.setMaximumSize(new java.awt.Dimension(200, 119));
320         jList1.setMinimumSize(new java.awt.Dimension(100, 119));
321         jList1.setVisibleRowCount(30);
322         gOnlineList.setViewportView(jList1);
323
324         gSplitPane1.setRightComponent(gOnlineList);
325
326         getContentPane().add(gSplitPane1, java.awt.BorderLayout.CENTER);
327
328         gLabelFriendsOnlineQty.setText("Friends: 000");
329
330         gLabelFriendRequestsQty.setText("Requests Pending: 000");
331
332         gLabelOnlineQty.setText("Online: 000");
333
334         javax.swing.GroupLayout gStatusPanelLayout = new javax.swing.GroupLayout(gStatusPanel);
335         gStatusPanel.setLayout(gStatusPanelLayout);
336         gStatusPanelLayout.setHorizontalGroup(
337             gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338             .addGroup(gStatusPanelLayout.createSequentialGroup()
339                 .addComponent(gLabelOnlineQty)
340                 .addGap(18, 18, 18)
341                 .addComponent(gLabelFriendsOnlineQty)
342                 .addGap(18, 18, 18)
343                 .addComponent(gLabelFriendRequestsQty)
344                 .addContainerGap(651, Short.MAX_VALUE))
345         );
346         gStatusPanelLayout.setVerticalGroup(
347             gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
348             .addGroup(gStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
349                 .addComponent(gLabelFriendsOnlineQty)
350                 .addComponent(gLabelFriendRequestsQty)
351                 .addComponent(gLabelOnlineQty))
352         );
353
354         getContentPane().add(gStatusPanel, java.awt.BorderLayout.SOUTH);
355
356         pack();
357     }// </editor-fold>//GEN-END:initComponents
358
359     private void gPersonalStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gPersonalStatusActionPerformed
360         // TODO add your handling code here:
361     }//GEN-LAST:event_gPersonalStatusActionPerformed
362
363     private void gSplitPane1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_gSplitPane1PropertyChange
364         // TODO add your handling code here:
365     }//GEN-LAST:event_gSplitPane1PropertyChange
366
367     private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
368         // TODO add your handling code here:
369     }//GEN-LAST:event_formWindowActivated
370
371     private ClientGUI initNeighbourListener() {
372         _multicastAdvertiserSA = new WSYD_SocketAddress(Network.MULTICAST_IP, Network.PORTS_MULTICAST_DISCOVERY, WSYD_SocketAddress.Protocol.UDP);
373         _multicastService = new NetworkServerUDPMulticast(_multicastAdvertiserSA, _title + "MC", _serviceToAddressMap, LOGGER);
374         _multicastService.getEventManager().addNetworkMessageEventListener(this, "Neighbour");
375         _multicastService.execute();
376         _serviceToAddressMap.put("all", new ServiceAddressMap.LastSeenHost(new InetSocketAddress(Network.MULTICAST_IP, Network.PORTS_MULTICAST_DISCOVERY), ServiceAddressMap.LastSeenHost.STATE.STATIC));
377                
378         return this;
379     }
380     
381     private void initListeners() {
382         
383         _udpNotificationServiceSA = new WSYD_SocketAddress(Network.IPv4_WILDCARD, Network.PORTS_EPHEMERAL, WSYD_SocketAddress.Protocol.UDP);
384         _udpNotificationService = new NetworkServerUDP(_udpNotificationServiceSA, _title + "_Notifier", _serviceToAddressMap, LOGGER);
385         _udpNotificationService.getEventManager().addNetworkMessageEventListener(this, "Notification");
386         _udpNotificationService.execute();
387         
388         _tcpChatServiceSA = new WSYD_SocketAddress(Network.IPv4_WILDCARD, Network.PORTS_EPHEMERAL, WSYD_SocketAddress.Protocol.TCP);
389         _tcpChatService = new NetworkServerTCP(_tcpChatServiceSA, _title + "_Chat", _serviceToAddressMap, _tcpStreamManager, LOGGER);
390         _tcpChatService.getEventManager().addNetworkMessageEventListener(this, "ChatRequest");
391         _tcpChatService.execute();
392         
393         ActionListener servicesAnnounceActionListener = new ActionListener() {
394             /**
395              * Perform regular house-keeping tasks.
396              * @param e 
397              */
398             @Override
399             public void actionPerformed(ActionEvent e) {   
400                 // clean up the known hosts map
401                 ArrayList<String> servicesRemoved = _serviceToAddressMap.cleanServiceAddressMap(5000);
402                 for (String service: servicesRemoved) {
403                     // FIXME: does the process care if hosts have been removed? if not, remove this array iteration
404                     switch (service) {
405                     }
406                 }
407                 
408                 // TODO: PING server
409
410             }
411         };
412         
413         _regularTasks = new Timer(1000, servicesAnnounceActionListener);
414         _regularTasks.setInitialDelay(100);
415         _regularTasks.start();
416         
417     }
418     
419     private void connectionDialog() {
420         JProgressBar progressBar = new JProgressBar(0,100);
421         progressBar.setValue(0);
422         progressBar.setIndeterminate(true);
423         progressBar.setString("Waiting for Server...");
424         progressBar.setStringPainted(true);
425         System.err.println("Progress Bar created");
426         
427         while (!_serviceToAddressMap.containsService("ServerSocialMC")) { 
428         }
429         
430         try {
431             socialSocket = new Socket(_serviceToAddressMap.getServiceAddress("ServerSocialMC").getAddress(), Network.PORTS_SERVER_SOCIAL);
432             NetworkStream newStream = new NetworkStream(socialSocket, _tcpStreamManager);
433             _tcpStreamManager.addStream(NetworkStreamManager.SERVERSOCIAL, newStream);
434         } catch (IOException ex) {
435             //Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
436             System.err.println("IOException in connectionDialog()");
437         }
438         //progressBar.setIndeterminate(false);
439         //progressBar.setValue(100);
440         loginDialog();
441     }
442     
443     private void loginDialog()
444     {
445         //WSYD_Login login = new Login(this, true);
446         login.setLocationRelativeTo(null);
447         login.setVisible(true);
448         if (loginSuccessful)
449         {
450             this.setLocationRelativeTo(null);
451             this.setVisible(true);
452         }
453     }
454     
455     public void loginAbort()
456     {
457         this.dispose();
458     }
459     
460     public boolean validateLogin(String uName, String pWord)
461     {
462         boolean result = false;
463         System.out.println(uName + pWord + "<");
464         
465         if (uName.equals("admin") && pWord.equals("admin"))
466         {
467             System.out.println("True");
468             loginSuccessful = true;
469             result = true;
470         }
471         else {
472             // TODO: wrap a login message with credentials
473             NetworkMessage message = new NetworkMessage("Login", null, new MessageLogin(uName, pWord));
474             _tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL).write(message);
475             // TODO: send login credentials to server for verification
476             result = true;
477         }
478         return result;
479     }
480     
481     public void regiProfileDialog()
482     {
483         EditProfile registration = new EditProfile(this, true);
484         registration.setLocationRelativeTo(null);
485         registration.setVisible(true);
486         if (regiSuccessful)
487         {
488             login.dispose();
489             this.setLocationRelativeTo(null);
490             this.setVisible(true);
491         }
492     }
493     
494     public boolean confirmRegistration(String uName, String pWord, String bPlace, String cLocation, TreeSet interests, String bio)
495     {
496         System.out.println(uName);
497         System.out.println(pWord);
498         System.out.println(bPlace);
499         System.out.println(cLocation);
500         
501         System.out.println(bio);
502         //TO DO: If server accepts registration return true
503         regiSuccessful = true;
504         return true;
505         //return false;
506     }
507     
508     
509     /**
510      * @param args the command line arguments
511      */
512     public static void main(String args[]) {
513         /* Set the Nimbus look and feel */
514         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
515         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
516          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
517          */
518         try {
519             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
520                 if ("Nimbus".equals(info.getName())) {
521                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
522                     break;
523                 }
524             }
525         } catch (ClassNotFoundException ex) {
526             java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
527         } catch (InstantiationException ex) {
528             java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
529         } catch (IllegalAccessException ex) {
530             java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
531         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
532             java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
533         }
534         //</editor-fold>
535         //</editor-fold>
536         //</editor-fold>
537         //</editor-fold>
538
539         /* Create and display the form */
540         java.awt.EventQueue.invokeLater(new Runnable() {
541             public void run() {
542                 new ClientGUI().initNeighbourListener().connectionDialog();
543             }
544         });
545     }
546
547     // Variables declaration - do not modify//GEN-BEGIN:variables
548     private javax.swing.JButton gButtonAddFriendChat;
549     private javax.swing.JTabbedPane gDetails;
550     private javax.swing.JPanel gFriendProfile;
551     private javax.swing.JLabel gLabelFriendBirthplace;
552     private javax.swing.JLabel gLabelFriendBirthplaceData;
553     private javax.swing.JLabel gLabelFriendInterests;
554     private javax.swing.JLabel gLabelFriendLocation;
555     private javax.swing.JLabel gLabelFriendLocationData;
556     private javax.swing.JLabel gLabelFriendName;
557     private javax.swing.JLabel gLabelFriendRequestsQty;
558     private javax.swing.JLabel gLabelFriendsOnlineQty;
559     private javax.swing.JLabel gLabelOnlineQty;
560     private javax.swing.JList gListFriendInterests;
561     private javax.swing.JScrollPane gOnlineList;
562     private javax.swing.JLabel gPersonalName;
563     private javax.swing.JList gPersonalNewsFeed;
564     private javax.swing.JPanel gPersonalProfile;
565     private javax.swing.JTextField gPersonalStatus;
566     private javax.swing.JScrollPane gScrollPane1;
567     private javax.swing.JSplitPane gSplitPane1;
568     private javax.swing.JPanel gStatusPanel;
569     private javax.swing.JTextArea gTAreaFriendBio;
570     private javax.swing.JTextArea gTAreaFriendStatuses;
571     private javax.swing.JList jList1;
572     private javax.swing.JScrollPane jScrollPane1;
573     private javax.swing.JScrollPane jScrollPane2;
574     private javax.swing.JScrollPane jScrollPane3;
575     // End of variables declaration//GEN-END:variables
576
577     @Override
578     public void NetworkMessageReceived(NetworkMessageEvent event) {
579         NetworkMessage nm = event.getNetworkMessage();
580         if (nm == null)
581             return;
582         
583         System.err.println(MessageFormat.format("Network Message received with intent {0} from sender {1}", nm.getIntent(), nm.getSender()));
584     }
585 }