Perforce JViews Framework Code Example: Lightweight Text
Description
This sample shows how to reduce the memory footprint of IlvText if not all features of IlvText are needed.
How to Use the Code Example
- The application displays a grapher containing a very large number of text objects.
- The checkbox "Lightweight Text" toggles between normal IlvText and lightweight text.
- The bottom panel displays the memory footprint history. It is updated every second. If you enable the lightweight text, you see that the yellow curve goes down, because the lightweight text uses much less memory than IlvText.
- At very small zoom levels, the lightweight text does not render the text anymore, because the text would anyway no longer be readable. Therefore it is much faster than IlvText at small zoom levels.
- At large zoom levels, IlvText is usually faster than lightweight text, but since only very few objects are displayed at large zoom levels, this slowdown is negligible.
- The same technique can be applied to any subclass of IlvGraphic. If you do not need all features of the predefined graphic classes, define a lightweight graphic that delegates to an instance of the predefined graphic classes on the fly. This reduces the memory footprint if the delegate is not cached, so that it can be garbage collected after usage.
-
The other buttons at the top of the application are used as follows:
- Set Pan mode. In Pan mode you can pan the view by dragging the image.
- Set Selection mode. In Selection mode you can select, move, and edit objects.
- Zoom in on an area. You can select the area to magnify.
- Zoom in.
- Zoom out.
- Make the entire image visible.
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,
lighttext.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
- Lightweight text
- How to reduce the memory footprint
Installation Directory
The Lightweight Text code example is installed here.
Classes Involved
- ilog.views.graphic.IlvText
- ilog.views.graphic.IlvTextSelection
- ilog.views.IlvGraphic
- ilog.views.IlvTextInterface
- ilog.views.IlvManager
- ilog.views.IlvManagerView
- ilog.views.swing.IlvJScrollManagerView
- ilog.views.swing.IlvJManagerViewControlBar