diff --git a/.idea/workspace.xml b/.idea/workspace.xml index eea1bb1bfa920991f2e04e4abc8572566327f4c7..057eb7107eb8a521fae926d7d4293b4233379e9d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,10 +3,8 @@ <component name="ChangeListManager"> <list default="true" id="688d774d-cfc7-4b0d-b00c-5ca931aba600" name="Default Changelist" comment=""> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/src/GUI/StartScreen.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/StartScreen.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/GUI/DrawingArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GUI/DrawingArea.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/client/DrawingUpdate.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/client/DrawingUpdate.java" afterDir="false" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="SHOW_DIALOG" value="false" /> @@ -238,17 +236,6 @@ <MESSAGE value="Changed the join method to send over a reference of the ClientUpdate Interface" /> <option name="LAST_COMMIT_MESSAGE" value="Changed the join method to send over a reference of the ClientUpdate Interface" /> </component> - <component name="XDebuggerManager"> - <breakpoint-manager> - <breakpoints> - <line-breakpoint enabled="true" type="java-line"> - <url>file://$PROJECT_DIR$/src/client/DrawingUpdate.java</url> - <line>25</line> - <option name="timeStamp" value="4" /> - </line-breakpoint> - </breakpoints> - </breakpoint-manager> - </component> <component name="simpleUML.UMLToolWindowPlugin"> <General> <option name="birdViewUpdateDelay" value="2000" /> diff --git a/src/GUI/DrawingArea.java b/src/GUI/DrawingArea.java index 6282dfd62a8d890332f3bc3ca669c8523e4835ac..94f45f403ab250a17e4283416c9c034e8e44cbaa 100644 --- a/src/GUI/DrawingArea.java +++ b/src/GUI/DrawingArea.java @@ -267,10 +267,17 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis public void mouseReleased(MouseEvent e) { IDrawingController drawingController = client.getDrawingController(); switch (currentMode) { + case FREEHAND: + if (startPoint.equals(previousPoint)) { + ((Line2D) drawing).setLine(startPoint, startPoint); + g2.setColor(shapeColor); + g2.setStroke(lineStroke); + g2.draw(drawing); + } + break; case OVAL: case RECTANGLE: case CIRCLE: - case FREEHAND: case LINE: g2.setColor(shapeColor); // g2.fill(drawing); /// Uncomment the line to fill the shapes with color /// @@ -289,12 +296,14 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis try { drawingController.broadcastDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); - if (currentMode == Mode.TEXT){ - notifyUsingTimer(); - } - else { - drawingController.broadcastDrawingUserStopped(client.getUserName()); - } + +// if (currentMode == Mode.TEXT){ +// notifyUsingTimer(); +// } +// else { +// drawingController.broadcastDrawingUserStopped(client.getUserName()); +// } + } catch (RemoteException ex) { ex.printStackTrace(); @@ -303,30 +312,32 @@ 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(); - } - } +// private void notifyUsingTimer() throws RemoteException { +// +// Timer timer = new Timer(4000, new ActionListener() +// { +// +// @Override +// public void actionPerformed(ActionEvent e) +// { +// try { +// client.getDrawingController().broadcastDrawingUserStopped(client.getUserName()); +// } catch (RemoteException ex) { +// ex.printStackTrace(); +// } +// +// } +// +// }); +// try { +// client.getDrawingController().broadcastDrawingUser(client.getUserName()); +// } catch (RemoteException ex) { +// ex.printStackTrace(); +// } +// timer.start(); +// } - }); - try { - client.getDrawingController().broadcastDrawingUser(client.getDefaultUserName()); - } catch (RemoteException ex) { - ex.printStackTrace(); - } - timer.start(); - } @Override public void mouseEntered(MouseEvent e) { @@ -403,7 +414,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis try { if (currentMode != Mode.TEXT){ drawingController.broadcastDraggingDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); - drawingController.broadcastDrawingUser(client.getUserName()); + +// drawingController.broadcastDrawingUser(client.getUserName()); + } } catch (RemoteException ex) { diff --git a/src/client/DrawingUpdate.java b/src/client/DrawingUpdate.java index 60ea6688da2a1f8f336a70813f61aa45dc9c472d..bb920065cd8235615d3fb9ad60f49bcf0b84e202 100644 --- a/src/client/DrawingUpdate.java +++ b/src/client/DrawingUpdate.java @@ -4,6 +4,8 @@ import remote.IDrawingUpdate; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -50,6 +52,29 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setColor(color); client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().drawString(text, startPoint.x, startPoint.y); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); + + removeClientTimer removeClient = new removeClientTimer(fromClient, client); + removeClient.start(); +// +// Timer timer = new Timer(1000, new ActionListener() +// { +// private int i = 0; +// @Override +// public void actionPerformed(ActionEvent e) +// { +// DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); +// System.out.println("action performed" + Integer.toString(i)); +// int elementIndex = -1; +// if(temp.contains(fromClient)){ +// elementIndex = temp.indexOf(fromClient); +// temp.remove(elementIndex); +// System.out.println("removed from list"); +// } +// } +// }); +// timer.start(); + + return true; } @@ -74,6 +99,12 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate g2.setColor(color); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); + DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); + int elementIndex = -1; + if(temp.contains(fromClient)){ + elementIndex = temp.indexOf(fromClient); + temp.remove(elementIndex); + } return true; } @@ -96,6 +127,15 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate break; } client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); + + DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); + if(temp.contains(fromClient)){ + System.out.println("Already in the list"); + } + else { + temp.addElement(fromClient); + } + return true; } @@ -121,3 +161,33 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate return true; } } + +class removeClientTimer extends Thread { + private String fromClient; + private Client client; + + public removeClientTimer (String fromClient, Client client) { + this.fromClient = fromClient; + this.client = client; + } + + @Override + public void run() + { + try { + DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel(); + if(!temp.contains(fromClient)) temp.addElement(fromClient); + + sleep(1000); + + int elementIndex = -1; + if(temp.contains(fromClient)){ + elementIndex = temp.indexOf(fromClient); + temp.remove(elementIndex); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file