...
Add a new method to your synthesis that transforms a
State
into a correspondingKNode
:Code Block language scala linenumbers true private def KNode transform(State state) { val stateNode = state.createNode().associateWith(state); return stateNode; }
While this method does indeed create a node for the state passed to it, KLighD wouldn't know how to render it yet. Let's draw the node as a rounded rectangle by adding the following line before the
return
statement:Code Block language java linenumbers true stateNode.addRoundedRectangle(4, 4, 2);
The only thing missing now is a label with the state's name:
Code Block language java linenumbers true stateNode.addInsideCenteredNodeLabel(state.name, KlighdConstants.DEFAULT_FONT_SIZE, KlighdConstants.DEFAULT_FONT_NAME); stateNode.addLayoutParam( LayoutOptions.SIZE_CONSTRAINT, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.NODE_LABELS));
Now that we know how to transform states, we have to call our new method from the main transformation method. Replace the comment in its body with the following line of code:
Code Block language scala linenumbers true model.states.forEach[ s | root.children += transform(s) ]
Let's see if our visualization works. Start your program (if you don't know how to do that, check out our Eclipse Plug-ins and Extension Points tutorial) and follow these steps:
...