Skip to content
Snippets Groups Projects
Select Git revision
  • 19d1d3f22c896ab51b96a1a063791099ef2f8a3d
  • master default protected
2 results

main.py

Blame
  • DrawingArea.java 11.86 KiB
    package GUI;
    
    import client.Client;
    import remote.IDrawingController;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Rectangle2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.io.Serializable;
    import java.rmi.RemoteException;
    
    public class DrawingArea extends JPanel implements MouseMotionListener, MouseListener, Serializable {
    
        /// enum for all different mode ///
        enum Mode { FREEHAND, LINE, CIRCLE, RECTANGLE, OVAL, ERASE, TEXT }
    
        /// Canvas size parameter ///
        private final static int AREA_WIDTH = 600;
        private final static int AREA_HEIGHT = 600;
    
        /// Shape to be drawn on the canvas ///
        private Client client;
    
        private Point startPoint;
        private Point previousPoint;
        private Point currentPoint;
    
        /// Default mode and color ///
        private Mode currentMode;
        private Color shapeColor;
        private Stroke lineStroke;
        private int strokeSize;
        private int eraserSize;
        private int textSize;
        private String textString;
    
        /// Create a empty canvas //
        private BufferedImage image;
        private Graphics2D g2;
        private Shape drawing;
    
        public DrawingArea(Client client) {
            this.client = client;
            setBackground(Color.WHITE); // Set Background color
            setDoubleBuffered(false);   // Non-buffered drawing
            image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
            shapeColor =  new Color(0, 0, 0);
            currentMode = Mode.FREEHAND;
            strokeSize = 3;
            lineStroke = new BasicStroke(strokeSize);
            eraserSize = 10;
            textSize = 60;
            textString = "Text here.";
            drawing = null;
            addMouseListener(this);
            addMouseMotionListener(this);
        }
    
        public Shape getDrawing() {
            return drawing;
        }
    
        public void setDrawing(Shape drawing) {