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.
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.
For graphical changes 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.
Graph elements that have been deleted and then get reinserted as a 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 methods listed in
API Excerpt 6.67, “Support for undo/redo history bracketing”.
If used, pre-event and post-event commands have to be properly balanced to guarantuee correct working of the undo/redo mechanism.
API Excerpt 6.67. Support for undo/redo history bracketing
// Open the bracket, i.e., insert a pre-event command into the undo/redo // history. // The subsequent commands present a single undo/redo step. firePreEvent() // Close the bracket, i.e., insert a post-event command into the undo/redo // history. firePostEvent()
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.
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.
Graph2DClipboard provides 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 GraphFactory object.
By default, this factory is an instance of class
Graph2DCopyFactory
.
Graph hierarchies, i.e., graphs with an associated
HierarchyManager
object, use a
specialized clipboard variant, class
Graph2DHierarchyClipboard
.
It supports copy and paste functionality for grouped nodes and nested graph
structures in a consistent manner.
ClipboardDemo.java is a tutorial demo that shows the yFiles clipboard functionality in an application context.
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.
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. In contrast, changes in width or height of any node are not animated.
|
Copyright ©2004-2008, yWorks GmbH. All rights reserved. |