diff --git a/src/GUI/ChatScreen.form b/src/GUI/ChatScreen.form
index 7ff8dffbe24b88abe437e256e76198ea323b9a90..9d8893e963fd7589e8246cf21b7735b63c75c9e6 100644
--- a/src/GUI/ChatScreen.form
+++ b/src/GUI/ChatScreen.form
@@ -8,7 +8,7 @@
<properties>
<maximumSize width="-1" height="-1"/>
<minimumSize width="-1" height="-1"/>
- <preferredSize width="1200" height="700"/>
+ <preferredSize width="1200" height="600"/>
</properties>
<border type="none"/>
<children>
@@ -185,7 +185,7 @@
<text value="Send Message To:"/>
</properties>
</component>
- <component id="cc35d" class="javax.swing.JComboBox" binding="sentMessageToComboBox">
+ <component id="cc35d" class="javax.swing.JComboBox" binding="sendMessageToComboBox">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java
index 987974f39199f5665b53d606cde6658e9228edcf..e786ca18065ea79e944442d121d84a902ba664cf 100644
--- a/src/GUI/ChatScreen.java
+++ b/src/GUI/ChatScreen.java
@@ -15,7 +15,7 @@ public class ChatScreen {
private JButton sendButton;
private JPanel drawingPanel;
private JPanel othersPanel;
- private JComboBox sentMessageToComboBox;
+ private JComboBox sendMessageToComboBox;
private JTextArea chatDisplayBox;
private JComboBox userSelectComboBox;
private JButton kickOutButton;
@@ -50,6 +50,8 @@ public class ChatScreen {
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
+
+ SwingUtilities.getRootPane(sendButton).setDefaultButton(sendButton);
}
private void createUIComponents() {
@@ -60,8 +62,9 @@ public class ChatScreen {
return chatDisplayBox;
}
- public JComboBox getSentMessageToComboBox() {
- return sentMessageToComboBox;
+ public JComboBox getSendMessageToComboBox()
+ {
+ return sendMessageToComboBox;
}
public JPanel getDrawingPanel() {
@@ -80,7 +83,17 @@ public class ChatScreen {
try
{
System.out.println("Send button pressed");
- chatController.broadcastMessage(client.getUserName(), message);
+
+ String toUser = sendMessageToComboBox.getSelectedItem().toString();
+
+ if( toUser.equals("All") )
+ {
+ chatController.broadcastMessage(client.getUserName(), message);
+ }
+ else
+ {
+ chatController.sendPrivateMessage(client.getUserName(), toUser, message);
+ }
}
catch (RemoteException ex)
{
diff --git a/src/client/ChatUpdate.java b/src/client/ChatUpdate.java
index 986f6a70224f04c9516b4c0813cd90305cf79f4b..ea4baf8749f7885125bb1027a2f2b6263cfdfff3 100644
--- a/src/client/ChatUpdate.java
+++ b/src/client/ChatUpdate.java
@@ -17,12 +17,23 @@ public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Seri
}
@Override
- public boolean notifyChat(String fromClient, String message) throws RemoteException
+ public boolean notifyChat(String fromClient, String message, boolean isPrivate) throws RemoteException
{
- client.getChatScreen().getChatDisplayBox().append(fromClient + ": " + message + "\n");
+ String outputString;
+
+ if( isPrivate )
+ {
+ outputString = "PRIVATE (from " + fromClient + "): " + message + "\n";
+ }
+ else
+ {
+ outputString = fromClient + ": " + message + "\n";
+ }
+
+ client.getChatScreen().getChatDisplayBox().append(outputString);
//client.setReceivedMessage(message);
- System.out.println(fromClient + ": " + message);
+ //System.out.println(fromClient + ": " + message);
return true;
}
diff --git a/src/client/Client.java b/src/client/Client.java
index 592b566b80efe3215d31915b4e0ece0bac29fc65..b5c34ee2fb7f85c513dac93d4208a17c0d12623a 100644
--- a/src/client/Client.java
+++ b/src/client/Client.java
@@ -13,26 +13,32 @@ import java.rmi.registry.Registry;
public class Client
{
- //test
private String userName;
private String serverAddress;
private Registry registryServer;
private IChatController chatController;
private IClientController clientController;
+
private IDrawingController drawingController;
private ClientUpdate clientUpdate;
+
private ChatUpdate chatUpdate;
private DrawingUpdate drawingUpdate;
-
private StartScreen startScreen;
+
private ChatScreen chatScreen;
-// private PaintGUI paintGUI;
+ private PaintGUI paintGUI;
-// public PaintGUI getPaintGUI() {
-// return paintGUI;
-// }
+ private String receivedMessage;
+
+ private String[] connectedUsers;
+
+
+ public PaintGUI getPaintGUI() {
+ return paintGUI;
+ }
public ChatScreen getChatScreen()
@@ -40,10 +46,12 @@ public class Client
return chatScreen;
}
+ public void setConnectedUsers(String[] users)
+ {
+ this.connectedUsers = users;
+ }
- private String receivedMessage;
-
public IChatController getChatController()
{
return chatController;
@@ -79,7 +87,7 @@ public class Client
this.drawingUpdate = new DrawingUpdate(this);
this.startScreen = new StartScreen(this);
this.chatScreen = new ChatScreen(this);
-// this.paintGUI = new PaintGUI(this);
+ this.paintGUI = new PaintGUI(this);
}
public static void main(String[] args)
@@ -97,6 +105,22 @@ public class Client
}
}
+// public void doSomething()
+// {
+//// new ChatScreen();
+//
+// try
+// {
+// new ChatScreen(this);
+// System.out.println("Sleeping...");
+// TimeUnit.MINUTES.sleep(5);
+// }
+// catch(Exception e)
+// {
+// e.printStackTrace();
+// }
+// }
+
public boolean connect()
{
try
@@ -107,7 +131,7 @@ public class Client
clientController = (IClientController) registryServer.lookup("ClientController");
drawingController = (IDrawingController) registryServer.lookup("DrawingController");
- if (clientController.join(userName, this.chatUpdate, this.drawingUpdate))
+ if (clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate))
{
System.out.println("Connected to server");
@@ -121,4 +145,14 @@ public class Client
return false;
}
+
+ public String getReceivedMessage()
+ {
+ return receivedMessage;
+ }
+
+ public void setReceivedMessage(String receivedMessage)
+ {
+ this.receivedMessage = receivedMessage;
+ }
}
\ No newline at end of file
diff --git a/src/client/ClientUpdate.java b/src/client/ClientUpdate.java
index 4faa2723f8733cb457feb1c3c7696330b5e02b56..83967bc77631a406b91fd2c60dda30d076d7e279 100644
--- a/src/client/ClientUpdate.java
+++ b/src/client/ClientUpdate.java
@@ -2,7 +2,9 @@ package client;
import remote.IClientUpdate;
+import javax.swing.*;
import java.io.Serializable;
+import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
@@ -19,7 +21,29 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate,
@Override
public boolean notifyClient(String fromClient, String newUsername) throws RemoteException
{
- client.getChatScreen().getSentMessageToComboBox().addItem(newUsername);
+ client.getChatScreen().getSendMessageToComboBox().addItem(newUsername);
+
+ return true;
+ }
+
+ @Override
+ public boolean updateUserList(String[] users) throws RemoteException
+ {
+ //client.setConnectedUsers(users);
+
+ JComboBox userBox = client.getChatScreen().getSendMessageToComboBox();
+
+ userBox.removeAllItems();
+
+ userBox.addItem("All");
+
+ for( String s : users )
+ {
+ if( !s.equals(client.getUserName()) )
+ {
+ userBox.addItem(s);
+ }
+ }
return true;
}
diff --git a/src/remote/IChatController.java b/src/remote/IChatController.java
index 64e681194d8783b3a45feb132b84d11140fa78d0..82305870e4b5438637dc6b8759ce3235b6a02dd0 100644
--- a/src/remote/IChatController.java
+++ b/src/remote/IChatController.java
@@ -8,4 +8,5 @@ public interface IChatController extends Remote
boolean broadcastMessage(String fromClient, String message) throws RemoteException;
boolean broadcastMessageUserLogin(String fromClient) throws RemoteException;
boolean broadcastMessageUserLogout(String fromClient) throws RemoteException;
+ boolean sendPrivateMessage(String fromClient, String toClient, String message) throws RemoteException;
}
diff --git a/src/remote/IChatUpdate.java b/src/remote/IChatUpdate.java
index 55b2e62445fe0e9d455518d4cbe188adfcb89a9e..0c9b54d9daab6367372e1987f2c988a94bcbde8d 100644
--- a/src/remote/IChatUpdate.java
+++ b/src/remote/IChatUpdate.java
@@ -6,7 +6,7 @@ import java.rmi.RemoteException;
public interface IChatUpdate extends Remote, Serializable
{
- boolean notifyChat(String fromClient, String message) throws RemoteException;
+ boolean notifyChat(String fromClient, String message, boolean isPrivate) throws RemoteException;
boolean notifyUserLogin(String fromClient) throws RemoteException;
boolean notifyUserLogout(String fromClient) throws RemoteException;
}
diff --git a/src/remote/IClientController.java b/src/remote/IClientController.java
index 70447fe97b800d4f5c90805d74153ea70498e316..bde0a0f500ed01f94c2485ba8de0bdea378d05d9 100644
--- a/src/remote/IClientController.java
+++ b/src/remote/IClientController.java
@@ -5,7 +5,7 @@ import java.rmi.RemoteException;
public interface IClientController extends Remote
{
- boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing) throws RemoteException;
+ boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException;
void quit(String username) throws RemoteException;
diff --git a/src/remote/IClientUpdate.java b/src/remote/IClientUpdate.java
index 9eb5bc90e58e864fdf182b29e871c410adf7f4fb..c1337f90f560c6b527bd067d7d5d2cf0d85ee234 100644
--- a/src/remote/IClientUpdate.java
+++ b/src/remote/IClientUpdate.java
@@ -7,4 +7,6 @@ import java.rmi.RemoteException;
public interface IClientUpdate extends Remote, Serializable {
boolean notifyClient(String fromClient, String newUsername) throws RemoteException;
+
+ boolean updateUserList(String[] users) throws RemoteException;
}
diff --git a/src/server/ChatController.java b/src/server/ChatController.java
index 79c344a9a50743c6dbeede8238f75b2ffb7ba579..8fbff1e4457c8c633893caad33f1ceeff7b6b49c 100644
--- a/src/server/ChatController.java
+++ b/src/server/ChatController.java
@@ -26,7 +26,7 @@ public class ChatController extends UnicastRemoteObject implements IChatControll
for( User u : server.users )
{
client = u.getIChatUpdate();
- client.notifyChat(fromClient, message);
+ client.notifyChat(fromClient, message, false);
}
System.out.print("...DONE\n");
@@ -69,4 +69,22 @@ public class ChatController extends UnicastRemoteObject implements IChatControll
return true;
}
+
+ @Override
+ public boolean sendPrivateMessage(String fromClient, String toClient, String message) throws RemoteException
+ {
+ int toClientIndex = server.clientController.getUserIndex(toClient);
+ int fromClientIndex = server.clientController.getUserIndex(fromClient);
+
+ if( toClientIndex >= 0 && fromClientIndex >= 0 )
+ {
+ server.users.get(toClientIndex).getIChatUpdate().notifyChat(fromClient, message, true);
+
+ server.users.get(fromClientIndex).getIChatUpdate().notifyChat(fromClient, message, true);
+
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/src/server/ClientController.java b/src/server/ClientController.java
index f3753fa6f0ad8660d87cb0cb91163a699329d17b..bcfd261f7da172aca929a6a4f291b39c277fb2b1 100644
--- a/src/server/ClientController.java
+++ b/src/server/ClientController.java
@@ -2,9 +2,11 @@ package server;
import remote.IChatUpdate;
import remote.IClientController;
+import remote.IClientUpdate;
import remote.IDrawingUpdate;
import java.io.Serializable;
+import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
@@ -18,11 +20,11 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
}
@Override
- public boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing) throws RemoteException
+ public boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException
{
server.chatController.broadcastMessageUserLogin(username);
- User newUser = new User(username, clientChat, clientDrawing);
+ User newUser = new User(username, clientChat, clientUpdate, clientDrawing);
server.users.add(newUser);
@@ -33,6 +35,8 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
System.out.println(username + " registered successfully");
+ broadcastUserList();
+
return true;
}
@@ -46,6 +50,8 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
server.users.remove(userIndex);
server.chatController.broadcastMessageUserLogout(username);
+
+ broadcastUserList();
}
}
@@ -74,13 +80,16 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
if ( adminIndex > 0 && userIndex > 0 && server.users.get(adminIndex).isAdmin() )
{
server.users.remove(userIndex);
+
+ broadcastUserList();
+
return true;
}
return false;
}
- private int getUserIndex(String username)
+ public int getUserIndex(String username)
{
int index = -1;
@@ -95,4 +104,19 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
return index;
}
+
+ private void broadcastUserList() throws RemoteException
+ {
+ String[] connectedUsers = new String[server.users.size()];
+
+ for( int i = 0; i<server.users.size(); i++ )
+ {
+ connectedUsers[i] = server.users.get(i).getUserName();
+ }
+
+ for( User u : server.users )
+ {
+ u.getIClientUpdate().updateUserList(connectedUsers);
+ }
+ }
}
diff --git a/src/server/User.java b/src/server/User.java
index 51047ae656f86c128b532782af263dbd91dceb7a..c4c174cde0d0cdfb8208d8860132769863991d44 100644
--- a/src/server/User.java
+++ b/src/server/User.java
@@ -5,13 +5,15 @@ public class User
private String username;
private remote.IChatUpdate IChatUpdate;
private remote.IDrawingUpdate IDrawingUpdate;
+ private remote.IClientUpdate IClientUpdate;
private boolean isAdmin;
- public User(String username, remote.IChatUpdate IChatUpdate, remote.IDrawingUpdate IDrawingUpdate)
+ public User(String username, remote.IChatUpdate IChatUpdate, remote.IClientUpdate IClientUpdate, remote.IDrawingUpdate IDrawingUpdate)
{
this.username = username;
this.IChatUpdate = IChatUpdate;
this.IDrawingUpdate = IDrawingUpdate;
+ this.IClientUpdate = IClientUpdate;
this.isAdmin = false;
}
@@ -35,5 +37,10 @@ public class User
return this.IChatUpdate;
}
+ public remote.IClientUpdate getIClientUpdate()
+ {
+ return this.IClientUpdate;
+ }
+
public remote.IDrawingUpdate getIDrawingUpdate() { return this.IDrawingUpdate; }
}