From 3e2664dbcafa7a3e1a7a14e7ba18adbd5feeebac Mon Sep 17 00:00:00 2001 From: Eddie Date: Tue, 2 Jun 2015 17:13:59 +0100 Subject: [PATCH] client: send and receive network messages --- src/uk/ac/ntu/n0521366/wsyd/client/Chat.form | 169 ++ src/uk/ac/ntu/n0521366/wsyd/client/Chat.java | 157 ++ .../ntu/n0521366/wsyd/client/ClientGUI.form | 424 +++++ .../ntu/n0521366/wsyd/client/ClientGUI.java | 585 +++++++ .../ntu/n0521366/wsyd/client/EditProfile.form | 1440 +++++++++++++++++ .../ntu/n0521366/wsyd/client/EditProfile.java | 288 ++++ src/uk/ac/ntu/n0521366/wsyd/client/Login.form | 740 +++++++++ src/uk/ac/ntu/n0521366/wsyd/client/Login.java | 228 +++ 8 files changed, 4031 insertions(+) create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/Chat.form create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/Chat.java create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.form create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.java create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.form create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.java create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/Login.form create mode 100644 src/uk/ac/ntu/n0521366/wsyd/client/Login.java diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/Chat.form b/src/uk/ac/ntu/n0521366/wsyd/client/Chat.form new file mode 100644 index 0000000..7e54b7b --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/Chat.form @@ -0,0 +1,169 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/Chat.java b/src/uk/ac/ntu/n0521366/wsyd/client/Chat.java new file mode 100644 index 0000000..55e699b --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/Chat.java @@ -0,0 +1,157 @@ +/* + * 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; + +/** + * + * @author Eddie Berrisford-Lynch + */ +public class Chat extends javax.swing.JDialog { + + /** + * Creates new form WSYD_Chat + */ + public Chat(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") + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + gPanelChatInstance = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + gListChatWindow = new javax.swing.JList(); + jPanel2 = new javax.swing.JPanel(); + gButtonAttach = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + gTAreaMessage = new javax.swing.JTextArea(); + gButtonSend = new javax.swing.JButton(); + gTPanelNewChat = new javax.swing.JTabbedPane(); + + gPanelChatInstance.setMinimumSize(new java.awt.Dimension(450, 350)); + gPanelChatInstance.setPreferredSize(new java.awt.Dimension(450, 350)); + gPanelChatInstance.setLayout(new java.awt.BorderLayout()); + + gListChatWindow.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N + gListChatWindow.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + gListChatWindow.setPreferredSize(new java.awt.Dimension(300, 180)); + gListChatWindow.setVisibleRowCount(20); + jScrollPane1.setViewportView(gListChatWindow); + + gPanelChatInstance.add(jScrollPane1, java.awt.BorderLayout.CENTER); + + jPanel2.setPreferredSize(new java.awt.Dimension(450, 70)); + jPanel2.setLayout(new java.awt.GridBagLayout()); + + gButtonAttach.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N + gButtonAttach.setText("Attach"); + gButtonAttach.setPreferredSize(new java.awt.Dimension(94, 50)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; + jPanel2.add(gButtonAttach, gridBagConstraints); + + jScrollPane2.setMinimumSize(new java.awt.Dimension(256, 100)); + + gTAreaMessage.setColumns(20); + gTAreaMessage.setRows(6); + jScrollPane2.setViewportView(gTAreaMessage); + + jPanel2.add(jScrollPane2, new java.awt.GridBagConstraints()); + + gButtonSend.setText("Send"); + gButtonSend.setPreferredSize(new java.awt.Dimension(94, 50)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; + jPanel2.add(gButtonSend, gridBagConstraints); + + gPanelChatInstance.add(jPanel2, java.awt.BorderLayout.PAGE_END); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + gTPanelNewChat.setMinimumSize(new java.awt.Dimension(450, 350)); + gTPanelNewChat.setPreferredSize(new java.awt.Dimension(500, 400)); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(gTPanelNewChat, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(gTPanelNewChat, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* 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(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Chat dialog = new Chat(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 gButtonAttach; + private javax.swing.JButton gButtonSend; + private javax.swing.JList gListChatWindow; + private javax.swing.JPanel gPanelChatInstance; + private javax.swing.JTextArea gTAreaMessage; + private javax.swing.JTabbedPane gTPanelNewChat; + private javax.swing.JPanel jPanel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.form b/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.form new file mode 100644 index 0000000..288b398 --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.form @@ -0,0 +1,424 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000..06daa9c --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.java @@ -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 _members; + + /** + * userIDs of members currently logged in + */ + ArrayList _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") + // //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(); + }// //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 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 */ + // + /* 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); + } + // + // + // + // + + /* 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())); + } +} diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.form b/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.form new file mode 100644 index 0000000..c822c42 --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.form @@ -0,0 +1,1440 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000..de8b655 --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.java @@ -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") + // //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(); + }// //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 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 */ + // + /* 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); + } + // + // + + /* 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 +} diff --git a/src/uk/ac/ntu/n0521366/wsyd/client/Login.form b/src/uk/ac/ntu/n0521366/wsyd/client/Login.form new file mode 100644 index 0000000..055281a --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/Login.form @@ -0,0 +1,740 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
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 index 0000000..db417c1 --- /dev/null +++ b/src/uk/ac/ntu/n0521366/wsyd/client/Login.java @@ -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") + // //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(); + }// //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 */ + // + /* 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); + } + // + // + + /* 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 +} -- 2.17.1