Class GObjectManager


  • public class GObjectManager
    extends Object
    The manager that manages all the graphical objects on the canvas.
    Author:
    Zhijie Lan

    create date: 2020/11/15

    • Field Detail

      • draggedObj

        public static GObject draggedObj
        the object that is being dragged on the canvas
      • inspectedObj

        public static GObject inspectedObj
        the selected object that is showed on the inspector panel
      • resizedObj

        public static GObject resizedObj
        the object that is being resized
      • resizePointObj

        public static GObject resizePointObj
        the object that shows the resize point
      • resizeRecs

        private static Rectangle2D[] resizeRecs
        the small rectangles on the diagonal of the shapes, used to resize the shapes
      • selectedResizePoint

        public static Point2D selectedResizePoint
        the selected resize rectangle
      • unselectedResizePoint

        public static Point2D unselectedResizePoint
        another resize rectangle, fixed when resizing
      • drawingObj

        public static GObject drawingObj
        the new object that is created by drawing
      • drawingType

        public static String drawingType
        the type of the new shape, empty when not drawing
      • drawingColor

        public static Color drawingColor
        the color of the new shape
      • drawingLineWidth

        public static int drawingLineWidth
        the line width of the new shape
      • drawingFilled

        public static boolean drawingFilled
        whether the new shape is filled
      • gObjectList

        protected static ArrayList<GObject> gObjectList
        the array list that holds all the GObject
      • mouseDispatcher

        private static final GObjectManager.MouseDispatcher mouseDispatcher
        the listener to dispatch the mouse event to the canvas in the presentation mode, so that the text area will not intercept the user input
    • Constructor Detail

      • GObjectManager

        public GObjectManager()
    • Method Detail

      • drawAll

        public static void drawAll​(Graphics2D g2)
        draw all the objects on canvas
        Parameters:
        g2 - graphics to paint
      • updateResizing

        public static GObject updateResizing​(Point2D start,
                                             Point2D current,
                                             GObject obj,
                                             String type)
        when dragging mouse to resize shapes, use this function to update the shape to have dynamic resizing effect
        Parameters:
        start - the start point of new shapes
        current - the current point of the cursor
        obj - the object to be resized
        type - the type of resized object
        Returns:
        the resized GObject
      • finishDrawingNew

        public static void finishDrawingNew()
        finishing drawing the new objects
      • addImageObject

        public static void addImageObject​(BufferedImage image)
        add a Image
        Parameters:
        image - the image source
      • drawResizePoints

        public static void drawResizePoints​(Graphics2D g2)
        to draw two small rectangle on the diagonal of shapes, let the shapes resizable by dragging those points.
        Parameters:
        g2 - the graphics to paint
      • getResizableRec

        public static Rectangle2D getResizableRec​(double x,
                                                  double y)
        find if the given x,y select a resize point
        Parameters:
        x - x
        y - y
        Returns:
        the selected rec, null if no rec is selected
      • getResizableRec

        public static Rectangle2D getResizableRec​(Point2D point)
        find if the given x,y select a resize point
        Parameters:
        point - point
        Returns:
        the selected rec, null if no rec is selected
      • updateResizablePoint

        public static void updateResizablePoint​(double x,
                                                double y)
        draw two resize point to the object located at the given x, y
        Parameters:
        x - x location
        y - y location
      • updateResizablePoint

        public static void updateResizablePoint​(Point2D point)
        draw two resize point to the object located at the given x, y
        Parameters:
        point - location
      • findSelected

        public static GObject findSelected​(double x,
                                           double y)
        find if the given x,y select an object
        Parameters:
        x - x
        y - y
        Returns:
        the selected object, null if no selected
      • findSelected

        public static GObject findSelected​(Point2D point2D)
        find if the given x,y select an object
        Parameters:
        point2D - the point
        Returns:
        the selected object, null if no selected
      • updateAllObject

        public static void updateAllObject()
        call the objects' attribute manager to update all their attributes
      • insertStateToGObjects

        public static void insertStateToGObjects()
        call the objects' attribute manager to insert a state to all objects
      • deleteStateToGObjects

        public static void deleteStateToGObjects​(int state)
        call the objects' attribute manager to delete a given state
        Parameters:
        state - the state to delete
      • addGObject

        public static void addGObject​(GObject obj)
        add a graphical object to the canvas
        Parameters:
        obj - the object to add
      • addTextArea

        public static void addTextArea​(GText textObj)
        add a JTextArea component to the list and center canvas
        Parameters:
        textObj - the GText object that holds the JTextArea
      • deleteTextArea

        public static void deleteTextArea​(GText textObj)
        remove a JTextArea from the canvas
        Parameters:
        textObj - the GText object to be deleted
      • deleteGObject

        public static void deleteGObject​(GObject obj)
        delete an object. If the object is a text box, delete the text area as well
        Parameters:
        obj - the object to be deleted
      • reloadAllTextArea

        public static void reloadAllTextArea()
        transverse all GObjects, and add all JTextAreas to the canvas
      • deleteAllTextArea

        public static void deleteAllTextArea()
        transverse all GObjects, and delete all JTextAreas to the canvas
      • addTextComponentToPresenter

        public static void addTextComponentToPresenter​(CenterCanvas presentCanvas)
        when start presenting, add all text areas components to the present canvas, and set the text areas being not editable and focusable
        Parameters:
        presentCanvas - the present canvas
      • resetTextComponentToCanvas

        public static void resetTextComponentToCanvas()
        when finishing presenting, reset all text areas back to the edit canvas