diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 78f9140fb9150b48bf0fed7e27e7ddc1d817a092..307e286aff2f5838348c13b603f7a8887d542f1c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,32 +2,17 @@ <project version="4"> <component name="ChangeListManager"> <list default="true" id="688d774d-cfc7-4b0d-b00c-5ca931aba600" name="Default Changelist" comment=""> - <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain$1.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ApplicationMain.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen$1.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/ChatScreen.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$1.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$Mode.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea$Mode.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/DrawingArea.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI$1.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/PaintGUI.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$1.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen$2.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/GUI/StartScreen.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/Client.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/Client.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate$1.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/ClientUpdate.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/client/DrawingUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/client/DrawingUpdate.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingController.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IDrawingUpdate.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ChatController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ChatController.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController$1.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/ClientController.class" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/server/DrawingController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/DrawingController.class" 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/StartScreen.form" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/StartScreen.form" 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" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="SHOW_DIALOG" value="false" /> @@ -39,20 +24,6 @@ <option name="testRunner" value="GRADLE" /> <option name="delegatedBuild" value="true" /> </component> - <component name="FindInProjectRecents"> - <findStrings> - <find>RMI</find> - <find>Black</find> - <find>colorOptions</find> - <find>Send</find> - <find>message</find> - <find>userSelectComboBox</find> - <find>updateUserList</find> - <find>send</find> - <find>broadcastMessage</find> - <find>sent</find> - </findStrings> - </component> <component name="Git.Settings"> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_BRANCH_BY_REPOSITORY"> diff --git a/out/production/infinitymonkeys/GUI/ApplicationMain$1.class b/out/production/infinitymonkeys/GUI/ApplicationMain$1.class index b1187184a7d1df0393b5425a90f5fec5ae5752c4..9da93fe0fd73725e577d5b9ba69a3176d358c79e 100644 Binary files a/out/production/infinitymonkeys/GUI/ApplicationMain$1.class and b/out/production/infinitymonkeys/GUI/ApplicationMain$1.class differ diff --git a/out/production/infinitymonkeys/GUI/ApplicationMain.class b/out/production/infinitymonkeys/GUI/ApplicationMain.class index 8d3bcf45652a542e4c792856d549a3c58e7915e7..1bf2fdcad9c9b55e317a65ae344460242967937c 100644 Binary files a/out/production/infinitymonkeys/GUI/ApplicationMain.class and b/out/production/infinitymonkeys/GUI/ApplicationMain.class differ diff --git a/out/production/infinitymonkeys/GUI/ChatScreen$1.class b/out/production/infinitymonkeys/GUI/ChatScreen$1.class index 0ccd94a6c9cf6ed21c140b999fcac6194e1b59c8..07f8ee41c99d3c6317448f4b363d6dad253fe0b1 100644 Binary files a/out/production/infinitymonkeys/GUI/ChatScreen$1.class and b/out/production/infinitymonkeys/GUI/ChatScreen$1.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen$2.class b/out/production/infinitymonkeys/GUI/StartScreen$2.class index d63c24176f2741b53b0d72388fafc5890ae9cdba..74f7a1f37aaa51d21871b6e1451170f89f8a8321 100644 Binary files a/out/production/infinitymonkeys/GUI/StartScreen$2.class and b/out/production/infinitymonkeys/GUI/StartScreen$2.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen.class b/out/production/infinitymonkeys/GUI/StartScreen.class index 8d5fb0f0d4f8e88d6b689cd43333c99d91cde9aa..a4214e9bb0dfb7117a8ca674a28ce3af7da6bfe8 100644 Binary files a/out/production/infinitymonkeys/GUI/StartScreen.class and b/out/production/infinitymonkeys/GUI/StartScreen.class differ diff --git a/out/production/infinitymonkeys/client/Client.class b/out/production/infinitymonkeys/client/Client.class index 01942ac35f8d2e1bc20af17f188c1e8561b4718c..880fad11de6ed664c25e794417fd4a85cf09d5d8 100644 Binary files a/out/production/infinitymonkeys/client/Client.class and b/out/production/infinitymonkeys/client/Client.class differ diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java index 2e6823a7ddf65b173a760f480840065b8152a812..0c3cc617d3f690afdb3a5641f0b88a870b5fea80 100644 --- a/src/GUI/ApplicationMain.java +++ b/src/GUI/ApplicationMain.java @@ -15,7 +15,7 @@ public class ApplicationMain extends JPanel { private Client client; private ChatScreen chatScreen; private PaintGUI paintGUI; - private JFrame frame; + JFrame frame; public ChatScreen getChatScreen() { return chatScreen; } @@ -110,52 +110,7 @@ public class ApplicationMain extends JPanel { @Override public void windowClosing(WindowEvent arg0) { - - try { - if (client.getUserName().equals(client.getClientController().getAdmin())) { - - int terminateAppAnswer = showManagerQuitMessage(); - // If the manager terminates the application - if (terminateAppAnswer == 0) { - client.getClientController().kickAll(client.getUserName()); - exitApplication(); - } - else if (terminateAppAnswer == 1) { - int answer = showNextManagerMessage(); - // If the manager wants to assign the next manager manually - if (answer == 0) { - String newManager = showAssignManagerMessage(); - client.getClientController().assignAdmin(client.getUserName(), newManager); - client.getClientController().quit(client.getUserName()); - exitApplication(); - } - // If the manager wants to assign the next manager by random choice - if (answer == 1) { - int numUsers = client.getChatScreen().getKickUserComboBox().getItemCount(); - Random random = new Random(); - int randomUserIndex = random.nextInt(numUsers); - String newManager = client.getChatScreen().getKickUserComboBox().getItemAt(randomUserIndex).toString(); - client.getClientController().assignAdmin(client.getUserName(), newManager); - client.getClientController().quit(client.getUserName()); - exitApplication(); - } - } - - } - else { - int reply = JOptionPane.showConfirmDialog(null, - "Are you sure you want to quit the session?", - "Shut down session", JOptionPane.YES_NO_OPTION); - if( reply == 0 ) - { - client.getClientController().quit(client.getUserName()); - exitApplication(); - } - } - } catch (RemoteException e) { - e.printStackTrace(); - } - + closeWindow(); } }); @@ -171,7 +126,6 @@ public class ApplicationMain extends JPanel { public void exitApplication(){ System.out.println("I am in exit application"); frame.setVisible(false); - frame.dispose(); client.setVisibleStartScreen(); } @@ -179,4 +133,52 @@ public class ApplicationMain extends JPanel { frame.setVisible(true); chatScreen.setUserName(client.getUserName()); } + + public void closeWindow() { + try { + if (client.getUserName().equals(client.getClientController().getAdmin())) { + + int terminateAppAnswer = showManagerQuitMessage(); + // If the manager terminates the application + if (terminateAppAnswer == 0) { + client.getClientController().kickAll(client.getUserName()); + exitApplication(); + } + else if (terminateAppAnswer == 1) { + int answer = showNextManagerMessage(); + // If the manager wants to assign the next manager manually + if (answer == 0) { + String newManager = showAssignManagerMessage(); + client.getClientController().assignAdmin(client.getUserName(), newManager); + client.getClientController().quit(client.getUserName()); + exitApplication(); + } + // If the manager wants to assign the next manager by random choice + if (answer == 1) { + int numUsers = client.getChatScreen().getKickUserComboBox().getItemCount(); + Random random = new Random(); + int randomUserIndex = random.nextInt(numUsers); + String newManager = client.getChatScreen().getKickUserComboBox().getItemAt(randomUserIndex).toString(); + client.getClientController().assignAdmin(client.getUserName(), newManager); + client.getClientController().quit(client.getUserName()); + exitApplication(); + } + } + + } + else { + int reply = JOptionPane.showConfirmDialog(null, + "Are you sure you want to quit the session?", + "Shut down session", JOptionPane.YES_NO_OPTION); + if( reply == 0 ) + { + client.getClientController().quit(client.getUserName()); + exitApplication(); + } + } + } catch (RemoteException e) { + e.printStackTrace(); + } + } + } diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index 6e86ccf552a8c42e06d51889dcf9916c71b51407..0e228cc9c8d9db51630e17fedd50d71219e9dee2 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -124,21 +124,11 @@ public class ChatScreen { } else if (e.getSource() == exitThisRoomButton) { - IClientController clientController = client.getClientController(); - try - { - System.out.println("Exit room button pressed"); - clientController.quit(client.getUserName()); - exitChatScreen(); - } - catch (RemoteException ex) - { - ex.printStackTrace(); - } + System.out.println("Exit room button pressed by: " + client.getUserName()); + client.getApplicationMain().closeWindow(); } else if (e.getSource() == kickOutButton) { - IClientController clientController = client.getClientController(); String toUser = kickUserComboBox.getSelectedItem().toString(); diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 6b6a4b53bfb7466916b97ed4f06073b92d3c927c..39a230fc4a45884c48c9c9696bc4de021b1a8e6c 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -111,9 +111,8 @@ public class StartScreen { //frame.getContentPane().add(new JPanelWithBackground("sample.jpeg")); frame.setVisible(true); - frame.addWindowListener(new WindowAdapter() { - @Override - public void windowOpened(WindowEvent e) { + frame.addComponentListener(new ComponentAdapter() { + public void componentShown(ComponentEvent e) { if (isAppTerminated()){ showKickAllMessage(); setAppTerminated(false); diff --git a/src/client/Client.java b/src/client/Client.java index a241d3301ac316466caf8ef33262d6f07ac28a1f..a4b16f54b01d7eb1c55652db21eff3d176a0ba9c 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -120,7 +120,6 @@ public class Client startScreen.setVisible(); } - public void startApplication() { applicationMain.createAndShowGUI();