Perforce JViews Diagrammer Sample: Content on Demand


Description

This sample shows how to use the Content on Demand tool for Perforce JViews Diagrammer.

How to Use the Sample

How to Run the Sample as an Application

This sample can be run as an application. The installation directory contains an executable JAR file, diagrammer-contentOnDemand.jar, that allows you to execute the sample 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 sample 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 sample and type:

ant run

Topics Covered

Detailed Description

This sample shows how to use Content on Demand tool for Perforce JViews Diagrammer. The typical use case is a large diagram where objects are expensive to load, in terms of time or in terms of space. For example, when the content comes from a slow database request, or represents several kilobytes per object in a diagram with thousands of objects. The Content on Demand tool offers a service of lazy loading to optimize and load heavy content only for objects that need it and at the right time. All the objects must be created at the beginning, but they can remain "hollow" until they need to be displayed correctly.
In this demo, the diagram is a grid of nodes represented by rectangles. Nodes have a property named content which is supposed to be filled only when necessary, that is, when the content is requested explicitly or when the node is visible in the main view.
The Content on Demand tool loads or unloads the content at the right time. The rectangles are displayed differently, according to the load status given by the controller:


The demo offers three different ways to interact with the Content on Demand controller:
  1. Select some nodes with the selection tool, then press one of the three buttons above the view to force the status of the selected nodes.
  2. Change the view size or zoom level, all the visible nodes are requested to be loaded. It is recommended to open the overview to see the evolution of the loaded status of all nodes.
  3. Use the area interactor: click the lowest button of the vertical toolbar to enable the area interactor, then click the main view. A rectangle is shown. All nodes that intersect with this rectangle are loaded. Drag the rectangle around to change the status of the nodes.

The demo contains several public variables that can be changed to modify the behavior. For example, it is possible to change the number of nodes, the cache size (which defaults to half the number of nodes), and whether grey rectangles should be displayed or not. The cache size is used to limit the number of loaded objects. When too many objects are loaded, the oldest ones are unloaded to keep the number of loaded objects below a fixed limit.

Installation Directory

The Content on Demand sample is installed here.

Classes Involved

Source Files

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