...
Note that this is not Java, but Xtend code. Xtend is a language that compiles to Java and has a bunch of nifty little features that make writing a synthesis easier. The main entry point of our synthesis is the transform
method. As you can see, the method gets a TuringMachine
instance and returns a KNode
. That KNode
will contain our actual diagram.
Visualizing States
Let's start by adding nodes for all states in the Turing machine.
Add a new method to your synthesis that transforms a
State
into a correspondingKNode
:Code Block language java 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));
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:
- Right-click the Package Explorer and select New -> Project.
- In the dialog, select General -> Project and click Next.
- Give the project a meaningful name (Foo is a classic) and click Finish.
- Right-click your new project in the Package Explorer and select New -> Other.
- In the dialog, select Example EMF Model Creation Wizards -> Turingmachine Model and click Next.
- Give your Turing machine file a meaning