Perforce JViews Diagrammer Code Example: Animated Layout (Multithreaded)


Description

This sample shows how to implement a multithreaded animation with the graphic framework.

A single-threaded version of the sample can be found here

How to Run the Code Example as an Application

This code example can be run as an application. The installation directory contains an executable JAR file, animation-multithreaded.jar, that allows you to execute the code example with a double click from a file browser. Note that if you are using Internet Explorer, you can open the installation directory and execute the JAR file from the browser. This technique may not work in other Web browsers.

Alternatively, you can run the code example application from the command line. First check that the Ant utility is properly configured. If not, see the instructions on how to configure Ant for Perforce JViews.

Then, go to the installation directory of the code example and type:

ant run

Topics Covered

Detailed Description

There are various ways to implement animation: If a diagram component (IlvDiagrammer instance) is used, an animation renderer (IlvAnimationRenderer) can be installed. If no diagram component is used, the animation can be implemented directly on top of the graphic framework. This sample shows the latter case: how to implement an animation directly with the graphic framework. It illustrates how to animate changes to node and link positions from a recorded state to a new state in an application. The sample uses various layout algorithms and shows with animation how the node and link positions change as result of the different layouts. Do not confuse this type of animation with the setAnimate option of some layout algorithms, which animate how the layout algorithm works internally. This sample shows the results of the layout algorithms using animation. Animation can help the user preserve a mental map of the graph when the positions of many nodes change at the same time.

Animation uses its own animation thread that runs concurrently with the AWT event thread. Multithreaded animation flickers less than single-threaded applications. The GUI remains operable while animation takes place. You are recommended to disable those GUI elements that may disturb animation while the animation thread is busy.


Animation works as follows:

  1. Attach an IlvManagerAnimator to the IlvManager.
  2. Create a Runnable that implements what should be done during animation. This Runnable should:
    1. Call IlvManagerAnimator.recordState() to store the current situation of the manager in the manager animator.
    2. After the (invisible) placement of nodes and links, call IlvManagerAnimator.animate() to animate changes to the manager.
  3. Pass the Runnable to IlvManagerAnimator.start(runnable) This will draw an animated movement of the objects from the positions recorded by recordState to the new object positions.
The animation framework allows you to control the animation rate (the number of steps performed to animate a movement) and the animation delay (the interval between two animation steps). Both parameters affect the animation speed.


Installation Directory

The Animated Layout (Multithreaded) code example is installed here.

Classes Involved

Source Files

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All rights reserved. Legal terms.