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

open file - debugging

parent 4f8b919a
No related branches found
No related tags found
1 merge request!36Hai
package GUI;
import client.Client;
import remote.IDrawingUpdate;
import javax.imageio.ImageIO;
import javax.swing.*;
......@@ -12,7 +13,9 @@ import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.rmi.RemoteException;
public class PaintGUI extends JPanel {
......@@ -236,8 +239,49 @@ public class PaintGUI extends JPanel {
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.openFile(file);
try
{
client.getDrawingController().broadcastClearCanvas(client.getUserName());
}
catch (RemoteException err)
{
err.printStackTrace();
}
SerializableImage serializableImage = new SerializableImage(600, 600, BufferedImage.TYPE_INT_ARGB);
try {
serializableImage.setImage(ImageIO.read(file));
} catch (IOException ex) {
ex.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
javax.imageio.ImageIO.write(serializableImage, "png", baos);
baos.flush();
baos.close();
}
catch (IOException err) {
err.printStackTrace();
}
try {
client.getDrawingController().updateImage(baos.toByteArray());
} catch (RemoteException ex) {
ex.printStackTrace();
}
try {
client.getDrawingController().broadcastUpdateImage(client.getUserName());
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
/// Save under project directory without filename (PNG file with default filename) ///
} else if (e.getSource() == saveBtn) {
......
......@@ -84,8 +84,8 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
// BufferedImage bufferedImage = client.getApplicationMain().getPaintGUI().getDrawingArea().getImage();
BufferedImage bufferedImage = javax.imageio.ImageIO.read(new ByteArrayInputStream(rawImage));
client.getApplicationMain().getPaintGUI().getDrawingArea().setImage(bufferedImage);
Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
client.getApplicationMain().getPaintGUI().getDrawingArea().setG2((Graphics2D) bufferedImage.getGraphics());
client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
client.getApplicationMain().getPaintGUI().getDrawingArea().repaint();
// do whatever you wish with the image
......
grant {
permission java.net.SocketPermission "10.13.64.162", "accept,connect";
};
......@@ -24,6 +24,8 @@ public interface IDrawingController extends Remote {
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 broadcastClearCanvas(String fromClient) throws RemoteException;
boolean broadcastUpdateImage(String fromClient) throws RemoteException;
boolean updateImage(byte[] rawImage) throws RemoteException;
ArrayList<Shape> getShapeList() throws RemoteException;
ArrayList<Color> getColorList() throws RemoteException;
......@@ -35,5 +37,6 @@ public interface IDrawingController extends Remote {
// BufferedImage getCurrentImage() throws RemoteException;
SerializableImage getCurrentImage() throws RemoteException;
void getImage(String fromClient) throws RemoteException;
// void setImage(String fromClient) throws RemoteException;
}
......@@ -21,7 +21,6 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
private Server server;
private SerializableImage serializableImage;
private BufferedImage bufferedImage;
private Graphics2D g2;
private ArrayList<Shape> shapeList;
......@@ -208,17 +207,69 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
return true;
}
public boolean broadcastUpdateImage(String fromClient) throws RemoteException {
System.out.print("Broadcasting new image loading to everyone...");
try {
// do whatever you wish with the image
IDrawingUpdate client;
for( User u : server.users )
{
if (!u.getUserName().equals(fromClient)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
client = u.getIDrawingUpdate();
try {
javax.imageio.ImageIO.write(serializableImage, "png", baos);
baos.flush();
client.receiveImage(baos.toByteArray());
}
catch (IOException err) {
err.printStackTrace();
}
baos.close();
}
}
}
catch (IOException err) {
err.printStackTrace();
}
System.out.print("...DONE\n");
return true;
}
public boolean updateImage(byte[] rawImage) throws RemoteException {
try {
BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(rawImage));
serializableImage.setImage(bufferedImage);
g2 = serializableImage.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// do whatever you wish with the image
}
catch (IOException err) {
err.printStackTrace();
}
return true;
}
public SerializableImage getCurrentImage() throws RemoteException {
return serializableImage;
}
public void getImage(String fromClient) throws RemoteException {
// if (serializableImage.getImage().)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IDrawingUpdate client;
try {
javax.imageio.ImageIO.write(serializableImage, "png", baos);
baos.flush();
baos.close();
}
catch (IOException err) {
err.printStackTrace();
......@@ -233,6 +284,7 @@ public class DrawingController extends UnicastRemoteObject implements IDrawingCo
}
}
public ArrayList<Shape> getShapeList() {
return shapeList;
}
......
......@@ -4,11 +4,15 @@ import remote.IChatController;
import remote.IClientController;
import remote.IDrawingController;
import javax.naming.NamingEnumeration;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
public class Server
......@@ -58,6 +62,10 @@ public class Server
{
LocateRegistry.createRegistry(1099);
Registry registry = LocateRegistry.getRegistry();
// if (System.getSecurityManager() == null) {
// System.setSecurityManager(new SecurityManager());
// }
// System.setProperty("java.security.policy", "file:/Users/haiho/OneDrive - The University of Melbourne/Distributed Systems (COMP90015)/Assignment 2/InfinityMonkeys-remaster/comp90015-dsass2-infinitymonkeys-remaster/src/server/server.policy");
String clientControllerName = "ClientController";
String chatControllerName = "ChatController";
......@@ -70,6 +78,18 @@ public class Server
registry.rebind(clientControllerName, clientController);
registry.rebind(chatControllerName, chatController);
registry.rebind(drawingControllerName, drawingController);
// registry.rebind(clientControllerName, UnicastRemoteObject.exportObject(clientController, 1099));
// registry.rebind(chatControllerName, UnicastRemoteObject.exportObject(chatController, 1099));
// registry.rebind(drawingControllerName, UnicastRemoteObject.exportObject(drawingController, 1099));
// try {
// Naming.rebind(clientControllerName, clientController);
// Naming.rebind(chatControllerName, chatController);
// Naming.rebind(drawingControllerName, drawingController);
// } catch (MalformedURLException e) {
// e.printStackTrace();
// }
System.out.println("Server is ready");
......
grant codeBase "file:/Users/haiho/OneDrive - The University of Melbourne/Distributed Systems (COMP90015)/Assignment 2/InfinityMonkeys-remaster/comp90015-dsass2-infinitymonkeys-remaster/out/production/comp90015-dsass2-infinitymonkeys-remaster/" {
permission java.security.AllPermission;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment