A sleek, dark-themed Java Swing code editor with robust Undo/Redo powered by the Memento Pattern.
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.
- 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.
---
Generate and paste UML diagram here.
The Memento Pattern provides the ability to restore an object to its previous state without exposing its internal structure. It involves three key participants:
-
Originator 🏭
- Holds the current state of the editor document (
String state). - Can create a Memento capturing its state and restore from it.
- Holds the current state of the editor document (
-
Memento 🎁
- A simple, immutable value object that stores the internal state snapshot.
- Does not expose its internals beyond what the Originator needs.
-
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.
- On Every Edit: A new Memento is saved to the undo stack. The redo stack is cleared.
- Undo 🔙: Pop the top Memento from undo → push it to redo → restore the previous snapshot.
- Redo 🔜: Pop the top Memento from redo → restore it → push it back on undo.
- Encapsulation: The editor’s text content is never exposed; only the Originator knows its state.
# Clone the repo
git clone https://github.com/Tharindu714/Code-Editor-Memento.git
# Open in your favorite IDE
gradle run # or mvn compile exec:javaPull requests and issues are welcome! Feel free to improve docs, add features, or optimize performance.
This project is licensed under the MIT License. See LICENSE for details.


