diff --git a/src/GUI/MenuBar.java b/src/GUI/MenuBar.java deleted file mode 100644 index b466e4b9cbe917d1c2acd97dee35ef4d995acfd8..0000000000000000000000000000000000000000 --- a/src/GUI/MenuBar.java +++ /dev/null @@ -1,7 +0,0 @@ -package GUI; - -import javax.swing.*; - -public class MenuBar extends JMenuBar { - JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn; -} diff --git a/src/GUI/StartScreen.form b/src/GUI/StartScreen.form index f266275f5779005b91d96dc1a9134323e557dfdb..a6eacb755c0f906ce615768a12eb2fb64b8fbcb2 100644 --- a/src/GUI/StartScreen.form +++ b/src/GUI/StartScreen.form @@ -11,10 +11,12 @@ <grid id="abaca" 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="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <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"> + <preferred-size width="100" height="70"/> + </grid> </constraints> <properties/> - <border type="none"/> + <border type="none" title=" "/> <children> <hspacer id="53fe0"> <constraints> @@ -23,52 +25,37 @@ </hspacer> <component id="ebca9" class="javax.swing.JLabel"> <constraints> - <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> + <font name="Apple SD Gothic Neo" size="20"/> <text value="Distributed Whiteboard App"/> </properties> </component> - <component id="d60e2" class="javax.swing.JTextArea" binding="information"> + <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"> - <preferred-size width="150" height="50"/> + <preferred-size width="150" height="70"/> </grid> </constraints> <properties> <editable value="false"/> - <text value="Welcome, please provide server's IP to connect to and nameto be identified by in the Whiteboard's chat."/> + <text value="Welcome to Distributed Whiteboard. Please provide server's IP, username, and password."/> </properties> </component> </children> </grid> - <grid id="790e1" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="790e1" 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="3" 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/> <border type="none"/> <children> - <component id="87b91" class="javax.swing.JLabel"> - <constraints> - <grid row="0" 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> - <text value="Your name:"/> - </properties> - </component> - <component id="e39f4" class="javax.swing.JTextField" binding="textField1" default-binding="true"> - <constraints> - <grid row="1" column="0" 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="ea0c1" class="javax.swing.JButton" binding="joinButton"> <constraints> - <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" 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="1" indent="0" use-parent-layout="false"/> </constraints> <properties> <text value="JOIN WHITEBOARD"/> @@ -76,22 +63,20 @@ </component> </children> </grid> - <grid id="6ef31" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="6ef31" 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="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <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"/> </constraints> - <properties/> - <border type="none"/> + <properties> + <name value=""/> + <requestFocusEnabled value="false"/> + </properties> + <border type="none" title=" "/> <children> - <hspacer id="23c9f"> - <constraints> - <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> - </constraints> - </hspacer> <component id="94078" class="javax.swing.JLabel"> <constraints> - <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> <text value="Server IP:"/> @@ -99,7 +84,7 @@ </component> <component id="63209" class="javax.swing.JTextField" binding="textField2"> <constraints> - <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <grid row="1" column="0" 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> @@ -107,6 +92,45 @@ <text value=""/> </properties> </component> + <vspacer id="bb71b"> + <constraints> + <grid row="0" column="2" 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="87b91" class="javax.swing.JLabel"> + <constraints> + <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Your name:"/> + </properties> + </component> + <component id="e39f4" class="javax.swing.JTextField" binding="textField1" default-binding="true"> + <constraints> + <grid row="1" column="3" 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="51d9f" class="javax.swing.JPasswordField" binding="passwordField"> + <constraints> + <grid row="3" column="0" 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> + <columns value="20"/> + </properties> + </component> + <component id="62e48" class="javax.swing.JLabel"> + <constraints> + <grid row="2" 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> + <text value="Password:"/> + </properties> + </component> </children> </grid> </children> diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 10ae2adbd8c2b4b5a47b8974c2eec8ab072b57be..70ac2f2e3dc766e42e22451279d9ea89a42fa30b 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -8,11 +8,13 @@ import java.awt.event.ActionListener; public class StartScreen { + private JTextPane information; private JPanel panel1; - private JTextArea information; private JTextField textField1; private JButton joinButton; private JTextField textField2; + private JTextField textField3; + private JPasswordField passwordField; JFrame frame; private Client client; @@ -35,8 +37,9 @@ public class StartScreen { { String serverAddress = textField2.getText(); String userName = textField1.getText(); + String password = new String(passwordField.getPassword()); - int connectionStatus = client.connect(userName, serverAddress); + int connectionStatus = client.connect(userName, serverAddress, password); if( connectionStatus == 1 ) { @@ -52,6 +55,10 @@ public class StartScreen { { showErrorMessage("Cannot connect to server: Please check the server address"); } + else if( connectionStatus == 4 ) + { + showErrorMessage("Incorrect Password"); + } else { showErrorMessage("Unknown Connection Status"); @@ -74,7 +81,9 @@ public class StartScreen { frame.setContentPane(panel1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); + frame.setLocationRelativeTo(null); + frame.getRootPane().setDefaultButton(joinButton); + joinButton.requestFocus(); frame.setVisible(true); } - } diff --git a/src/GUI/ToolBar.java b/src/GUI/ToolBar.java deleted file mode 100644 index 04087e80db705c26881b58bcde46bfead77687d7..0000000000000000000000000000000000000000 --- a/src/GUI/ToolBar.java +++ /dev/null @@ -1,100 +0,0 @@ -package GUI; - -import javax.swing.*; -import java.awt.*; - -public class ToolBar extends JPanel { - private DrawingArea drawingArea; - - public ToolBar() { - - } -} - -class Tools extends JPanel { - -} - -class ColorPallete extends JPanel { - private Color color; - - public ColorPallete() { - this.color = new Color(0, 0, 0); // Black - } - - public void setColor(Color color) { - this.color = color; - } - - public void setColorRBG(int r, int b, int g) { - this.color = new Color(r, b, g); - } - - public Color getColor() { - return this.color; - } - - public void setColorAqua() { - this.color = new Color(0,255, 255); - } - - public void setColorBlack() { - this.color = new Color(0, 0, 0); - } - - public void setColorBlue() { - this.color = new Color(0, 0, 255); - } - - public void setColorFuchsia() { - this.color = new Color(255, 0, 255); - } - - public void setColorGray() { - this.color = new Color(128, 128, 128); - } - - public void setColorGreen() { - this.color = new Color(0, 128, 0); - } - - public void setColorLime() { - this.color = new Color(0, 255, 0); - } - - public void setColorMaroon() { - this.color = new Color(128,0, 0); - } - - public void setColorNavy() { - this.color = new Color(0, 0, 128); - } - - public void setColorOlive() { - this.color = new Color(128, 128, 0); - } - - public void setColorPurple() { - this.color = new Color(128, 0, 128); - } - - public void setColorRed() { - this.color = new Color(255, 0, 0); - } - - public void setColorSilver() { - this.color = new Color(192, 192, 192); - } - - public void setColorTeal() { - this.color = new Color(0, 128, 128); - } - - public void setColorWhite() { - this.color = new Color(255, 255, 255); - } - - public void setColorYellow() { - this.color = new Color(255, 255, 0); - } -} \ No newline at end of file diff --git a/src/client/Client.java b/src/client/Client.java index 5eed15f56e0382d5755970a297a77061654b344c..800fac6e8eb9444b5018277491d4e3dc6cec8b47 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -28,9 +28,8 @@ public class Client private ClientUpdate clientUpdate; private ChatUpdate chatUpdate; private DrawingUpdate drawingUpdate; - + private ApplicationMain applicationMain; private StartScreen startScreen; - private PaintGUI paintGUI; public String getUserName() @@ -53,13 +52,9 @@ public class Client this.serverAddress = serverAddress; } - private ApplicationMain applicationMain; - public ApplicationMain getApplicationMain() { return applicationMain; } - public PaintGUI getPaintGUI() { - return paintGUI; - } + public ApplicationMain getApplicationMain() { return applicationMain; } public ChatScreen getChatScreen() { return getApplicationMain().getChatScreen(); @@ -98,6 +93,7 @@ public class Client catch (Exception e) { StartScreen.showErrorMessage("Error starting up client"); + System.exit(0); } } @@ -117,7 +113,8 @@ public class Client // return = 1 -> connected successfully // return = 2 -> duplicate username // return = 3 -> error in locating the server - public int connect(String userName, String serverAddress) + // return = 4 -> incorrect password entered + public int connect(String userName, String serverAddress, String password) { if( !userName.trim().isEmpty() ) { @@ -134,31 +131,38 @@ public class Client try { - System.out.println("Server address:" + serverAddress); + 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"); + System.out.println("User name: " + userName); + System.out.println("Password: " + password); - return 1; + if( clientController.checkPassword(password) ) + { + if( clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate) ) + { + System.out.println("Connected to server"); + + return 1; + } + else + { + return 2; + } } else { - return 2; + return 4; } } catch (Exception e) { //e.printStackTrace(); - return 3; } } - } \ No newline at end of file diff --git a/src/client/ClientUpdate.java b/src/client/ClientUpdate.java index 9fdef79bf4438c8af406c61911df11a72583d383..5bcea9acfb809807f3e99c6874533a956439d243 100644 --- a/src/client/ClientUpdate.java +++ b/src/client/ClientUpdate.java @@ -41,18 +41,14 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate, { printUserList(users); - 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()) ) diff --git a/src/remote/IClientController.java b/src/remote/IClientController.java index 349297d37ca18e26184c87e1d7754b5299718340..1dcd165573a381d245924c9966d8a13367439a3f 100644 --- a/src/remote/IClientController.java +++ b/src/remote/IClientController.java @@ -18,4 +18,6 @@ public interface IClientController extends Remote boolean broadcastManagerMessage(String toClient, Action action) throws RemoteException; String getAdmin() throws RemoteException; + + boolean checkPassword(String password) throws RemoteException; } diff --git a/src/server/ClientController.java b/src/server/ClientController.java index dfdb350ab7698554b76cf1eed74f27fc168d0107..4c710bbc9d0fa508751c3db651f717aed06798f4 100644 --- a/src/server/ClientController.java +++ b/src/server/ClientController.java @@ -62,7 +62,7 @@ public class ClientController extends UnicastRemoteObject implements IClientCont broadcastUserList(); } - printUserList(); + //printUserList(); } // for debuggins purposes @@ -71,7 +71,7 @@ public class ClientController extends UnicastRemoteObject implements IClientCont System.out.print("Currently connected users: "); for( User u : server.users ) { - System.out.print(u.getUserName()); + System.out.print(u.getUserName() + " "); } System.out.println(); } @@ -105,10 +105,12 @@ public class ClientController extends UnicastRemoteObject implements IClientCont if ( adminIndex >= 0 && userIndex >= 0 && server.users.get(adminIndex).isAdmin() ) { - try { + try + { server.users.get(userIndex).getIClientUpdate().terminateChat(); } - finally { + finally + { System.out.print(server.users); server.users.remove(userIndex); System.out.print(server.users); @@ -202,4 +204,23 @@ public class ClientController extends UnicastRemoteObject implements IClientCont return true; } + + @Override + public boolean checkPassword(String password) + { + if( server.users.size() == 0 ) + { + server.setPassword(password); + + return true; + } + else if( server.getPassword().equals(password) ) + { + return true; + } + else + { + return false; + } + } } diff --git a/src/server/Server.java b/src/server/Server.java index 02172a2b8dcee73a78134e6651f1debc376203e8..0160269bb14d69676c82e568f5521ab9d84ae94d 100644 --- a/src/server/Server.java +++ b/src/server/Server.java @@ -17,14 +17,27 @@ public class Server protected ChatController chatController; protected DrawingController drawingController; + private String password; + public Server() throws RemoteException { + password = null; users = new ArrayList<User>(); clientController = new ClientController(this); chatController = new ChatController(this); drawingController = new DrawingController(this); } + protected void setPassword(String password) + { + this.password = password; + } + + protected String getPassword() + { + return password; + } + public static void main(String[] args) { try @@ -49,17 +62,13 @@ public class Server String chatControllerName = "ChatController"; String drawingControllerName = "DrawingController"; -// IClientController clientController = new ClientController(this); -// IChatController chatController = new ChatController(this); -// IDrawingController drawingController = new DrawingController(this); - - IClientController iclientController = this.clientController; - IChatController ichatController = this.chatController; - IDrawingController idrawingController = this.drawingController; + IClientController clientController = this.clientController; + IChatController chatController = this.chatController; + IDrawingController drawingController = this.drawingController; - registry.rebind(clientControllerName, iclientController); - registry.rebind(chatControllerName, ichatController); - registry.rebind(drawingControllerName, idrawingController); + registry.rebind(clientControllerName, clientController); + registry.rebind(chatControllerName, chatController); + registry.rebind(drawingControllerName, drawingController); System.out.println("Server is ready"); }