Skip to content
Snippets Groups Projects
Commit cdea11be authored by Ho Dac Hai's avatar Ho Dac Hai
Browse files

Merge branch 'hai' into 'master'

Fixed bugs and added functions

See merge request 1050369/comp90015-dsass2-infinitymonkeys-remaster!32
parents 9baba739 206b08c2
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
<grid id="bad73" binding="myAreaPanel" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="bad73" binding="myAreaPanel" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="-1"/>
</grid>
</constraints> </constraints>
<properties/> <properties/>
<border type="none" title="My Area"/> <border type="none" title="My Area"/>
...@@ -124,7 +126,9 @@ ...@@ -124,7 +126,9 @@
<grid id="5d886" binding="chatPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="5d886" binding="chatPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="7" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="2" col-span="1" vsize-policy="7" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="300" height="-1"/>
</grid>
</constraints> </constraints>
<properties/> <properties/>
<border type="none" title="Chat Area"/> <border type="none" title="Chat Area"/>
......
...@@ -61,7 +61,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -61,7 +61,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
lineStroke = new BasicStroke(strokeSize); lineStroke = new BasicStroke(strokeSize);
eraserSize = 10; eraserSize = 10;
textSize = 60; textSize = 60;
textString = "Enter text..."; textString = "Text here.";
drawing = null; drawing = null;
addMouseListener(this); addMouseListener(this);
addMouseMotionListener(this); addMouseMotionListener(this);
...@@ -218,70 +218,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -218,70 +218,6 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
eraserSize = size; eraserSize = size;
} }
// public void setColorAqua() {
// shapeColor = new Color(0,255, 255);
// }
//
// public void setColorBlack() {
// shapeColor = new Color(0, 0, 0);
// }
//
// public void setColorBlue() {
// shapeColor = new Color(0, 0, 255);
// }
//
// public void setColorFuchsia() {
// shapeColor = new Color(255, 0, 255);
// }
//
// public void setColorGray() {
// shapeColor = new Color(128, 128, 128);
// }
//
// public void setColorGreen() {
// shapeColor = new Color(0, 128, 0);
// }
//
// public void setColorLime() {
// shapeColor = new Color(0, 255, 0);
// }
//
// public void setColorMaroon() {
// shapeColor = new Color(128,0, 0);
// }
//
// public void setColorNavy() {
// shapeColor = new Color(0, 0, 128);
// }
//
// public void setColorOlive() {
// shapeColor = new Color(128, 128, 0);
// }
//
// public void setColorPurple() {
// shapeColor = new Color(128, 0, 128);
// }
//
// public void setColorRed() {
// shapeColor = new Color(255, 0, 0);
// }
//
// public void setColorSilver() {
// shapeColor = new Color(192, 192, 192);
// }
//
// public void setColorTeal() {
// shapeColor = new Color(0, 128, 128);
// }
//
// public void setColorWhite() {
// shapeColor = new Color(255, 255, 255);
// }
//
// public void setColorYellow() {
// shapeColor = new Color(255, 255, 0);
// }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
startPoint = e.getPoint(); startPoint = e.getPoint();
...@@ -298,6 +234,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -298,6 +234,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
} catch (RemoteException ex) { } catch (RemoteException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
repaint();
break;
default:
break; break;
} }
} }
...@@ -327,8 +266,8 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -327,8 +266,8 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
drawing = new Rectangle2D.Double(); drawing = new Rectangle2D.Double();
break; break;
// case TEXT: case TEXT:
//
// g2.setFont(new Font("TimesRoman", Font.PLAIN, textSize)); // g2.setFont(new Font("TimesRoman", Font.PLAIN, textSize));
// g2.drawString(textString, startPoint.x, startPoint.y); // g2.drawString(textString, startPoint.x, startPoint.y);
// try { // try {
...@@ -336,6 +275,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -336,6 +275,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
// } catch (RemoteException ex) { // } catch (RemoteException ex) {
// ex.printStackTrace(); // ex.printStackTrace();
// } // }
// repaint();
// break; // break;
} }
} }
...@@ -347,20 +287,17 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -347,20 +287,17 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
case OVAL: case OVAL:
case RECTANGLE: case RECTANGLE:
case CIRCLE: case CIRCLE:
/// Abort drawing if 2D has no width or height ///
if (((RectangularShape) drawing).getWidth() == 0 || ((RectangularShape) drawing).getHeight() == 0) {
break;
}
case FREEHAND: case FREEHAND:
case LINE: case LINE:
// Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(shapeColor); g2.setColor(shapeColor);
// g2.fill(drawing); /// Uncomment the line to fill the shapes with color ///
/// Uncomment the line below to fill the shapes with color ///
// g2.fill(drawing);
g2.setStroke(lineStroke); g2.setStroke(lineStroke);
g2.draw(drawing); g2.draw(drawing);
break;
case TEXT:
case ERASE:
default:
break;
} }
g2 = (Graphics2D) image.getGraphics(); g2 = (Graphics2D) image.getGraphics();
......
...@@ -13,6 +13,7 @@ import java.awt.event.FocusEvent; ...@@ -13,6 +13,7 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.rmi.RemoteException;
public class PaintGUI extends JPanel { public class PaintGUI extends JPanel {
...@@ -165,7 +166,24 @@ public class PaintGUI extends JPanel { ...@@ -165,7 +166,24 @@ public class PaintGUI extends JPanel {
/// Clear button /// /// Clear button ///
if (e.getSource() == clearBtn) { if (e.getSource() == clearBtn) {
int reply = JOptionPane.showConfirmDialog(null,
"Do you want to save the canvas before clearing?",
"Canvas clearance", JOptionPane.YES_NO_OPTION);
if( reply == JOptionPane.YES_OPTION )
{
try
{
client.getDrawingController().broadcastClearCanvas(client.getUserName());
}
catch (RemoteException err)
{
JOptionPane.showMessageDialog(null,
"Error in clearing the canvas", "Error", JOptionPane.ERROR_MESSAGE);
}
drawingArea.clear(); drawingArea.clear();
}
/// Create new canvas /// /// Create new canvas ///
} else if (e.getSource() == newBtn) { } else if (e.getSource() == newBtn) {
......
package GUI;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class SerializableImage implements Serializable {
transient BufferedImage image;
public void writeObject(ObjectOutputStream output) throws IOException {
output.defaultWriteObject();
ImageIO.write(image, "png", output);
}
public void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
input.defaultReadObject();
image = ImageIO.read(input);
}
}
...@@ -70,4 +70,9 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -70,4 +70,9 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint();
return true; return true;
} }
public boolean notifyCanvasClearance(String fromClient) throws RemoteException {
client.getApplicationMain().getPaintGUI().getDrawingArea().clear();
return true;
}
} }
...@@ -20,6 +20,8 @@ public interface IDrawingController extends Remote { ...@@ -20,6 +20,8 @@ public interface IDrawingController extends Remote {
boolean broadcastText(String fromClient, String text, Font font, Point startPoint) throws RemoteException; boolean broadcastText(String fromClient, String text, Font font, Point startPoint) throws RemoteException;
boolean broadcastDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException; boolean broadcastDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException;
boolean broadcastDraggingDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException; boolean broadcastDraggingDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException;
boolean broadcastClearCanvas(String fromClient) throws RemoteException;
ArrayList<Shape> getShapeList() throws RemoteException; ArrayList<Shape> getShapeList() throws RemoteException;
ArrayList<Color> getColorList() throws RemoteException; ArrayList<Color> getColorList() throws RemoteException;
ArrayList<Integer> getStrokeSizeList() throws RemoteException; ArrayList<Integer> getStrokeSizeList() throws RemoteException;
......
...@@ -9,4 +9,5 @@ public interface IDrawingUpdate extends Remote, Serializable { ...@@ -9,4 +9,5 @@ public interface IDrawingUpdate extends Remote, Serializable {
boolean notifyTextDrawing(String fromClient, String text, Font font, Point startPoint) throws RemoteException; boolean notifyTextDrawing(String fromClient, String text, Font font, Point startPoint) throws RemoteException;
boolean notifyDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException; boolean notifyDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException;
boolean notifyDraggingDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException; boolean notifyDraggingDrawing(String fromClient, Shape drawing, String mode, Color color, int strokeSize) throws RemoteException;
boolean notifyCanvasClearance(String fromClient) throws RemoteException;
} }
package server; package server;
import GUI.SerializableImage;
import remote.IDrawingController; import remote.IDrawingController;
import remote.IDrawingUpdate; import remote.IDrawingUpdate;
...@@ -21,6 +22,7 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo ...@@ -21,6 +22,7 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
private final static int AREA_HEIGHT = 620; private final static int AREA_HEIGHT = 620;
private Server server; private Server server;
private SerializableImage serializableImage;
private BufferedImage bufferedImage; private BufferedImage bufferedImage;
private Graphics2D g2; private Graphics2D g2;
...@@ -35,9 +37,15 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo ...@@ -35,9 +37,15 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
protected DrawingController(Server server) throws RemoteException { protected DrawingController(Server server) throws RemoteException {
this.server = server; this.server = server;
this.bufferedImage = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB); this.bufferedImage = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) bufferedImage.getGraphics(); g2 = (Graphics2D) bufferedImage.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// this.serializableImage = new SerializableImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
// g2 = (Graphics2D) bufferedImage.getGraphics();
// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
this.shapeList = new ArrayList<Shape>(); this.shapeList = new ArrayList<Shape>();
this.colorList = new ArrayList<Color>(); this.colorList = new ArrayList<Color>();
this.strokeSizeList = new ArrayList<Integer>(); this.strokeSizeList = new ArrayList<Integer>();
...@@ -118,6 +126,32 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo ...@@ -118,6 +126,32 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
return true; return true;
} }
public boolean broadcastClearCanvas(String fromClient) throws RemoteException {
System.out.print("Broadcasting canvas clearance to everyone...");
IDrawingUpdate client;
this.shapeList.clear();
this.colorList.clear();
this.strokeSizeList.clear();
this.textList.clear();
this.fontList.clear();
this.textStartPointList.clear();
for( User u : server.users )
{
if (!u.getUserName().equals(fromClient)) {
client = u.getIDrawingUpdate();
client.notifyCanvasClearance(fromClient);
}
}
System.out.print("...DONE\n");
return true;
}
// public ImageCanvas getCurrentImage() { // public ImageCanvas getCurrentImage() {
// return image; // return image;
// } // }
......
...@@ -49,13 +49,17 @@ public class Server ...@@ -49,13 +49,17 @@ public class Server
String chatControllerName = "ChatController"; String chatControllerName = "ChatController";
String drawingControllerName = "DrawingController"; String drawingControllerName = "DrawingController";
IClientController clientController = new ClientController(this); // IClientController clientController = new ClientController(this);
IChatController chatController = new ChatController(this); // IChatController chatController = new ChatController(this);
IDrawingController drawingController = new DrawingController(this); // IDrawingController drawingController = new DrawingController(this);
registry.rebind(clientControllerName, clientController); IClientController iclientController = this.clientController;
registry.rebind(chatControllerName, chatController); IChatController ichatController = this.chatController;
registry.rebind(drawingControllerName, drawingController); IDrawingController idrawingController = this.drawingController;
registry.rebind(clientControllerName, iclientController);
registry.rebind(chatControllerName, ichatController);
registry.rebind(drawingControllerName, idrawingController);
System.out.println("Server is ready"); System.out.println("Server is ready");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment