Where to Find Up-to-date yFiles Information

This page is from the outdated yFiles for Java 2.13 documentation. You can find the most up-to-date documentation for all yFiles products on the yFiles documentation overview page.

Please see the following links for more information about the yFiles product family of diagramming programming libraries and corresponding yFiles products for modern web apps, for cross-platform Java(FX) applications, and for applications for the Microsoft .NET environment.

More about the yFiles product family Close X

Advanced Application Logic

The yFiles library provides advanced functionality to be used in an application context. Besides support to undo/redo user actions inside a view, there is also support to generate an animated transformation for graph layout changes.

Undo/Redo

Class Graph2DUndoManager provides undo/redo support for Graph2D changes of both structural and graphical nature. It implements the interfaces GraphListener and Graph2D.BackupRealizersHandler, and is accordingly registered twice with a Graph2D object.

Figure 6.69. Class complex around undo/redo functionality

Class complex around undo/redo functionality.

For non-structural changes (like visual aspects, position, size, etc.), Graph2DUndoManager relies on the correct replication behavior of realizers, since the actual undo mechanism keeps backup copies of all node and edge realizers that are associated with modified or even deleted graph elements.

This backup store is filled by means of the backupRealizers methods in class Graph2D. In interactive scenarios where a user modifies graph elements, these methods are used behind the scenes (e.g., by the involved yFiles view modes); in non-interactive scenarios, when graph elements are modified programmatically, client code has to call these methods explicitly.

Note

Graph elements that have been deleted (a structural change) and then get reinserted as the result of an undo command, are represented by their original objects. The realizer objects that are associated with these reinserted graph elements are also taken from the backup store. However, the graph structure has a different order after a reinsert operation, since the graph elements are merely appended to the respective graph data structures.

To reduce the number of actual undo/redo steps, sequences of graph changes can be grouped into single undo/redo commands. So-called pre-event and post-event commands provided by class GraphEvent serve as special bracketing indicators. Class Graph offers direct support to insert these commands into the undo/redo history, see the following methods for undo/redo history bracketing.

Important

If used, pre-event and post-event commands have to be properly balanced to guarantee correct working of the undo/redo mechanism.

void firePreEvent()
Description Opens the bracket, i.e., inserts a pre-event command into the undo/redo history. The subsequent commands present a single undo/redo step.
void firePostEvent()
Description Closes the bracket, i.e., inserts a post-event command into the undo/redo history.

Graph2DUndoManager has getter methods that return complete Swing Actions for integration of both undo and redo operations into an application's context.

UndoRedoDemo.java is a tutorial demo that shows the yFiles support for undo/redo functionality in an application context.

Clipboard

Class Graph2DClipboard provides clipboard functionality for Graph2D objects. The clipboard can be used to create a copy of selected parts of a Graph2D instance, and can also be used to paste a previously copied subgraph back into a graph again.

Figure 6.70. Clipboard classes hierarchy

Clipboard classes hierarchy.

Graph2DClipboard provides Java Swing actions that encapsulate all necessary clipboard functionality, namely the three operations Cut, Copy, and Paste. Copies of graph elements are created by means of a GraphCopier.CopyFactory implementation. By default, the CopyFactory implementation that is registered with the graph is used to this end. Alternatively, the setCopyFactory method can be used to set a different CopyFactory.

Graph2DClipboard also supports copy and paste functionality for grouped nodes and nested graph structures from a graph hierarchy, i.e., a graph with an associated HierarchyManager instance, in a consistent manner.

The Paste action supports pasting the contents of the clipboard directly into a group node. Through the setPasteTargetGroupPolicy(byte) method, the action can be customized to use one of several policies that determine the group node into which to paste.

ClipboardDemo.java is a tutorial demo that shows the yFiles clipboard functionality in an application context.

Layout Morphing

Class LayoutMorpher is an implementation of the general animation concept defined by interface AnimationObject. It generates a smooth animation that shows a graph's transformation from one layout to another. To this end class LayoutMorpher utilizes an object of type GraphLayout that is expected to hold positional information for all graph elements from the original graph which is displayed by the associated Graph2DView.

Figure 6.71. Usage relations for class LayoutMorpher

Usage relations for class LayoutMorpher.

LayoutMorpher provides methods to optionally animate changes in the viewport's clipping and zoom level, or to end the animation with a specific node being in the center of the view. To start the generated animation method execute() has to be called.

Note that the calculated animation highlights changes in the locations of nodes and the locations of control points of edges. Also animated are changes in width and height of nodes as well as changes in the locations and directions of node and edge labels.