Can I use Memento Design Pattern for JFreeChart?

39 Views Asked by At

Is it possible to use the memento pattern for undo operation in JFreeChart?

If it's possible please give me some examples of it.

1

There are 1 best solutions below

0
trashgod On

Yes, the memento pattern can be used with JFreeChart. This typical example manages a String, but your Memento class would contain a suitable concrete implementation of your chosen Dataset. An instance of that dataset would be held by your Originator. Your Caretaker would then contain a List<Originator.Memento>. Your implementation of Originator::set and Originator::restoreFromMemento can use setDataset(), as shown here, to set the chart's current dataset or restore the chart to any previously saved state. For convenience, many implementations of Dataset implement Cloneable.