...
Add the following constants:
Code Block language java /** default value for spacing between nodes. */ private static final float DEFAULT_SPACING = 15.0f;
Use the following code as the skeleton of the
doLayout(...)
method:Code Block language java progressMonitor.begin("Login_name layouter", 1); KShapeLayout parentLayout = layoutNodeparentNode.getData(KShapeLayout.class); float objectSpacing = parentLayout.getPRopertygetProperty(LayoutOptions.SPACING); if (objectSpacing < 0) { objectSpacing = DEFAULT_SPACING; } float borderSpacing = parentLayout.getProperty(LayoutOptions.BORDER_SPACING); if (borderSpacing < 0) { borderSpacing = DEFAULT_SPACING; } // TODO: Insert actual layout code. progressMonitor.done();
Put the following code at the end of the
doLayout(...)
method:Code Block language java progressMonitor.done();
This exercise will introduce the usage of the Eclipse Plugin Development Environment for developing new layout algorithms to be used in Eclipse diagram editors. Replace each <login> by your own login name (e.g. msp), and each <Login> by your login name with capitalized first letter (e.g. Msp). For any questions contact msp.
- Implement the layout provider class
- Add the following constant to the class:
/** default value for spacing between nodes. */ private static final float DEFAULT_SPACING = 15.0f;
- Write the following lines at the beginning of the
doLayout
method:progressMonitor.begin("<Login> Layouter", 1); KShapeLayout parentLayout = layoutNode.getData(KShapeLayout.class); float objectSpacing = parentLayout.getProperty(LayoutOptions.SPACING); if (objectSpacing < 0) { objectSpacing = DEFAULT_SPACING; } float borderSpacing = parentLayout.getProperty(LayoutOptions.BORDER_SPACING); if (borderSpacing < 0) { borderSpacing = DEFAULT_SPACING; }
- Write the following line at the end of the
doLayout
method:progressMonitor.done();
Implement the rest of the layouter such that the nodes of the input graph are all put in a row. - See the KGraph and KLayoutData data structures: the input is a KNode and holds the nodes of the graph in its list of children
- Iterate over the nodes in the
getChildren()
list of thelayoutNode
input Retrieve the size of a node using the following code: It is now time to write the code that places the nodes. Here's two suggestions for how you can place them: - The simplest way is to place nodes in a row, next to each other. To make this more interesting, you could also place the nodes along the graph of a Sine function.
- Another way might be to place them in a square or a circle. You would have to think about how exactly to align the nodes, which may well vary in size.
Info | |||||
---|---|---|---|---|---|
| |||||
The following tips might come in handy...
|
...
|
...
nodeLayout.setXpos(x); nodeLayout.setYpos(y);
...
|
This exercise will introduce the usage of the Eclipse Plugin Development Environment for developing new layout algorithms to be used in Eclipse diagram editors. Replace each <login> by your own login name (e.g. msp), and each <Login> by your login name with capitalized first letter (e.g. Msp). For any questions contact msp.
- Open the file META-INF/MANIFEST.MF → Extensions tab
- Add an extension for de.cau.cs.kieler.kiml.layout.layoutProviders
- Right-click the extension → New → layoutProvider
- Set name to <Login> Test Layouter, class to de.cau.cs.rtprak.<login>.tutorial2.<Login>LayoutProvider
- Right-click the new layoutProvider → New → knownOption, set option to de.cau.cs.kieler.spacing
- Add another knownOption, set to de.cau.cs.kieler.borderSpacing
- Run → Run Configurations... → right-click Eclipse Application → New
- Name: Layout
- For testing the layouter, a new workspace location will be created; you may configure its destination in Workspace Data → Location
- Add the program arguments
-debug -consoleLog
in the Arguments tab. - Go to Plug-ins tab, select Launch with: plug-ins selected below only
- Deselect All, activate Workspace checkbox, Add Required Plug-ins, Apply, Run
- Test the layouter in the new Eclipse instance:
- New → Project... → General → Project, name test
- Right-click test project → New → Other... → KEG Diagram (TODO: if graphs shall be created in another way, describe it here)
- Create a graph using the palette on the right.
- Window → Show View → Other... → KIELER → Layout
- While the graph diagram is open, set Layout Provider or Type in the Layout view to <Login> Test Layouter.
- Open the additional views Layout Graph and Layout Time.
- Trigger layout with the KIELER Layout button in the toolbar or Ctrl+R L (first Ctrl+R, then L).
- See the direct input and output of your algorithm in the Layout Graph view.
- See the execution time analysis in the Layout Time view.
- Implement another class EdgeRouter.
- Add the following method:
/**
* Route the edges that are connected with the children of the given node.
* @param parentNode the parent node of the input graph
*/
public void routeEdges(final KNode parentNode) {
getMonitor().begin("Edge Routing", 1);
getMonitor().done();
} - Add the following code to the end of the
doLayout
method in your layout provider:EdgeRouter edgeRouter = new EdgeRouter(); edgeRouter.routeEdges(layoutNode);
- Implement the
routeEdges
method:- Each edge shall be drawn with three line segments: one vertical segment starting below the source node, one horizonzal segment, and another vertical segment ending below the target node.
- The horizontal segments of two different edges shall not have the same y-coordinate; for consecutive edges, the distance between their horizontal segments shall equal
objectSpacing
. - See the attached image test-drawing.png for an example.
- Find the edges using
getOutgoingEdges()
orgetIncomingEdges()
on a node. - Get the edge layout of an edge to set bend points using this code:
KEdgeLayout edgeLayout = edge.getData(KEdgeLayout.class);
- Create a bend point using this code:
KPoint point = KLayoutDataFactory.eINSTANCE.createKPoint();
- Use the
getBendPoints()
list on theedgeLayout
to add bend points (clear the list first to remove points from the previous layout). - Set the values of the points returned by
getSourcePoint()
andgetTargetPoint()
according to the positions where the edge leaves its source node and reches its target node.
- Add the following method:
- Use your previous run configuration to test the edge router.