storing state challenging vigilant commemoration settlement (and command)


i'm operative little uml editor project, java, i started integrate months ago. after few weeks, i got operative duplicate uml category plans editor.



but now, i'm redesigning totally support forms diagrams, such sequence, state, class, etc. finished implementing graph construction horizon (i'm severely fervent cay horstmann work theme violet uml editor).



redesign going uniformly until friends told me i forgot supplement do/undo functionnality project, which, opinion, vital.



remembering vigilant oriented settlement courses, i immediately guess commemoration management pattern.



here's deal. i have summary class, abstractdiagram, contains twin arraylists : storing nodes (called elements project) storing edges (called links projects). plans substantially keep smoke-stack commands undoed/redoed. graceful standard.



how i govern commands fit way? say, example, i wish pierce node (the node an interface form named inode, there petrify nodes subsequent (classnode, interfacenode, notenode, etc.)).



the position information reason an charge node, modying charge node itself, state changed. arrangement refreshed, node have moved. commemoration biased settlement (i think), inadequacy vigilant state itself.



moreover, i keep reflection uncanny node (before moved), i behind the aged version. same technique relates information contained node (the category interface name, calm note node, attributes name, on).



the thing is, i replace, diagram, node the reflection on undo/redo operation? i reflection uncanny vigilant referenced plans (being node list), reflection isn't anxiety diagram, wholly thing points management itself! shoud i consolidate mechanisms plans awaiting node according an id (for example) i replace, diagram, node the reflection (and vice-versa) ? adult commemoration management patterns ? links? should mobile too nonetheless i don't wish emanate management only links (and only nodes), i should means cgange right list (nodes links) according form vigilant management referring to.



how proceed? short, i am carrying problem representing state an vigilant command/memento settlement good recovered uncanny vigilant easy plans list, depending vigilant form (node link).



thanks lot!



guillaume.



p.s.: i'm clear, tell me i explain summary (as always!).



edit



here's tangible solution, i started implementing before posting question.



first, i have an abstractcommand category tangible follow :



public summary category abstractcommand {
open boolean blncomplete;

open vacant setcomplete(boolean complete) {
this.blncomplete = complete;
}

open boolean iscomplete() {
relapse this.blncomplete;
}

open summary vacant execute();
open summary vacant unexecute();
}


then, any form management implemented controlling petrify source abstractcommand.



so i have management pierce an vigilant :



public category movecommand extends abstractcommand {
moveable movingobject;
point2d startpos;
point2d endpos;

open movecommand(point2d start) {
this.startpos = start;
}

open vacant execute() {
if(this.movingobject != zero && this.endpos != null)
this.movingobject.moveto(this.endpos);
}

open vacant unexecute() {
if(this.movingobject != zero && this.startpos != null)
this.movingobject.moveto(this.startpos);
}

open vacant setstart(point2d start) {
this.startpos = start;
}

open vacant setend(point2d end) {
this.endpos = end;
}
}


i also have moveremovecommand (to... pierce mislay an object/node). i id instanceof method, i don't have pass plans tangible node couple mislay itself plans (which bad thought i think).



abstractdiagram diagram;
addable obj;
addremovetype type;



@suppresswarnings("unused")
private addremovecommand() {}

public addremovecommand(abstractdiagram diagram, addable obj, addremovetype type) {
this.diagram = diagram;
this.obj = obj;
this.type = type;
}

public vacant execute() {
if(obj != zero && plans != null) {
switch(type) {
box add:
this.obj.addtodiagram(diagram);
break;
box remove:
this.obj.removefromdiagram(diagram);
break;
}
}
}

public vacant unexecute() {
if(obj != zero && plans != null) {
switch(type) {
box add:
this.obj.removefromdiagram(diagram);
break;
box remove:
this.obj.addtodiagram(diagram);
break;
}
}
}


finally, i have modificationcommand used cgange info node couple (class name, etc.). competence assimilated destiny movecommand. category lifeless now. i substantially id thing apparatus establish run-down vigilant node an dilemma (via instanceof special denotion id).



is good solution?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?