Commit 4833de50 authored by Ali Saeed's avatar Ali Saeed

Upload My Updates

parent fa645660
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="ChatClient" /> <module name="ChatClient" />
<module name="Client_Side" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
</component> </component>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="7b8eead6-3c0f-4198-a97c-e7ea933bffc2" name="Changes" comment=""> <list default="true" id="7b8eead6-3c0f-4198-a97c-e7ea933bffc2" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/Message.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/Message.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/Room.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/Room.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/src/main/java/Data/User.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/src/main/java/SharedInterface/ChatInterface.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/src/main/java/SharedInterface/ChatInterface.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/src/main/java/org/example/ChatServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/src/main/java/org/example/ChatServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/ChatClientService.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/Message.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/Message.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/Room.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/Room.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/User.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/target/classes/Data/User.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../ChatServer/target/classes/SharedInterface/ChatInterface.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/target/classes/SharedInterface/ChatInterface.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../ChatServer/target/classes/org/example/ChatServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../ChatServer/target/classes/org/example/ChatServiceImpl.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -28,7 +32,7 @@ ...@@ -28,7 +32,7 @@
</option> </option>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component> </component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
...@@ -44,8 +48,9 @@ ...@@ -44,8 +48,9 @@
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;ToolWindowRun.ShowToolbar&quot;: &quot;false&quot;,
&quot;UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH&quot;: &quot;193&quot;, &quot;UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH&quot;: &quot;193&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/dell/IdeaProjects/ChatClient/src/Images&quot;, &quot;last_opened_file_path&quot;: &quot;C:/Users/dell/IdeaProjects/Chat_App/ChatServer&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot; &quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
}, },
&quot;keyToStringList&quot;: { &quot;keyToStringList&quot;: {
...@@ -66,10 +71,23 @@ ...@@ -66,10 +71,23 @@
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\Images" /> <recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\Images" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Application.ChatClientService"> <component name="RunManager" selected="Application.client3">
<configuration name="ChatClientService" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="ChatClientService" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.ChatClientService" /> <option name="MAIN_CLASS_NAME" value="org.example.ChatClientService" />
<module name="ChatClient" /> <module name="Client_Side" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.example.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ChatRoomForm" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.ChatRoomForm" />
<module name="Client_Side" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="org.example.*" /> <option name="PATTERN" value="org.example.*" />
...@@ -100,9 +118,32 @@ ...@@ -100,9 +118,32 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="client2" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.example.ChatClientService" />
<module name="Client_Side" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="client3" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.example.ChatClientService" />
<module name="Client_Side" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.client2" />
<item itemvalue="Application.client3" />
<item itemvalue="Application.ChatClientService" />
<item itemvalue="Application.ChatRoomForm" />
<item itemvalue="Application.LoginForm" />
<item itemvalue="Application.RegistrationForm" />
</list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Application.ChatClientService" /> <item itemvalue="Application.ChatClientService" />
<item itemvalue="Application.ChatRoomForm" />
<item itemvalue="Application.LoginForm" /> <item itemvalue="Application.LoginForm" />
<item itemvalue="Application.RegistrationForm" /> <item itemvalue="Application.RegistrationForm" />
</list> </list>
......
package Data; package Data;
public class Message { import java.io.Serializable;
public class Message implements Serializable {
private String sender;
private String receiver;
private String details;
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public Message() {
this.details = "";
this.receiver = "";
this.sender = "";
}
public Message(String sender, String receiver, String details) {
this.sender = sender;
this.receiver = receiver;
this.details = details;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
} }
package Data; package Data;
import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Room { public class Room implements Serializable {
private String roomName; private String roomName;
private List<User> users; private List<User> users;
private User owner; private User owner;
private List<String> messages;
private List<User> loggedInUsers;
public Room(String roomName, List<User> users, User owner) {
public Room(String roomName, List<User> users, User owner,List<String> messages) {
this.roomName = roomName; this.roomName = roomName;
this.users = users; this.users = users;
this.owner = owner; this.owner = owner;
this.messages = messages;
this.loggedInUsers = new ArrayList<>();
}
public List<String> getMessages() {
return messages;
}
public List<User> getLoggedInUsers() {
return loggedInUsers;
}
public void setLoggedInUsers(List<User> loggedInUsers) {
this.loggedInUsers = loggedInUsers;
}
public void setMessages(List<String> messages) {
this.messages = messages;
} }
public Room() { public Room() {
......
package Data; package Data;
import SharedInterface.IClientChat;
import java.io.Serializable; import java.io.Serializable;
public class User implements Serializable { public class User implements Serializable {
private IClientChat clientChat;
private String userName; private String userName;
private String firstName; private String firstName;
private String lastName; private String lastName;
private String password; private String password;
public User(String userName, String firstName, String lastName, String password, IClientChat clientChat) {
public User(String userName, String firstName, String lastName, String password) {
this.userName = userName; this.userName = userName;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
this.password = password; this.password = password;
this.clientChat = clientChat;
} }
public User() { public User() {
this.userName = ""; this.userName = "";
this.firstName = ""; this.firstName = "";
this.lastName = ""; this.lastName = "";
this.password = ""; this.password = "";
this.clientChat = null;
} }
public String getUserName() { public String getUserName() {
return userName; return userName;
} }
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
public String getPassword() { public String getPassword() {
return password; return password;
} }
...@@ -50,6 +49,14 @@ public class User implements Serializable { ...@@ -50,6 +49,14 @@ public class User implements Serializable {
this.lastName = lastName; this.lastName = lastName;
} }
public IClientChat getClientChat() {
return clientChat;
}
public void setClientChat(IClientChat clientChat) {
this.clientChat = clientChat;
}
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
......
package SharedInterface; package SharedInterface;
import Data.Message;
import Data.Result; import Data.Result;
import Data.Room;
import Data.User; import Data.User;
import java.rmi.Remote; import java.rmi.Remote;
...@@ -10,16 +12,28 @@ import java.util.List; ...@@ -10,16 +12,28 @@ import java.util.List;
public interface ChatInterface extends Remote { public interface ChatInterface extends Remote {
Result addChatRoom(String roomName, User owner) throws RemoteException; Result addChatRoom(String roomName, User owner) throws RemoteException;
Result deleteChatRoom(String roomName, User owner) throws RemoteException; Result deleteChatRoom(String roomName, User owner) throws RemoteException;
Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException; Result registerUser(String userName, String password, String firstName, String secondName, IClientChat clientChat) throws RemoteException;
Result loginToSystem(String userName, String password) throws RemoteException; Result loginToSystem(String userName, String password) throws RemoteException;
Result logoutFromSystem(String userName) throws RemoteException;
Result login(String userName, String password, String roomName) throws RemoteException; Result login(String userName, String password, String roomName) throws RemoteException;
Result logout(String userName, String roomName) throws RemoteException; Result logout(String userName, String roomName) throws RemoteException;
List<String> getAvailableChatRooms() throws RemoteException; Result leaveRoom(String userName, String roomName) throws RemoteException;
List<Room> getAvailableChatRooms(User user) throws RemoteException;
List<String> getClientsInChatRoom() throws RemoteException; List<String> getClientsInChatRoom() throws RemoteException;
void sendMessageToClient(String sender, String receiver, String message) throws RemoteException; void sendMessageToClient(String sender, String receiver, String message) throws RemoteException;
void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException; void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException;
User getUserInfo(String username) throws RemoteException; User getUserInfo(String username) throws RemoteException;
Room getRoomByName(String roomName) throws RemoteException;
List<Message> getChatMessages(String senderName, String receiverName) throws RemoteException;
Result addUserToRoom(String roomName,String userName, User owner) throws RemoteException;
Result removeUserFromRoom(String roomName,String userName, User owner) throws RemoteException;
void setClientChatInterfaceForUsers(IClientChat clientChat , String roomName, String userName) throws RemoteException;
void setClientChatInterfaceForUser(IClientChat clientChat , String user) throws RemoteException;
List<User> getAllUsers(String userName) throws RemoteException;
void setLoggedInUsersForRoom(String roomName, String user) throws RemoteException;
} }
package SharedInterface;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IClientChat extends Remote {
String receiveMessage(String message, String username) throws RemoteException;
String receiveMessageFromClient(String message, String username) throws RemoteException;
}
...@@ -38,9 +38,8 @@ public class AddRoomForm extends JDialog{ ...@@ -38,9 +38,8 @@ public class AddRoomForm extends JDialog{
} }
try { try {
Result result = new Result(); Result result = new Result();
User user = new User();
result = chatInterface.addChatRoom(roomName, SharedVariables.getUser()); result = chatInterface.addChatRoom(roomName, SharedVariables.user);
if(result.isSuccess()){ if(result.isSuccess()){
JOptionPane.showMessageDialog(AddRoomPanel, result.getDescription() JOptionPane.showMessageDialog(AddRoomPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE); ,"Success", JOptionPane.INFORMATION_MESSAGE);
......
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.AddUserToRoom">
<grid id="27dc6" binding="addPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="45" y="20" width="475" height="414"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="8e6cc" class="javax.swing.JLabel" binding="lTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="28" style="1"/>
<text value="Add a new user to room"/>
</properties>
</component>
<component id="c7fbc" class="javax.swing.JLabel" binding="lUsername">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="User name"/>
</properties>
</component>
<component id="61698" class="javax.swing.JTextField" binding="tfUsername">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="6e988" class="javax.swing.JButton" binding="addButton" default-binding="true">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Add"/>
</properties>
</component>
<component id="c1bca" class="javax.swing.JButton" binding="cancelButton" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class AddUserToRoom extends JDialog {
private String roomName;
private JPanel addPanel;
private JLabel lTitle;
private JButton cancelButton;
private JTextField tfUsername;
private JButton addButton;
private JLabel lUsername;
public AddUserToRoom(ChatInterface chatInterface, String roomName) {
this.roomName = roomName;
setTitle("Add new user to room");
setContentPane(addPanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = tfUsername.getText();
if(username.isEmpty()){
JOptionPane.showMessageDialog(addPanel, "please enter user name"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
result = chatInterface.addUserToRoom(roomName,username,SharedVariables.getUser());
if(result.isSuccess()){
JOptionPane.showMessageDialog(addPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
ChatRoomForm chatRoomForm = new ChatRoomForm(chatInterface,roomName);
}
else{
JOptionPane.showMessageDialog(addPanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
ChatRoomForm dashboard = new ChatRoomForm(chatInterface,roomName);
}
});
setVisible(true);
}
}
package org.example;
import SharedInterface.IClientChat;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ChatClientImpl extends UnicastRemoteObject implements IClientChat {
ChatForm chatForm;
protected ChatClientImpl(ChatForm chatForm) throws RemoteException {
this.chatForm = chatForm;
}
@Override
public String receiveMessage(String message, String userName) throws RemoteException {
chatForm.setTextAreaRecievedMessages(userName+": "+message);
return null;
}
@Override
public String receiveMessageFromClient(String message, String username) throws RemoteException {
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.ChatForm">
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</form>
package org.example;
import javax.swing.*;
public abstract class ChatForm extends JDialog {
public abstract void setTextAreaRecievedMessages(String msg);
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.ChatRoomForm">
<grid id="27dc6" binding="roomPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<vspacer id="3488b">
<constraints>
<grid row="2" column="0" row-span="4" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="bf47f" class="javax.swing.JButton" binding="showAllUsersButton" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Show all users"/>
</properties>
</component>
<component id="da1ca" class="javax.swing.JButton" binding="startChatButton" default-binding="true">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Start Chat"/>
</properties>
</component>
<component id="62fe0" class="javax.swing.JButton" binding="addUserButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Add User"/>
</properties>
</component>
<component id="2184a" class="javax.swing.JButton" binding="removeUserButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Remove User"/>
</properties>
</component>
<component id="8ce5b" class="javax.swing.JButton" binding="cancelButton" default-binding="true">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
<component id="df721" class="javax.swing.JButton" binding="leaveRoomButton" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Leave room"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class ChatRoomForm extends JDialog{
private JPanel roomPanel;
private JButton addUserButton;
private JButton showAllUsersButton;
private JButton startChatButton;
private JButton removeUserButton;
private JButton cancelButton;
private JButton leaveRoomButton;
public ChatRoomForm(ChatInterface chatInterface,String roomName) {
setTitle("Room dashboard");
setContentPane(roomPanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addUserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
AddUserToRoom addUserToRoom = new AddUserToRoom(chatInterface,roomName);
}
});
removeUserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
RemoveUserFromRoom removeUserFromRoom = new RemoveUserFromRoom(chatInterface,roomName);
}
});
showAllUsersButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
ShowAllRoomUsers showAllRoomUsers = new ShowAllRoomUsers(chatInterface,roomName);
}
});
startChatButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
PublicChatForm publicChatForm = new PublicChatForm(chatInterface, roomName);
try {
ChatClientImpl chatClient = new ChatClientImpl(publicChatForm);
chatInterface.setClientChatInterfaceForUsers(chatClient,roomName, SharedVariables.getUser().getUserName());
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm homeForm = new HomeForm(chatInterface);
}
});
leaveRoomButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Result result = new Result();
try {
result = chatInterface.leaveRoom(SharedVariables.getUser().getUserName(), roomName);
if(result.isSuccess()){
JOptionPane.showMessageDialog(roomPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
HomeForm home = new HomeForm(chatInterface);
}
else{
JOptionPane.showMessageDialog(roomPanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.HomeForm"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.HomeForm">
<grid id="27dc6" binding="HomePanel" layout-manager="GridLayoutManager" row-count="10" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="HomePanel" layout-manager="GridLayoutManager" row-count="13" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="500" height="400"/>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<grid id="1bb98" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="1bb98" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/> <margin top="10" left="10" bottom="10" right="10"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="10" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="13" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<background color="-4924033"/> <background color="-4924033"/>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<grid id="2f855" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="2f855" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="1" column="2" row-span="9" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="1" column="2" row-span="12" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</grid> </grid>
<hspacer id="432b7"> <hspacer id="432b7">
<constraints> <constraints>
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="12" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<component id="eca81" class="javax.swing.JButton" binding="btnAdd"> <component id="eca81" class="javax.swing.JButton" binding="btnAdd">
...@@ -105,21 +105,35 @@ ...@@ -105,21 +105,35 @@
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</vspacer> </vspacer>
<vspacer id="e288e"> <component id="2070" class="javax.swing.JButton" binding="btnLogout">
<constraints> <constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Logout"/>
</properties>
</component>
<vspacer id="acbbf">
<constraints>
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</vspacer> </vspacer>
<component id="2070" class="javax.swing.JButton" binding="btnLogout"> <component id="f6941" class="javax.swing.JButton" binding="allUsersButton" default-binding="true">
<constraints> <constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Segoe Print" size="18" style="1"/> <font name="Segoe Print" size="18" style="1"/>
<text value="Logout"/> <text value="All users"/>
</properties> </properties>
</component> </component>
<vspacer id="acbbf"> <vspacer id="f4d62">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="643cb">
<constraints> <constraints>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
......
package org.example; package org.example;
import Data.Result;
import SharedInterface.ChatInterface; import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class HomeForm extends JDialog { public class HomeForm extends JDialog {
private JPanel HomePanel; private JPanel HomePanel;
...@@ -15,6 +18,7 @@ public class HomeForm extends JDialog { ...@@ -15,6 +18,7 @@ public class HomeForm extends JDialog {
private JButton btnRemove; private JButton btnRemove;
private JButton btnShow; private JButton btnShow;
private JButton btnLogout; private JButton btnLogout;
private JButton allUsersButton;
public HomeForm(ChatInterface chatInterface){ public HomeForm(ChatInterface chatInterface){
setTitle("Home"); setTitle("Home");
...@@ -44,18 +48,52 @@ public class HomeForm extends JDialog { ...@@ -44,18 +48,52 @@ public class HomeForm extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
dispose(); dispose();
try {
ShowRoomsForm show = new ShowRoomsForm(chatInterface); ShowRoomsForm show = new ShowRoomsForm(chatInterface);
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
// SwingUtilities.invokeLater(() -> {
// ShowRoomsForm show = new ShowRoomsForm(chatInterface);
// });
} }
}); });
btnLogout.addActionListener(new ActionListener() { btnLogout.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Result result = new Result();
try {
result = chatInterface.logoutFromSystem(SharedVariables.getUser().getUserName());
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
if(result.isSuccess()){
JOptionPane.showMessageDialog(HomePanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
LoginForm home = new LoginForm(chatInterface);
}
else {
JOptionPane.showMessageDialog(HomePanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
}
});
allUsersButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
try {
ShowAllUsersForm showAllUsersForm = new ShowAllUsersForm(chatInterface);
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
} }
}); });
setVisible(true); setVisible(true);
......
package org.example; package org.example;
import SharedInterface.ChatInterface;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class ItemPanel extends JPanel { public class ItemPanel extends JPanel {
private static final int PANEL_HEIGHT = 30;
private String itemName; private String itemName;
private JLabel nameLabel; private JLabel nameLabel;
public ItemPanel(String itemName) { public ItemPanel(String itemName, ChatInterface chatInterface) {
this.itemName = itemName; this.itemName = itemName;
setLayout(new FlowLayout()); setLayout(new BorderLayout());
setPreferredSize(new Dimension(300, PANEL_HEIGHT));
nameLabel = new JLabel(itemName); nameLabel = new JLabel(itemName);
nameLabel.addMouseListener(new ItemClickListener()); nameLabel.setFont(new Font("Arial", Font.BOLD, 18));
add(nameLabel); nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
add(nameLabel, BorderLayout.WEST);
addMouseListener(new ItemClickListener(chatInterface,itemName));
} }
private class ItemClickListener extends MouseAdapter { private class ItemClickListener extends MouseAdapter {
ChatInterface chatInterface;
String roomName;
public ItemClickListener(ChatInterface chatInterface, String roomName) {
this.chatInterface = chatInterface;
this.roomName = roomName;
}
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
// Handle item click event here ShowRoomsForm showRoomsForm = (ShowRoomsForm) SwingUtilities.getWindowAncestor(ItemPanel.this);
System.out.println(itemName+" is clicked "); showRoomsForm.dispose();
JOptionPane.showMessageDialog(ItemPanel.this, "Item clicked: " + itemName); ChatRoomForm chatRoomForm = new ChatRoomForm(chatInterface,roomName);
} }
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.PrivateChatForm">
<grid id="27dc6" binding="ChatPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="a8d68" class="javax.swing.JTextArea" binding="tfTextArea">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="3efa0" class="javax.swing.JTextField" binding="tfWriteMessage">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="cc480" class="javax.swing.JButton" binding="sendButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Send"/>
</properties>
</component>
<component id="2a5e3" class="javax.swing.JButton" binding="backButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Back"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Message;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
public class PrivateChatForm extends ChatForm{
private JPanel ChatPanel;
private JTextArea tfTextArea;
private JTextField tfWriteMessage;
private JButton sendButton;
private JButton backButton;
public PrivateChatForm(ChatInterface chatInterface,String receiver){
setTitle("Chat");
setContentPane(ChatPanel);
setSize(800,700);
tfTextArea.setEditable(false);
List<Message> messageList = new ArrayList<>();
try {
messageList = chatInterface.getChatMessages(SharedVariables.getUser().getUserName(), receiver);
if(messageList != null && !messageList.isEmpty()){
for(Message msg : messageList){
setTextAreaRecievedMessages(msg.getDetails());
}
}
} catch (RemoteException e) {
throw new RuntimeException(e);
}
sendButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String message = tfWriteMessage.getText();
if(message.isEmpty() ){
JOptionPane.showMessageDialog(ChatPanel, "please write message to send"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
tfWriteMessage.setText("");
chatInterface.sendMessageToClient(SharedVariables.getUser().getUserName(),receiver,message);
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm HomeForm = new HomeForm(chatInterface);
}
});
setVisible(true);
}
@Override
public void setTextAreaRecievedMessages(String msg) {
this.tfTextArea.append("\n"+msg);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.PublicChatForm">
<grid id="27dc6" binding="ChatAppPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="15" left="15" bottom="15" right="15"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4792e" class="javax.swing.JTextArea" binding="tfTextArea">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="dd6e6" class="javax.swing.JTextField" binding="tfWriteMessage">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="9fa98" class="javax.swing.JButton" binding="sendButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Send"/>
</properties>
</component>
<component id="c583f" class="javax.swing.JButton" binding="backButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Back"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Room;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.List;
public class PublicChatForm extends ChatForm{
private JPanel ChatAppPanel;
private JTextArea tfTextArea;
private JTextField tfWriteMessage;
private JButton sendButton;
private JButton backButton;
public PublicChatForm(ChatInterface chatInterface, String roomName){
setTitle("Chat");
setContentPane(ChatAppPanel);
setSize(800,700);
tfTextArea.setEditable(false);
System.out.println("1");
try {
Room room = chatInterface.getRoomByName(roomName);
if (room != null) {
List<String> messages = room.getMessages();
if (messages != null && !messages.isEmpty()) {
for (String message : messages) {
setTextAreaRecievedMessages(message);
}
}
} else {
JOptionPane.showMessageDialog(ChatAppPanel, "Room not found", "Error", JOptionPane.ERROR_MESSAGE);
dispose();
return;
}
} catch (RemoteException e) {
throw new RuntimeException(e);
}
System.out.println("1");
sendButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String message = tfWriteMessage.getText();
if(message.isEmpty() ){
JOptionPane.showMessageDialog(ChatAppPanel, "please write message to send"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
tfWriteMessage.setText("");
chatInterface.sendMessageToRoom(SharedVariables.getUser().getUserName(),roomName,message);
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
try {
chatInterface.setLoggedInUsersForRoom(roomName,SharedVariables.getUser().getUserName());
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
ChatRoomForm chatRoomForm = new ChatRoomForm(chatInterface,roomName);
}
});
setVisible(true);
}
public void setTextAreaRecievedMessages(String msg) {
this.tfTextArea.append("\n"+msg);
}
}
...@@ -46,7 +46,8 @@ public class RegistrationForm extends JDialog { ...@@ -46,7 +46,8 @@ public class RegistrationForm extends JDialog {
} }
try { try {
Result result = new Result(); Result result = new Result();
result = chatInterface.registerUser(username,password,firstname,lastname); // ChatClientImpl chatClient = new ChatClientImpl(new PublicChatForm(chatInterface));
result = chatInterface.registerUser(username,password,firstname,lastname,null);
if(result.isSuccess()){ if(result.isSuccess()){
JOptionPane.showMessageDialog(RegisterPanel, result.getDescription() JOptionPane.showMessageDialog(RegisterPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE); ,"Success", JOptionPane.INFORMATION_MESSAGE);
......
...@@ -4,7 +4,6 @@ import Data.Result; ...@@ -4,7 +4,6 @@ import Data.Result;
import Data.User; import Data.User;
import SharedInterface.ChatInterface; import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables; import SharedVariables.SharedVariables;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
......
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.RemoveUserFromRoom">
<grid id="27dc6" binding="removePanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="6ffac" class="javax.swing.JLabel" binding="lTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Remove user from room"/>
</properties>
</component>
<component id="9c97c" class="javax.swing.JLabel" binding="lUsername">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="User name"/>
</properties>
</component>
<component id="592d9" class="javax.swing.JTextField" binding="tfUsername">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="a245" class="javax.swing.JButton" binding="removeButton" default-binding="true">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Remove"/>
</properties>
</component>
<component id="16772" class="javax.swing.JButton" binding="cancelButton" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class RemoveUserFromRoom extends JDialog{
private String roomName;
private JButton removeButton;
private JButton cancelButton;
private JTextField tfUsername;
private JLabel lTitle;
private JLabel lUsername;
private JPanel removePanel;
public RemoveUserFromRoom(ChatInterface chatInterface, String roomName) {
this.roomName = roomName;
setTitle("Remove user from room");
setContentPane(removePanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
ChatRoomForm dashboard = new ChatRoomForm(chatInterface,roomName);
}
});
removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = tfUsername.getText();
if(username.isEmpty()){
JOptionPane.showMessageDialog(removePanel, "please enter user name"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
result = chatInterface.removeUserFromRoom(roomName,username,SharedVariables.getUser());
if(result.isSuccess()){
JOptionPane.showMessageDialog(removePanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
ChatRoomForm chatRoomForm = new ChatRoomForm(chatInterface,roomName);
}
else{
JOptionPane.showMessageDialog(removePanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.ShowAllRoomUsers">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="62fc1" binding="scroll">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="82a10" binding="showPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
<border type="none"/>
<children>
<component id="e669f" class="javax.swing.JButton" binding="backButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Back"/>
</properties>
</component>
</children>
</grid>
</children>
</scrollpane>
</children>
</grid>
</form>
package org.example;
import Data.User;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.List;
public class ShowAllRoomUsers extends JDialog{
private JPanel panel1;
private JScrollPane scroll;
private JPanel showPanel;
private JButton backButton;
private static final int SCROLL_PANE_HEIGHT = 500;
public ShowAllRoomUsers(ChatInterface chatInterface, String roomName){
setTitle("Show all rooms");
showPanel = new JPanel();
showPanel.setLayout(new BoxLayout(showPanel, BoxLayout.Y_AXIS));
List<User> users = null;
try {
users = chatInterface.getRoomByName(roomName).getUsers();
} catch (RemoteException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
UserRoomItemPanel itemPanel = new UserRoomItemPanel(user.getUserName(), chatInterface);
if (i != 0) {
showPanel.add(Box.createRigidArea(new Dimension(0, 10)));
showPanel.add(new JSeparator(SwingConstants.HORIZONTAL));
}
showPanel.add(itemPanel);
}
scroll = new JScrollPane(showPanel);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setPreferredSize(new Dimension(450, SCROLL_PANE_HEIGHT));
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(scroll, BorderLayout.CENTER);
setContentPane(contentPane);
backButton = new JButton("Back");
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
ChatRoomForm chatRoomForm = new ChatRoomForm(chatInterface,roomName);
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(backButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
scroll.getVerticalScrollBar().setValue(0);
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack();
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.ShowAllUsersForm">
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="e5cfa" binding="scroll">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="d707a" binding="showPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
<border type="none"/>
<children>
<component id="cab6a" class="javax.swing.JButton" binding="backButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Back"/>
</properties>
</component>
</children>
</grid>
</children>
</scrollpane>
</children>
</grid>
</form>
package org.example;
import Data.User;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.List;
public class ShowAllUsersForm extends JDialog{
private JScrollPane scroll;
private JPanel showPanel;
private JButton backButton;
private static final int SCROLL_PANE_HEIGHT = 500;
public ShowAllUsersForm(ChatInterface chatInterface) throws RemoteException {
setTitle("Show all rooms");
showPanel = new JPanel();
showPanel.setLayout(new BoxLayout(showPanel, BoxLayout.Y_AXIS));
List<User> users = chatInterface.getAllUsers(SharedVariables.getUser().getUserName());
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
UserItemPanel itemPanel = new UserItemPanel(user.getUserName(), chatInterface);
if (i != 0) {
showPanel.add(Box.createRigidArea(new Dimension(0, 10))); // Add spacing between items
showPanel.add(new JSeparator(SwingConstants.HORIZONTAL)); // Add horizontal line between items
}
showPanel.add(itemPanel);
}
scroll = new JScrollPane(showPanel);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setPreferredSize(new Dimension(450, SCROLL_PANE_HEIGHT));
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(scroll, BorderLayout.CENTER);
setContentPane(contentPane);
backButton = new JButton("Back");
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm chatRoomForm = new HomeForm(chatInterface);
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(backButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
scroll.getVerticalScrollBar().setValue(0);
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack();
setVisible(true);
}
}
...@@ -12,15 +12,33 @@ ...@@ -12,15 +12,33 @@
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties>
<background color="-4923980"/>
</properties>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="cf056" binding="ShowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="cf056" binding="ShowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="5" left="5" bottom="5" right="5"/>
<constraints/> <constraints/>
<properties/> <properties>
<background color="-4924033"/>
</properties>
<border type="none"/> <border type="none"/>
<children/> <children>
<vspacer id="28f44">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="85218" class="javax.swing.JButton" binding="backButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Back"/>
</properties>
</component>
</children>
</grid> </grid>
</children> </children>
</scrollpane> </scrollpane>
......
package org.example; package org.example;
import Data.Room;
import SharedInterface.ChatInterface; import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.List;
public class ShowRoomsForm extends JDialog{ public class ShowRoomsForm extends JDialog {
private JScrollPane scroll; private JScrollPane scroll;
private JPanel ShowPanel; private JPanel ShowPanel;
private JButton backButton;
private static final int SCROLL_PANE_HEIGHT = 500;
public ShowRoomsForm(ChatInterface chatInterface) throws RemoteException {
public ShowRoomsForm(ChatInterface chatInterface) {
setTitle("Show all rooms"); setTitle("Show all rooms");
setPreferredSize(new Dimension(450, 474)); // Set the preferred size for the ShowPanel
ShowPanel = new JPanel(); ShowPanel = new JPanel();
ShowPanel.setLayout(new BoxLayout(ShowPanel, BoxLayout.Y_AXIS)); ShowPanel.setLayout(new BoxLayout(ShowPanel, BoxLayout.Y_AXIS));
List<Room> roomList = chatInterface.getAvailableChatRooms(SharedVariables.getUser());
for (int i = 0; i < roomList.size(); i++) {
Room room = roomList.get(i);
ItemPanel itemPanel = new ItemPanel(room.getRoomName(), chatInterface);
if (i != 0) {
ShowPanel.add(Box.createRigidArea(new Dimension(0, 10))); // Add spacing between items
ShowPanel.add(new JSeparator(SwingConstants.HORIZONTAL)); // Add horizontal line between items
}
String[] itemList = {"Item 1", "Item 4", "Item 5", "Item 3", "Item 4", "Item 5", "Item 2", "Item 3", "Item 4", "Item 5"};
for (String item : itemList) {
ItemPanel itemPanel = new ItemPanel(item);
ShowPanel.add(itemPanel); ShowPanel.add(itemPanel);
} }
scroll = new JScrollPane(ShowPanel); scroll = new JScrollPane(ShowPanel);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setPreferredSize(new Dimension(450, SCROLL_PANE_HEIGHT));
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(scroll, BorderLayout.CENTER);
setContentPane(contentPane);
backButton = new JButton("Back");
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm homeForm = new HomeForm(chatInterface);
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(backButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
scroll.getVerticalScrollBar().setValue(0);
setContentPane(scroll);
setModal(true); setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack(); pack();
setVisible(true); setVisible(true);
} }
// public ShowRoomsForm(ChatInterface chatInterface){
// setTitle("Show all rooms");
//// setContentPane(scroll);
//// setMinimumSize(new Dimension(450, 474));
//// setModal(true);
//// setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// ShowPanel = new JPanel();
//
// ShowPanel.setLayout(new BoxLayout(ShowPanel, BoxLayout.Y_AXIS));
// scroll = new JScrollPane(ShowPanel);
//
// setContentPane(scroll);
// setMinimumSize(new Dimension(450, 474));
// setModal(true);
// setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// String[] itemList = {"Item 1", "Item 4", "Item 5", "Item 3", "Item 4", "Item 5", "Item 2", "Item 3", "Item 4", "Item 5"};
// JPanel itemContainer = new JPanel();
// itemContainer.setLayout(new BoxLayout(itemContainer, BoxLayout.Y_AXIS));
// for (String item : itemList) {
// ItemPanel itemPanel = new ItemPanel(item);
// itemContainer.add(itemPanel);
// }
// scroll.setViewportView(itemContainer);
// pack();
// setVisible(true);
// }
} }
package org.example;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.rmi.RemoteException;
public class UserItemPanel extends JPanel {
private static final int PANEL_HEIGHT = 30;
private String itemName;
private JLabel nameLabel;
public UserItemPanel(String itemName, ChatInterface chatInterface) {
this.itemName = itemName;
setLayout(new BorderLayout());
setPreferredSize(new Dimension(300, PANEL_HEIGHT));
nameLabel = new JLabel(itemName);
nameLabel.setFont(new Font("Arial", Font.BOLD, 18));
nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
add(nameLabel, BorderLayout.WEST);
addMouseListener(new ItemClickListener(chatInterface,itemName));
}
private class ItemClickListener extends MouseAdapter {
ChatInterface chatInterface;
String userName;
public ItemClickListener(ChatInterface chatInterface, String userName) {
this.chatInterface = chatInterface;
this.userName = userName;
}
@Override
public void mouseClicked(MouseEvent e) {
ShowAllUsersForm showForm = (ShowAllUsersForm) SwingUtilities.getWindowAncestor(UserItemPanel.this);
showForm.dispose();
PrivateChatForm privateChatForm = new PrivateChatForm(chatInterface, userName);
try {
ChatClientImpl chatClient = new ChatClientImpl(privateChatForm);
chatInterface.setClientChatInterfaceForUser(chatClient, SharedVariables.getUser().getUserName());
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
}
}
\ No newline at end of file
package org.example;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.rmi.RemoteException;
public class UserRoomItemPanel extends JPanel{
private static final int PANEL_HEIGHT = 30;
private String itemName;
private JLabel nameLabel;
public UserRoomItemPanel(String itemName, ChatInterface chatInterface) {
this.itemName = itemName;
setLayout(new BorderLayout());
setPreferredSize(new Dimension(300, PANEL_HEIGHT));
nameLabel = new JLabel(itemName);
nameLabel.setFont(new Font("Arial", Font.BOLD, 18));
nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
add(nameLabel, BorderLayout.WEST);
addMouseListener(new UserRoomItemPanel.ItemClickListener(chatInterface,itemName));
}
private class ItemClickListener extends MouseAdapter {
ChatInterface chatInterface;
String userName;
public ItemClickListener(ChatInterface chatInterface, String userName) {
this.chatInterface = chatInterface;
this.userName = userName;
}
@Override
public void mouseClicked(MouseEvent e) {
ShowAllRoomUsers showAllRoomUsers = (ShowAllRoomUsers) SwingUtilities.getWindowAncestor(UserRoomItemPanel.this);
showAllRoomUsers.dispose();
PrivateChatForm privateChatForm = new PrivateChatForm(chatInterface, userName);
try {
ChatClientImpl chatClient = new ChatClientImpl(privateChatForm);
chatInterface.setClientChatInterfaceForUser(chatClient, SharedVariables.getUser().getUserName());
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -5,14 +5,43 @@ ...@@ -5,14 +5,43 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e25cce4c-cf2f-4ddb-9eec-8aa7eed92b1a" name="Changes" comment=""> <list default="true" id="e25cce4c-cf2f-4ddb-9eec-8aa7eed92b1a" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/compiler.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/Message.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/Message.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/Room.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/Room.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/Data/User.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/SharedInterface/ChatInterface.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/SharedInterface/ChatInterface.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/ChatServiceImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/AddRoomForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/AddRoomForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/HomeForm.form" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/HomeForm.form" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/HomeForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/HomeForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ItemPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ItemPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/RegistrationForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/RegistrationForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/RemoveRoomForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/RemoveRoomForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ShowRoomsForm.form" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ShowRoomsForm.form" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ShowRoomsForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/src/main/java/org/example/ShowRoomsForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/Message.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/Message.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/Room.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/Room.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/User.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/Data/User.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/SharedInterface/ChatInterface.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/SharedInterface/ChatInterface.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/AddRoomForm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$3.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$4.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm$4.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/HomeForm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ItemPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ItemPanel$ItemClickListener.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ItemPanel$ItemClickListener.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ItemPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ItemPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RegistrationForm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/RemoveRoomForm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ShowRoomsForm.class" beforeDir="false" afterPath="$PROJECT_DIR$/../ChatClient/Client_Side/target/classes/org/example/ShowRoomsForm.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -22,13 +51,13 @@ ...@@ -22,13 +51,13 @@
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="Interface" />
<option value="Class" /> <option value="Class" />
<option value="Interface" />
</list> </list>
</option> </option>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component> </component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
...@@ -39,13 +68,14 @@ ...@@ -39,13 +68,14 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"SHARE_PROJECT_CONFIGURATION_FILES": "true" &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/dell/IdeaProjects/Chat_App/ChatServer&quot;
} }
}]]></component> }</component>
<component name="RunManager"> <component name="RunManager">
<configuration name="ChatServer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="ChatServer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.ChatServer" /> <option name="MAIN_CLASS_NAME" value="org.example.ChatServer" />
......
package Data; package Data;
public class Message { import java.io.Serializable;
public class Message implements Serializable {
private String sender;
private String receiver;
private String details;
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public Message() {
this.details = "";
this.receiver = "";
this.sender = "";
}
public Message(String sender, String receiver, String details) {
this.sender = sender;
this.receiver = receiver;
this.details = details;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
} }
package Data; package Data;
import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Room { public class Room implements Serializable {
private String roomName; private String roomName;
private List<User> users; private List<User> users;
public List<User> getLoggedInUsers() {
return loggedInUsers;
}
public void setLoggedInUsers(List<User> loggedInUsers) {
this.loggedInUsers = loggedInUsers;
}
private List<User> loggedInUsers;
private List<String> messages;
private User owner; private User owner;
public Room(String roomName, List<User> users, User owner) { public Room(String roomName, List<User> users, User owner, List<String> messages) {
this.roomName = roomName; this.roomName = roomName;
this.users = users; this.users = users;
this.owner = owner; this.owner = owner;
this.messages = messages;
this.loggedInUsers = new ArrayList<>();
} }
public Room() { public Room() {
} }
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
this.messages = messages;
}
public User getOwner() { public User getOwner() {
return owner; return owner;
} }
...@@ -47,4 +71,5 @@ public class Room { ...@@ -47,4 +71,5 @@ public class Room {
public void setUsers(List<User> users) { public void setUsers(List<User> users) {
this.users = users; this.users = users;
} }
} }
package Data; package Data;
import SharedInterface.IClientChat;
import java.io.Serializable; import java.io.Serializable;
public class User implements Serializable { public class User implements Serializable {
private IClientChat clientChat;
private String userName; private String userName;
private String firstName; private String firstName;
private String lastName; private String lastName;
private String password; private String password;
public User(String userName, String firstName, String lastName, String password) { public User(String userName, String firstName, String lastName, String password, IClientChat clientChat) {
this.userName = userName; this.userName = userName;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
this.password = password; this.password = password;
this.clientChat = clientChat;
} }
public User() { public User() {
this.userName = ""; this.userName = "";
this.firstName = ""; this.firstName = "";
this.lastName = ""; this.lastName = "";
this.password = ""; this.password = "";
this.clientChat = null;
} }
public String getUserName() { public String getUserName() {
return userName; return userName;
...@@ -44,6 +49,14 @@ public class User implements Serializable { ...@@ -44,6 +49,14 @@ public class User implements Serializable {
this.lastName = lastName; this.lastName = lastName;
} }
public IClientChat getClientChat() {
return clientChat;
}
public void setClientChat(IClientChat clientChat) {
this.clientChat = clientChat;
}
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
......
package SharedInterface; package SharedInterface;
import Data.Message;
import Data.Result; import Data.Result;
import Data.Room;
import Data.User; import Data.User;
import java.rmi.Remote; import java.rmi.Remote;
import java.rmi.RemoteException; import java.rmi.RemoteException;
...@@ -9,14 +11,29 @@ import java.util.List; ...@@ -9,14 +11,29 @@ import java.util.List;
public interface ChatInterface extends Remote { public interface ChatInterface extends Remote {
Result addChatRoom(String roomName, User owner) throws RemoteException; Result addChatRoom(String roomName, User owner) throws RemoteException;
Result deleteChatRoom(String roomName, User owner) throws RemoteException; Result deleteChatRoom(String roomName, User owner) throws RemoteException;
Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException; Result registerUser(String userName, String password, String firstName, String secondName, IClientChat clientChat) throws RemoteException;
Result loginToSystem(String userName, String password) throws RemoteException; Result loginToSystem(String userName, String password) throws RemoteException;
Result login(String userName, String password, String roomName) throws RemoteException; Result login(String userName, String password, String roomName) throws RemoteException;
Result logout(String userName, String roomName) throws RemoteException; Result logout(String userName, String roomName) throws RemoteException;
List<String> getAvailableChatRooms() throws RemoteException; Result leaveRoom(String userName, String roomName) throws RemoteException;
List<String> getClientsInChatRoom() throws RemoteException; List<Room> getAvailableChatRooms(User user) throws RemoteException;
List<User> getClientsInChatRoom(String roomName) throws RemoteException;
void sendMessageToClient(String sender, String receiver, String message) throws RemoteException; void sendMessageToClient(String sender, String receiver, String message) throws RemoteException;
void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException; void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException;
User getUserInfo(String username) throws RemoteException; User getUserInfo(String username) throws RemoteException;
Room getRoomByName(String roomName) throws RemoteException;
List<Message> getChatMessages(String senderName, String receiverName) throws RemoteException;
Result addUserToRoom(String roomName,String userName, User owner) throws RemoteException;
Result removeUserFromRoom(String roomName,String userName, User owner) throws RemoteException;
void setClientChatInterfaceForUsers(IClientChat clientChat , String roomName, String userName) throws RemoteException;
void setClientChatInterfaceForUser(IClientChat clientChat, String user) throws RemoteException;
void setLoggedInUsersForRoom(String roomName, String user) throws RemoteException;
Result logoutFromSystem(String userName) throws RemoteException;
List<User> getAllUsers(String userName) throws RemoteException;
} }
package SharedInterface;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IClientChat extends Remote {
String receiveMessage(String message, String username) throws RemoteException;
}
package org.example; package org.example;
import Data.Message;
import Data.Result; import Data.Result;
import Data.Room; import Data.Room;
import Data.User; import Data.User;
import SharedInterface.ChatInterface; import SharedInterface.ChatInterface;
import SharedInterface.IClientChat;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterface { public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterface {
private List<Room> chatRooms; private List<Room> chatRooms;
private List<User> registeredUsers; private List<User> registeredUsers;
private List<User> loggedInUsers; private List<User> loggedInUsers;
private List<Message> messages;
protected ChatServiceImpl() throws RemoteException { protected ChatServiceImpl() throws RemoteException {
super(); super();
...@@ -68,7 +73,7 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac ...@@ -68,7 +73,7 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac
} }
@Override @Override
public Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException { public Result registerUser(String userName, String password, String firstName, String secondName, IClientChat clientChat) throws RemoteException {
System.out.println("there is user want to register"); System.out.println("there is user want to register");
Result result = new Result(); Result result = new Result();
for(User user : registeredUsers){ for(User user : registeredUsers){
...@@ -78,7 +83,7 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac ...@@ -78,7 +83,7 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac
return result; return result;
} }
} }
User newuser = new User(userName,firstName,secondName,password); User newuser = new User(userName,firstName,secondName,password,clientChat);
registeredUsers.add(newuser); registeredUsers.add(newuser);
result.setSuccess(true); result.setSuccess(true);
result.setDescription("registration done successfully"); result.setDescription("registration done successfully");
...@@ -169,23 +174,120 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac ...@@ -169,23 +174,120 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac
} }
@Override @Override
public List<String> getAvailableChatRooms() throws RemoteException { public Result leaveRoom(String userName, String roomName) throws RemoteException {
return null; Result result = new Result();
for (Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
for (User usr : room.getUsers()){
if(usr.getUserName().equals(userName)){
room.getUsers().remove(usr);
result.setDescription("you left this room");
result.setSuccess(true);
return result;
}
}
result.setDescription("you is not in this room");
result.setSuccess(false);
return result;
}
} }
result.setDescription("room not found");
result.setSuccess(false);
return result; }
@Override @Override
public List<String> getClientsInChatRoom() throws RemoteException { public List<Room> getAvailableChatRooms(User user) throws RemoteException {
List<Room> availableRooms= new ArrayList<Room>();
for (Room room : chatRooms){
if(room.getOwner().getUserName().equals(user.getUserName())){
availableRooms.add(room);
}
else{
for (User usr : room.getUsers()){
if(usr.getUserName().equals(user.getUserName())){
availableRooms.add(room);
}
}
}
}
return availableRooms;
}
@Override
public List<User> getClientsInChatRoom(String roomName) throws RemoteException {
for(Room room : chatRooms) {
if(room.getRoomName().equals(roomName)){
return room.getUsers();
}
}
return null; return null;
} }
@Override @Override
public void sendMessageToClient(String sender, String receiver, String message) throws RemoteException { public void sendMessageToClient(String sender, String receiver, String message) throws RemoteException {
List<User> users = new ArrayList<>();
if(messages == null){
messages = new ArrayList<>();
}
Message msg = new Message();
msg.setDetails(sender+" : "+message);
msg.setReceiver(receiver);
msg.setSender(sender);
messages.add(msg);
for (User usr : registeredUsers) {
if(usr.getUserName().equals(receiver) || usr.getUserName().equals(sender)){
users.add(usr);
}
}
List<User> deadUsers = new ArrayList<>(users.stream()
.filter(e -> {
try {
if(e.getClientChat() != null){
e.getClientChat().receiveMessage(message, sender);
return false;
}
else {
return true;
}
} catch (RemoteException ex) {
return true;
}
})
.collect(Collectors.toList()));
users.removeAll(deadUsers);
} }
@Override @Override
public void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException { public void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException {
Room rm = new Room();
for(Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
rm = room;
}
}
List<String> messages;
messages= rm.getMessages();
if(messages == null){
messages = new ArrayList<>();
}
messages.add(sender+" : "+message);
rm.setMessages(messages);
List<User> deadUsers = new ArrayList<>(rm.getLoggedInUsers().stream()
.filter(e -> {
try {
e.getClientChat().receiveMessage(message, sender);
return false;
} catch (RemoteException ex) {
return true;
}
})
.collect(Collectors.toList()));
rm.getLoggedInUsers().removeAll(deadUsers);
} }
@Override @Override
...@@ -197,4 +299,180 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac ...@@ -197,4 +299,180 @@ public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterfac
} }
return null; return null;
} }
@Override
public Room getRoomByName(String roomName) throws RemoteException {
for (Room room : chatRooms)
{
if(room.getRoomName().equals(roomName)){
return room;
}
}
return null;
}
@Override
public List<Message> getChatMessages(String senderName, String receiverName) throws RemoteException {
List<Message> messageList = new ArrayList<>();
if (messages != null) {
for (Message msg : messages) {
if ((msg.getReceiver().equals(receiverName) || msg.getReceiver().equals(senderName) )&& (msg.getSender().equals(senderName) || msg.getSender().equals(receiverName))) {
messageList.add(msg);
}
}
}
return messageList;
}
@Override
public Result addUserToRoom(String roomName, String userName, User owner) throws RemoteException {
System.out.println("roomname: "+roomName+"\n userName: "+userName+"\n owner "+owner.getUserName());
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
if(room.getOwner().getUserName().equals(owner.getUserName())){
System.out.println("1");
for(User usr : room.getUsers()){
if(usr.getUserName().equals(userName)){
System.out.println("1");
result.setDescription(userName+" already exist");
result.setSuccess(false);
return result;
}
}
System.out.println("3");
for(User user : registeredUsers){
if(user.getUserName().equals(userName)){
System.out.println("4");
room.getUsers().add(user);
result.setDescription(userName+" added successfully");
result.setSuccess(true);
return result;
}
}
System.out.println("5");
result.setDescription(userName+" not registered in the system");
result.setSuccess(false);
}
else{
System.out.println("6");
result.setDescription("Permission denied");
result.setSuccess(false);
}
return result;
}
}
result.setDescription("Room not found");
result.setSuccess(false);
return result;
}
@Override
public Result removeUserFromRoom(String roomName, String userName, User owner) throws RemoteException {
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
if(room.getOwner().getUserName().equals(owner.getUserName())){
for(User user : room.getUsers()){
if(user.getUserName().equals(userName)){
room.getUsers().remove(user);
result.setDescription(userName+" added successfully");
result.setSuccess(true);
return result;
}
}
result.setDescription(userName+" not found in this room");
result.setSuccess(false);
}
else{
result.setDescription("Permission denied");
result.setSuccess(false);
}
return result;
}
}
result.setDescription("Room not found");
result.setSuccess(false);
return result;
}
@Override
public void setClientChatInterfaceForUsers(IClientChat clientChat, String roomName, String userName) throws RemoteException {
for (Room rm : chatRooms) {
if (rm.getRoomName().equals(roomName)) {
for (User user : rm.getUsers()) {
if (user.getUserName().equals(userName)) {
user.setClientChat(clientChat);
System.out.println("1");
List<User> users = rm.getLoggedInUsers();
if (users == null) {
users = new ArrayList<>();
}
users.add(user);
rm.setLoggedInUsers(users);
System.out.println(users.get(0).getUserName());
System.out.println("2");
}
}
}
}
}
@Override
public void setClientChatInterfaceForUser(IClientChat clientChat, String user) throws RemoteException {
for (User usr : registeredUsers) {
if(usr.getUserName().equals(user)){
usr.setClientChat(clientChat);
}
}
}
@Override
public void setLoggedInUsersForRoom(String roomName, String user) throws RemoteException {
for (Room rm : chatRooms) {
if (rm.getRoomName().equals(roomName)) {
for(User usr: rm.getUsers()){
if(usr.getUserName().equals(user)){
rm.getLoggedInUsers().remove(usr);
break;
}
}
}
}
}
@Override
public Result logoutFromSystem(String userName) throws RemoteException {
Result result = new Result();
for (User user : loggedInUsers){
if(user.getUserName().equals(userName)){
loggedInUsers.remove(user);
result.setSuccess(true);
result.setDescription("logout done successfully");
return result;
}
}
result.setSuccess(false);
result.setDescription("user not found");
return result;
}
@Override
public List<User> getAllUsers(String userName) throws RemoteException {
List<User> users = new ArrayList<>();
for(User usr : registeredUsers){
if(!usr.getUserName().equals(userName)){
users.add(usr);
}
}
return users;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment