In the preceding chapter, you used the PROTOTYPE pattern to design a simulation that let users speculatively create new machine simulators from existing ones. Your users like the simulation, but they sometimes make changes that they wish they could undo.
You might consider using the javax.swing.undo package to support an undo operation. However, the undo package focuses its support on operations for textual Swing components. In this application, it is simpler to apply the MEMENTO pattern to save and to restore the state of the simulation at key points.
Each time the user adds or moves a machine in the visualization, your code will create a memento of the simulated factory and add it to a stack.
Each time the user clicks the Undo ...