GLG Toolkit v. 4.2

com.genlogic.GraphLayout
Class GlgGraphLayout

java.lang.Object
  extended by com.genlogic.GraphLayout.GlgGraphLayout

public class GlgGraphLayout
extends java.lang.Object

Graph layout. Implements spring-embedder and circular graph layouts.


Field Summary
static int CIRCULAR_GRAPH
          Graph type constant for creating circular demo graphs.
static GlgObject DefEdgeIcon
          Default edge icon to use if no palette is defined.
static GlgObject DefNodeIcons
          A group of default node icons to use if no palette is defined.
static GlgObject DefViewportIcon
          Default viewport to use to render the graph.
 GlgCube dimensions
          Dimensions of the graph rendering, [-800;800] by default.
 GlgObject edge_array
          Array of all graph's edges.
 double end_temperature
          The end temperature defining the end of the layout process, 0.2 by default.
 boolean finished
          Is set to true when graph layout finishes positioning the nodes.
 int iteration
          Current iteration number.
 GlgObject node_array
          Array of all graph's nodes.
 GlgObject palette
          Graph's palette object.
static int RANDOM_GRAPH
          Graph type constant for creating random demo graphs.
static int STAR_GRAPH
          Graph type constant for creating demo graphs with a star shape.
 int update_rate
          Update rate: the graph is redrawn after each update_rate iterations.
 double z
          Z coordinate of the graph.
 
Constructor Summary
GlgGraphLayout()
          Constructor.
 
Method Summary
 GlgGraphEdge AddEdge(GlgGraphNode start_node, GlgGraphNode end_node, GlgObject graphics, int edge_type, java.lang.Object data)
          Creates a new edge and adds it to the graph.
 GlgGraphNode AddNode(GlgObject graphics, int node_type, java.lang.Object data)
          Creates a new node and adds it to the graph.
 void CircularLayout()
          Performs circular layout.
 void CreateGraphics(GlgObject viewport, GlgObject group)
          Loads icons from the palette and creates a Glg drawing to render the graph.
static GlgGraphLayout CreateRandom(int num_nodes, int num_node_types, int graph_type)
          Demo constructor.
 void DeleteEdge(GlgGraphEdge edge)
          Deletes edge from the graph.
 void DeleteNode(GlgGraphNode node)
          Deletes node from the graph.
 void Destroy()
          Destroys all graph's objects.
 void DestroyGraphics()
          Destroys graph's drawing and all graphical objects used to render nodes and edges.
static void Error(java.lang.String string)
          Error message handler.
 GlgGraphEdge FindEdge(GlgObject edge_graphics)
          Finds the edge object by its graphics.
 GlgGraphNode FindNode(GlgObject node_graphics)
          Finds the node object by its graphics.
 GlgGraphEdge GetEdge(int i)
          Finds the node object by its index.
 GlgGraphNode GetNode(int i)
          Finds the edge object by its index.
 GlgPoint GetNodePosition(GlgGraphNode node)
          Queries node position.
 boolean GetUntangle()
          Returns true if the untangling algorithm is enabled.
 GlgObject GetViewport()
          Returns the viewport of the graph's drawing.
 int GlgGraphGetEdgeIndex(GlgGraphEdge edge)
          Returns edge's index.
 int GlgGraphGetNodeIndex(GlgGraphNode node)
          Returns node's index.
 void IncreaseTemperature(boolean init)
          Forces the graph to continue layout after it's finished.
 boolean NodesConnected(GlgGraphNode node1, GlgGraphNode node2)
          Connectivity test.
 void Scramble()
          Demo method: Randomly scrambles the graph's nodes
static void SetDefPalette(GlgObject palette_drawing)
          Sets default icon palette.
 void SetNodePosition(GlgGraphNode node, double x, double y, double z)
          Sets node position in Glg coordinates as defined by the graph's dimension.
 void SetPalette(GlgObject palette_drawing)
          Sets graph's icon palette.
 void SetUntangle(boolean untangle)
          Enables or disables untangling algorithm.
 boolean SpringIterate()
          Performs one iteration of the spring embedder layout.
static void UnloadDefPalette()
          Unsets the default palette
 void Update()
          Updates graphics display to show results of the spring layout.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RANDOM_GRAPH

public static final int RANDOM_GRAPH
Graph type constant for creating random demo graphs.

See Also:
Constant Field Values

CIRCULAR_GRAPH

public static final int CIRCULAR_GRAPH
Graph type constant for creating circular demo graphs.

See Also:
Constant Field Values

STAR_GRAPH

public static final int STAR_GRAPH
Graph type constant for creating demo graphs with a star shape.

See Also:
Constant Field Values

DefNodeIcons

public static GlgObject DefNodeIcons
A group of default node icons to use if no palette is defined.


DefEdgeIcon

public static GlgObject DefEdgeIcon
Default edge icon to use if no palette is defined.


DefViewportIcon

public static GlgObject DefViewportIcon
Default viewport to use to render the graph.


node_array

public GlgObject node_array
Array of all graph's nodes.


edge_array

public GlgObject edge_array
Array of all graph's edges.


finished

public boolean finished
Is set to true when graph layout finishes positioning the nodes.


iteration

public int iteration
Current iteration number.


update_rate

public int update_rate
Update rate: the graph is redrawn after each update_rate iterations.


end_temperature

public double end_temperature
The end temperature defining the end of the layout process, 0.2 by default.


dimensions

public GlgCube dimensions
Dimensions of the graph rendering, [-800;800] by default.


z

public double z
Z coordinate of the graph.


palette

public GlgObject palette
Graph's palette object. Defines node and edge icons.

Constructor Detail

GlgGraphLayout

public GlgGraphLayout()
Constructor.

Method Detail

CreateRandom

public static GlgGraphLayout CreateRandom(int num_nodes,
                                          int num_node_types,
                                          int graph_type)
Demo constructor. Creates a graph layout and populates it with nodes and edges.

Parameters:
num_nodes - Number of nodes to create
num_node_types - Number of node types to use for rendering
graph_type - Graph type constant: RANDOM_GRAPH, CIRCULAR_GRAPH or STAR_GRAPH.
Returns:
Graph layout object.

AddNode

public GlgGraphNode AddNode(GlgObject graphics,
                            int node_type,
                            java.lang.Object data)
Creates a new node and adds it to the graph.

Parameters:
graphics - Optional custom node icon (to override the icon from the palette)
node_type - Palette index, specifies what icon to use from the node palette if no custom graphics is specified. The value of -1 can be used to define an external node with no graphics. External nodes will not be moved by the layout.
data - Custom data to attach to the node
Returns:
New node object

AddEdge

public GlgGraphEdge AddEdge(GlgGraphNode start_node,
                            GlgGraphNode end_node,
                            GlgObject graphics,
                            int edge_type,
                            java.lang.Object data)
Creates a new edge and adds it to the graph.

Parameters:
start_node - Edge's start node
end_node - Edge's end node
graphics - Optional custom edge icon (to override the icon from the palette)
edge_type - Palette index, specifies what icon to use from the edge palette if no custom graphics is specified. This parameter is reserved for the future use and the value of 0 must be used for regular nodes. The value of -1 can be used to define an external edge with no graphics that connects to an external node.
data - Custom data to attach to the edge
Returns:
New edge object

DeleteNode

public void DeleteNode(GlgGraphNode node)
Deletes node from the graph. Also delets all edges connected to the node.

Parameters:
node - Node object to be deleted

DeleteEdge

public void DeleteEdge(GlgGraphEdge edge)
Deletes edge from the graph.

Parameters:
edge - Edge object to be deleted

Destroy

public void Destroy()
Destroys all graph's objects.


SetDefPalette

public static void SetDefPalette(GlgObject palette_drawing)
Sets default icon palette. The default palette is used by all graph layouts if no graph-specific palette is defined to override the default one.

Parameters:
palette_drawing - Palette drawing object. See description of the SetPalette method for more details.

SetPalette

public void SetPalette(GlgObject palette_drawing)
Sets graph's icon palette. Palette drawing must contain node icons named Node0, Node1, Node2 and so on. Each node icon must contain a G-type resource named Position, which is used by the graph layout to position the node. The palette must also contain an edge icon (a polygon object named Edge), which is used to define edges' attributes.


UnloadDefPalette

public static void UnloadDefPalette()
Unsets the default palette


CreateGraphics

public void CreateGraphics(GlgObject viewport,
                           GlgObject group)
Loads icons from the palette and creates a Glg drawing to render the graph.

Parameters:
viewport - An optional viewport parameter. If it's not null, it's used as a viewport for the graph's drawing, rendering the graph in an existing object hierarchy. If it's null, the graph will create a new viewport to render the graph.
group - An optional group parameter. If it's not null, it defines the group container to add nodes and edges to (used when several graph layouts reside in the same viewport). If it's null, the graph's viewport is used as a container.

DestroyGraphics

public void DestroyGraphics()
Destroys graph's drawing and all graphical objects used to render nodes and edges.


FindNode

public GlgGraphNode FindNode(GlgObject node_graphics)
Finds the node object by its graphics. Is used to handle mouse selections.

Parameters:
node_graphics - Graphical object used to render the node in the drawing
Returns:
Node object

FindEdge

public GlgGraphEdge FindEdge(GlgObject edge_graphics)
Finds the edge object by its graphics. Is used to handle mouse selection.

Parameters:
edge_graphics - Graphical object used to render the edge in the drawing
Returns:
Edge object

GetNode

public GlgGraphNode GetNode(int i)
Finds the edge object by its index.


GetEdge

public GlgGraphEdge GetEdge(int i)
Finds the node object by its index.


GlgGraphGetNodeIndex

public int GlgGraphGetNodeIndex(GlgGraphNode node)
Returns node's index.


GlgGraphGetEdgeIndex

public int GlgGraphGetEdgeIndex(GlgGraphEdge edge)
Returns edge's index.


CircularLayout

public void CircularLayout()
Performs circular layout.


NodesConnected

public boolean NodesConnected(GlgGraphNode node1,
                              GlgGraphNode node2)
Connectivity test.

Parameters:
node1 - Node object
node2 - Node object
Returns:
true if there is an edge connecting the two nodes

Update

public void Update()
Updates graphics display to show results of the spring layout. There is no need to update the display after every iteration: it may be updated after every N iterations or just once, when the layout is finished.


SpringIterate

public boolean SpringIterate()
Performs one iteration of the spring embedder layout.

Returns:
Returns true if the layout process has finished.

IncreaseTemperature

public void IncreaseTemperature(boolean init)
Forces the graph to continue layout after it's finished. Increases the "temperature" of the graph by a small increment if the init parameter is false, or by a large increment if init is true.


Scramble

public void Scramble()
Demo method: Randomly scrambles the graph's nodes


SetNodePosition

public void SetNodePosition(GlgGraphNode node,
                            double x,
                            double y,
                            double z)
Sets node position in Glg coordinates as defined by the graph's dimension. The default dimension is [-800;+800].

Parameters:
node - Node to position
x - X coordinate
y - Y coordinate
z - Z coordinate

GetNodePosition

public GlgPoint GetNodePosition(GlgGraphNode node)
Queries node position.

Parameters:
node - Node to query
Returns:
Node position in Glg coordinates as defined by the graph's dimension. The default dimension is [-800;+800].

GetViewport

public GlgObject GetViewport()
Returns the viewport of the graph's drawing.


GetUntangle

public boolean GetUntangle()
Returns true if the untangling algorithm is enabled. The untangling algorithm helps the graph layout to avoid local minimums in the form of intersecting edges. Using it doubles the time it takes to finish the layout.


SetUntangle

public void SetUntangle(boolean untangle)
Enables or disables untangling algorithm.

Parameters:
untangle - true to enable untangling

Error

public static void Error(java.lang.String string)
Error message handler. May be overridden by subclasses to implement custom error handling.

Parameters:
string - Error message

GLG Toolkit v. 4.2