Skip to content
Snippets Groups Projects
Commit c35150cb authored by Pedroza Aguirre Isaac's avatar Pedroza Aguirre Isaac
Browse files

Solving conflicts with Max changes

parents 663ace1b 319c99e6
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<<<<<<< HEAD
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
=======
<component name="ProjectRootManager" version="2" languageLevel="JDK_12" default="false" project-jdk-name="12" project-jdk-type="JavaSDK">
>>>>>>> 319c99e690794f9fba4fc91d12c81e0115df012a
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
......@@ -5,7 +5,11 @@
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/GUI/ApplicationMain.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ApplicationMain.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/GUI/ChatScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ChatScreen.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/GUI/StartScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/StartScreen.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/Client.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/client/ClientUpdate.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/ClientUpdate.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/server/ChatController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/server/ChatController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/server/ClientController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/server/ClientController.java" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -122,7 +126,7 @@
<option name="presentableId" value="Default" />
<updated>1571631720382</updated>
<workItem from="1571631723795" duration="17601000" />
<workItem from="1571654347656" duration="23038000" />
<workItem from="1571654347656" duration="25114000" />
</task>
<task id="LOCAL-00001" summary="Changed the join method to send over a reference of the ClientUpdate Interface">
<created>1571646862883</created>
......
......@@ -28,36 +28,45 @@ public class ApplicationMain extends JPanel {
this.paintGUI = new PaintGUI(client);
}
public void createAndShowGUI() {
public void createAndShowGUI()
{
frame = new JFrame("Application Main");
JFrame.setDefaultLookAndFeelDecorated(true);
Container content = frame.getContentPane();
content.setLayout(new BorderLayout());
content.add(paintGUI.getGlobal(), BorderLayout.WEST);
content.add(chatScreen.panel2, BorderLayout.EAST);
chatScreen.setUserName(client.getUserName());
SwingUtilities.getRootPane(chatScreen.getSendButton()).setDefaultButton(chatScreen.getSendButton());
frame.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent arg0)
{
int answer = JOptionPane.showConfirmDialog(null,
int reply = JOptionPane.showConfirmDialog(null,
"Are you sure you want to quit the session?",
"Shut down session", JOptionPane.YES_NO_OPTION);
System.out.println(answer);
if (answer == 0)
if( reply == JOptionPane.YES_OPTION )
{
System.out.println("Quitting session");
try
{
client.getClientController().quit(client.getUserName());
}
catch (RemoteException e)
{
e.printStackTrace();
StartScreen.showErrorMessage("Error in quitting the server");
//e.printStackTrace();
}
System.exit(0);
}
if( reply == JOptionPane.NO_OPTION )
{
//do nothing
}
}
});
......@@ -68,5 +77,4 @@ public class ApplicationMain extends JPanel {
frame.pack();
frame.setVisible(true);
}
}
......@@ -39,18 +39,21 @@ public class ChatScreen {
public Client client;
public ChatScreen(Client client)
{
this.client = client;
yourNameDisplay.setText(client.getUserName());
exitThisRoomButton.addActionListener(actionListener);
quitButton.addActionListener(actionListener);
sendButton.addActionListener(actionListener);
kickOutButton.addActionListener(actionListener);
promoteToManagerButton.addActionListener(actionListener);
}
public void setUserName(String userName)
{
this.yourNameDisplay.setText(userName);
}
public JButton getSendButton() {
return sendButton;
......
......@@ -33,32 +33,42 @@ public class StartScreen {
{
if (e.getSource() == joinButton)
{
client.setServerAddress(textField2.getText());
client.setUsername(textField1.getText());
String serverAddress = textField2.getText();
String userName = textField1.getText();
if( client.connect() )
int connectionStatus = client.connect(userName, serverAddress);
if( connectionStatus == 1 )
{
frame.setVisible(false);
frame.dispose();
//client.doSomething();
new ChatScreen(client);
client.startApplication();
}
else if( connectionStatus == 2 )
{
showErrorMessage("Duplicate username: Please enter a new username");
}
else if( connectionStatus == 3 )
{
showErrorMessage("Cannot connect to server: Please check the server address");
}
else
{
showErrorMessage("Could not connect to server...");
showErrorMessage("Unknown Connection Status");
}
}
}
};
private void showErrorMessage(String message)
public static void showErrorMessage(String message)
{
JOptionPane.showMessageDialog(null,
message, "Error", JOptionPane.PLAIN_MESSAGE);
message, "Error", JOptionPane.ERROR_MESSAGE);
}
public void go(){
public void go()
{
joinButton.addActionListener(actionListener);
frame = new JFrame("StartScreen");
frame.setContentPane(panel1);
......
......@@ -14,6 +14,9 @@ import java.rmi.registry.Registry;
public class Client
{
private final String DEFAULT_USERNAME = "Anonymous";
private final String DEFAULT_SERVER_ADDRESS = "localhost";
private String userName;
private String serverAddress;
......@@ -28,9 +31,30 @@ public class Client
private StartScreen startScreen;
private PaintGUI paintGUI;
private ApplicationMain applicationMain;
public String getUserName()
{
return this.userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getServerAddress()
{
return serverAddress;
}
public void setServerAddress(String serverAddress)
{
this.serverAddress = serverAddress;
}
private ApplicationMain applicationMain;
public ApplicationMain getApplicationMain() { return applicationMain; }
public PaintGUI getPaintGUI() {
......@@ -53,21 +77,6 @@ public class Client
public IDrawingController getDrawingController() { return drawingController; }
public void setUsername(String userName)
{
this.userName = userName;
}
public String getUserName()
{
return this.userName;
}
public void setServerAddress(String serverAddress)
{
this.serverAddress = serverAddress;
}
public Client(String username) throws RemoteException
{
......@@ -75,6 +84,7 @@ public class Client
this.clientUpdate = new ClientUpdate(this);
this.chatUpdate = new ChatUpdate(this);
this.drawingUpdate = new DrawingUpdate(this);
this.startScreen = new StartScreen(this);
this.applicationMain = new ApplicationMain(this);
}
......@@ -83,40 +93,72 @@ public class Client
try
{
Client client = new Client(args[0]);
client.connect();
client.getApplicationMain().createAndShowGUI();
client.getChatScreen().setManagerToolsVisibility();
client.showStartScreen();
}
catch (Exception e)
{
e.printStackTrace();
StartScreen.showErrorMessage("Error starting up client");
}
}
public boolean connect()
public void showStartScreen()
{
startScreen.go();
}
public void startApplication()
{
applicationMain.createAndShowGUI();
applicationMain.getChatScreen().setManagerToolsVisibility();
}
// return = 1 -> connected successfully
// return = 2 -> duplicate username
// return = 3 -> error in locating the server
public int connect(String userName, String serverAddress)
{
if( !userName.trim().isEmpty() )
{
setUserName(userName);
}
userName = getUserName();
if( serverAddress.trim().isEmpty() )
{
serverAddress = DEFAULT_SERVER_ADDRESS;
setServerAddress(serverAddress);
}
setServerAddress(serverAddress);
try
{
System.out.println("Server address:" + serverAddress);
registryServer = LocateRegistry.getRegistry(serverAddress);
chatController = (IChatController) registryServer.lookup("ChatController");
clientController = (IClientController) registryServer.lookup("ClientController");
drawingController = (IDrawingController) registryServer.lookup("DrawingController");
System.out.println("User name:" + userName);
if( clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate) )
{
System.out.println("Connected to server");
return true;
return 1;
}
else
{
return 2;
}
}
catch (Exception e)
{
e.printStackTrace();
}
//e.printStackTrace();
return false;
return 3;
}
}
}
\ No newline at end of file
......@@ -18,19 +18,41 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate,
this.client = client;
}
public boolean notifyClient(String fromClient, String newUsername) throws RemoteException
{
client.getApplicationMain().getChatScreen().getSendMessageToComboBox().addItem(newUsername);
return true;
}
// for debuggins purposes
private void printUserList(String[] users)
{
System.out.print("Currently connected users: ");
for( String s : users )
{
System.out.print(s + " ");
}
System.out.println();
}
@Override
public boolean updateUserList(String[] users) throws RemoteException
{
//client.setConnectedUsers(users);
printUserList(users);
JComboBox userBox = client.getChatScreen().getSendMessageToComboBox();
System.out.println("TEST1");
JComboBox userBox = client.getApplicationMain().getChatScreen().getSendMessageToComboBox();
JComboBox kickUserBox = client.getChatScreen().getKickUserComboBox();
System.out.println("TEST2");
userBox.removeAllItems();
kickUserBox.removeAllItems();
System.out.println("TEST3");
userBox.addItem("All");
System.out.println("TEST4");
for( String s : users )
{
if( !s.equals(client.getUserName()) )
......
......@@ -21,12 +21,9 @@ public class ChatController extends UnicastRemoteObject implements IChatControll
{
System.out.print("Broadcasting message to everyone...");
IChatUpdate client;
for( User u : server.users )
{
client = u.getIChatUpdate();
client.notifyChat(fromClient, message, false);
u.getIChatUpdate().notifyChat(fromClient, message, false);
}
System.out.print("...DONE\n");
......
......@@ -22,6 +22,9 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
@Override
public boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException
{
if( getUserIndex(username) < 0 )
{
// user with same username is not connected
server.chatController.broadcastMessageUserLogin(username);
User newUser = new User(username, clientChat, clientUpdate, clientDrawing);
......@@ -30,7 +33,7 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
if(server.users.size() == 1)
{
server.users.get(0).setAdmin(true);
newUser.setAdmin(true);
}
System.out.println(username + " registered successfully");
......@@ -39,6 +42,11 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
return true;
}
else
{
return false;
}
}
@Override
public void quit(String username) throws RemoteException
......@@ -53,6 +61,19 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
broadcastUserList();
}
printUserList();
}
// for debuggins purposes
private void printUserList()
{
System.out.print("Currently connected users: ");
for( User u : server.users )
{
System.out.print(u.getUserName());
}
System.out.println();
}
@Override
......@@ -119,16 +140,20 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
public void broadcastUserList() throws RemoteException
{
String[] connectedUsers = new String[server.users.size()];
String[] connectedUsers = new String[server.users.size()];
for( int i = 0; i<server.users.size(); i++ )
{
connectedUsers[i] = server.users.get(i).getUserName();
}
printUserList();
for( User u : server.users )
{
System.out.print(u.getUserName() + " being notified");
u.getIClientUpdate().updateUserList(connectedUsers);
System.out.println("...DONE");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment