From d1ed051fce8b81dc51b5118bb72e715aedb03886 Mon Sep 17 00:00:00 2001
From: Hai HoDac <hhodac@student.unimelb.edu.au>
Date: Tue, 22 Oct 2019 22:32:05 +1100
Subject: [PATCH] new GUI adjusted size fixed close window button bug

---
 src/GUI/ApplicationMain.java |   7 +-
 src/GUI/ChatScreen.form      |   4 +-
 src/GUI/DrawingArea.java     | 219 ++++++++++++++---------
 src/GUI/PaintGUI.java        | 326 ++++++++++++++++++++++++-----------
 4 files changed, 363 insertions(+), 193 deletions(-)

diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java
index f58583c..21558c5 100644
--- a/src/GUI/ApplicationMain.java
+++ b/src/GUI/ApplicationMain.java
@@ -62,18 +62,13 @@ public class ApplicationMain extends JPanel {
 
                     System.exit(0);
                 }
-
-                if( reply == JOptionPane.NO_OPTION )
-                {
-                    //do nothing
-                }
             }
         });
 
         frame.setSize(1200, 700);
         frame.setLocationRelativeTo( null );
         frame.setResizable(false);
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frame.pack();
         frame.setVisible(true);
     }
diff --git a/src/GUI/ChatScreen.form b/src/GUI/ChatScreen.form
index d333744..a7545b5 100644
--- a/src/GUI/ChatScreen.form
+++ b/src/GUI/ChatScreen.form
@@ -8,7 +8,7 @@
     <properties>
       <maximumSize width="-1" height="-1"/>
       <minimumSize width="-1" height="-1"/>
-      <preferredSize width="700" height="600"/>
+      <preferredSize width="500" height="600"/>
     </properties>
     <border type="none"/>
     <children>
@@ -163,7 +163,7 @@
                   <component id="c55f3" class="javax.swing.JTextArea" binding="chatDisplayBox">
                     <constraints/>
                     <properties>
-                      <editable value="true"/>
+                      <editable value="false"/>
                       <lineWrap value="true"/>
                     </properties>
                   </component>
diff --git a/src/GUI/DrawingArea.java b/src/GUI/DrawingArea.java
index a6bb2ad..b49cf7d 100644
--- a/src/GUI/DrawingArea.java
+++ b/src/GUI/DrawingArea.java
@@ -6,9 +6,7 @@ import remote.IDrawingController;
 import javax.imageio.ImageIO;
 import javax.swing.*;
 import java.awt.*;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
+import java.awt.event.*;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.Line2D;
 import java.awt.geom.Rectangle2D;
@@ -21,36 +19,32 @@ 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 }
+    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 = 620;
+    private final static int AREA_HEIGHT = 600;
 
     /// Shape to be drawn on the canvas ///
     private Client client;
 
-    private Shape drawing;
-
     private Point startPoint;
     private Point previousPoint;
-
     private Point currentPoint;
-    /// Default mode and color ///
-    private Color shapeColor;// = new Color(0, 0, 0);
-
-    private Mode currentMode;// = Mode.FREEHAND;
-
-    /// Create a empty canvas ///
 
-    private BufferedImage image;// = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
-
-    /// Drawing tool
-
-    private Graphics2D g2;// = (Graphics2D) image.getGraphics();
+    /// Default mode and color ///
+    private Mode currentMode;
+    private Color shapeColor;
+    private Stroke lineStroke;
+    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;
@@ -62,6 +56,10 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         shapeColor =  new Color(0, 0, 0);
         currentMode = Mode.FREEHAND;
+        lineStroke = new BasicStroke(3);
+        eraserSize = 10;
+        textSize = 60;
+        textString = "Enter text...";
         drawing = null;
         addMouseListener(this);
         addMouseMotionListener(this);
@@ -120,19 +118,38 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
             Color borderColor = currentMode != Mode.ERASE ? shapeColor : Color.WHITE;
             g2.setColor(borderColor);
             g2.draw(drawing);
-
         }
     }
 
 /// File manipulations (PNG only) ///
-    public void saveFile() {
+
+    public void saveAsPNGFile(File file) {
+        try {
+            ImageIO.write(image, "PNG", file);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void saveAsJPGFile(File file) {
+
+        BufferedImage imageJPG = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
+        imageJPG.createGraphics().drawImage(image, 0, 0, Color.WHITE, null);
         try {
-            ImageIO.write(image, "PNG", new File("Saved_White_Board.png"));
+            ImageIO.write(imageJPG, "JPG", file);
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
 
+//    public void saveFile() {
+//        try {
+//            ImageIO.write(image, "PNG", new File("Saved_White_Board.png"));
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//    }
+
     public void saveAsFile(File file) {
         try {
             ImageIO.write(image, "PNG", file);
@@ -176,71 +193,91 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
         currentMode = Mode.ERASE;
     }
 
-/// Drawing color setters ///
-
-    public void setColorAqua() {
-        shapeColor = new Color(0,255, 255);
-    }
-
-    public void setColorBlack() {
-        shapeColor = new Color(0, 0, 0);
+    public void setModeText(String string, int size) {
+        currentMode = Mode.TEXT;
+        textString = string;
+        textSize = size;
     }
 
-    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);
-    }
+/// Drawing color setters ///
 
-    public void setColorYellow() {
-        shapeColor = new Color(255, 255, 0);
-    }
+    public void setColor(Color color) {
+        shapeColor = color;
+    }
+
+/// Drawing stroke setter ///
+
+    public void setStroke(int size) {
+        lineStroke = new BasicStroke(size);
+    }
+
+    public void setEraserSize(int 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
     public void mouseClicked(MouseEvent e) {
@@ -271,6 +308,12 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
 
                 drawing = new Rectangle2D.Double();
                 break;
+
+            case TEXT:
+
+                g2.setFont(new Font("TimesRoman", Font.PLAIN, textSize));
+                g2.drawString(textString, startPoint.x, startPoint.y);
+                break;
         }
     }
 
@@ -339,6 +382,7 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
 
                 ((Line2D) drawing).setLine(currentPoint, previousPoint);
                 g2.setColor(shapeColor);
+                g2.setStroke(lineStroke);
                 g2.draw(drawing);
                 previousPoint = currentPoint;
                 break;
@@ -377,6 +421,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
 
                 ((Rectangle2D) drawing).setFrame(x, y, width, height);
                 break;
+
+            case TEXT:
+                break;
         }
 
         repaint();
diff --git a/src/GUI/PaintGUI.java b/src/GUI/PaintGUI.java
index fd2a2e3..0621a49 100644
--- a/src/GUI/PaintGUI.java
+++ b/src/GUI/PaintGUI.java
@@ -2,29 +2,43 @@ package GUI;
 
 import client.Client;
 
+import javax.imageio.ImageIO;
 import javax.swing.*;
+import javax.swing.filechooser.FileFilter;
+import javax.swing.filechooser.FileNameExtensionFilter;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.image.BufferedImage;
 import java.io.File;
 
 public class PaintGUI extends JPanel {
 
     Client client;
+    DrawingArea drawingArea;
 
-    String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"};
-    String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"};
+    String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser", "Text"};
+    String[] strokes = {"Small", "Medium", "Large"};
+    String[] eraserSizes = {"Small", "Medium", "Large"};
     JFrame frame;
-    JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn;
-    JComboBox colorOptions;
-    JComboBox shapeOptions;
-    DrawingArea drawingArea;
+    JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn;
+    JButton freehandBtn, lineBtn, circleBtn, rectBtn, ovalBtn, eraserBtn, textBtn;
+    JButton colorPaletteBtn, setFontBtn;
+    JTextField textInput, textSize;
+    JComboBox strokeOptions;
+    JComboBox eraserSizeOptions;
 
+    String filePath = "";
+    Color currentColor = Color.BLACK;
 
     JPanel global = new JPanel();
-    JFileChooser fileChooser= new JFileChooser();
     JPanel toolbox = new JPanel();
+    JPanel toolbox1 = new JPanel();
+    JPanel toolbox2 = new JPanel();
     JPanel fileControl = new JPanel();
+    JFileChooser fileChooser= new JFileChooser();
 
     /// GUI setup ///
     public PaintGUI(Client client) {
@@ -33,16 +47,71 @@ public class PaintGUI extends JPanel {
 
 /// Main drawing area ///
         drawingArea = new DrawingArea(client);
+//        drawingArea.setPreferredSize(new Dimension(600, 620));
 
 /// Set up main frame and container ///
         global.setLayout(new BorderLayout());
+        toolbox.setLayout(new BorderLayout());
+
+        /// Set up button icons ///
+        try {
+            String path = System.getProperty("user.dir");
+            System.out.println(path);
+            File palettePic = new File(path + "/src/GUI/icon/palette.png");
+            File freehandPic = new File(path + "/src/GUI/icon/freehand.png");
+            File linePic = new File(path + "/src/GUI/icon/line.png");
+            File circlePic = new File(path + "/src/GUI/icon/circle.png");
+            File rectPic = new File(path + "/src/GUI/icon/rectangle.png");
+            File ovalPic = new File(path + "/src/GUI/icon/oval.png");
+            File eraserPic = new File(path + "/src/GUI/icon/eraser.png");
+            File textPic = new File(path + "/src/GUI/icon/text.png");
+            BufferedImage paletteIcon = ImageIO.read(palettePic);
+            BufferedImage freehandIcon = ImageIO.read(freehandPic);
+            BufferedImage lineIcon = ImageIO.read(linePic);
+            BufferedImage circleIcon = ImageIO.read(circlePic);
+            BufferedImage rectIcon = ImageIO.read(rectPic);
+            BufferedImage ovalIcon = ImageIO.read(ovalPic);
+            BufferedImage eraserIcon = ImageIO.read(eraserPic);
+            BufferedImage textIcon = ImageIO.read(textPic);
+            colorPaletteBtn = new JButton(new ImageIcon(paletteIcon));
+            colorPaletteBtn.addActionListener(actionListener);
+            freehandBtn = new JButton(new ImageIcon(freehandIcon));
+            freehandBtn.addActionListener(actionListener);
+            lineBtn = new JButton(new ImageIcon(lineIcon));
+            lineBtn.addActionListener(actionListener);
+            circleBtn = new JButton(new ImageIcon(circleIcon));
+            circleBtn.addActionListener(actionListener);
+            rectBtn = new JButton(new ImageIcon(rectIcon));
+            rectBtn.addActionListener(actionListener);
+            ovalBtn = new JButton(new ImageIcon(ovalIcon));
+            ovalBtn.addActionListener(actionListener);
+            eraserBtn = new JButton(new ImageIcon(eraserIcon));
+            eraserBtn.addActionListener(actionListener);
+            textBtn = new JButton(new ImageIcon(textIcon));
+            textBtn.addActionListener(actionListener);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        strokeOptions = new JComboBox(strokes);
+        strokeOptions.setSelectedItem("Small");
+        strokeOptions.addActionListener(actionListener);
+        eraserSizeOptions = new JComboBox(eraserSizes);
+        eraserSizeOptions.setSelectedItem("Small");
+        eraserSizeOptions.addActionListener(actionListener);
+
+        //        setFontBtn = new JButton("Font");
+//        setFontBtn.addActionListener(actionListener);
+        textInput = new JTextField("Text here.");
+        textInput.setColumns(8);
+        textInput.addFocusListener(focusListener);
+//        textInput.setVisible(false);
+        textSize = new JTextField("12");
+        textSize.setColumns(2);
+        textSize.addFocusListener(focusListener);
+//        textSize.setVisible(false);
 
 /// Set up elements ///
-        shapeOptions = new JComboBox(shapes);
-        shapeOptions.addActionListener(actionListener);
-        colorOptions = new JComboBox(colors);
-        colorOptions.setSelectedItem("Black");
-        colorOptions.addActionListener(actionListener);
         clearBtn = new JButton("Clear");
         clearBtn.addActionListener(actionListener);
         newBtn = new JButton("New");
@@ -53,22 +122,32 @@ public class PaintGUI extends JPanel {
         saveBtn.addActionListener(actionListener);
         saveAsBtn = new JButton("Save As");
         saveAsBtn.addActionListener(actionListener);
-        closeBtn = new JButton("Close");
-        closeBtn.addActionListener(actionListener);
 
 /// Toolbox panel ///
-        toolbox.add(colorOptions);
-        toolbox.add(shapeOptions);
-        toolbox.add(clearBtn);
+        toolbox1.add(colorPaletteBtn);
+//        toolbox.add(setFontBtn);
+        toolbox1.add(freehandBtn);
+        toolbox1.add(lineBtn);
+        toolbox1.add(circleBtn);
+        toolbox1.add(rectBtn);
+        toolbox1.add(ovalBtn);
+        toolbox1.add(eraserBtn);
+        toolbox1.add(textBtn);
+        toolbox2.add(textInput);
+        toolbox2.add(textSize);
+        toolbox2.add(strokeOptions);
+        toolbox2.add(eraserSizeOptions);
+        toolbox2.add(clearBtn);
 
 /// File control panel ///
         fileControl.add(newBtn);
         fileControl.add(openBtn);
         fileControl.add(saveBtn);
         fileControl.add(saveAsBtn);
-        fileControl.add(closeBtn);
 
 /// Layout ///
+        toolbox.add(toolbox1, BorderLayout.NORTH);
+        toolbox.add(toolbox2, BorderLayout.SOUTH);
         global.add(fileControl, BorderLayout.NORTH);
         global.add(drawingArea);
         global.add(toolbox, BorderLayout.SOUTH);
@@ -78,6 +157,8 @@ public class PaintGUI extends JPanel {
         return global;
     }
 
+    public DrawingArea getDrawingArea() { return drawingArea; }
+
     ActionListener actionListener = new ActionListener() {
 
         public void actionPerformed(ActionEvent e) {
@@ -88,10 +169,19 @@ public class PaintGUI extends JPanel {
 
 /// Create new canvas ///
             } else if (e.getSource() == newBtn) {
+                File file;
+
                 int returnVal = JOptionPane.showConfirmDialog(new JFrame(), "Save your current whiteboard?", "Save or Discard", JOptionPane.YES_NO_CANCEL_OPTION);
                 if (returnVal == JOptionPane.YES_OPTION) {
 
-                    drawingArea.saveFile();
+                    if (filePath.isEmpty()) {
+                        file = chooseSaveFile();
+
+                    } else {
+                        file = new File(filePath);
+
+                    }
+                    drawingArea.saveAsPNGFile(file);
                     drawingArea.clear();
 
                 } else if (returnVal == JOptionPane.NO_OPTION) {
@@ -110,108 +200,146 @@ public class PaintGUI extends JPanel {
 
 /// Save under project directory without filename (PNG file with default filename) ///
             } else if (e.getSource() == saveBtn) {
-                drawingArea.saveFile();
+
+                File file;
+
+                if (filePath.isEmpty()) {
+                    file = chooseSaveFile();
+                } else {
+                    file = new File(filePath);
+
+                }
+                if (file != null) {
+                    if (filePath.endsWith(".jpg")) {
+                        drawingArea.saveAsJPGFile(file);
+                    } else if (filePath.endsWith(".png")) {
+                        drawingArea.saveAsPNGFile(file);
+                    }
+                }
 
 /// Save with other filename (PNG only) ///
             } else if (e.getSource() == saveAsBtn) {
-                fileChooser = new JFileChooser();
-                int returnVal = fileChooser.showSaveDialog(frame);
-                if (returnVal == JFileChooser.APPROVE_OPTION) {
-                    File file = fileChooser.getSelectedFile();
-                    drawingArea.saveAsFile(file);
-                }
 
-/// Close application ///
-            } else if (e.getSource() == closeBtn) {
-                System.exit(0);
+                File file = chooseSaveFile();
+
+                if (file != null) {
+                    if (filePath.endsWith(".jpg")) {
+                        drawingArea.saveAsJPGFile(file);
+                    } else if (filePath.endsWith(".png")) {
+                        drawingArea.saveAsPNGFile(file);
+                    }
+                }
 
 /// Choose drawing color ///
-            } else if (e.getSource() == colorOptions) {
+            } else if (e.getSource() == colorPaletteBtn) {
+                drawingArea.setColor(JColorChooser.showDialog(null, "Choose a Color", currentColor));
 
-                String colorChosen = (String) colorOptions.getSelectedItem();
+/// Choose drawing tool ///
+            } else if (e.getSource() == freehandBtn) {
+                drawingArea.setModeFreehand();
 
-                switch (colorChosen){
-                    case "Aqua":
-                        drawingArea.setColorAqua();
-                        break;
-                    case "Black":
-                        drawingArea.setColorBlack();
-                        break;
-                    case "Blue":
-                        drawingArea.setColorBlue();
-                        break;
-                    case "Fuchsia":
-                        drawingArea.setColorFuchsia();
-                        break;
-                    case "Gray":
-                        drawingArea.setColorGray();
-                        break;
-                    case "Green":
-                        drawingArea.setColorGreen();
-                        break;
-                    case "Lime":
-                        drawingArea.setColorLime();
-                        break;
-                    case "Maroon":
-                        drawingArea.setColorMaroon();
-                        break;
-                    case "Navy":
-                        drawingArea.setColorNavy();
-                        break;
-                    case "Olive":
-                        drawingArea.setColorOlive();
-                        break;
-                    case "Purple":
-                        drawingArea.setColorPurple();
-                        break;
-                    case "Red":
-                        drawingArea.setColorRed();
-                        break;
-                    case "Silver":
-                        drawingArea.setColorSilver();
-                        break;
-                    case "Teal":
-                        drawingArea.setColorTeal();
-                        break;
-                    case "White":
-                        drawingArea.setColorWhite();
-                        break;
-                    case "Yellow":
-                        drawingArea.setColorYellow();
-                        break;
-                }
+            } else if (e.getSource() == lineBtn) {
+                drawingArea.setModeLine();
 
-/// Choose drawing tool ///
-            } else if (e.getSource() == shapeOptions) {
+            } else if (e.getSource() == circleBtn) {
+                drawingArea.setModeCircle();
+
+            } else if (e.getSource() == rectBtn) {
+                drawingArea.setModeRectangle();
+
+            } else if (e.getSource() == ovalBtn) {
+                drawingArea.setModeOval();
+
+            } else if (e.getSource() == eraserBtn) {
+                drawingArea.setModeErase();
 
-                String shapeChosen = (String) shapeOptions.getSelectedItem();
+            } else if (e.getSource() == textBtn) {
+    //                textInput.setVisible(true);
+    //                textSize.setVisible(true);
+                setTextDetail();
+            } else if (e.getSource() == strokeOptions) {
+                String strokeChosen = (String) strokeOptions.getSelectedItem();
 
-                switch (shapeChosen){
-                    case "Freehand":
-                        drawingArea.setModeFreehand();
+                switch (strokeChosen) {
+                    case "Small":
+                        drawingArea.setStroke(3);
                         break;
-                    case "Line":
-                        drawingArea.setModeLine();
+                    case "Medium":
+                        drawingArea.setStroke(6);
                         break;
-                    case "Circle":
-                        drawingArea.setModeCircle();
+                    case "Large":
+                        drawingArea.setStroke(10);
                         break;
-                    case "Rectangle":
-                        drawingArea.setModeRectangle();
+                }
+
+            } else if (e.getSource() == eraserSizeOptions) {
+                String eraserSizeChosen = (String) eraserSizeOptions.getSelectedItem();
+
+                switch (eraserSizeChosen) {
+                    case "Small":
+                        drawingArea.setEraserSize(10);
                         break;
-                    case "Oval":
-                        drawingArea.setModeOval();
+                    case "Medium":
+                        drawingArea.setEraserSize(20);
                         break;
-                    case "Eraser":
-                        drawingArea.setModeErase();
+                    case "Large":
+                        drawingArea.setEraserSize(30);
                         break;
                 }
             }
         }
     };
 
-    public DrawingArea getDrawingArea() {
-        return drawingArea;
+    FocusListener focusListener = new FocusListener() {
+        @Override
+        public void focusGained(FocusEvent e) {
+            setTextDetail();
+        }
+
+        @Override
+        public void focusLost(FocusEvent e) {
+            setTextDetail();
+        }
+    };
+
+    private File chooseSaveFile() {
+
+        fileChooser = new JFileChooser();
+        FileFilter png = new FileNameExtensionFilter("PNG format", "png");
+        FileFilter jpg = new FileNameExtensionFilter("JPG format", "jpg");
+        fileChooser.addChoosableFileFilter(png);
+        fileChooser.addChoosableFileFilter(jpg);
+        fileChooser.setFileFilter(png);
+        int returnVal = fileChooser.showSaveDialog(frame);
+        if (returnVal == JFileChooser.APPROVE_OPTION) {
+            File file = fileChooser.getSelectedFile();
+            filePath = file.getAbsolutePath();
+
+            if (fileChooser.getFileFilter().getDescription().equals("JPG format")) {
+                if (!filePath.toLowerCase().endsWith(".jpg")) {
+                    filePath = filePath + ".jpg";
+                    file = new File(file + ".jpg");
+                }
+                return file;
+            } else {
+                if (!filePath.toLowerCase().endsWith(".png")) {
+                    filePath = filePath + ".png";
+                    file = new File(file + ".png");
+                }
+                return file;
+            }
+
+        } else {
+            return null;
+        }
+    }
+
+
+    private void setTextDetail() {
+        String textString = textInput.getText();
+        int size = Integer.parseInt(textSize.getText());
+
+        drawingArea.setModeText(textString, size);
     }
 
 
-- 
GitLab