Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Nodes



A node is an instance of the GraphMLNode.

GraphMLNodes are terminal nodes. The library also support group nodes. See Group node for more information.

Creating a node

To create a node directly under the diagram, you must use the GraphMLDiagram.addNode() method. The method return the node which you will be able to customize (for example, to add a label).

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

Customizing a node

Main Article: ShapeNode

The ShapeNode class allows to set various properties of the node Shape:
  • Border style
  • Label
  • Background color
  • Node geometry
  • Node type (rectangle, circle, etc...)
  • Node drop shadow
Some of these properties can directly be set or get through the node.

To set the position and size of a node:
      GraphMLNode node = diagram.addNode();
      node.setX(10);
      node.setY(10);
To set the size of a node:
      GraphMLNode node = diagram.addNode();
      node.setWidth(50);
      node.setHeight(100);
To set the size of a node, such that it will always be set to correctly enclose its label:
      GraphMLNode node = diagram.addNode();
      node.setAutosized(true);
To set the color of a node:
      GraphMLNode node = diagram.addNode();
      node.getShapeNode().setFillColor("red");
You can also specify that the fill or the border of the node will be transparent. For example:
      GraphMLNode node = diagram.addNode();
      node.setHasFillColor(false);
      node.setHasBorderColor(false);      

Node label

Main Article: Node labels

To set the label of a node:
      GraphMLNode node = diagram.addNode();
      node.setLabel("The Label");

You can also create the node and sets its label at the same time by using the GraphMLDiagram.addNodeWithLabel(String) method.


By default the text color is black, but it is possible to set the text color. For example:
      GraphMLNode node = diagram.addNode();
      NodeLabel label = node.setLabel("The Label");
      label.setTextColor(Color.RED);

Node label position

Main Article: Node label position

It is possible to customize the node label position.

Node type

By default the type of the node is a rectangle. To set another type for a node (for example, here it is a round rectangle):
      GraphMLNode node = diagram.addNode();
      node.setType(ShapeType.ROUNDRECTANGLE);

Node drop shadow

To add a drop shadow to a node with a default black color and an offset of 3 on x and y:
      GraphMLNode node = diagram.addNode();
      DropShadow dropShadow = new DropShadow(3, 3);
      node.setDropShadow(dropShadow);
By default the text color is black, but it is possible to set the text color. For example:
      GraphMLNode node = diagram.addNode();
      NodeLabel label = node.setLabel("The Label");
      label.setTextColor(Color.RED);

Node autosizing

Main Article: Node autosizing

The GraphML library allows to perform the autosizing automatically. If the GraphMLNode.setAutosized(boolean) is set to true, then the node size will be fit to adapt to its label size. The ShapeNode.getWidthPadding() and ShapeNode.getHeightPadding() will be used to fit the node size around the label.

Naming

The generic JUNG library uses the name vertex, so you will see the name node for the graphml implementation but vertex for the genzric library. In all cases, methods which refer to vertex deal with nodes because they refer to the same concept.

The reason why we still use the name node for the graphml implementation is because it is the name which is used in the XML format and specification.

Example

      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();

      GraphMLNode node = diagram.addNode();
      node.setX(10);
      node.setY(10);

Port constraint

Main Article: Port constraint

It is possible to set the constraints on all the edges of a node.

See also


Categories: general | nodes

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