Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Templates



It is possible to create nodes and edges templates to reuse their characteristics. This creation is performed at the GraphMLFactory level.

For example, you can define a type of node with a specific fill color and shape and reuse this type when creating new nodes.

Create a template

Several methods in the GraphMLFactory class allow to create a template.

Note that a template can't be used directly in a diagram.

Create a node template

To create a node template, you must use the GraphMLFactory.createGraphMLNodeTemplate(String). The argument is the name of the template. After the creation, you will be able to set any property you need on the created templated node.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLNodeTemplate template = factory. createGraphMLNodeTemplate("myNodeTemplate");
      template.setType(ShapeType.ELLIPSE);
      template.setFillColor(Color.GREEN);

Create a group node template

To create a group node template, you must use the GraphMLFactory.createGraphMLGroupNodeTemplate(String). The argument is the name of the template. After the creation, you will be able to set any property you need on the created templated group node.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLNodeTemplate template = factory. createGraphMLGroupNodeTemplate("myGroupTemplate");
      template.setType(ShapeType.RECTANGLE3D);
      template.setFillColor(Color.BLUE);  

Create an edge template

To create an edge template, you must use the GraphMLFactory.createGraphMLEdgeTemplate(String). The argument is the name of the template. After the creation, you will be able to set any property you need on the created templated edge.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLNodeTemplate template = factory. createGraphMLEdgeTemplate("myEdgeTemplate");
      LineStyle lineStyle = new LineStyle();
      lineStyle.setLineStyle(LineStyle.DASHED);
      template.setLineStyle(lineStyle);

Using a template

Several methods in the GraphMLDiagram and GraphMLGroupNode classes allow to use a template to create a node or an edge.

Note that if the specified template does not exist, or is not of the correct type, the associated methods will throw a TemplateAccessException exception.

Create a node in a parent diagram

The GraphMLDiagram.addNodeFromTemplate(String) allow to create a node as a child of the diagram, using the caracteristics of the specified template.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLNodeTemplate template = factory.createGraphMLNodeTemplate("myNodeTemplate");
      template.setType(ShapeType.ELLIPSE);
      template.setFillColor(Color.GREEN);
      
      GraphmlDiagram diagram = factory.newDiagram();
      GraphMLNode node = diagram.addNodeFromTemplate("myNodeTemplate");

Create a group node in a parent diagram

The GraphMLDiagram.addGroupNodeFromTemplate(String) allow to create a group node as a child of the diagram, using the caracteristics of the specified template.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLGroupNodeTemplate template = factory.createGraphMLGroupNodeTemplate("myGroupTemplate");
      template.setType(ShapeType.RECTANGLE3D);
      template.setFillColor(Color.BLUE);  
      
      GraphmlDiagram diagram = factory.newDiagram();
      GraphMLGroupNode gnode = diagram.addGroupNodeFromTemplate("myGroupTemplate");

Create a node or a group node in a parent group node

The GraphMLGroupNode.addNodeFromTemplate(String) allow to create a node as a child of the group node, using the caracteristics of the specified template.

The GraphMLGroupNode.addGroupNodeFromTemplate(String) allow to create a group node as a child of the group node, using the caracteristics of the specified template.

Create an edge

The GraphMLDiagram.addEdgeFromTemplate(IGraphMLNode, IGraphMLNode, String) allow to create an edge between tow nodes, using the caracteristics of the specified template.

For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphMLNodeTemplate template = factory. createGraphMLEdgeTemplate("myEdgeTemplate");
      LineStyle lineStyle = new LineStyle();
      lineStyle.setLineStyle(LineStyle.DASHED);
      template.setLineStyle(lineStyle);
      
      GraphmlDiagram diagram = factory.newDiagram();
      GraphMLNode node1 = diagram.addNode();
      node1.setX(10);
      node1.setY(10);
      GraphMLNode node2 = diagram.addNode();
      node2.setX(100);
      node2.setY(100);
      
      GraphMLEdge edge = diagram.addEdgeFromTemplate(node1, node2, "myEdgeTemplate");

Categories: edges | general | nodes

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