Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Group nodes



A group node is an instance of the GraphMLGroupNode.

Creating a group node

To create a group node in the main diagram, you must use the GraphMLDiagram.addGroupNode() method. The method return the group node which you will be able to customize (for example, to add a label).

You can also create a group node and sets its label at the same time with the GraphMLDiagram.addGroupNodeWithLabel(String) method

Group node states

A group node has two states:

Adding a node in a group node

You can add a node as a child of the group node by GraphMLGroupNode.addNode(), or by GraphMLGroupNode.addNodeWithLabel(String)

You can also create a group node as child of a group node by GraphMLGroupNode.addGroupNode(), or by GraphMLGroupNode.addGroupNodeWithLabel(String)

Computing the node size

Main Article: diagram

It is possible to compute the group node size using the children nodes using AbstractGraphMLNode.computeSize(boolean) or GraphMLGroupNode.computeSize(float, boolean). The way the size is computed depends on the GraphMLGroupNode.getGroupOpenedNodeSizeType():
The computeSize(boolean) uses the groupNodePadding property of the defaults between the children nodes. The computeSize(float, boolean) uses a custom groupNodePadding.

Customizing the node

Main Article: ShapeNode

As for the GraphMLNode, you can access the properties of ShapeNode class allows to set various properties of the ShapeNode through one of the following methods: Most of the methods of the ShapeNode class are available on the GraphMLGroupNode. These methods will set the properties on the two node states. For example:
      GraphMLNode node = diagram.addNode();
      node.setFillColor("red"); // will fill the two states of the group node

Example

In this example, we create a diagram with two group nodes, and two nodes in each of the groups:
      GraphMLFactory factory = GraphMLFactory.getInstance();
      GraphMLDiagram diagram = factory.newDiagram();

      // create first group
      GraphMLGroupNode gnode1 = diagram.addGroupNode();
      gnode1.setLabel("Group 1");
      GraphMLNode node1 = gnode1.addNode();
      node1.setLabel("Node 1");
      GraphMLNode node2 = gnode1.addNode();
      node2.setLabel("Node 2");

      // create second group
      GraphMLGroupNode gnode2 = diagram.addGroupNode();
      gnode2.setLabel("Group 2");
      GraphMLNode node3 = gnode2.addNode();
      node3.setLabel("Node 3");
      GraphMLNode node4 = gnode2.addNode();
      node4.setLabel("Node 4");

      // create edges
      GraphMLEdge edge = node1.addEdgeTo(node2);
      GraphMLEdge edge2 = node3.addEdgeTo(node4);
      GraphMLEdge edge3 = node1.addEdgeTo(node4);

See also


Categories: general | nodes

Copyright 2021 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence