Show last authors
1 These instructions should guide you if you'd like to try out using KLighD for visualizing your own models or data structures. A minimal example is shown where a Xtext model from a textual editor is visualized with KLighD.
2
3 == Step-By-Step Guide ==
4
5 In order to get this example working, please follow the instructions below:
6
7 1. Download Eclipse Kepler (Modeling Edition) and install KIELER Pragmatics 0.10.0 ([[according to these instructions>>doc:Minimal Example HowTo]])
8 1. Download the following files, unzip them and import them as existing projects into your Eclipse workspace:
9 [[attach:de.cau.cs.kieler.klighd.example.myxtextdata.zip]]
10 [[attach:de.cau.cs.kieler.klighd.example.myxtextdata.ui.zip]]
11 [[attach:de.cau.cs.kieler.klighd.example.myxtextdata.klighd.zip]]
12 1. You may now create a new run-configuration ([[according to these instructions>>doc:Minimal Example HowTo]]) and run everything as an Eclipse Application.
13 1. Once you create a new text file with the ending "*.myxtextdata" and enter some content (Ctrl+Space gives you content assist), you should see the synthesized diagram as follows:
14 [[image:attach:myxtextdata.png]]
15
16
17
18 == The Details ==
19
20 The following files are involved:
21
22 1. **MyXtextData.xtext **(de.cau.cs.kieler.klighd.example.myxtextdata) : It contains a very simple Xtext grammar for the textual language
23 1. **ShowDiagramCombination.java** (de.cau.cs.kieler.klighd.example.myxtextdata.klighd) : This is a KIELER combination for triggering the automatic diagram synthesis when editing the model in the textual editor.
24 1. **MyXtextDataDiagramSynthesis.xtend** (de.cau.cs.kieler.klighd.example.myxtextdata.klighd) : This is the most essential part, it is the transformation from your data/model to the view model (the diagram). You can use this as a bare bone example and extend it as you like. Note that it already uses several KLighD extension libraries that are included. These libraries can be inspected also if you are searching for further features that you want to use, they contain the most common features already.
25
26 == The Files ==
27
28 {{code title="MyXtextData.xtext" language="java"}}
29 grammar de.cau.cs.kieler.klighd.example.myxtextdata.MyXtextData with org.eclipse.xtext.common.Terminals
30
31 generate myXtextData "http://www.cau.de/cs/kieler/klighd/example/myxtextdata/MyXtextData"
32
33 Model:
34 name=ID (':' '{'
35 subData+=Model*
36 '}')?;
37
38 {{/code}}
39
40
41
42
43
44 {{code title="ShowDiagramCombination.java" language="java"}}
45  
46 {{/code}}
47
48 {{code title="MyDataDiagramSynthesis.xtend"}}
49 class MyDataDiagramSynthesis extends AbstractDiagramSynthesis<MyData> {
50 @Inject extension KNodeExtensions
51 @Inject extension KEdgeExtensions
52 @Inject extension KPortExtensions
53 @Inject extension KLabelExtensions
54 @Inject extension KRenderingExtensions
55 @Inject extension KContainerRenderingExtensions
56 @Inject extension KPolylineExtensions
57 @Inject extension KColorExtensions
58 // Some self-defined colors
59 private static val KColor BLUE1 = RENDERING_FACTORY.createKColor() =>
60 [it.red = 248; it.green = 249; it.blue = 253];
61 private static val KColor BLUE2 = RENDERING_FACTORY.createKColor() =>
62 [it.red = 205; it.green = 220; it.blue = 243];
63 // Additional transformation option to hide or show a shadow
64 private static val SynthesisOption SHOW_SHADOW = SynthesisOption::createCheckOption("Shadow", true);
65 // Add all transformation options (comma separated)
66 override getDisplayedSynthesisOptions() {
67 return ImmutableList::of(
68 SHOW_SHADOW
69 );
70 }
71 override KNode transform(MyData data) {
72 val root = data.createNode()
73 root.putToLookUpWith(data) => [
74 // Optional Layout parameters can be set
75 //it.addLayoutParam(LayoutOptions::ALGORITHM, "de.cau.cs.kieler.kiml.ogdf.planarization");
76 //it.addLayoutParam(LayoutOptions::SPACING, 75f);
77 //it.addLayoutParam(LayoutOptions::DIRECTION, Direction::UP);
78 // A rounded rectangle is created for every MyData instance
79 it.addRoundedRectangle(5, 5) => [
80 // Set linewith, foreground color, and a fading background color
81 it.lineWidth = 1;
82 it.setForeground("darkGray".color)
83 // We need a fresh copy of each color item, because it is contained by its element
84 it.setBackgroundGradient(BLUE1.copy, BLUE2.copy, 90)
85 // Here we see a how to use a boolean transformation/diagram option
86 if (SHOW_SHADOW.booleanValue) {
87 it.shadow = "black".color;
88 }
89 // Set a text
90 it.addText(" " + data.name + " ") => [
91 it.setFontSize(9)
92 it.setForeground("black".color)
93 ]
94 // If this is a hierarchical MyData instance, then create horizontal splitter,
95 // a child area, and add its children
96 if (data.subData.length > 0) {
97 it.setGridPlacement(1);
98 it.addHorizontalSeperatorLine(1, 2).setForeground("darkGray".color)
99 it.addChildArea().setGridPlacementData() => [
100 from(LEFT, 3, 0, TOP, 3, 0).to(RIGHT, 3, 0, BOTTOM, 3, 0)
101 minCellHeight = 5;
102 minCellWidth = 5;
103 ];
104 for (subData : data.subData) {
105 // To the recursive call to transform for all children
106 val child = subData.transform
107 // It is important to add all children to the root!
108 root.children.add(child)
109 }
110 }
111 ]
112 ]
113 return root;
114 }
115 }
116 {{/code}}
117
118
119
120
121
122 Eclipse