{"id":30048555,"url":"https://github.com/tharindu714/document-name-editor-app-composite","last_synced_at":"2025-08-07T10:38:37.905Z","repository":{"id":306396075,"uuid":"1026031993","full_name":"Tharindu714/Document-name-editor-app-composite","owner":"Tharindu714","description":"A Java Swing application demonstrating the Composite Design Pattern in a simple interactive document editor.","archived":false,"fork":false,"pushed_at":"2025-07-25T07:51:58.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-25T13:27:38.590Z","etag":null,"topics":["composite-pattern","design-patterns","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tharindu714.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-25T07:43:38.000Z","updated_at":"2025-07-25T07:53:12.000Z","dependencies_parsed_at":"2025-07-25T13:34:41.357Z","dependency_job_id":"0e4bf9d2-5d56-414b-8e83-fc72d42a4fc0","html_url":"https://github.com/Tharindu714/Document-name-editor-app-composite","commit_stats":null,"previous_names":["tharindu714/document-name-editor-app-composite"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Tharindu714/Document-name-editor-app-composite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FDocument-name-editor-app-composite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FDocument-name-editor-app-composite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FDocument-name-editor-app-composite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FDocument-name-editor-app-composite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tharindu714","download_url":"https://codeload.github.com/Tharindu714/Document-name-editor-app-composite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FDocument-name-editor-app-composite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269244280,"owners_count":24384537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composite-pattern","design-patterns","java"],"created_at":"2025-08-07T10:38:36.304Z","updated_at":"2025-08-07T10:38:37.898Z","avatar_url":"https://github.com/Tharindu714.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Editable Document Editor\n\nA Java Swing application demonstrating the **Composite Design Pattern** in a simple interactive document editor.\n\n---\n\n## Table of Contents\n\n1. [Overview](#overview)\n2. [Features](#features)\n3. [Design Pattern: Composite](#design-pattern-composite)\n4. [Getting Started](#getting-started)\n\n   * [Prerequisites](#prerequisites)\n   * [Project Structure](#project-structure)\n   * [Running the Application](#running-the-application)\n5. [How It Works](#how-it-works)\n6. [Extending the App](#extending-the-app)\n7. [License](#license)\n\n---\n\n## Overview\n\n`EditableDocEditor` is a desktop Java application built with **Swing** that lets users:\n\n* Click to select text boxes.\n* Edit existing text in those boxes.\n* Remove text boxes.\n* Add new text boxes dynamically at clicked locations.\n\nAll document elements (text boxes) are managed through the **Composite Pattern**, enabling uniform treatment of both individual elements and groups of elements.\n\n---\n\n## Features\n\n* **Interactive Editing**: Click any text box to select it, change its content via the toolbar.\n* **Dynamic Addition**: Type new text, click “Add Text,” and place new boxes at the last-clicked canvas location.\n* **Removal**: Remove the currently selected box with a single button click.\n* **Visual Feedback**: Console logs illustrate leaf vs. composite operations.\n\n---\n\n## Design Pattern: Composite\n\nThe **Composite Design Pattern** lets you treat both single objects (leaves) and compositions of objects (composites) uniformly.\n\n### Key Components\n\n1. **Component Interface (`DocumentElement`)**\n\n   * Declares common operations: `move()`, `resize()`, `draw()`, `contains()`.\n\n2. **Leaf (`EditableTextBox`)**\n\n   * Implements `DocumentElement` for individual text boxes.\n   * Handles its own drawing, hit-testing, and state (position, text, font size).\n\n3. **Composite (`EditableGroup`)**\n\n   * Implements `DocumentElement`, stores child `DocumentElement`s in a list.\n   * Forwards `move()`, `resize()`, and `draw()` calls to all children.\n\n4. **Client (`ActualDocEditor`)**\n\n   * Builds and manages the UI.\n   * Operates on `DocumentElement` references without knowing whether they are leaves or composites.\n\n### Why Use Composite?\n\n* **Scalability**: New element types (e.g., images, shapes) can be added easily.\n* **Uniformity**: Client code treats everything as `DocumentElement`, simplifying operations like rendering and hit-testing.\n* **Maintainability**: Clear separation between object behaviors (leaf) and object aggregates (composite).\n\n---\n\n## Getting Started\n\n### Prerequisites\n\n* Java JDK 11 or higher\n* IntelliJ IDEA (or any Java IDE)\n* Maven or Gradle (if using a build tool)\n\n### Project Structure\n\n```\nproject-root/\n├─ src/\n│  ├─ main/\n│  │  ├─ java/\n│  │  │   └─ com/tharindu/composite/\n│  │  │       ├─ ActualDocEditor.java\n│  │  │       └─ DocEditor.java\n│  │  └─ resources/\n│  │       └─ logo.png\n├─ README.md\n└─ pom.xml (or build.gradle)\n```\n\n### Running the Application\n\n1. **Import** the project into IntelliJ IDEA.\n2. Right‑click on `ActualDocEditor.java` → **Run**.\n3. Use the toolbar to add, select, edit, and remove text boxes.\n\n---\n\n## How It Works\n\u003cimg width=\"983\" height=\"726\" alt=\"image\" src=\"https://github.com/user-attachments/assets/b6cf256c-fdfe-4762-beb7-f63a20c3610e\" /\u003e\n\n1. **Initialization**\n   The client (`ActualDocEditor`) creates an `EditableGroup` and adds a couple of `EditableTextBox` leaves.\n\n2. **UI Setup**\n   A `JToolBar` hosts text fields and buttons; a custom `JPanel` (`DrawPanel`) overrides `paintComponent()` to draw all `DocumentElement`s.\n\n3. **User Interaction**\n\n   * **Click** on a text box → `page.findElementAt()` checks each leaf’s `contains()`.\n   * **Apply Text** → `setText()` on the selected leaf, followed by `repaint()`.\n   * **Add Text** → Reads input, creates a new leaf at the last click point, and adds it to the composite.\n   * **Remove** → Calls `remove()` on the composite to drop the selected leaf.\n\n4. **Console Logging**\n   Print statements tagged `[Leaf]`, `[Composite]`, and `[Client]` illustrate pattern operations in real time.\n\n---\n\n## Extending the App\n\n* **Image Support**: Implement an `ImageElement` leaf that loads and draws an image.\n* **Drag \u0026 Drop**: Allow users to drag text boxes around the canvas.\n* **Grouping**: Let users group multiple elements and treat them as a single composite.\n* **Export**: Add functionality to export the canvas to PDF or PNG.\n\n---\n\n## License\n\nLicensed under the MIT License. Feel free to reuse and adapt for your learning projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharindu714%2Fdocument-name-editor-app-composite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftharindu714%2Fdocument-name-editor-app-composite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharindu714%2Fdocument-name-editor-app-composite/lists"}