类 Drawing

java.lang.Object
com.example.graphics.Drawing
所有已实现的接口:
Serializable

public class Drawing extends Object implements Serializable
Main drawing class that manages shapes and rendering. This class integrates the various design patterns.
另请参阅:
  • 字段详细资料

    • serialVersionUID

      private static final long serialVersionUID
      另请参阅:
    • shapes

      private final List<Shape> shapes
    • commandManager

      private final CommandManager commandManager
    • shapeSubject

      private final ShapeSubject shapeSubject
    • renderer

      private transient Renderer renderer
  • 构造器详细资料

    • Drawing

      public Drawing(Renderer renderer)
      Constructor initializes the drawing
      参数:
      renderer - the renderer to use
  • 方法详细资料

    • addShape

      public void addShape(Shape shape)
      Add a shape to the drawing using the Command pattern
      参数:
      shape - the shape to add
    • removeShape

      public void removeShape(Shape shape)
      Remove a shape from the drawing using the Command pattern
      参数:
      shape - the shape to remove
    • moveShape

      public void moveShape(Shape shape, int x, int y)
      Move a shape to a new position using the Command pattern
      参数:
      shape - the shape to move
      x - the new x coordinate
      y - 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

      public void addObserver(ShapeObserver observer)
      Add an observer to be notified of shape changes
      参数:
      observer - the observer to add
    • removeObserver

      public void removeObserver(ShapeObserver observer)
      Remove an observer from the notification list
      参数:
      observer - the observer to remove
    • setRenderer

      public void setRenderer(Renderer renderer)
      Set the renderer to use
      参数:
      renderer - the renderer to use
    • getRenderer

      public Renderer getRenderer()
      Get the current renderer
      返回:
      the current renderer
    • getShapes

      public List<Shape> getShapes()
      Get the list of shapes
      返回:
      the list of shapes
    • render

      public void render()
      Render all shapes using the current renderer
    • acceptVisitor

      public void acceptVisitor(ShapeVisitor visitor)
      Apply a visitor to all shapes
      参数:
      visitor - the visitor to apply