类 Drawing
java.lang.Object
com.example.graphics.Drawing
- 所有已实现的接口:
Serializable
Main drawing class that manages shapes and rendering.
This class integrates the various design patterns.
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final CommandManager
private Renderer
private static final long
private final ShapeSubject
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void
acceptVisitor
(ShapeVisitor visitor) Apply a visitor to all shapesvoid
addObserver
(ShapeObserver observer) Add an observer to be notified of shape changesvoid
Add a shape to the drawing using the Command patternGet the current rendererGet the list of shapesvoid
Move a shape to a new position using the Command patternboolean
redo()
Redo the last undone commandvoid
removeObserver
(ShapeObserver observer) Remove an observer from the notification listvoid
removeShape
(Shape shape) Remove a shape from the drawing using the Command patternvoid
render()
Render all shapes using the current renderervoid
setRenderer
(Renderer renderer) Set the renderer to useboolean
undo()
Undo the last command
-
字段详细资料
-
serialVersionUID
private static final long serialVersionUID- 另请参阅:
-
shapes
-
commandManager
-
shapeSubject
-
renderer
-
-
构造器详细资料
-
Drawing
Constructor initializes the drawing- 参数:
renderer
- the renderer to use
-
-
方法详细资料
-
addShape
Add a shape to the drawing using the Command pattern- 参数:
shape
- the shape to add
-
removeShape
Remove a shape from the drawing using the Command pattern- 参数:
shape
- the shape to remove
-
moveShape
Move a shape to a new position using the Command pattern- 参数:
shape
- the shape to movex
- the new x coordinatey
- the new y coordinate
-
undo
public boolean undo()Undo the last command- 返回:
- true if a command was undone, false if there are no commands to undo
-
redo
public boolean redo()Redo the last undone command- 返回:
- true if a command was redone, false if there are no commands to redo
-
addObserver
Add an observer to be notified of shape changes- 参数:
observer
- the observer to add
-
removeObserver
Remove an observer from the notification list- 参数:
observer
- the observer to remove
-
setRenderer
Set the renderer to use- 参数:
renderer
- the renderer to use
-
getRenderer
Get the current renderer- 返回:
- the current renderer
-
getShapes
Get the list of shapes- 返回:
- the list of shapes
-
render
public void render()Render all shapes using the current renderer -
acceptVisitor
Apply a visitor to all shapes- 参数:
visitor
- the visitor to apply
-