This Paint App is a dynamic drawing application that synergizes Vue.js for a responsive frontend and Spring Boot for a robust backend. Vue.js ensures a smooth user interface, while Spring Boot handles backend operations and API integrations. This collaboration enables real-time synchronization, enhancing performance. The app leverages APIs for features like an AI image generator, image import, and versatile file format support. This amalgamation positions the Paint App as a versatile and user-friendly tool, empowering users to bring their artistic visions to life.
- Draw Shapes (Circle, Ellipse, Triangle, Square, Rectangle, Line, Pentagon, Hexagon) By Mouse Dragging:
- The application supports drawing various shapes by dragging the mouse, including circles, ellipses, triangles, squares, rectangles, lines, pentagons, and hexagons.
- Free-Hand Drawing:
- Users can engage in free-hand drawing, allowing them to create custom shapes or patterns on the canvas.
- Cloning:
- The cloning feature enables users to duplicate existing shapes, providing a convenient way to reproduce elements on the canvas.
- Coloring + Color Picker:
- Shapes can be colored using a color picker, giving users the flexibility to choose a wide range of colors for their drawings.
- Selection + Window Selection:
- Users can select individual shapes or perform window selection to choose multiple shapes at once. This makes it easier to manipulate and manage groups of shapes.
- Grouping:
- Grouping functionality allows users to combine multiple shapes into a single group, simplifying the manipulation of related elements.
- Resize:
- Shapes can be resized, giving users control over the dimensions of each element on the canvas.
- Scaling:
- Scaling functionality allows users to proportionally adjust the size of shapes, maintaining their aspect ratios.
- Rotate:
- Shapes can be rotated, providing users with the ability to orient elements in different directions.
- Move:
- Users can move shapes across the canvas, repositioning them as needed.
- Delete:
- Shapes or groups of shapes can be deleted, allowing users to remove unwanted elements.
- Clear All:
- The "Clear All" feature removes all shapes from the canvas, providing a quick way to start fresh.
- Undo:
- The undo functionality lets users revert the canvas to its previous state, step by step.
- Redo:
- The redo functionality allows users to reapply actions that were undone, restoring the canvas to a later state.
- Save as XML, JSON, Image:
- Users can save their drawings in different formats such as XML, JSON, or as image files.
- Load XML, JSON:
- Drawings saved in XML or JSON format can be loaded back into the application for editing.
- Import Images 👽:
- Users can import external images into the canvas, providing additional elements for their drawings.
- AI Image Generator 🤖:
- The application features an AI image generator, allowing users to create images automatically through artificial intelligence algorithms.
- Factory Method Pattern (in
ShapeFactory
):- The
ShapeFactory
class acts as a factory method pattern. It encapsulates the logic for creating different types of shapes based on the providedshapeType
. This pattern promotes flexibility by allowing the addition of new shape types without modifying existing code.
- The
- Singleton Pattern (in
ShapeManager
):- The
ShapeManager
class follows the singleton pattern, ensuring that only one instance of the manager exists throughout the application. This is useful for maintaining a centralized point of control for managing shapes and their history.
- The
- Command Pattern (in
ShapeManager
for undo and redo):- The undo and redo functionality in the
ShapeManager
follows a command pattern. Each change in the state of the shapes is considered a command, and the manager keeps a history of these commands. Undo and redo operations execute these commands in reverse or forward order.
- The undo and redo functionality in the
- Interface Segregation:
- The
Shape
interface follows the Interface Segregation Principle, as it defines only the methods relevant to a shape, avoiding unnecessary methods that might not be applicable to all shapes.
- The
- Inheritance and Polymorphism:
- The use of inheritance and polymorphism is evident in the various shape classes (
Circle
,Rectangle
,PolygonShape
, etc.). It allows for treating objects of derived classes uniformly through the commonShape
interface.
- The use of inheritance and polymorphism is evident in the various shape classes (
- Encapsulation:
- Each shape class encapsulates its attributes and behavior, providing a clean and modular design. This encapsulation ensures that changes to one part of the system don't affect other parts.
- Composition over Inheritance (in
Square
):- The
Square
class extendsRectangle
, showcasing a form of composition over inheritance. It inherits behavior common to rectangles and adds specific behavior for a square without duplicating code.
- The
- RESTful API Design:
- The
ShapesController
class follows RESTful API design principles, with different HTTP methods (POST
,PUT
,GET
,DELETE
) corresponding to specific actions on shapes. This makes the API intuitive and easy to use.
- The
- Serialization/Deserialization:
- XML and JSON serialization/deserialization in the
ShapeManager
demonstrates a flexible approach for saving and loading shapes. Different formats can be easily added in the future.
- XML and JSON serialization/deserialization in the
- Command and History Management:
- The
ShapeManager
effectively manages a history of shape states, providing undo and redo functionality. This aligns with the Command Pattern, where each action is a command, and the manager keeps a record of these commands.
- The
- Annotation-Based Configuration (in
ShapesController
):- The use of annotations from the Spring Framework (
@RestController
,@PostMapping
,@PutMapping
, etc.) simplifies the configuration and mapping of HTTP requests to methods.
- The use of annotations from the Spring Framework (
This section provides a high-level overview of the Unified Modeling Language (UML) representation for the Drawing Application. UML diagrams serve as visual aids to understand the structural and behavioral aspects of the application's design.
- Each function corresponds to a specific shape type (circle, ellipse, rectangle, image, etc.).
- The functions use the
fetch
API to send aPOST
request to the corresponding backend endpoint (http://localhost:8080/circle
,http://localhost:8080/ellipse
, etc.). - They pass shape information (e.g., position, dimensions, color) in the request body as JSON.
- After posting, they log the success message and return the response data.
createFromJson(shape)
:- Creates a Konva shape based on the provided JSON data.
- Handles different shape types (circle, ellipse, rectangle, etc.) using a switch statement.
- Adds the new shape to the Konva layer and calls
toBackend
to save it on the backend.
toBackend(shape, type)
:- Saves a Konva shape to the backend using the corresponding API function (e.g.,
CreateCircle
,CreateEllipse
, etc.).
- Saves a Konva shape to the backend using the corresponding API function (e.g.,
createShape(pos)
:- Creates a new Konva shape based on the drawing mode (
drawingShape
) and the current color.
- Creates a new Konva shape based on the drawing mode (
startDrawing(event)
:- Initiates the drawing process based on the selected shape.
- Calls the corresponding API function to create the shape on the backend.
stopDrawing(event)
anddrawing(event)
:- Handle the end and ongoing drawing processes, respectively.
- Update the shape's properties and call the corresponding API function for real-time updates.
undo()
andredo()
:- Handle undo and redo actions by navigating through the history array.
- Send requests to the backend (
http://localhost:8080/layer/undo
,http://localhost:8080/layer/redo
) for server-side history management.
drawNewLayer()
:- Updates the Konva layer based on the current state in the history array.
clearHistory()
:- Clears the history array up to the current history index.
saveRecord()
:- Saves the current state of the Konva layer to the history array.
- Sends a request to the backend (
http://localhost:8080/layer/record
) for server-side recording.
getType(shape)
:- Determines the type of a given Konva shape (circle, rectangle, ellipse, etc.).
updateShape(shape)
andcreateShape(shape, id)
:- Update or create a shape on the backend based on its type.
- Use the corresponding API functions (
UpdateCircle
,CreateRectangle
, etc.).
forceLoadImage
:- A utility function that returns a Promise, resolving when an image is fully loaded.
downloadImage(url, fileName)
:- Downloads an image from the specified URL with an optional filename.
In summary, Paint is a collaborative Vue.js and Spring Boot application that offers a seamless drawing experience. With a user-friendly interface, versatile features like shape creation, free-hand drawing, and AI image generation, Paint provides a dynamic canvas for creativity. The README provides a comprehensive guide, covering features, design patterns, and the application's structural overview. Paint invites users and developers to explore its possibilities and contribute to a vibrant artistic community. Happy Drawing! 🎨