diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 307e286aff2f5838348c13b603f7a8887d542f1c..cd073818600ff16ecd032ff184098891b457be37 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,13 +6,32 @@ <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/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/remote/IClientController$Action.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientController$Action.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientController.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientController.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate$Action.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate$Action.class" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/remote/IClientUpdate.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/Server.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/infinitymonkeys/server/Server.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/ChatScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/ChatScreen.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/GUI/PaintGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/PaintGUI.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/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/remote/IClientController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/remote/IClientController.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/remote/IClientUpdate.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/remote/IClientUpdate.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/server/ClientController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/server/ClientController.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/server/Server.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/server/Server.java" afterDir="false" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="SHOW_DIALOG" value="false" /> @@ -24,6 +43,13 @@ <option name="testRunner" value="GRADLE" /> <option name="delegatedBuild" value="true" /> </component> + <component name="FileTemplateManagerImpl"> + <option name="RECENT_TEMPLATES"> + <list> + <option value="Class" /> + </list> + </option> + </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 9da93fe0fd73725e577d5b9ba69a3176d358c79e..fcdc48602cd2ed6ab5078d1bea4bbab1255dd03a 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 1bf2fdcad9c9b55e317a65ae344460242967937c..b19dc9d9b2eada94e9f2c8851184354cf191d3c1 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 07f8ee41c99d3c6317448f4b363d6dad253fe0b1..790e81e667f103031c8e45d78f22ffb1d5ee5de7 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/ChatScreen.class b/out/production/infinitymonkeys/GUI/ChatScreen.class index 46d8367ae972f7677755c399620f7213700f8aaf..24e02855f9471b8d068e3d2a0c3f59575a2cf3ac 100644 Binary files a/out/production/infinitymonkeys/GUI/ChatScreen.class and b/out/production/infinitymonkeys/GUI/ChatScreen.class differ diff --git a/out/production/infinitymonkeys/GUI/PaintGUI.class b/out/production/infinitymonkeys/GUI/PaintGUI.class index 2f6725da139d32563c716118e1249fad9798d7cc..67b2337d0fbc2a6ad287527d86196b8f5d27c0c3 100644 Binary files a/out/production/infinitymonkeys/GUI/PaintGUI.class and b/out/production/infinitymonkeys/GUI/PaintGUI.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen$1.class b/out/production/infinitymonkeys/GUI/StartScreen$1.class index 3e4336e2780d89088da9bfcd22e775729e478fc0..ce43dd31418e8591774c3831e2576d713e707fab 100644 Binary files a/out/production/infinitymonkeys/GUI/StartScreen$1.class and b/out/production/infinitymonkeys/GUI/StartScreen$1.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen$2.class b/out/production/infinitymonkeys/GUI/StartScreen$2.class index 74f7a1f37aaa51d21871b6e1451170f89f8a8321..990bec20e03310c91bf7b97debdded2d1dd03c30 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$3.class b/out/production/infinitymonkeys/GUI/StartScreen$3.class new file mode 100644 index 0000000000000000000000000000000000000000..0be661b8057c888f890e19e6ae5c15ce9e7041b1 Binary files /dev/null and b/out/production/infinitymonkeys/GUI/StartScreen$3.class differ diff --git a/out/production/infinitymonkeys/GUI/StartScreen.class b/out/production/infinitymonkeys/GUI/StartScreen.class index a4214e9bb0dfb7117a8ca674a28ce3af7da6bfe8..dbf9f6b974b0d0fde53e901f7cd0980230de39a8 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 880fad11de6ed664c25e794417fd4a85cf09d5d8..7b171c082450f039a3cd482cbc0d730563997f5f 100644 Binary files a/out/production/infinitymonkeys/client/Client.class and b/out/production/infinitymonkeys/client/Client.class differ diff --git a/out/production/infinitymonkeys/client/ClientUpdate$1.class b/out/production/infinitymonkeys/client/ClientUpdate$1.class index 9f508e3770770bb0b90f6d8bc7cdc965e9ad66a5..4bcf9636a6fb854dde6e263d81fc41f259703c55 100644 Binary files a/out/production/infinitymonkeys/client/ClientUpdate$1.class and b/out/production/infinitymonkeys/client/ClientUpdate$1.class differ diff --git a/out/production/infinitymonkeys/client/ClientUpdate.class b/out/production/infinitymonkeys/client/ClientUpdate.class index c82484b525905baada51fc5778f3b5c6b9e7ccc4..1554fe715b5103907147acd114f82a60bd60cdcc 100644 Binary files a/out/production/infinitymonkeys/client/ClientUpdate.class and b/out/production/infinitymonkeys/client/ClientUpdate.class differ diff --git a/out/production/infinitymonkeys/remote/IClientController$Action.class b/out/production/infinitymonkeys/remote/IClientController$Action.class index b4c2cef704873af62401e4a1eb634a818a4d812d..035ddf1381adff501a6e806d89ed427882488ad0 100644 Binary files a/out/production/infinitymonkeys/remote/IClientController$Action.class and b/out/production/infinitymonkeys/remote/IClientController$Action.class differ diff --git a/out/production/infinitymonkeys/remote/IClientController.class b/out/production/infinitymonkeys/remote/IClientController.class index f0570f208a2b61645357e61733a8760bb450a683..ab5e065a224484d13368745498a84b2720abdb90 100644 Binary files a/out/production/infinitymonkeys/remote/IClientController.class and b/out/production/infinitymonkeys/remote/IClientController.class differ diff --git a/out/production/infinitymonkeys/remote/IClientUpdate$Action.class b/out/production/infinitymonkeys/remote/IClientUpdate$Action.class index dd382481d4ab540e1f2e62b16ff37ddabd2cb284..45c78af26c807b84f2065b100c89470d2f837048 100644 Binary files a/out/production/infinitymonkeys/remote/IClientUpdate$Action.class and b/out/production/infinitymonkeys/remote/IClientUpdate$Action.class differ diff --git a/out/production/infinitymonkeys/remote/IClientUpdate.class b/out/production/infinitymonkeys/remote/IClientUpdate.class index 7d8923621a39f42b6628c674a2a110f8b54dd03d..cf1adf4c123b7ac99404efbeece8fb67c6d819de 100644 Binary files a/out/production/infinitymonkeys/remote/IClientUpdate.class and b/out/production/infinitymonkeys/remote/IClientUpdate.class differ diff --git a/out/production/infinitymonkeys/server/ClientController$1.class b/out/production/infinitymonkeys/server/ClientController$1.class index cb6060440a9f351d1a83801bacf34cb7966f7940..35d99027b635a76211ddf6ed9731e0785e4ac005 100644 Binary files a/out/production/infinitymonkeys/server/ClientController$1.class and b/out/production/infinitymonkeys/server/ClientController$1.class differ diff --git a/out/production/infinitymonkeys/server/ClientController.class b/out/production/infinitymonkeys/server/ClientController.class index 67913932995b7befd2ca552d73cee8caf7a6d463..1323063bdd741b05765fdf485cffca7210e6d2a6 100644 Binary files a/out/production/infinitymonkeys/server/ClientController.class and b/out/production/infinitymonkeys/server/ClientController.class differ diff --git a/out/production/infinitymonkeys/server/Server.class b/out/production/infinitymonkeys/server/Server.class index adabadce0f0b08ff96e1e31afdb03dd14a91cb01..8884fc35671e4085f5b8100ebd585fa634eb19f0 100644 Binary files a/out/production/infinitymonkeys/server/Server.class and b/out/production/infinitymonkeys/server/Server.class differ diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java index 0c3cc617d3f690afdb3a5641f0b88a870b5fea80..0d13b9b72e81728f5e07a27b805a4e358b33f142 100644 --- a/src/GUI/ApplicationMain.java +++ b/src/GUI/ApplicationMain.java @@ -39,8 +39,7 @@ public class ApplicationMain extends JPanel { return answer; } - public String showAssignManagerMessage() { - int numUsers = client.getChatScreen().getKickUserComboBox().getItemCount(); + public String showAssignManagerMessage(int numUsers) { String[] userOptions = new String[numUsers]; for (int i = 0; i < numUsers; i++) { userOptions[i] = client.getChatScreen().getKickUserComboBox().getItemAt(i).toString(); @@ -124,7 +123,6 @@ public class ApplicationMain extends JPanel { } public void exitApplication(){ - System.out.println("I am in exit application"); frame.setVisible(false); client.setVisibleStartScreen(); } @@ -136,8 +134,8 @@ public class ApplicationMain extends JPanel { public void closeWindow() { try { - if (client.getUserName().equals(client.getClientController().getAdmin())) { - + int numUsers = client.getChatScreen().getKickUserComboBox().getItemCount(); + if (client.getUserName().equals(client.getClientController().getAdmin()) && numUsers > 0) { int terminateAppAnswer = showManagerQuitMessage(); // If the manager terminates the application if (terminateAppAnswer == 0) { @@ -148,14 +146,13 @@ public class ApplicationMain extends JPanel { int answer = showNextManagerMessage(); // If the manager wants to assign the next manager manually if (answer == 0) { - String newManager = showAssignManagerMessage(); + String newManager = showAssignManagerMessage(numUsers); 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(); @@ -164,14 +161,12 @@ public class ApplicationMain extends JPanel { 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 ) - { + if (reply == 0) { client.getClientController().quit(client.getUserName()); exitApplication(); } diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index 0e228cc9c8d9db51630e17fedd50d71219e9dee2..bae244257a3e5fbd5646fbd37aed6af3f200d62b 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -79,10 +79,18 @@ public class ChatScreen { public void setManagerToolsVisibility() { try { if (client.getClientController().getAdmin().equals(client.getUserName())){ - managersPanel.setVisible(true); + managersPanel.setEnabled(true); + kickUserComboBox.setEnabled(true); + kickOutButton.setEnabled(true); + promoteToManagerButton.setEnabled(true); + client.getApplicationMain().getPaintGUI().enableFileControl(); } else { - managersPanel.setVisible(false); + managersPanel.setEnabled(false); + kickUserComboBox.setEnabled(false); + kickOutButton.setEnabled(false); + promoteToManagerButton.setEnabled(false); + client.getApplicationMain().getPaintGUI().disableFileControl(); } } catch (RemoteException e) { e.printStackTrace(); diff --git a/src/GUI/PaintGUI.java b/src/GUI/PaintGUI.java index 7f8e024d960bfaa3001f404bdae4ee55288b7ed0..2fc328d3b627b847d3d0262c55fd11bfe9666d6e 100644 --- a/src/GUI/PaintGUI.java +++ b/src/GUI/PaintGUI.java @@ -414,4 +414,18 @@ public class PaintGUI extends JPanel { drawingArea.setModeText(textString, size); } + public void disableFileControl() { + newBtn.setEnabled(false); + openBtn.setEnabled(false); + saveBtn.setEnabled(false); + saveAsBtn.setEnabled(false); + } + + public void enableFileControl() { + newBtn.setEnabled(true); + openBtn.setEnabled(true); + saveBtn.setEnabled(true); + saveAsBtn.setEnabled(true); + } + } \ No newline at end of file diff --git a/src/GUI/StartScreen.form b/src/GUI/StartScreen.form index f348817e1243275dfd3dd145b7bc1983957c0624..c6bb9dc4eec1db5e8c1867f31a1ed3d089b864e1 100644 --- a/src/GUI/StartScreen.form +++ b/src/GUI/StartScreen.form @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.StartScreen"> - <grid id="27dc6" binding="panel1" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" 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="833" height="400"/> + <xy x="20" y="20" width="833" height="417"/> </constraints> <properties/> <border type="none"/> <children> - <grid id="abaca" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="abaca" binding="titlePanel" layout-manager="GridLayoutManager" row-count="3" 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> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"> @@ -29,33 +29,33 @@ </constraints> <properties> <font name="Apple SD Gothic Neo" size="20"/> - <text value="Distributed Whiteboard App"/> + <text value="Shared Whiteboard App"/> </properties> </component> <component id="e3c91" class="javax.swing.JTextPane" binding="information"> <constraints> - <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"> <preferred-size width="150" height="70"/> </grid> </constraints> <properties> <editable value="false"/> - <text value="Please provide your username and password, as well as server's IP to start."/> + <text value="Please provide your username and password, as well as server's IP to join."/> </properties> </component> </children> </grid> - <grid id="790e1" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="790e1" binding="joinButtonPanel" 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> - <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> <children> <component id="ea0c1" class="javax.swing.JButton" binding="joinButton"> <constraints> - <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> <text value="JOIN WHITEBOARD"/> @@ -63,10 +63,10 @@ </component> </children> </grid> - <grid id="6ef31" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="6ef31" binding="logInPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties> <name value=""/> @@ -133,6 +133,35 @@ </component> </children> </grid> + <grid id="a1249" binding="waitingPanel" 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"/> + <constraints> + <grid row="1" 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> + <visible value="false"/> + </properties> + <border type="none"/> + <children> + <vspacer id="b85ee"> + <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="3a3ef" class="javax.swing.JTextPane"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="70"/> + </grid> + </constraints> + <properties> + <editable value="false"/> + <text value="Waiting for manager's approval ..."/> + <visible value="true"/> + </properties> + </component> + </children> + </grid> </children> </grid> </form> diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 39a230fc4a45884c48c9c9696bc4de021b1a8e6c..914b944282084a1fcf8af96b298b90aeae63b0e3 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -2,20 +2,18 @@ package GUI; import client.Client; -import javax.imageio.ImageIO; import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import java.awt.event.*; -import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; public class StartScreen { private JTextPane information; - private JPanel panel1; + private JPanel mainPanel; private JTextField usernameField; private JButton joinButton; @@ -26,6 +24,11 @@ public class StartScreen { private JTextField serverField; private JTextField textField3; private JPasswordField passwordField; + private JPanel logInPanel; + private JPanel joinButtonPanel; + private JPanel titlePanel; + private JPanel waitingPanel; + private ButtonModel joinButtonModel = joinButton.getModel(); JFrame frame; @@ -36,6 +39,20 @@ public class StartScreen { this.client = client; } + ChangeListener changeListener = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if (joinButtonModel.isPressed()){ + waitingPanel.setVisible(true); + logInPanel.setVisible(false); + } + else { + waitingPanel.setVisible(false); + logInPanel.setVisible(true); + } + } + }; + ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) @@ -48,7 +65,7 @@ public class StartScreen { int connectionStatus = client.connect(userName, serverAddress, password); - if( connectionStatus == 1 ) + if( connectionStatus == 0 ) { frame.setVisible(false); frame.dispose(); @@ -60,11 +77,14 @@ public class StartScreen { client.clearDrawingArea(); client.setVisibleApplication(); } - } - else if( connectionStatus == 2 || connectionStatus == 6 ) + else if( connectionStatus == 1 || connectionStatus == 6) + { + showErrorMessage("The manager rejected your join request"); + } + else if( connectionStatus == 2 || connectionStatus == 7 ) { - showErrorMessage("Duplicate usernameField: Please enter a new usernameField"); + showErrorMessage("Duplicate username: Please enter a different username"); } else if( connectionStatus == 3 ) { @@ -90,18 +110,18 @@ public class StartScreen { }; - public static void showErrorMessage(String message) { JOptionPane.showMessageDialog(null, - message, "Error", JOptionPane.ERROR_MESSAGE); + message, "Error", JOptionPane.ERROR_MESSAGE); } public void go() { joinButton.addActionListener(actionListener); + joinButtonModel.addChangeListener(changeListener); frame = new JFrame("StartScreen"); - frame.setContentPane(panel1); + frame.setContentPane(mainPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); diff --git a/src/client/Client.java b/src/client/Client.java index a4b16f54b01d7eb1c55652db21eff3d176a0ba9c..98776a725a87a9e0e6481ba69c7e1a9053a56e6c 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -157,15 +157,8 @@ public class Client if( clientController.checkPassword(password) ) { - if (clientController.join(getUserName(), this.chatUpdate, this.clientUpdate, this.drawingUpdate, this.encryptionUpdate)) - { - System.out.println("Connected to server"); - return 5; - } - else - { - return 6; - } + int joinStatus = clientController.join(getUserName(), this.chatUpdate, this.clientUpdate, this.drawingUpdate); + return joinStatus + 5; } else { @@ -188,15 +181,8 @@ public class Client if( clientController.checkPassword(password) ) { - if (clientController.join(getUserName(), this.chatUpdate, this.clientUpdate, this.drawingUpdate, this.encryptionUpdate)) - { - System.out.println("Connected to server"); - return 1; - } - else - { - return 2; - } + int joinStatus = clientController.join(getUserName(), this.chatUpdate, this.clientUpdate, this.drawingUpdate); + return joinStatus; } else { diff --git a/src/client/ClientUpdate.java b/src/client/ClientUpdate.java index 860a34b829d1685b3150a8394c9137e14b61eeb5..1e5389a054f6e48ff5860df8efd68a5f1f03c990 100644 --- a/src/client/ClientUpdate.java +++ b/src/client/ClientUpdate.java @@ -80,7 +80,8 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate, } @Override - public void notifyManagerActions(String toClient, Action action) throws RemoteException { + public int notifyManagerActions(String toClient, Action action) throws RemoteException { + int answer = -1; switch (action) { case KICKOUT: client.getChatScreen().getChatDisplayBox().append(toClient + " has been kicked out by the manager.\n"); @@ -91,6 +92,16 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate, case KICKALL: client.getStartScreen().setAppTerminated(true); client.getApplicationMain().exitApplication(); + break; + case JOINAPPROVAL: + if (client.getUserName().equals(client.getClientController().getAdmin())) { + answer = JOptionPane.showConfirmDialog(null, + "The user: " + toClient + " wants to join to your whiteboard, do you want to accept?", + "Join request", JOptionPane.YES_NO_OPTION); + } + break; } + return answer; } + } diff --git a/src/remote/IClientController.java b/src/remote/IClientController.java index a8b583f54c6e13d9bf60c7450dab34118ae8045b..ca006a90b1a83ff2e45f39a2e74cd46d34e7d055 100644 --- a/src/remote/IClientController.java +++ b/src/remote/IClientController.java @@ -5,9 +5,9 @@ import java.rmi.RemoteException; public interface IClientController extends Remote { - enum Action {KICKOUT, ASSIGNADMIN, KICKALL}; + enum Action {KICKOUT, ASSIGNADMIN}; - boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing, IEncryptionUpdate encryptionUpdate) throws RemoteException; + int join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException; void quit(String username) throws RemoteException; @@ -22,4 +22,7 @@ public interface IClientController extends Remote String getAdmin() throws RemoteException; boolean checkPassword(String password) throws RemoteException; + + void removeFromWaitingList(String username) throws RemoteException; + } diff --git a/src/remote/IClientUpdate.java b/src/remote/IClientUpdate.java index 3788bd2810f5cf17dd822be3dc4a45f2b308ca4e..0f818fb80ae5664b6b0312ad30a83dd18f515c58 100644 --- a/src/remote/IClientUpdate.java +++ b/src/remote/IClientUpdate.java @@ -6,10 +6,10 @@ import java.rmi.RemoteException; public interface IClientUpdate extends Remote, Serializable { - enum Action {KICKOUT, ASSIGNADMIN, KICKALL}; + enum Action {KICKOUT, ASSIGNADMIN, KICKALL, JOINAPPROVAL}; boolean updateUserList(String[] users) throws RemoteException; void terminateChat() throws RemoteException; - void notifyManagerActions(String toClient, Action action) throws RemoteException; + int notifyManagerActions(String toClient, Action action) throws RemoteException; void setVisibility() throws RemoteException; } diff --git a/src/server/ClientController.java b/src/server/ClientController.java index 6ff46e6e94e5dc7a6cc1d986ced4ff7866e9181f..14627722ee38d2be30f0bcbddc0d0137fe33a0fc 100644 --- a/src/server/ClientController.java +++ b/src/server/ClientController.java @@ -17,34 +17,56 @@ public class ClientController extends UnicastRemoteObject implements IClientCont } @Override - public boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing, IEncryptionUpdate encryptionUpdate) throws RemoteException + public int join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException { - System.out.println("I am in join"); - if( getUserIndex(username) < 0 ) - { - // user with same username is not connected - server.chatController.broadcastMessageUserLogin(username); - - new MySharedKey(encryptionUpdate); - + // If there is no user in the list then let the user be the manager + if(server.users.size() == 0) { User newUser = new User(username, clientChat, clientUpdate, clientDrawing); - server.users.add(newUser); - - if(server.users.size() == 1) - { - newUser.setAdmin(true); + newUser.setAdmin(true); + broadcastUserList(); + clientUpdate.setVisibility(); + return 0; + } + // If there are users in the user list, then check if the username is used + else if (getUserIndex(username) < 0 ) { + // Ask the manager for the join approval + int managerIndex = getUserIndex(getAdmin()); + User manager = server.users.get(managerIndex); + IClientUpdate client; + client = manager.getIClientUpdate(); + int answer = client.notifyManagerActions(username, IClientUpdate.Action.JOINAPPROVAL); + + // If the manager accepts the new user to enter, then add the user to the list + if (answer == 0) { + server.chatController.broadcastMessageUserLogin(username); + User newUser = new User(username, clientChat, clientUpdate, clientDrawing); + server.users.add(newUser); + broadcastUserList(); + return 0; } + else { + return 1; + } + } + else { + return 2; + } - System.out.println(username + " registered successfully"); - - broadcastUserList(); + } - return true; + @Override + public void removeFromWaitingList(String username) throws RemoteException { + int userIndex = -1; + for( int i = 0; i < server.waitingList.size(); i++ ) { + if (server.waitingList.get(i).getUserName().equals(username)) { + userIndex = i; + break; + } } - else + if( userIndex >= 0 ) { - return false; + server.waitingList.remove(userIndex); } } @@ -206,11 +228,13 @@ public class ClientController extends UnicastRemoteObject implements IClientCont int adminIndex = getUserIndex(manager); IClientUpdate client; String toClient; + String[] connectedUsers = {}; if (server.users.get(adminIndex).isAdmin()) { for (User u : server.users) { client = u.getIClientUpdate(); toClient = u.getUserName(); + client.updateUserList(connectedUsers); client.notifyManagerActions(toClient, remote.IClientUpdate.Action.KICKALL); } server.users.clear(); diff --git a/src/server/Server.java b/src/server/Server.java index 5a9b983141a46f1dd5fd60d0076f0e733aadff47..3c87547eb432efd1ece33613e411299c4df13e07 100644 --- a/src/server/Server.java +++ b/src/server/Server.java @@ -18,6 +18,7 @@ import java.util.ArrayList; public class Server { protected ArrayList<User> users; + protected ArrayList<User> waitingList; protected ClientController clientController; protected ChatController chatController; @@ -29,6 +30,7 @@ public class Server { password = null; users = new ArrayList<User>(); + waitingList = new ArrayList<User>(); clientController = new ClientController(this); chatController = new ChatController(this); drawingController = new DrawingController(this);