Skip to content
Snippets Groups Projects
Commit e11739bf authored by Hai HoDac's avatar Hai HoDac
Browse files

Merged with master (Eldar code)

parent f4f4b9dc
Branches
No related tags found
No related merge requests found
...@@ -129,13 +129,17 @@ ...@@ -129,13 +129,17 @@
<properties/> <properties/>
<border type="none" title="Drawing Users"/> <border type="none" title="Drawing Users"/>
<children> <children>
<component id="9aa9f" class="javax.swing.JList" binding="list1" default-binding="true"> <component id="2214f" class="javax.swing.JList" binding="allUsersList">
<constraints> <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"> <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"/> <preferred-size width="150" height="50"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<model>
<item value="drawingUserList"/>
</model>
</properties>
</component> </component>
</children> </children>
</grid> </grid>
......
...@@ -32,13 +32,13 @@ public class ChatScreen { ...@@ -32,13 +32,13 @@ public class ChatScreen {
private JPanel managersPanel; private JPanel managersPanel;
private JPanel chatPanel; private JPanel chatPanel;
private JButton exitThisRoomButton; private JButton exitThisRoomButton;
private JList list1; private DefaultListModel defaultListModel;
public JTextArea getActiveDrawingUserBox() { public DefaultListModel getAllUserModel() {
return activeDrawingUserBox; return defaultListModel;
} }
private JTextArea activeDrawingUserBox; private JList allUsersList;
private JFrame frame; private JFrame frame;
public Client getClient() { public Client getClient() {
...@@ -50,12 +50,29 @@ public class ChatScreen { ...@@ -50,12 +50,29 @@ public class ChatScreen {
public ChatScreen(Client client) public ChatScreen(Client client)
{ {
this.client = client; this.client = client;
activeDrawingUserBox = new JTextArea();
yourNameDisplay.setText(client.getUserName()); yourNameDisplay.setText(client.getUserName());
exitThisRoomButton.addActionListener(actionListener); exitThisRoomButton.addActionListener(actionListener);
sendButton.addActionListener(actionListener); sendButton.addActionListener(actionListener);
kickOutButton.addActionListener(actionListener); kickOutButton.addActionListener(actionListener);
promoteToManagerButton.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) public void setUserName(String userName)
...@@ -180,4 +197,5 @@ public class ChatScreen { ...@@ -180,4 +197,5 @@ public class ChatScreen {
} }
}; };
} }
...@@ -10,7 +10,6 @@ import java.awt.event.*; ...@@ -10,7 +10,6 @@ import java.awt.event.*;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -290,7 +289,13 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -290,7 +289,13 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
try { try {
drawingController.broadcastDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); 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) { } catch (RemoteException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
...@@ -298,6 +303,31 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -298,6 +303,31 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
drawing = null; 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 @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
...@@ -371,7 +401,11 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -371,7 +401,11 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
g2.setStroke(lineStroke); g2.setStroke(lineStroke);
repaint(); repaint();
try { try {
if (currentMode != Mode.TEXT){
drawingController.broadcastDraggingDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); drawingController.broadcastDraggingDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize);
drawingController.broadcastDrawingUser(client.getUserName());
}
} catch (RemoteException ex) { } catch (RemoteException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
package client; package client;
import GUI.DrawingArea;
import remote.IDrawingUpdate; import remote.IDrawingUpdate;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
...@@ -21,10 +21,28 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -21,10 +21,28 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
} }
public boolean notifyUserIsDrawing(String fromClient) throws RemoteException { 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; 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 @Override
public boolean notifyTextDrawing(String fromClient, String text, Font font, Color color, Point startPoint) throws RemoteException { 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); client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
...@@ -55,6 +73,7 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -55,6 +73,7 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(color); g2.setColor(color);
client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint();
return true; return true;
} }
......
...@@ -23,4 +23,5 @@ public interface IDrawingController extends Remote { ...@@ -23,4 +23,5 @@ public interface IDrawingController extends Remote {
boolean updateImage(byte[] rawImage) throws RemoteException; boolean updateImage(byte[] rawImage) throws RemoteException;
void broadcastDrawingUser (String fromClient) throws RemoteException; void broadcastDrawingUser (String fromClient) throws RemoteException;
void getImage(String fromClient) throws RemoteException; void getImage(String fromClient) throws RemoteException;
void broadcastDrawingUserStopped (String fromClient) throws RemoteException;
} }
...@@ -12,4 +12,5 @@ public interface IDrawingUpdate extends Remote, Serializable { ...@@ -12,4 +12,5 @@ public interface IDrawingUpdate extends Remote, Serializable {
boolean notifyCanvasClearance(String fromClient) throws RemoteException; boolean notifyCanvasClearance(String fromClient) throws RemoteException;
boolean receiveImage(byte[] rawImage) throws RemoteException; boolean receiveImage(byte[] rawImage) throws RemoteException;
boolean notifyUserIsDrawing(String fromClient) throws RemoteException; boolean notifyUserIsDrawing(String fromClient) throws RemoteException;
void notifyUserStoppedDrawing(String fromClient) throws RemoteException;
} }
...@@ -175,6 +175,16 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo ...@@ -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 { public boolean broadcastUpdateImage(String fromClient) throws RemoteException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment