https://github.com/tharindu714/code-editor-memento
A sleek, dark-themed Java Swing code editor with robust Undo/Redo powered by the Memento Pattern.
https://github.com/tharindu714/code-editor-memento
code java memento-pattern oodp
Last synced: 5 months ago
JSON representation
A sleek, dark-themed Java Swing code editor with robust Undo/Redo powered by the Memento Pattern.
- Host: GitHub
- URL: https://github.com/tharindu714/code-editor-memento
- Owner: Tharindu714
- License: mit
- Created: 2025-08-07T10:35:25.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-08-07T10:56:09.000Z (6 months ago)
- Last Synced: 2025-08-07T12:34:02.788Z (6 months ago)
- Topics: code, java, memento-pattern, oodp
- Language: Java
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π Code-Editor-Memento
> A sleek, dark-themed Java Swing code editor with robust **Undo/Redo** powered by the **Memento** Pattern.
---
## π Scenario
> You are building an **online code editor** that lets users write and edit code in real-time. It needs **Undo** and **Redo** functionality without exposing internal state or hogging memory.
---
## βοΈ Features
* **Dark Mode UI**: Eye-friendly dark background with light-colored monospaced font.
* **Memento-based History**: Encapsulated state snapshots enable efficient undo/redo.
* **Stack-based Navigation**: Unlimited undo/redo operations via two history stacks.
* **Fluent GUI Controls**: Toolbar buttons for seamless user interaction.
---
## πΈ GUI Screenshot
---
## π UML Class Diagram
> *Generate and paste UML diagram here.*
---
## π Memento Pattern Theory
The **Memento** Pattern provides the ability to restore an object to its previous state without exposing its internal structure. It involves three key participants:
1. **Originator** π
* Holds the current state of the editor document (`String state`).
* Can create a **Memento** capturing its state and restore from it.
2. **Memento** π
* A simple, immutable value object that stores the internal state snapshot.
* Does **not** expose its internals beyond what the Originator needs.
3. **Caretaker** π€΅
* Manages saving and retrieving Memento objects.
* Maintains two stacks: one for **undo** and one for **redo** history.
* Controls when to clear redo history to preserve correct behavior.
### How It Works in Our App
1. **On Every Edit**: A new Memento is saved to the **undo** stack. The **redo** stack is cleared.
2. **Undo** π: Pop the top Memento from undo β push it to redo β restore the previous snapshot.
3. **Redo** π: Pop the top Memento from redo β restore it β push it back on undo.
4. **Encapsulation**: The editorβs text content is never exposed; only the Originator knows its state.
---
## π Usage
```bash
# Clone the repo
git clone https://github.com/Tharindu714/Code-Editor-Memento.git
# Open in your favorite IDE
gradle run # or mvn compile exec:java
```
---
## π€ Contributing
Pull requests and issues are welcome! Feel free to improve docs, add features, or optimize performance.
---
## π License
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.