diff --git a/src/GUI/ChatScreen.form b/src/GUI/ChatScreen.form index 8d821a823277ef2693243eb5e949cc285b0c8033..140273c130f937107baf67db482203bc8ef15290 100644 --- a/src/GUI/ChatScreen.form +++ b/src/GUI/ChatScreen.form @@ -129,13 +129,17 @@ <properties/> <border type="none" title="Drawing Users"/> <children> - <component id="9aa9f" class="javax.swing.JList" binding="list1" default-binding="true"> + <component id="2214f" class="javax.swing.JList" binding="allUsersList"> <constraints> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false"> <preferred-size width="150" height="50"/> </grid> </constraints> - <properties/> + <properties> + <model> + <item value="drawingUserList"/> + </model> + </properties> </component> </children> </grid> diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index e98608ce5139a8e682f05d2117044b29a7e9043c..1ffd49fbd11023d27ec0e09eaf2d679e1c1310fd 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -32,13 +32,13 @@ public class ChatScreen { private JPanel managersPanel; private JPanel chatPanel; private JButton exitThisRoomButton; - private JList list1; + private DefaultListModel defaultListModel; - public JTextArea getActiveDrawingUserBox() { - return activeDrawingUserBox; + public DefaultListModel getAllUserModel() { + return defaultListModel; } - private JTextArea activeDrawingUserBox; + private JList allUsersList; private JFrame frame; public Client getClient() { @@ -50,12 +50,29 @@ public class ChatScreen { public ChatScreen(Client client) { this.client = client; - activeDrawingUserBox = new JTextArea(); yourNameDisplay.setText(client.getUserName()); exitThisRoomButton.addActionListener(actionListener); sendButton.addActionListener(actionListener); kickOutButton.addActionListener(actionListener); promoteToManagerButton.addActionListener(actionListener); + defaultListModel = new DefaultListModel(); + allUsersList.setModel(defaultListModel); + + allUsersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + allUsersList.setSelectedIndex(0); + allUsersList.setVisibleRowCount(5); + + + + + } + + public void addUserToList(){ + + } + + public void removeUserFromList(){ + } public void setUserName(String userName) @@ -180,4 +197,5 @@ public class ChatScreen { } }; + } diff --git a/src/GUI/DrawingArea.java b/src/GUI/DrawingArea.java index a670fea18a7073dd8c5ce08804bea484a2bddb71..6282dfd62a8d890332f3bc3ca669c8523e4835ac 100644 --- a/src/GUI/DrawingArea.java +++ b/src/GUI/DrawingArea.java @@ -10,7 +10,6 @@ import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; -import java.awt.geom.RectangularShape; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -290,7 +289,13 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis try { drawingController.broadcastDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); - drawingController.broadcastDrawingUser(client.getUserName()); + if (currentMode == Mode.TEXT){ + notifyUsingTimer(); + } + else { + drawingController.broadcastDrawingUserStopped(client.getUserName()); + } + } catch (RemoteException ex) { ex.printStackTrace(); } @@ -298,6 +303,31 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis drawing = null; } + private void notifyUsingTimer() throws RemoteException { + + Timer timer = new Timer(4000, new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + try { + client.getDrawingController().broadcastDrawingUserStopped(client.getDefaultUserName()); + } catch (RemoteException ex) { + ex.printStackTrace(); + } + + } + + }); + try { + client.getDrawingController().broadcastDrawingUser(client.getDefaultUserName()); + } catch (RemoteException ex) { + ex.printStackTrace(); + } + timer.start(); + } + @Override public void mouseEntered(MouseEvent e) { @@ -371,7 +401,11 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis g2.setStroke(lineStroke); repaint(); try { - drawingController.broadcastDraggingDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); + if (currentMode != Mode.TEXT){ + drawingController.broadcastDraggingDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); + drawingController.broadcastDrawingUser(client.getUserName()); + } + } catch (RemoteException ex) { ex.printStackTrace(); } diff --git a/src/client/DrawingUpdate.java b/src/client/DrawingUpdate.java index 0b9d0862ca3198d34761a4591bb1d43a1df2be5f..60ea6688da2a1f8f336a70813f61aa45dc9c472d 100644 --- a/src/client/DrawingUpdate.java +++ b/src/client/DrawingUpdate.java @@ -1,8 +1,8 @@ package client; -import GUI.DrawingArea; import remote.IDrawingUpdate; +import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -21,10 +21,28 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate } public boolean notifyUserIsDrawing(String fromClient) throws RemoteException { - client.getApplicationMain().getChatScreen().getActiveDrawingUserBox().append(fromClient); + System.out.println("Adding name of user to the list of drawing users"); + DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); + if(temp.contains(fromClient)){ + System.out.println("Already in the list"); + } + else { + temp.addElement(fromClient); + } + return true; } + public void notifyUserStoppedDrawing(String fromClient) throws RemoteException{ + DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); + int elementIndex = -1; + if(temp.contains(fromClient)){ + elementIndex = temp.indexOf(fromClient); + temp.remove(elementIndex); + } + + } + @Override public boolean notifyTextDrawing(String fromClient, String text, Font font, Color color, Point startPoint) throws RemoteException { client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -55,6 +73,7 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(color); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); + return true; } diff --git a/src/remote/IDrawingController.java b/src/remote/IDrawingController.java index 8b2e030b1842076a371d4c5a63c4b0a86ee71e17..571cd2f437c83d5bb8f0eb8897fa5c67d68547cf 100644 --- a/src/remote/IDrawingController.java +++ b/src/remote/IDrawingController.java @@ -23,4 +23,5 @@ public interface IDrawingController extends Remote { boolean updateImage(byte[] rawImage) throws RemoteException; void broadcastDrawingUser (String fromClient) throws RemoteException; void getImage(String fromClient) throws RemoteException; + void broadcastDrawingUserStopped (String fromClient) throws RemoteException; } diff --git a/src/remote/IDrawingUpdate.java b/src/remote/IDrawingUpdate.java index cd066027f26d6395dc372d6f5351c182fc8e6b3e..3509141895adebdf35afe1b9fd9f321ee5e8235a 100644 --- a/src/remote/IDrawingUpdate.java +++ b/src/remote/IDrawingUpdate.java @@ -12,4 +12,5 @@ public interface IDrawingUpdate extends Remote, Serializable { boolean notifyCanvasClearance(String fromClient) throws RemoteException; boolean receiveImage(byte[] rawImage) throws RemoteException; boolean notifyUserIsDrawing(String fromClient) throws RemoteException; + void notifyUserStoppedDrawing(String fromClient) throws RemoteException; } diff --git a/src/server/DrawingController.java b/src/server/DrawingController.java index efae67e3bf13f533c33a6a8545ffed378b6beb2b..38a850dfd4cb60d66164a30eae13543b837f88ad 100644 --- a/src/server/DrawingController.java +++ b/src/server/DrawingController.java @@ -175,6 +175,16 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo } + public void broadcastDrawingUserStopped (String fromClient) throws RemoteException{ + System.out.println("Current user stopped drawing" + fromClient); + IDrawingUpdate client; + for (User u: server.users){ + client = u.getIDrawingUpdate(); + client.notifyUserStoppedDrawing(fromClient); + } + + } + public boolean broadcastUpdateImage(String fromClient) throws RemoteException {