I'm designing a vector drawing app.
I need to implemente copy and paste, shapes insertion, deletion and transforming while still being capable of including new tools with easy in the future.
The way I think about it, this is a finite state machine, so i thought about a State Pattern. The stage behaves differently based on it internal state. Each state would be a tool.
var stage = new StageManager(); var insert = new InsertTool(); var copy = new CopyTool(); var paste = new PasteTool(); var select = new SelectTool(); stage.registerTool(insert); stage.registerTool(copy); stage.registerTool(paste); stage.registerTool(select);
If, say, user just pasted a shape, StageManager transitions to selection mode (SelectTool).
onMouseUp(event){
this.stageManager.addShapes(this.stageManager.clipboard.getAll());
// Just pasted, transition to selectionTool
this.stageManager.chooseTool('selection-tool');
}
// From now on, stage behaves like a selectionTool.
Is that a wise architecture for a diagram app?