Package prezoom.controller
Class GObjectManager
- java.lang.Object
-
- prezoom.controller.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGObjectManager.MouseDispatcherthe listener to dispatch the mouse event to the canvas in the presentation mode, so that the text area will not intercept the user input
-
Field Summary
Fields Modifier and Type Field Description static GObjectdraggedObjthe object that is being dragged on the canvasstatic ColordrawingColorthe color of the new shapestatic booleandrawingFilledwhether the new shape is filledstatic intdrawingLineWidththe line width of the new shapestatic GObjectdrawingObjthe new object that is created by drawingstatic StringdrawingTypethe type of the new shape, empty when not drawingprotected static ArrayList<GObject>gObjectListthe array list that holds all the GObjectstatic GObjectinspectedObjthe selected object that is showed on the inspector panelprivate static GObjectManager.MouseDispatchermouseDispatcherthe listener to dispatch the mouse event to the canvas in the presentation mode, so that the text area will not intercept the user inputstatic GObjectresizedObjthe object that is being resizedstatic GObjectresizePointObjthe object that shows the resize pointprivate static Rectangle2D[]resizeRecsthe small rectangles on the diagonal of the shapes, used to resize the shapesstatic Point2DselectedResizePointthe selected resize rectanglestatic Point2DunselectedResizePointanother resize rectangle, fixed when resizing
-
Constructor Summary
Constructors Constructor Description GObjectManager()
-
Method Summary
Modifier and Type Method Description static voidaddGObject(GObject obj)add a graphical object to the canvasstatic voidaddImageObject(BufferedImage image)add a Imagestatic voidaddTextArea(GText textObj)add a JTextArea component to the list and center canvasstatic voidaddTextComponentToPresenter(CenterCanvas presentCanvas)when start presenting, add all text areas components to the present canvas, and set the text areas being not editable and focusablestatic voiddeleteAllTextArea()transverse all GObjects, and delete all JTextAreas to the canvasstatic voiddeleteGObject(GObject obj)delete an object.static voiddeleteStateToGObjects(int state)call the objects' attribute manager to delete a given statestatic voiddeleteTextArea(GText textObj)remove a JTextArea from the canvasstatic voiddrawAll(Graphics2D g2)draw all the objects on canvasstatic voiddrawResizePoints(Graphics2D g2)to draw two small rectangle on the diagonal of shapes, let the shapes resizable by dragging those points.static GObjectfindSelected(double x, double y)find if the given x,y select an objectstatic GObjectfindSelected(Point2D point2D)find if the given x,y select an objectstatic voidfinishDrawingNew()finishing drawing the new objectsstatic Rectangle2DgetResizableRec(double x, double y)find if the given x,y select a resize pointstatic Rectangle2DgetResizableRec(Point2D point)find if the given x,y select a resize pointstatic voidinsertStateToGObjects()call the objects' attribute manager to insert a state to all objectsstatic voidreloadAllTextArea()transverse all GObjects, and add all JTextAreas to the canvasstatic voidresetTextComponentToCanvas()when finishing presenting, reset all text areas back to the edit canvasstatic voidupdateAllObject()call the objects' attribute manager to update all their attributesstatic voidupdateResizablePoint(double x, double y)draw two resize point to the object located at the given x, ystatic voidupdateResizablePoint(Point2D point)draw two resize point to the object located at the given x, ystatic GObjectupdateResizing(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
-
-
-
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
-
-
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 shapescurrent- the current point of the cursorobj- the object to be resizedtype- 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- xy- 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 locationy- 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- xy- 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
-
-