annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.desc=Social Networking and Chat client and server
application.title=WSYD
-application.vendor=TJ <hacker@iam.tj>
+application.vendor=Eddie Berrisford-Lynch <dev@fun2be.me>
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
-main.class=
+main.class=uk.ac.ntu.n0521366.wsyd.Launcher
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
--- /dev/null
+/*
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package uk.ac.ntu.n0521366.wsyd;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import uk.ac.ntu.n0521366.wsyd.server.ServerSocial;
+import uk.ac.ntu.n0521366.wsyd.management.ServerManagement;
+import uk.ac.ntu.n0521366.wsyd.client.ClientGUI;
+
+/**
+ *
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
+ */
+public class Launcher {
+
+ static class App implements Runnable {
+
+ private final Class<?> _classRef;
+ private final String[] _args;
+
+ public App(Class<?> classRef, String[] args) {
+ _classRef = classRef;
+ _args = args;
+ }
+
+ @Override
+ public void run() {
+ try {
+ ClassLoader cl = _classRef.getClassLoader();
+ try {
+ Object o = cl.loadClass(_classRef.getName()).newInstance();
+ Class<?> newClass = o.getClass();
+ Method m = newClass.getMethod("main", String[].class);
+ m.invoke(null, (Object) this._args);
+ } catch (ClassNotFoundException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ } catch (NoSuchMethodException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (SecurityException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IllegalArgumentException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InvocationTargetException ex) {
+ Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ }
+ }
+ static ArrayList<App> apps;
+
+ public static void main(String[] args) {
+
+ apps = new ArrayList<>();
+
+ apps.add(new App( ServerSocial.class, args));
+ apps.add(new App(ServerManagement.class, args));
+ for (int qty = 1; qty <= 1; qty++) {
+ apps.add(new App(ClientGUI.class, args));
+ }
+
+ for (App app: apps) {
+ System.out.println("Starting app " + app._classRef.getTypeName());
+ new Thread(app).start();
+ }
+ }
+
+}
/*
- * 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.
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
*/
package uk.ac.ntu.n0521366.wsyd.client;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.SortedMap;
import javax.swing.JDialog;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JProgressBar;
+import javax.swing.ProgressMonitor;
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.message.MessageMember;
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;
private boolean loginSuccessful = false;
- private boolean regiSuccessful = false;
+ private boolean registrationSuccessful = false;
+
+ private final Login loginDialog = new Login(this, true);
+ private final EditProfile registrationDialog = new EditProfile(this, true);
- private Login login = new Login(this, true);
+ /**
+ * Member record for this client's user.
+ */
+ private WSYD_Member myMember;
Socket socialSocket;
/**
* Readable/displayable name of this application
*
- * Will be assigned userID when SocialServer connection established
+ * TODO: title should be assigned userID when SocialServer connection established
*/
- private String _title = null;
+ private String _title = null;
/**
* Network services to address map.
}
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")) {
- }
+ /* FIXME: progress monitor
+ ProgressMonitor pm = new ProgressMonitor(this, "Waiting for the Server...", "", 0, 10);
+ pm.setMillisToPopup(100);
+ pm.setProgress(1);
+ */
+ while (!_serviceToAddressMap.containsService("ServerSocialMC"));
+
+ // pm.setProgress(10);
try {
socialSocket = new Socket(_serviceToAddressMap.getServiceAddress("ServerSocialMC").getAddress(), Network.PORTS_SERVER_SOCIAL);
NetworkStream newStream = new NetworkStream(socialSocket, _tcpStreamManager);
_tcpStreamManager.addStream(NetworkStreamManager.SERVERSOCIAL, newStream);
+ newStream.getEventManager().addNetworkMessageEventListener(this);
} 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);
+ //WSYD_Login loginDialog = new Login(this, true);
+ loginDialog.setLocationRelativeTo(null);
+ loginDialog.setVisible(true);
if (loginSuccessful)
{
this.setLocationRelativeTo(null);
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;
+ NetworkStream ns = _tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL);
+ if (ns != null) {
+ ns.write(message);
+ result = true;
+ }
+ else
+ System.err.println(" validateLogin(): do not know where ServerSocial is");
}
return result;
}
- public void regiProfileDialog()
+ public void registrationProfileDialog()
{
- EditProfile registration = new EditProfile(this, true);
- registration.setLocationRelativeTo(null);
- registration.setVisible(true);
- if (regiSuccessful)
- {
- login.dispose();
- this.setLocationRelativeTo(null);
- this.setVisible(true);
- }
+ registrationDialog.setLocationRelativeTo(null);
+ registrationDialog.setVisible(true);
}
- public boolean confirmRegistration(String uName, String pWord, String bPlace, String cLocation, TreeSet interests, String bio)
+ public void confirmRegistration(WSYD_Member registrationData)
{
- 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;
+ // TODO: confirmRegistration(): submit registrationDialog data to SocialServer
+ if (registrationData != null) {
+ NetworkMessage message = new NetworkMessage("Register", null, new MessageMember(registrationData));
+ NetworkStream ns = this._tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL);
+ if (ns != null) {
+ ns.write(message);
+ }
+ else
+ System.err.println("confirmRegistration(): do not know where SocialServer is");
+ }
}
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()));
+ switch (nm.getIntent()) {
+ case "Login":
+ MessageLogin ml = (MessageLogin) nm.getMessage();
+ if (ml != null) {
+ this.loginSuccessful = ml._loggedIn;
+ if (ml._loggedIn)
+ this.loginDialog.dispose();
+ else
+ loginDialog.setUserName("Invalid Login: retry");
+ }
+ break;
+ case "Register":
+ MessageMember mm = (MessageMember) nm.getMessage();
+ if (mm != null) {
+ if (mm.getRegistered() == MessageMember.STATE.REGISTERED) {
+ this.myMember = mm.getMember();
+ this.registrationSuccessful = true;
+ // dismiss the dialogs and show client's main window
+ registrationDialog.dispose();
+ loginDialog.dispose();
+ this.setTitle("WSYD logged in as " + this.myMember._userName);
+ this.setLocationRelativeTo(null);
+ this.setVisible(true);
+ } else
+ javax.swing.JOptionPane.showMessageDialog(registrationDialog, mm.getStatus(), "Registration failed", javax.swing.JOptionPane.ERROR_MESSAGE);
+ }
+ break;
+ default:
+ System.err.println(MessageFormat.format("Unhandled NetworkMessage received with intent {0} from sender {1}", nm.getIntent(), nm.getSender()));
+
+ }
}
}
<SubComponents>
<Component class="javax.swing.JLabel" name="gLabelUsername">
<Properties>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gFieldUsername"/>
+ </Property>
<Property name="text" type="java.lang.String" value="Username:"/>
</Properties>
<Constraints>
</Component>
<Component class="javax.swing.JLabel" name="gLabelPassword">
<Properties>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gPFieldPassword"/>
+ </Property>
<Property name="text" type="java.lang.String" value="Password:"/>
</Properties>
<Constraints>
</Component>
<Component class="javax.swing.JLabel" name="gLabelPConfirmation">
<Properties>
- <Property name="text" type="java.lang.String" value="Confirm:"/>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gPFieldPConfirmation"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Password:"/>
+ <Property name="toolTipText" type="java.lang.String" value="Repeat password"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
</Constraint>
</Constraints>
</Component>
- <Component class="javax.swing.JLabel" name="gLabelBirthplace">
+ <Component class="javax.swing.JLabel" name="gLabelBirthDate">
<Properties>
- <Property name="text" type="java.lang.String" value="Birthplace:"/>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gFieldBirthDate"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Birth Date:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
</Constraint>
</Constraints>
</Component>
- <Component class="javax.swing.JTextField" name="gFieldBirthplace">
+ <Component class="javax.swing.JTextField" name="gFieldBirthDate">
<Properties>
+ <Property name="text" type="java.lang.String" value="YYYY-mm-dd"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 25]"/>
</Property>
</Property>
</Properties>
<Events>
- <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="gFieldBirthplaceActionPerformed"/>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="gFieldBirthDateActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
</Component>
<Component class="javax.swing.JLabel" name="gLabelCurrLocation">
<Properties>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gLabelCurrLocation"/>
+ </Property>
<Property name="text" type="java.lang.String" value="Current City/Town:"/>
</Properties>
<Constraints>
</Component>
<Component class="javax.swing.JLabel" name="gLabelInterests">
<Properties>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gListInterests"/>
+ </Property>
<Property name="text" type="java.lang.String" value="Interests:"/>
</Properties>
<Constraints>
<SubComponents>
<Component class="javax.swing.JList" name="gListInterests">
<Properties>
- <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
- <StringArray count="8">
- <StringItem index="0" value="Item1"/>
- <StringItem index="1" value="Item2"/>
- <StringItem index="2" value="Item3"/>
- <StringItem index="3" value="Item4"/>
- <StringItem index="4" value="Item5"/>
- <StringItem index="5" value="Item6"/>
- <StringItem index="6" value="Item7"/>
- <StringItem index="7" value="Item8"/>
- </StringArray>
+ <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+ <Connection code="getInterestsListModel()" type="code"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Select the interests you have, they will be displayed (Hold CTRL + Click)"/>
</Properties>
</Container>
<Component class="javax.swing.JLabel" name="gLabelBio">
<Properties>
- <Property name="text" type="java.lang.String" value="Bio:"/>
+ <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+ <ComponentRef name="gTAreaBio"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Biography:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
</StatementProvider>
<Parameters>
- <CodeExpression id="51_gLabelBirthplace">
- <CodeVariable name="gLabelBirthplace" type="8194" declaredType="javax.swing.JLabel"/>
+ <CodeExpression id="51_gLabelBirthDate">
+ <CodeVariable name="gLabelBirthDate" type="8194" declaredType="javax.swing.JLabel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
- <ComponentRef name="gLabelBirthplace"/>
+ <ComponentRef name="gLabelBirthDate"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
</StatementProvider>
<Parameters>
- <CodeExpression id="55_gFieldBirthplace">
- <CodeVariable name="gFieldBirthplace" type="8194" declaredType="javax.swing.JTextField"/>
+ <CodeExpression id="55_gFieldBirthDate">
+ <CodeVariable name="gFieldBirthDate" type="8194" declaredType="javax.swing.JTextField"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
- <ComponentRef name="gFieldBirthplace"/>
+ <ComponentRef name="gFieldBirthDate"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
+/*
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package uk.ac.ntu.n0521366.wsyd.client;
+import java.awt.Color;
+import java.lang.reflect.Array;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.TreeSet;
+import javax.swing.DefaultListModel;
+import javax.swing.JOptionPane;
+import javax.swing.ListModel;
+import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
initComponents();
}
+ /**
+ * Populate a model with the applications pre-defined interests.
+ *
+ * @return the model
+ */
+ DefaultListModel getInterestsListModel() {
+ DefaultListModel<String> m = new DefaultListModel<>();
+ for (String i : WSYD_Member.Interests)
+ m.addElement(i);
+ System.err.println(m.toString());
+ return m;
+ }
/**
* 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
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();
+ gLabelBirthDate = new javax.swing.JLabel();
+ gFieldBirthDate = new javax.swing.JTextField();
gLabelCurrLocation = new javax.swing.JLabel();
gFieldCurrLocation = new javax.swing.JTextField();
gLabelInterests = new javax.swing.JLabel();
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.setLabelFor(gFieldUsername);
gLabelUsername.setText("Username:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
getContentPane().add(gButtonConfirmation, gridBagConstraints);
+ gLabelPassword.setLabelFor(gPFieldPassword);
gLabelPassword.setText("Password:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
getContentPane().add(gPFieldPassword, gridBagConstraints);
- gLabelPConfirmation.setText("Confirm:");
+ gLabelPConfirmation.setLabelFor(gPFieldPConfirmation);
+ gLabelPConfirmation.setText("Password:");
+ gLabelPConfirmation.setToolTipText("Repeat password");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
getContentPane().add(gLabelPWarning, gridBagConstraints);
- gLabelBirthplace.setText("Birthplace:");
+ gLabelBirthDate.setLabelFor(gFieldBirthDate);
+ gLabelBirthDate.setText("Birth Date:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
- getContentPane().add(gLabelBirthplace, gridBagConstraints);
+ getContentPane().add(gLabelBirthDate, gridBagConstraints);
- gFieldBirthplace.setMinimumSize(new java.awt.Dimension(100, 25));
- gFieldBirthplace.setPreferredSize(new java.awt.Dimension(200, 25));
- gFieldBirthplace.addActionListener(new java.awt.event.ActionListener() {
+ gFieldBirthDate.setText("YYYY-mm-dd");
+ gFieldBirthDate.setMinimumSize(new java.awt.Dimension(100, 25));
+ gFieldBirthDate.setPreferredSize(new java.awt.Dimension(200, 25));
+ gFieldBirthDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
- gFieldBirthplaceActionPerformed(evt);
+ gFieldBirthDateActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 6;
- getContentPane().add(gFieldBirthplace, gridBagConstraints);
+ getContentPane().add(gFieldBirthDate, gridBagConstraints);
+ gLabelCurrLocation.setLabelFor(gLabelCurrLocation);
gLabelCurrLocation.setText("Current City/Town:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 8;
getContentPane().add(gFieldCurrLocation, gridBagConstraints);
+ gLabelInterests.setLabelFor(gListInterests);
gLabelInterests.setText("Interests:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
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.setModel(getInterestsListModel());
gListInterests.setToolTipText("Select the interests you have, they will be displayed (Hold CTRL + Click)");
jScrollPane1.setViewportView(gListInterests);
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
getContentPane().add(jScrollPane1, gridBagConstraints);
- gLabelBio.setText("Bio:");
+ gLabelBio.setLabelFor(gTAreaBio);
+ gLabelBio.setText("Biography:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 12;
pack();
}// </editor-fold>//GEN-END:initComponents
- private void gFieldBirthplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthplaceActionPerformed
+ private void gFieldBirthDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthDateActionPerformed
// TODO add your handling code here:
- }//GEN-LAST:event_gFieldBirthplaceActionPerformed
+ }//GEN-LAST:event_gFieldBirthDateActionPerformed
+ /**
+ * Verify the user-entered data before attempting to submit it to SocialServer.
+ *
+ * Provides error feedback to the user in the form of a message dialog with a list of problems
+ * and sets the colour of field data to red if an error was found, or green otherwise.
+ *
+ * @param evt
+ */
private void gButtonConfirmationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonConfirmationMouseClicked
// TODO add your handling code here:
+ boolean dataGood = true; // assume user input is OK until errors found
+ ArrayList<String> errorMessages = new ArrayList<>();
+
+ String birthdateFormat = "YYYY-mm-dd";
+ SimpleDateFormat sd = new SimpleDateFormat(birthdateFormat);
+
+ WSYD_Member m = new WSYD_Member();
+
+ m._userName = this.gFieldUsername.getText();
+ if (m._userName.length() == 0) {
+ this.gFieldUsername.setForeground(Color.red);
+ errorMessages.add("Username cannot be empty");
+ }
+ else
+ this.gFieldUsername.setForeground(Color.green);
+
+ if (Array.getLength(this.gPFieldPassword.getPassword()) == 0 || Array.getLength(this.gPFieldPConfirmation.getPassword()) == 0) {
+ dataGood = false;
+ this.gPFieldPassword.setForeground(Color.red);
+ this.gPFieldPConfirmation.setForeground(Color.red);
+ errorMessages.add("Password cannot be empty");
+ } else if (!Arrays.equals(this.gPFieldPassword.getPassword(), this.gPFieldPConfirmation.getPassword())) {
+ dataGood = false;
+ this.gPFieldPassword.setForeground(Color.red);
+ this.gPFieldPConfirmation.setForeground(Color.red);
+ errorMessages.add("Passwords do not match");
+ } else {
+ this.gPFieldPassword.setForeground(Color.green);
+ this.gPFieldPConfirmation.setForeground(Color.green);
+ m._password = new String(this.gPFieldPassword.getPassword());
+ }
+
+ try {
+ m._birthDate = sd.parse(this.gFieldBirthDate.getText());
+ this.gFieldBirthDate.setForeground(Color.green);
+ } catch(java.text.ParseException e) {
+ dataGood = false;
+ this.gFieldBirthDate.setForeground(Color.red);
+ errorMessages.add("Birth Date format is " + birthdateFormat);
+ }
+
+ m._bio = this.gTAreaBio.getText();
+ m._currentLocation = this.gFieldCurrLocation.getText();
+
+ java.util.List<?> selectedInterests = this.gListInterests.getSelectedValuesList();
+ if (selectedInterests.isEmpty()) {
+ dataGood = false;
+ this.gListInterests.setForeground(Color.red);
+ errorMessages.add("Must select at least 1 interest");
+ } else
+ this.gListInterests.setForeground(Color.green);
+
+ m._interests = new TreeSet<>();
+ m._interests.addAll(this.gListInterests.getSelectedValuesList());
+ if (!dataGood) {
+ DefaultListModel<String> errorModel = new DefaultListModel<>();
+ for (String s: errorMessages)
+ errorModel.addElement(s);
+ javax.swing.JList errorList = new javax.swing.JList();
+ errorList.setModel(errorModel);
+ JOptionPane.showMessageDialog(this, errorList, "Errors in Registration details", JOptionPane.ERROR_MESSAGE);
+ }
+ else {
+ // trigger sending of the data to SocialServer
+ ((ClientGUI)this.getOwner()).confirmRegistration(m);
+ }
+ // FIXME: gButtonConfirmationMouseClicked(): remove superceded code that has been commented out
+ /*
TreeSet<String> interests = null;
- /*
+
for (int i = 0; i < gListInterests.getModel().getSize(); i++)
{
interests.add(((String)gListInterests.getModel().getElementAt(i)));
- }*/
+ }
if (((ClientGUI)this.getOwner()).confirmRegistration(gFieldUsername.getText(),
new String(gPFieldPassword.getPassword()),
- gFieldBirthplace.getText(),
+ gFieldBirthDate.getText(),
gFieldCurrLocation.getText(),
interests,
gTAreaBio.getText())) this.dispose();
else gLabelPWarning.setText("Server failed to register. Retry.");
+ */
}//GEN-LAST:event_gButtonConfirmationMouseClicked
/**
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton gButtonConfirmation;
- private javax.swing.JTextField gFieldBirthplace;
+ private javax.swing.JTextField gFieldBirthDate;
private javax.swing.JTextField gFieldCurrLocation;
private javax.swing.JTextField gFieldUsername;
private javax.swing.JLabel gLabelBio;
- private javax.swing.JLabel gLabelBirthplace;
+ private javax.swing.JLabel gLabelBirthDate;
private javax.swing.JLabel gLabelCurrLocation;
private javax.swing.JLabel gLabelInterests;
private javax.swing.JLabel gLabelPConfirmation;
/*
- * 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.
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
*/
package uk.ac.ntu.n0521366.wsyd.client;
public Login(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
+ this.getRootPane().setDefaultButton(gButtonLogin);
+
+ }
+ public void setUserName(String newName) {
+ if (newName != null)
+ gFieldName.setText(newName);
}
-
/**
* 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
// TODO add your handling code here:
}//GEN-LAST:event_gFieldPasswordActionPerformed
+ /**
+ * Send the Username Password pair to the server to be validated.
+ *
+ * @param evt
+ */
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...");
+ ((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()));
}//GEN-LAST:event_gButtonLoginMouseClicked
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
private void gButtonRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonRegisterMouseClicked
// TODO add your handling code here:
- ((ClientGUI)this.getOwner()).regiProfileDialog();
+ ((ClientGUI)this.getOwner()).registrationProfileDialog();
}//GEN-LAST:event_gButtonRegisterMouseClicked
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.TreeSet;
* WSYD_Member_Comparator_UserID supports sorted Maps with userID as the sort key
* WSYD_Member_Comparator_UserName supports sorted Sets and Collections with userName as the sort key
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_Member implements java.io.Serializable, java.lang.Comparable<WSYD_Member> {
+
+ /**
+ * Choices for _interests
+ */
+ public static String[] Interests = {"Computers","Driving","DIY","Gardening","Games","Gym","Music","Reading" };
+
public long _userID;
public String _userName;
public String _password;
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* Implements serializable in order that the Collection using it doesn't cause
* deserialize Exceptions due to missing Comparator
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_Member_Comparator_UserID implements Comparator<Long>, Serializable {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* Implements serializable in order that the Collection using it doesn't cause
* deserialize Exceptions due to missing Comparator
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_Member_Comparator_UserName implements Comparator<WSYD_Member>, Serializable {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
*
* @see java.util.logging.Handler
* @see uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class PacketHandler extends Handler {
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* @see javax.swing.JScrollPane
* @see javax.swing.JTable
* @see javax.swing.table.DefaultTableModel
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class TableModelHandler extends Handler {
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/**
* Base class of all Message types.
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public abstract class MessageAbstract implements Serializable {
/**
* @return E.g. "LogRecord", "FriendOnline", "ChatRequest"
*/
public abstract String getMessageType();
-
- /**
- * IP address of the sending host.
- *
- * This should be set by the <em>receiving service</em> using the value obtained from
- * the packet or connection the message arrived in.
- *
- * FIXME: sourceAddress: is this really needed? the message encapsulated in a NetworkMessage already
- */
- public InetAddress sourceAddress;
-
- public MessageAbstract() {
- sourceAddress = null;
- }
+
}
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* A specialised message containing a LogRecord
*
* @see java.util.logging.LogRecord
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class MessageLogRecord extends MessageAbstract {
private static final String _type = "LogRecord";
*/
package uk.ac.ntu.n0521366.wsyd.libs.message;
+import java.io.Serializable;
+
/**
* Message used to authenticate a login with the SocialServer.
*
* @author eddie
*/
-public class MessageLogin extends MessageAbstract {
+public class MessageLogin extends MessageAbstract implements Serializable {
+ /**
+ * Message type.
+ */
private static final String _type = "Login";
+ /**
+ * A Username.
+ */
public final String _uName;
+ /**
+ * A password.
+ */
public final String _uPass;
+ /**
+ * After login the user's ID.
+ */
public long _userID = 0;
+ /**
+ * Result of a login request.
+ */
public boolean _loggedIn = false;
+ /**
+ * Make the Message printable.
+ *
+ * @return human readable text
+ */
+ public String toString() {
+ return new String("_uName:" + _uName +
+ ",_uPass:" + _uPass +
+ ",_userID:" + _userID +
+ ",_loggedIn:" + _loggedIn
+ );
+ }
+
+ /**
+ * The Message Class type.
+ *
+ * @return Message type
+ */
public static String getType() {
return _type;
}
this._uPass = null;
}
+ /**
+ * Construct with a Username Password pair.
+ *
+ * @param uName Username
+ * @param uPass Password
+ */
public MessageLogin (String uName, String uPass) {
this._uName = uName;
this._uPass = uPass;
- }
-
+ }
}
--- /dev/null
+/*
+ * The MIT License
+ *
+ * Copyright 2015 TJ <hacker@iam.tj>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package uk.ac.ntu.n0521366.wsyd.libs.message;
+
+import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
+
+/**
+ * A specialised message containing a WSYD_Member.
+ *
+ * @author TJ <hacker@iam.tj>
+ */
+public class MessageMember extends MessageAbstract {
+
+ public static enum STATE {UNREGISTERED, REGISTERED};
+ private static final String _type = "WSYD_Member";
+
+ private WSYD_Member _member;
+ private STATE _registered;
+ private String _status;
+
+ public static String getType() {
+ return _type;
+ }
+
+ @Override
+ public String getMessageType() {
+ return _type;
+ }
+
+ public MessageMember(WSYD_Member member, STATE registered, String status) {
+ _member = member;
+ _registered = registered;
+ _status = status;
+ }
+
+ public MessageMember(WSYD_Member member) {
+ this(member, STATE.UNREGISTERED, null);
+ }
+
+ public MessageMember() {
+ this(null, STATE.UNREGISTERED, null);
+ }
+
+ /**
+ * Get the Member contained in this message.
+ *
+ * @return
+ */
+ public WSYD_Member getMember() {
+ return _member;
+ }
+
+ /**
+ * Current registration state of the member record contained in this message.
+ *
+ * @return
+ */
+ public STATE getRegistered() {
+ return _registered;
+ }
+
+ /**
+ * Update the registration state of the member record contained in this message.
+ *
+ * @param registered
+ */
+ public void setRegistered(STATE registered) {
+ _registered = registered;
+ }
+
+ /**
+ * Get registration status message.
+ *
+ * @return
+ */
+ public String getStatus() {
+ return _status;
+ }
+
+ /**
+ * Set registration status message.
+ *
+ * ServerSocial may set this with text describing why a registration failed.
+ * @param status
+ */
+ public void setStatus(String status) {
+ _status = status;
+ }
+}
\ No newline at end of file
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class MessagePresence extends MessageAbstract {
private static final String _type = "Presence";
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class Network {
public static final int PORTS_SERVER_SOCIAL = 50000;
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* Wraps an object and intent label together for passing over a network.
*
* @see NetworkMessageEvent
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class NetworkMessage implements Serializable, Cloneable {
/**
*/
long _key;
- Class<?> _class;
+ // Class<?> _class;
MessageAbstract _message;
/**
_intent = null;
_serviceSender = null;
_serviceTarget = null;
- _class = null;
+ // _class = null;
_message = null;
}
+ /**
+ * Make the NetworkMessage printable.
+ *
+ * @return human readable text
+ */
+ @Override
+ public String toString() {
+ return new String("_serializedLength:" + _serializeLength +
+ ",_intent:" + _intent +
+ ",_serviceSender:" + _serviceSender +
+ ",_serviceTarget:" + _serviceTarget +
+ ",_message:" + _message.toString()
+ );
+ }
/**
* Create a message for passing over the network.
*
_serviceSender = null;
_serviceTarget = target;
_message = message;
- _class = _message.getClass();
+ // _class = _message.getClass();
}
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj.
+ * Copyright 2015 Eddie Berrisfor-Lynch <dev@fun2be.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
*
* @see NetworkMessageEventGenerator
* @see NetworkMessageEventListener
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class NetworkMessageEvent extends EventObject {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* @see NetworkMessageEvent
* @see NetworkMessageEventListener
* @see NetworkMessageEventListenerManager
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public interface NetworkMessageEventGenerator {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* @see NetworkMessage
* @see NetworkMessageEvent
* @see NetworkMessageEventGenerator
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public interface NetworkMessageEventListener {
public void NetworkMessageReceived(NetworkMessageEvent event);
public synchronized void fireNetworkMessageEvent(NetworkMessage message) {
NetworkMessageEvent event = new NetworkMessageEvent(this, message);
for (NetworkMessageEventListenerWithIntent intentListener : _NetworkMessageEventListeners) {
- if (intentListener._intent.equals(message._intent) || intentListener._intent == null)
+ System.err.println("fireNetworkMessageEvent() intent: " + intentListener._intent);
+ if (intentListener._intent == null || (intentListener._intent != null && intentListener._intent.equals(message._intent)))
intentListener._listener.NetworkMessageReceived(event);
}
}
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
*
* @see javax.swing.SwingWorker
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public abstract class NetworkServerAbstract extends SwingWorker<Integer, NetworkMessage> {
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* or in a Swing GUI application as a background worker thread.
*
* @see NetworkServerAbstract
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class NetworkServerTCP extends NetworkServerAbstract {
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* or in a Swing GUI application as a background worker thread.
*
* @see NetworkServerAbstract
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class NetworkServerUDP extends NetworkServerAbstract {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class NetworkServerUDPMulticast extends NetworkServerUDP {
boolean expectingLong = true;
while (!this.isCancelled()) {
-
// check for incoming message
+ if (_socketIS.available() > 0) {
+ System.err.println(" reading Object from stream, bytes available: " + _socketIS.available());
+ read();
+ }
+ /*
if (_ois.available() >= expectedLength) {
if (expectingLong == true) {
expectedLength = _ois.readLong();
expectingLong = true;
}
}
+ */
// send a queued message
NetworkMessage temp = this.sendMessage();
if (temp != null) {
try {
_oos.writeObject(message);
_oos.flush();
- long messageSize = _baos.size();
- _socketOS.writeLong(messageSize);
- System.err.println(" bytes to write: " + messageSize);
- _baos.writeTo(_socketOS);
+ Long messageSize = new Long(_baos.size());
+ _socketOS.writeObject(message);
_socketOS.flush();
- System.err.println("baos.size()=" + _baos.size());
+ System.err.println(" bytes written: " + messageSize);
result = true;
try {
NetworkMessage message = null;
+ String s = null;
- try {
- message = (NetworkMessage)_ois.readObject();
- } catch (java.io.OptionalDataException ex) {
- System.err.println("Length: " + ex.length + " EOF: " + ex.eof);
- ex.printStackTrace();
- }
+ message = (NetworkMessage)_ois.readObject();
+ System.err.println(" received: " + message.toString());
message.setKey(_key);
publish(message);
result = true;
+ } catch (java.io.OptionalDataException ex) {
+ System.err.println("Length: " + ex.length + " EOF: " + ex.eof);
+ ex.printStackTrace();
} catch (IOException ex) {
Logger.getLogger(NetworkStream.class.getName()).log(Level.SEVERE, null, ex);
// FIXME: Replace logger
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iamtj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/**
* Maps service names on hosts to an InetAddress:Port pair.
*
- * @author TJ <hacker@iamtj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
+
*/
public class ServiceAddressMap {
/**
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
*
* Serializable to allow passing between separate local and remote processes
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_SocketAddress implements java.io.Serializable {
Boolean _multicast;
<Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
- <Property name="text" type="java.lang.String" value="Server Management client
© Copyright 2015 TJ <hacker@iam.tj>

<<< Click on the mug to learn more!

I will disappear in 20 seconds.

"/>
+ <Property name="text" type="java.lang.String" value="Server Management client
© Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>

<<< Click on the mug to learn more!

I will disappear in 20 seconds.

"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
import uk.ac.ntu.n0521366.wsyd.libs.net.ServiceAddressMap.LastSeenHost;
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class ServerManagement extends javax.swing.JFrame implements NetworkMessageEventListener, Filter {
/**
gTextAreaAbout.setEditable(false);
gTextAreaAbout.setColumns(20);
gTextAreaAbout.setRows(5);
- gTextAreaAbout.setText("Server Management client\n© Copyright 2015 TJ <hacker@iam.tj>\n\n<<< Click on the mug to learn more!\n\nI will disappear in 20 seconds.\n\n");
+ gTextAreaAbout.setText("Server Management client\n© Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>\n\n<<< Click on the mug to learn more!\n\nI will disappear in 20 seconds.\n\n");
gTextAreaAbout.setBorder(null);
gDialogAbout.getContentPane().add(gTextAreaAbout);
gTextAreaAbout.setBounds(310, 30, 270, 200);
/*
* The MIT License
*
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member_Comparator_UserID;
import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogin;
+import uk.ac.ntu.n0521366.wsyd.libs.message.MessageMember;
import uk.ac.ntu.n0521366.wsyd.libs.message.MessageMemberState;
import uk.ac.ntu.n0521366.wsyd.libs.message.MessagePresence;
import uk.ac.ntu.n0521366.wsyd.libs.message.MessageServerControl;
* exitRequested and restartRequested. This can be done by an optional
* Management GUI application.
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public final class ServerSocial implements NetworkMessageEventListener, ConnectionEstablishedEventListener {
/**
return result;
}
+ private void notifyMemberPrescence(long userID, boolean state) {
+ NetworkMessage message = new NetworkMessage("MemberNotification", null, new MessageMemberState(userID, state));
+ for (long ID : _membersOnline) {
+ _tcpStreamManager._tcpStreams.get(ID).write(message);
+ }
+ }
+
+ private void memberOnline (long userID) {
+ if (!_membersOnline.contains(userID)) {
+ notifyMemberPrescence(userID, true);
+ _membersOnline.add(userID);
+ }
+ }
+
+ private void memberOffline (long userID) {
+ if (_membersOnline.contains(userID)) {
+ _membersOnline.remove(userID);
+ notifyMemberPrescence(userID, false);
+ }
+ }
+
+ @Override
+ public void connectionEstablished(ConnectionEstablishedEvent event) {
+ System.err.println("connectionEstablished()");
+ event.getStream().getEventManager().addNetworkMessageEventListener(this);
+ }
+ /**
+ * Process received network messages.
+ *
+ * @param event the network message event
+ */
@Override
public void NetworkMessageReceived(NetworkMessageEvent event)
{
- System.err.println("NetworkMessage received");
- //TODO: NetworkMessageReceived: Handle Messages
NetworkMessage nm = event.getNetworkMessage();
if (nm == null)
return;
- //Exit or Restart?
- System.err.println("Packet Received for intent " + nm.getIntent());
+ System.err.println("NetworkMessage received for intent " + nm.getIntent());
String type = nm.getMessage().getMessageType();
switch (nm.getIntent()) {
- case "Control":
+ case "Control": // Exit or Restart?
if (type.equals(MessageServerControl.getType())) { // ServerControl
if ("ServerManagement".equals(nm.getSender())) {
MessageServerControl mp = (MessageServerControl)nm.getMessage();
break;
case "Login":
if (type.equals(MessageLogin.getType())) {
+ NetworkStream ns = _tcpStreamManager._tcpStreams.get(nm.getKey());
MessageLogin ml = (MessageLogin)nm.getMessage();
Set<Map.Entry<Long, WSYD_Member>> tempSet = _members.entrySet();
ml._loggedIn = true;
_tcpStreamManager.updateKey(nm.getKey(), element.getKey()); // replace temp key in stream manager
_membersOnline.add(element.getKey()); // make the member online
+ break;
+ }
+ }
+ if (ns != null)
+ ns.write(nm);
+ else
+ System.err.println("Login: cannot find stream for ID:" + nm.getKey());
+ }
+ case "Register":
+ if (type.equals(MessageMember.getType())) {
+ NetworkStream ns = _tcpStreamManager._tcpStreams.get(nm.getKey());
+ MessageMember mm = (MessageMember)nm.getMessage();
+ // assume username can be registered unless username found
+ mm.setRegistered(MessageMember.STATE.REGISTERED);
+
+ Set<Map.Entry<Long, WSYD_Member>> tempSet = _members.entrySet();
+ Iterator<Map.Entry<Long, WSYD_Member>> tempIter = tempSet.iterator();
+ while (tempIter.hasNext()) {
+ Map.Entry<Long, WSYD_Member> element = tempIter.next();
+ if (element.getValue()._userName.equals(mm.getMember()._userName)) {
+ mm.setRegistered(MessageMember.STATE.UNREGISTERED);
+ mm.setStatus("Member already registered: " + mm.getMember()._userName);
+ break;
}
}
- _tcpStreamManager._tcpStreams.get(nm.getKey()).write(nm);
+ // register the new member
+ if (mm.getRegistered() == MessageMember.STATE.REGISTERED) {
+ // get the next unallocated user ID
+ long newUserID = _members.lastKey().longValue() + 1;
+ _members.put(newUserID, mm.getMember());
+ // update the object so the ID can be returned to the client
+ mm.getMember()._userID = newUserID;
+ // update the on-disk membership data
+ writeMembers(_membersFile);
+ }
+ if (ns != null)
+ ns.write(nm);
+ else
+ System.err.println("Login: cannot find stream for ID:" + nm.getKey());
+
}
+ break;
+ default:
+ System.err.println("Unhandled NetworkMessage received for intent " + nm.getIntent());
}
}
- private void notifyMemberPrescence(long userID, boolean state) {
- NetworkMessage message = new NetworkMessage("MemberNotification", null, new MessageMemberState(userID, state));
- for (long ID : _membersOnline) {
- _tcpStreamManager._tcpStreams.get(ID).write(message);
- }
- }
-
- private void memberOnline (long userID) {
- if (!_membersOnline.contains(userID)) {
- notifyMemberPrescence(userID, true);
- _membersOnline.add(userID);
- }
- }
-
- private void memberOffline (long userID) {
- if (_membersOnline.contains(userID)) {
- _membersOnline.remove(userID);
- notifyMemberPrescence(userID, false);
- }
- }
/**
* Entry point which starts, restarts, and exits the application.
}
}
}
-
- @Override
- public void connectionEstablished(ConnectionEstablishedEvent event) {
- System.err.println("connectionEstablished()");
- event.getStream().getEventManager().addNetworkMessageEventListener(this);
- }
}
-
-
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_MemberTest {
public WSYD_Member instance;
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_Member_Comparator_UserIDTest {
WSYD_Member_Comparator_UserID instance;
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_Member_Comparator_UserNameTest {
WSYD_Member_Comparator_UserName instance;
/**
*
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
*/
public class WSYD_SocketAddressTest {