Perforce JViews TGO Sample: Equipment Component - Image Renderer
Description
This sample shows how to create new card and port types using images and represent these new objects with the equipment component.
How to Use the Sample
The Perforce JViews TGO equipment component provides multiple predefined modes of interaction. In this sample, the default behavior is to allow objects to be selected but not moved. A pop-up menu is associated with the objects to add, acknowledge and clear alarms. This pop-up menu can be seen by clicking with the right mouse button on the object base.
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
equipment-image-renderer.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
- Basic initialization
See theequipment/basic
sample for details - Extending the predefined card and port types
- Listening to object state changes
- Mapping attributes to graphic properties using cascading style sheets
Detailed Description
This sample shows how to create a JTGO equipment component and use its basic and advanced features.
The code specific to this sample is in the doSample method of the class imageRenderer.Main. This sample includes the following steps:
- Initialize the application using the method ilog.cpl.IlpSystem.Init. You can pass a deployment descriptor file to this method. The deployment descriptor contains information about global settings for the application.
In this sample, the deployment descriptor is called deploy. The deployment descriptor also contains directories to be added to the search path. These directories are necessary to locate:- the images that are used to reprensent the custom ports and cards
- the data source file, the styles and the equipment configuration file in the data directory.
- Create new
IltCard
andIltPort
types that will be graphically represented using images. The methodinitTelecom
loads the TGO settings file that defines the new types and associates these new types with custom renderers that are able to display images as ports and cards. The new types must be created before creating the business objects. - Create an equipment component and load its configuration from a CSS file.
The equipment component is an instance of the class ilog.cpl.IlpEquipment. In its constructor, you pass the name of a configuration file (equipment) which describes the:- View configuration
- Toolbar configuration
- Default interactor configuration and object interactor configuration
- Background configuration
- Object configuration
- Create a standard data source of class ilog.tgo.datasource.IltDefaultDataSource
- Read a data file into the data source
The data file equipment contains instances of: shelves, cards, ports and LEDs. - Attach the equipment component to the data source
Use the ilog.cpl.IlpEquipment.setDataSource method. - Add the equipment to your Swing application
IlpEquipment
is a SwingJComponent
, which means that it can be added to your application like any other Swing component.
data/images/cards
, data/images/ports
and data/images/leds
.
Finally, in this sample the state of some LEDs depends on the state of a corresponding port. The association between port and LED states is accomplished using an ilog.cpl.model.AttributeValueListener. The LED state is graphically represented using property foreground
, which is set using CSS selectors that depend on attribute values.
Installation Directory
The Equipment Component - Image Renderer sample is installed here.
Classes Involved
-
ilog.cpl.IlpSystem
The class that initializes a JViews TGO application.
-
ilog.cpl.IlpEquipment
The equipment component.
-
ilog.tgo.model.IltCard
The Card busines object implementation.
-
ilog.tgo.model.IltPort
The Port busines object implementation.
-
ilog.tgo.model.IltLed
The LED busines object implementation.
-
ilog.tgo.graphic.renderer.IltCardImageBaseRendererFactory
The factory that allows creation of new types of cards based on a single image.
-
ilog.tgo.graphic.renderer.IltPortImageBaseRendererFactory
The factory that allows creation of new types of ports based on a single image.
-
ilog.tgo.resource.IltSettings
The Global Settings entry point.
-
ilog.tgo.datasource.IltDefaultDataSource
The default datasource implementation.
-
ilog.cpl.model.AttributeValueListener
The entity that allows interested parties to listen on model attribute changes.
Source Files
-
imageRenderer.Main
The entry point of the sample.
-
imageRenderer.PopupMenuFactory
The factory that creates the pop-up menu in the objects.
-
imageRenderer.PortStateListener
The listener that associates the state of a port to the state of a LED.
-
imageRenderer.PortBaseRendererFactory
The base renderer factory for the custom port types.
-
imageRenderer.CardBaseRendererFactory
The base renderer factory for the custom card types.
-
imageRenderer.LedBaseRendererFactory
The base renderer factory for the custom LED types.