Using the Java version of the GLG Toolkit

Introduction

The Java version of the GLG Toolkit provides a 100% pure Java class library that loads and displays GLG drawings in Java applications. The Java version of the GLG library supports all the GLG Toolkit features available to C and C++ applications, and provides the GLG Standard and Extended APIs for Java applications.

It also provides the GLG Bean, a Java bean component that seemlessly integrates the GLG Toolkit into a Java environment, embedding Java-based GLG components into Java application frameworks and Java IDEs. The bean may also be used as an applet, integrating GLG components as Java applets into a browser and HTML environment.

The Java version of the Toolkit uses GLG drawings saved with the GLG Graphics Builder. The drawings must be saved in ASCII format, either compressed or uncompressed. The same drawing may be used by both the Java and C/C++ versions of the Toolkit. The drawing can also be generated on the fly using the Extended API.

GlgObject is the main class of the Java version of the GLG Toolkit. The GlgObject class contains all the functionality available to GLG objects. Since all objects implement the Get and SetResource functions central to the GLG architecture, it's only natural that the GlgObject superclass is heavily used, making it a Superclass in a more general sense. Using one main superclass also makes it easier to deal with GLG objects by limiting the number of classes and methods one has to learn.

The GLG Toolkit also contains Java classes for different GLG objects: polygons, arcs, etc. However, only the constructors of these classes are used. Once the object is created, all further object manipulation is done by using the GlgObject methods.

The GLG Toolkit also provides classes such as GlgPoint , GlgCube and some other utility classes, mainly used to exchange information between different object methods.

There are three GLG listeners: GlgInputListener , GlgSelectListener and GlgTraceListener used to handle user interaction and object selection. These listeners are supported by both the GlgObject and GlgBean classes, as described below.

In addition to GlgObject , several GlgBean classes are provided:

GlgBean

AWT-based Java bean and applet.

GlgJBean

Heavyweight Swing-based Java bean and applet (JApplet).

GlgJLWBean

Lightweight Swing-based Java bean for use with JDesktopPane and JInternalFrame.

All GlgBean classes have the same Glg-inherited interface and differ only in the methods inherited from respective AWT or Swing superclasses. The AWT and Swing-based GLG beans should not be intermixed in one application. The light-weight version of the GLG bean (GlgJLWBean) uses Swing's light-weight model which imposes a performance penalty related to the absence of a native window and a necessity to handle clipping in software. Although it is OK to use the light-weight component for small to medium drawings, a heavy-weight component is recommended for large graphically-intensive drawings.

The type of the top level bean may be different from the type of the components used to render GLG viewport objects displayed inside the GlgBean and GlgJBean. By default, the GlgBean uses AWT components, while the GlgJBean and GlgJLWBean use Swing-based components.

The GlgSwingUsage global configuration resource described on page 285 of Appendices may be used to change the default type of components used to render GLG viewport objects inside the bean. See the GlgSwingUsage resource description for details. The resource is global, affects all GLG viewports and must be set at the application start-up. If the resource is not used, the type of components is determined by the type the GLG Bean (AWT or Swing) used by an application.

The GLG Bean is a Java bean encapsulation of a GLG viewport object that loads, displays and animates a GLG drawing. The bean provides several properties that facilitate loading the drawing and using the bean as an applet in a browser environment.

The GLG Bean exposes methods similar to those of GlgObject . While the GlgObject methods have to be invoked for individual objects, the bean provides a central place for invoking methods on any object or resource. Since the methods exposed by the GLG Bean are the same as the methods of the GlgObject class, there are two ways of using GLG and GLG Bean in a Java application:

The GLG Bean may be used to integrate a GLG drawing into a Java application by creating a GLG Bean and using its SetDrawing methods to load a drawing. After loading the drawing, the viewport object (a GlgObject ) of the loaded drawing may be extracted by calling GLG Bean 's GetDrawingObject method, after which all further processing may be done using the GlgObject class methods of the viewport or individual objects inside the viewport.

The GLG Bean may only be used with the methods exposed by the GLG Bean itself. This is especially convenient when the GLG Bean is used as an applet inside a web browser that supports Java Script and the object's methods are invoked by the script.

In addition to the input, select and trace listeners, the bean provides a few additional listeners, GlgHListener, GlgVListener and GlgReadyListener, which simplify setting the initial resources and program initialization. The bean implements all listener interfaces and acts as a default listener. This makes it more convenient to create custom beans by subclassing the Glg bean and overriding some or all of its listener interfaces.

The Toolkit also provides a GlgErrorHandler interface for custom error handling.

The GlgAntiAliasing global configuration resource described on page 285 of Appendices controls the use of anti-aliasing.

JSP Servlets and the GLG Graphics Server

A separate GLG class library for the JSP environment is provided in the GlgServer.jar file. This class library provides the same API but supports headless operation as well as a multi-threaded access by the servlet threads. When used in a servlet, the GlgObject classes should be used instead of the GLG Bean. The examples_jsp directory contains elaborate examples of the GLG servlets with the source code.

Using the Documentation

This chapter describes language-specific details of using the Java version of the Toolkit. Refer to Using the C/C++ version of the Toolkit for a detailed description of semantics of the Standard and Extended API methods, as well as details of handling user input (described in Handling Input Events on page 87). The semantics of all API methods is the same in all versions of the Toolkit, and the C/C++ section provides examples and details of using them.

Refer to the GLG Programming Tutorial for Java for detailed examples and a walk-through tutorial.

An on-line documentation for the Toolkit's Java class library in the JavaDoc format is also provided. The JavaDoc documentation is intended as a quick reference for the GLG Java classes and their methods, but not as a definitive guide to using the Toolkit in Java. Refer to Using the Java version of the GLG Toolkit for more details. Refer to Using the C/C++ version of the Toolkits for examples of using the GLG methods for specific tasks.

Jar Files

The Java version of the Toolkit uses the GLG Java Class Library from the GlgCE.jar, Glg2.jar or GlgExt2.jar files. The GlgCE.jar file supplies a free evaluation version, the Glg2.jar supplies a purchased version with the GLG Standard API, and the GlgExt2.jar file supplies the purchased version with the GLG Extended API.

All three libraries use Java2D renderer and support anti-aliasing, gradient shading, transparency and alpha blending, as well as Swing and light-weight components.

The GlgDemo.jar archive contains the class files of the GLG demos.

For the JSP Servlet use, the GlgServerCE.jar file supplies a free evaluation version and the GlgServer.jar supplies the purchased version of both the GLG Standard and Extended APIs.

Interfaces

GlgInputListener

public interface GlgInputListener

The main listener interface for handling user interaction.

Methods
public void InputCallback( GlgObject object, GlgObject message_object )

This callback method is invoked every time a user interacts with input objects in the drawing or selects objects in the drawing with the mouse. More information about the type of the input activity may be extracted from the message object passed by the message_object parameter. The object parameter is the listener's viewport object. Refer to Input Callback of Handling Input Events for more details.

GlgSelectListener

public interface GlgSelectListener

Listener interface used to handle an object selection with the mouse, provides a simplified name-based interface for object selection handling.

Methods
public void SelectCallback( GlgObject object, Object[ ] name_array, int button )

This callback is invoked every time user uses the mouse to select one or more objects in the drawing. The name_array parameter is a null-terminated array of names of selected objects. The button parameter is the mouse button used for selection (1, 2 or 3). The object parameter is the listener's viewport object. Refer to Selection Callback of Handling Input Events for more details.

GlgTraceListener

public interface GlgTraceListener

Listener interface used to handle low-level AWT events.

Methods
public void TraceCallback( GlgObject object, GlgTraceData trace_info )

This callback is invoked for every event occurring in any of the drawing's viewports and may be used to implement custom selection or hot-spots logic and to handle Java events. The object parameter is the listener's viewport object. Refer to Trace Callbacks of Handling Input Events for more details.

GlgHListener

public interface GlgHListener

Interface for setting the initial values of the Glg bean.

Methods
public void HCallback( GlgObject viewport )

This callback is invoked after the bean's drawing is loaded, but before the drawing hierarchy is set up. It may be used to set the initial resources of the bean's drawing, such as the number of samples in a GLG graph object. The viewport parameter is the listener's viewport object.

GlgVListener

public interface GlgVListener

Interface for setting the initial values of the Glg bean.

Methods
public void VCallback( GlgObject viewport )

This callback is invoked after the bean's drawing is loaded and set up, but before it is displayed for the first time. It may be used to set the initial resources of the bean's drawing. For example, it may be used to supply data for the initial appearance of a GLG graph object. The viewport parameter is the listener's viewport object.

GlgReadyListener

public interface GlgReadyListener

Interface for detecting the Ready event.

Methods
public void ReadyCallback( GlgObject viewport )

This callback is invoked after the bean's drawing is loaded, setup and displayed for the first time. It may be used to detect when the bean is ready and begin updating the drawing with data. The viewport parameter is the listener's viewport object.

GlgErrorHandler

public interface GlgErrorHandler

Error handling interface.

Methods
public void Error( String message )

Displays the error message. The string parameter is the error message.

GlgBean class

GlgJBean class

GlgJLWBean class

public class GlgBean extends Applet implements GlgInputListener, GlgSelectListener, GlgTraceListener, GlgErrorHandler

AWT-based Java bean and applet.

public class GlgJBean extends JApplet implements GlgInputListener, GlgSelectListener, GlgTraceListener, GlgErrorHandler

Heavyweight Swing-based Java bean and applet.

public class GlgJLWBean extends JPanel implements GlgInputListener, GlgSelectListener, GlgTraceListener, GlgErrorHandler

Lightweight Swing-based Java bean for use with JDesktopPane and JInternalFrame.

GLG Beans are Java bean components that integrate GLG objects into the Java environment. The GLG Bean is a Java Bean encapsulation of a GLG viewport object that loads, displays and animates a GLG drawing. All GLG Bean classes have the same Glg-inherited interface and differ only in the methods inherited from their respective AWT or Swing superclasses. The AWT and Swing-based GLG beans should not be intermixed in one application.

The GLG Bean provides methods similar to those of GlgObject . Methods of the GLG Bean and the bean's viewport GlgObject may be used interchangeably.

The GLG Bean implements all GLG listener interfaces and automatically adds listeners for all GLG events. The bean's listener interface methods may be overwritten by the bean's subclass.

The GLG Bean provides functionality for following HTML links when used in the browser and HTML environment. If an object contains an S resource named "$href" , the value of the resource is interpreted as a URL which defines an HTML link. If the user selects an object in the drawing which has an HTML link, the link's URL will be automatically loaded. Custom Properties may be used to attach the "$href" property to objects in the Builder. The HRefTarget property of the bean may be used to define an html target name to open the link in a different browser window.

If the TraceHRef property of the bean in set to true , the bean also traces the link's hot spot and changes the cursor shape when cursor moves over an object that represents a link.

Properties

DrawingURL

The URL of the drawing to be loaded into the bean. If a relative filename, such as drawing.g , is used, it will be interpreted relatively to the applet's DocumentBase .

DrawingFile

The filename of the drawing to be loaded into the bean.

DrawingName

A relative drawing name. This can be used to transparently specify the drawing location for both the applet and stand-alone Java application. For an applet, it is relative to it's DocumentBase . For a stand-alone application, it is relative to the current directory.

DrawingResource

The name of the drawing file in a jar file.

SetupDataURL

The URL of the setup script in the Glg Script Format to use for initializing drawing's resources.

DataURL

The URL of the data script in the Glg Script Format to use for periodic updates of the drawing's resources.

UpdatePeriod

Double value that defines an update interval for reading DataURL , in seconds.

HResource0

HResource1

HResource2

HResource3

HResource4

String properties used to initialize drawing's resources before hierarchy setup. For information about the format of the strings see Dynamic Resource String Syntax on page 175.

VResource0

VResource1

VResource2

VResource3

VResource4

String properties used to initialize drawing's resources after hierarchy setup. For information about the format of the strings see Dynamic Resource String Syntax on page 175.

TraceHRef

If set to true , the bean will trace the hot spots for http links which are defined in the drawing. To make a graphical object a hot spot, it needs to have a custom property of an S type named " $href ". The value of the custom property defines link's URL. When the mouse moves over an object with a link, the cursor will change and, if the bean is used inside the browser, the links' URLs will be displayed in the browser's status area. The default value of the property is false .

HRefTarget

Specifies a name of the browser frame to use when opening http links defined in the drawing. The default value is null , causing link's URL to replace the bean.

JavaLog

Enables Java Console logging of bean events for debugging bean problems.

ResourceLog

Enables Java Console logging of resource settings from the SetupDataURL and DataURL to debug data scripts.

APILog

Enables Java Console logging of the bean's GLG API methods.

Constructors

public GlgBean()

public GlgJBean()

public GlgJLWBean()

Create a GLG bean.

Methods

public void PrintToJavaConsole( String message )

Prints the message to stdout. Provided for convenience when used with Java Script in a web browser.

public void SetDrawingName( String drawing_resource )

Sets a new value of the DrawingName property, loads the drawing and displays it in the bean. If the bean is used as an applet or part of another applet (bean's SetParentApplet method was used), the DrawingName is interpreted as a URL relative to the applet's document base directory. Otherwise, the DrawingName is interpreted as a file relative to the current directory.

public String GetDrawingName()

Returns the current value of the DrawingName property.

public void SetDrawingURL( String drawing_url )

Sets a new value of the DrawingURL property, loads the drawing from the URL and displays it in the bean.

public String GetDrawingURL()

Returns the current value of the DrawingURL property.

public void SetDrawingFile( String drawing_file )

Sets a new value of the DrawingFile property, loads the drawing from the file and displays it in the bean.

public String GetDrawingFile()

Returns the current value of the DrawingFile property.

public GlgObject GetDrawingObject()

Returns the viewport object of the bean's drawing.

public boolean SetDrawingObject( GlgObject viewport )

Sets a new viewport object as a drawing for the bean and displays the new drawing.

public void SetDataURL( String data_url )

Sets a new value of the DataURL property, reads and executes the new DataURL script. If the UpdatePeriod property is greater then 0, the DataURL will be read periodically with the period defined by the UpdatePeriod. The data script will be read once each time the drawing is reloaded using the SetDrawing methods, and then periodically if the UpdatePeriod property is set.

public String GetDataURL()

Returns the current value of the DataURL property.

public void SetSetupDataURL( String setup_data_url )

Sets a new value of the SetupDataURL property. The SetupDataURL script is read and executed once after a new drawing is loaded into a bean and every time the drawing is reloaded by using the SetDrawing methods.

public String GetSetupDataURL()

Returns the current value of the SetupDataURL property.

public void SetUpdatePeriod( double update_period )

Sets a new value of the UpdatePeriod property and starts or stops periodic reading of DataURL if necessary. The DataURL is read periodically if the UpdatePeriod is greater then 0.

public double GetUpdatePeriod()

Returns the current value of the UpdatePeriod property.

public void SetJavaLog( boolean active )

Activates logging debugging messages to stdout or the Java Console.

public boolean GetJavaLog()

Returns the current value of the JavaLog property.

public void SetResourceLog( boolean active )

Activates logging messages for setting resources from data scripts.

public boolean GetResourceLog()

Returns the current value of the ResourceLog property.

public void SetAPILog( boolean active )

Activates logging API calls, which is convenient for debugging Java Scripts in a web browser.

public boolean GetAPILog()

Returns the current value of the APILog property.

public void SetHResource0( String value )

public void SetHResource1( String value )

public void SetHResource2( String value )

public void SetHResource3( String value )

public void SetHResource4( String value )

Set the value of the H properties. These properties are used to set resources of the bean's drawing before the drawing's object hierarchy is created.

The syntax of these properties is described in Dynamic Resource String Syntax of Using the ActiveX Control. Refer to H and V Resources of Details of using GLG Standard API for C and C++ for more details on H and V resources.

public String GetHResource0()

public String GetHResource1()

public String GetHResource2()

public String GetHResource3()

public String GetHResource4()

Return the current value of H properties.

public void SetVResource0( String value )

public void SetVResource1( String value )

public void SetVResource2( String value )

public void SetVResource3( String value )

public void SetVResource4( String value )

Set the value of the V properties. These properties are used to set resources of the bean's drawing after the drawing's object hierarchy is created.

The syntax of these properties is described in Dynamic Resource String Syntax of Using the ActiveX Control. Refer to H and V Resources of Details of using GLG Standard API for C and C++ for more details on H and V resources.

public String GetVResource0()

public String GetVResource1()

public String GetVResource2()

public String GetVResource3()

public String GetVResource4()

Return the current value of V properties.

public void SetTraceHRef( boolean trace )

Sets the value of the TraceHRef property. If the property is set to true , the bean traces the mouse movements and changes the cursor shape when cursor moves over objects in the drawing which have HTML links. If an object contains an S resource named "$href" , the value of the resource is interpreted as a URL which defines an HTML link.

public boolean GetTraceHRef()

Returns the current value of the TraceHRef property.

public void SetHRefTarget( String target )

Sets the value of the TraceHRef property which defines the target name for showing html links. If set to null, clicking on the hot spot defined by the "$href" property with the left mouse button opens the link in the same browser window, or in a separate window with the "_blank" target name if other mouse buttons are used. If HRefTarget property is not null, the link is always opened in a separate window with the target name defined by the HRefTarget property.

public String GetHTarget()

Returns the current value of the HRefTarget property.

public void SetIgnoreErrors( boolean ignore )

Sets the value of the IgnoreErrors properties. If set to true , suppresses GLG error messages.

This is useful in the bean box test program, which tries to set the value of a string property on every starting change before the entry is finished, which results in errors for the string properties that define URLs.

public boolean GetIgnoreErrors()

Returns the current value of the IgnoreErrors property.

public boolean IsReady()

Returns the Ready status of the bean. The bean is ready when it finished loading the drawing and reading setup data and data URLs.

public Applet SetParentApplet( Applet parent_applet )

Sets the parent applet used to determine the document base when the bean is used as part of another applet.Use null for the parent_applet parameter to unset the parent applet.

public String GetFullPath( String filename )

Returns the full path name. If the bean is used as an applet or a part of another applet (the SetParentApplet method was used), the method prepends the applet's document path to the filename. Otherwise, the filename parameter is returned unchanged.

public double GetDResource( String res_name )

public double GetDTag( String tag_source )

Return the value of the D-type resource or tag of the bean's drawing.

public String GetSResource( String res_name )

public String GetSTag( String tag_source )

Return the value of the S-type resource or tag of the bean's drawing.

public double GetXResource( String res_name )

public double GetYResource( String res_name )

public double GetZResource( String res_name )

public double GetXTag( String tag_source )

public double GetYTag( String tag_source )

public double GetZTag( String tag_source )

Return the X, Y or Z values of the G-type resource or tag of the bean's drawing.

public boolean HasResourceObject( String res_name )

Returns true if the bean's drawing contains a resource with the specified name.

public boolean HasTagName( String tag_name )

public boolean HasTagSource( String tag_source )

Return true if the bean's drawing contains a tag with a specified tag name or tag source.

public boolean SetDResource( String res_name, double dvalue )

public boolean SetDResource( String res_name, double dvalue, boolean if_changed )

public boolean SetDTag( String tag_source, double dvalue, boolean if_changed )

Set the value of the D-type resource or tag of the bean's drawing. Returns true if the value of the resource or tag was successfully changed.

public boolean SetSResource( String res_name, String svalue )

public boolean SetSResource( String res_name, String svalue, boolean if_changed )

public boolean SetSTag( String tag_source, String svalue, boolean if_changed )

Set the value of the S-type resource or tag of the bean's drawing. Returns true if the value of the resource or tag was successfully changed.

public boolean SetGResource( String res_name, double dvalue1, double dvalue2, double dvalue3 )

public boolean SetGResource( String res_name, double dvalue1, double dvalue2, double dvalue3, boolean if_changed )

public boolean SetGTag( String tag_source, double dvalue1, double dvalue2, double dvalue3, boolean if_changed )

Set the values of the G-type resource or tag of the bean's drawing (x, y and z values of a point or R, G and B values or a color). Returns true if the value of the resource or tag was successfully changed.

public boolean SetSResourceFromD( String res_name, String format, double dvalue )

Sets the value of the S-type resource of the bean's drawing to a string obtained by converting the supplied double value ( dvalue ) according to the given format. The format parameter is a C-like format string. Returns true if the value of the resource was successfully changed.

public boolean SetZoom( String res_name, int type, double value )

Performs a zoom or pan operation specified by the type parameter. If the res_name parameter is null, the bean's viewport is zoomed. Otherwise, the zoom operation will be performed on its child viewport specified by the res_name parameter. The value parameter defines a zoom factor or pan distance. Refer to GlgSetZoom on page 71 for a complete list of all zoom and pan types.

If the method attempts to set a very large zoom factor which would result in the overflow of the integer coordinate values used by the native windowing system, the zoom operation is not performed and the method returns false.

public void Update()

Updates the bean's drawing to display the latest resource settings.

public void Reset()

Resets the object hierarchy of the bean's drawing.

public GlgObject LoadWidget( String filename, int media_type )

Loads a viewport named "$Widget" from a file or URL, and returns the viewport object. The media type parameter defines the loading type (URL or FILE). Returns null if the drawing can't be loaded or if it the "$Widget" viewport can't be found.

public GlgObject LoadWidget( GlgObject object )

Finds a viewport named "$Widget" inside the object and returns the viewport. Returns null if the "$Widget" viewport can't be found.

public static GlgObject LoadObject( String filename, int media_type )

Loads an object from a file or URL, and returns the loaded object. The media_type parameter defines the loading type (URL or FILE). Returns null if the object can't be loaded.

public void InitialDraw( GlgObject object )

Draws a viewport object for the first time. If the viewport object does not have a parent, it will appear as a separate top level window. Sets up the hierarchy if it hasn't been set up yet.

public void SetupHierarchy( GlgObject object )

Sets up the viewport's object hierarchy.

public void ResetHierarchy( GlgObject object )

Resets the viewport's object hierarchy.

public void Bell()

Emits an audio beep.

public boolean Print( String filename, double x, double y, double width, double height, boolean portrait, boolean stretch )

Prints the bean's drawing and saves it in a PostScript file. Returns true if the drawing was successfully printed. The inherited print() method is used for native Java printing.

public String CreateIndexedName( String template_name, int resource_index )

Creates and returns a resource name string by inserting a number ( resource_index ) to the template string ( template_name ). The number is inserted at the position indicated by the "%" character, or at the end of the template name if it does not contain the "%" character.

public boolean IsDemo()

Returns true if an evaluation version of the GlgBean is used.

public boolean SetInputUpdate( boolean update )

Enables or disables an automatic update performed at the end of the bean's InputCallback . Returns the previous enabled status.

public void AddListener( int callback_type, Object listener)

Adds a GLG event listener to the bean. The callback_type parameter may have one of the following values: SELECT_CB, INPUT_CB, TRACE_CB, TRACE2_CB, H_CB, V_CB or READY_CB. The type of the listener provided by the second parameter must match the type parameter and may have one of the following values: GlgSelectListener, GlgInputListener, GlgTraceListener, GlgHListener, GlgVListener or GlgReadyListener, respectively. Only one listener of each type may be added. If no listener was added for some event types, the bean is used as a default listener. Use with null as the listener parameter to remove the listener specified by the callback_type parameter.

public void HCallback( GlgObject vp )

The default HCallback invoked after the bean's drawing is loaded, but before its object hierarchy is set up. The bean's AddListener method may be used to change the default callback. The vp parameter is the top level viewport of the bean's drawing.

public void VCallback( GlgObject vp )

The default VCallback invoked after the bean's drawing is loaded and set up, but before it is displayed for the first time. The bean's AddListener method may be used to change the default callback. The vp parameter is the top level viewport of the bean's drawing.

synchronized public void ReadyCallback( GlgObject vp )

The default ReadyCallback invoked after the bean has finished loading the drawing and reading its data. The bean's AddListener method may be used to change the default callback. The vp parameter is the top level viewport of the bean's drawing.

public void UpdateCallback()

This callback is invoked after the bean finished reading data on periodic updates. The ReadyCallback is invoked the first time, and the UpdateCallback is invoked on any subsequent data updates.

public void InputCallback( GlgObject vp, GlgObject message_object )

The default InputCallback invoked every time the user interacts with input objects in the drawing. More information about the type of the input activity may be extracted from the message_object parameter. Refer to Input Callback of Handling Input Events for more details. The bean's AddListener method may be used to change the default callback. The vp parameter is the top level viewport of the bean's drawing.

public void SelectCallback( GlgObject vp, Object[] name_array, int button )

The default SelectCallback invoked every time the user selects one or more objects in the drawing with the mouse. The name_array parameter is a null-terminated array of names of selected objects. The button parameter is the mouse button used for selection (1, 2 or 3). Refer to Selection Callback Handling Input Events for more details. The bean's AddListener method may be used to change the default callback. The vp parameter is the top level viewport of the bean's drawing.

public void TraceCallback( GlgObject top_viewport, GlgTraceData trace_info )
public void Trace2Callback( GlgObject top_viewport, GlgTraceData trace_info )

The TraceCallback and Trace2Callbacks are invoked for every event occurring in any of the drawing's viewports. They may be used as an escape mechanism to handle low-level Java events. The TraceCallback is invoked before dispatching the event for processing, while the Trace2Callback is invoked after the event has been processed. The vp parameter is the top level viewport of the bean's drawing. These callbacks are disabled by default and must be explicitly enabled by invoking the bean's AddListener method.

public String GetFullPath( String filename )

Given a relative filename, returns a full path relative to the document base. If the filename is not a relative path, it is returned unchanged.

Extended API Methods

public GlgObject CopyObject( GlgObject object )

Creates and returns a copy of the object.

public GlgObject CloneObject( GlgObject object, int clone_type )

Creates and returns an full or constrained copy of an object according the clone_type (WEAK_CLONE, STRONG_CLONE, FULL_CLONE or CONSTRAINED_CLONE).

public boolean SaveObject( GlgObject object, String filename )

Saves the object into a file with the given filename . Returns true if the object was successfully saved.

public boolean AddObjectToTop( GlgObject container, Object object )

Adds the object to the beginning of the container . Returns true if the object was successfully added.

public boolean AddObjectToBottom( GlgObject container, Object object )

Adds the object to the end of container . Returns true if the object was successfully added.

public boolean AddObjectAt( GlgObject container, int index )

Adds the object to the container at the index position . Returns false if index is invalid.

public boolean AddObject( GlgObject container, Object object,
int access_type, int position_modifier )

Adds an object to the container at the position indicated by the access_type (BOTTOM, TOP or CURRENT). If the access type is CURRENT, the object is added before or after the element indicated by the container's current position, as indicated by the position_modifier parameter (BEFORE or AFTER). Sets the container's current position to point to the added object. Returns true if the object was successfully added.

public boolean DeleteTopObject( GlgObject container )

Deletes the first object of this container. Returns true if the object was successfully deleted.

public boolean DeleteBottomObject( GlgObject container )

Deletes the first object of this container. Returns true if the object was successfully deleted.

public boolean DeleteObjectAt( GlgObject container, int index )

Deletes the object of the container at the index position . Returns false if index is invalid.

public boolean DeleteObject( GlgObject container, Object object )

Deletes an object from container . Returns true if the object was successfully deleted.

public boolean ContainsObject( GlgObject container, Object object )

Returns true if the object is contained in container .

public Object GetElement( GlgObject container, int index )

Returns the element of the container indicated by the index .

public int GetIndex( Object object )

Returns the index of the first occurrence of the object in the container or -1 if the object wasn't found in the container.

public int GetStringIndex( String string )

Returns an index of the first occurrence of the string in the container or -1 if the string wasn't found in the container.

public GlgObject GetNamedObject( GlgObject container, String name )

Returns the named element of the container defined by the name parameter.

public boolean ReorderElement( GlgObject container, int old_index, int new_index )

Moves the container's element from the old_index to the new_index position. The function returns false if indexes are out of range.

public void SetStart( GlgObject container )

Initializes the container for traversing. This function should be called before invoking the container's Iterate method.

public Object Iterate( GlgObject container )

Returns the next element of container .

public int GetSize( GlgObject container )

Returns the size of container .

public boolean SetXform( GlgObject object, GlgObject xform )

Sets the object's transformation to a constrained copy of the xform parameter. If the object has already been drawn, it has to be suspended with the SuspendObject method before setting its transformation. If the xform parameter is null, the function removes any object transformations. The CopyObject and CloneObject methods may be used in conjunction with the SetXform to add unconstrained copies of the same transformation to several objects.

public GlgObject GetResourceObject( GlgObject object, String res_name )

Finds and returns a named resource or an attribute of the object. The resource or attribute must be of the GlgObject type, and is specified with the res_name parameter.

public boolean SetResourceObject( String resource_name, GlgObject value )

Sets the new value of the object's attribute specified by the resource_name . It is used for attaching Custom Property objects and aliases .

public Object GetResource( GlgObject object, String res_name )

Finds and returns a named resource or an attribute of the object. The resource or attribute may be of the Object type or any subclass of the Object .

public boolean ConstrainObject( GlgObject from_object, GlgObject to_object )

Constrains an attribute object ( from_object ) to the object defined by the to_object attribute parameter. The attribute object being constrained must be obtained by using either a default attribute name at the end of the resource path name, or using the container access functions. If the object has already been drawn, a SuspendObject method should be invoked on either the attribute object or its parent before constraining.

public boolean UnconstrainObject( GlgObject object )

Unconstrains the input attribute object. The input object is obtained by using either a default attribute name at the end of the resource path name, or using container access functions. If the object has already been drawn, a SuspendObject method should be invoked on either the attribute object or its parent before constraining.

public GlgObject SuspendObject( GlgObject object )

Suspends the object for editing. This function must be called before adding a transformation or constraining attributes of the object whose object hierarchy has been setup (the object has been drawn). The method returns a GlgObject , which can be used as the suspend_info parameter to a subsequent call to the ReleaseObject method.

public void ReleaseObject( GlgObject object, GlgObject suspend_info )

Releases the object after suspending for editing. The suspend_info parameter is a returned value of a previous call to SuspendObject.

public int GetNumParents( GlgObject object )

Returns the number of parents of the object. Used to determine a type of the return value of the GetParent method.

public GlgObject GetParent( GlgObject object )

Returns the objects' parent if the object has one parent. If object has more than one parent, returns an array of parents. The type of the return value may be determined by using GetNumParents method.

public void Inverse( GlgObject container )

Reverses the order of objects in the container .

public double GetDResource( GlgObject object, String res_name )

Returns the value of an object's D-type resource specified by res_name .

public String GetSResource( GlgObject object, String res_name )

Returns the value of an object's S-type resource specified by res_name .

public double GetXResource( GlgObject object, String res_name )

public double GetYResource( GlgObject object, String res_name )

public double GetZResource( GlgObject object, String res_name )

Return the X, Y or Z values of an object's G-type resource specified by res_name .

public boolean SetDResource( GlgObject object, String res_name, double dvalue )

Sets the value of the D-type resource (specified by res_name ) of object to dvalue . Returns true if the value of the resource was successfully changed.

public boolean SetSResource( GlgObject object, String res_name, String svalue )

Sets the value of the S-type resource (specified by res_name ) of the object. Returns true if the value of the resource was successfully changed.

public boolean SetGResource( GlgObject object, String res_name,
double dvalue1, double dvalue2, double dvalue3 )

Sets the new values of the G-type resource (specified by res_name ) of the object. Returns true if the value of the resource was successfully changed.

public void Update( GlgObject viewport )

Updates the viewport to display the latest resource settings.

public boolean Print( GlgObject object, String filename, double x, double y, double width,
double height, boolean portrait, boolean stretch )

Prints a drawing of the viewport to a PostScript file. The x, y, width and height parameters define the page layout of the print output in the GLG coordinate system (use x=-1000, y=-1000, width=2000, height = 2000 to use the whole page). The portrait parameter defines the portrait or landscape orientation. If the stretch parameter is false, the aspect ratio of the drawing is preserved. The function returns true if the drawing was successfully printed.

public boolean SetResourceFromObject( GlgObject object, String res_name, GlgObject o_value )

Sets the value of the data or matrix resource (specified by res_name ) to the value of the o_value object. The resource types should match, otherwise false is returned . Returns true if the value of the resource was successfully changed.

public boolean SetSResourceFromD( GlgObject object, String res_name, String format,
double dvalue )

Sets the value of the input object's S-type resource (specified by res_name ) to a string obtained by converting the supplied double value ( dvalue ) according to the format. The format parameter is a C-like format string. Returns true if the value of the resource was successfully changed.

public boolean IsDemo()

Returns true if an evaluation version of the GlgBean 's Extended API is in use.

GlgObject class

abstract public class GlgObject

GlgObject is the main class of the Java implementation of the GLG Toolkit. It provides functionality available to all GLG objects. The instances of this class are never created directly. Instead, GLG objects are either loaded from a GLG drawing created using the GLG Graphics Builder, or, for advanced users, created using one of the constructors for the GLG graphical objects (See the GLG objects classes later in this chapter) and then accessed using the GlgObject superclass.

Variables

Refer to the JavaDoc version of the documentation for a list of all variables of the GlgObject class.

Methods

The GlgObject class provides the following public methods.

public void SetupHierarchy()

Sets up the viewport's object hierarchy.

public void ResetHierarchy()

Resets the viewport's object hierarchy.

public void InitialDraw()

Draws a viewport object for the first time. If the viewport object does not have a parent, it will appear as a separate top level window. Sets up the hierarchy if it wasn't set up yet.

public boolean SetZoom( String res_name, int type, double value )

Performs a zoom or pan operation specified by the type parameter. If the res_name parameter is null, the viewport itself is zoomed. Otherwise, the zoom operation will be performed on its child viewport specified by the res_name parameter. The value parameter defines the zoom factor or pan distance. Refer to GlgSetZoom on page 71 for a complete list of all zoom and pan types.

If the method attempts to set a very large zoom factor which would result in the overflow of the integer coordinate values used by the native windowing system, the zoom operation is not performed and the method returns false.

public boolean SetGISZoom( String res_name, GlgObject gis_object, String gis_name )

Sets or resets a viewport's GIS Zoom Mode. If the GIS zoom mode is set, any zooming and panning operations invoked by the SetZoom method will zoom and pan the map displayed in the viewport's GIS Object instead of being applied to the viewport's drawing. If the res_name parameter is null, the GIS zoom mode of the viewport itself will be set. Otherwise, the GIS zoom mode will be set for its child viewport specified by the res_name parameter. If the gis_name parameter is not null, it specifies the resource path of the GIS Object relative to the gis_object parameter, or relative to the viewport if the gis_object parameter is null. The method may be invoked with gis_object=null and gis_name=null to reset the GIS zoom mode.

public static GlgObject LoadObject( String filename, int media_type )

Loads an object from a file or URL (given by filename ) and returns it. The media_type parameter defines the loading type (URL or FILE). Returns null if the object can't be loaded.

public static GlgObject LoadWidget( String filename, int media_type )

Loads a viewport named "$Widget" from a file or URL, and returns it. The media_type parameter defines the loading type (URL or FILE). Returns null if the drawing can't be loaded or if it the "$Widget" viewport can't be found.

public static GlgObject LoadWidget( GlgObject object )

Finds a viewport named "$Widget" inside the object and returns it. Returns null if the "$Widget" viewport can't be found.

public boolean Update()

Updates the viewport to display the latest resource settings.

public boolean Reset()

Resets the viewport.

Object SendMessage( String res_name, char * message, Object param1,
Object param2, Object param3, Object param4 )

Sends a message specified by the message parameter. If the res_name parameter is null, the message is sent to the object itself. Otherwise, the message is sent to the object's child specified by the res_name parameter. The param<n> arguments define additional parameters of the message depending on the message type. The Integer object must be used to pass integer values to the message. Integer values returned by the query messages are returned as Integer objects.

Refer to Input Objects on page 105 of the GLG User's Guide and Builder Reference Manual for a list of messages supported by each type of the available input handlers.

int ExportStrings( GlgObject object, String filename, char separator1, char separator2,
String encoding )

Writes all text strings defined in the drawing specified by the object parameter into a string translation file using requested separator characters and encoding. Refer to Localization Support on page 103 of the GLG User's Guide and Builder Reference Manual for information about the string translation file format. The method returns the number of exported strings or -1 in case of an error.

int ImportStrings( GlgObject object, String filename, String encoding )

Replaces text strings in the drawing defined by the object parameter with the strings loaded from a string translation file with the specified encoding. Refer to Localization Support on page 103 of the GLG User's Guide and Builder Reference Manual for information about the string translation file format.The method returns the number of imported strings or -1 in case of an error.

int ExportTags( GlgObject object, String filename, char separator1, char separator2,
String encoding )

Writes tag names and tag sources of all tags defined in the drawing specified by the object parameter into a file using requested separator characters and encoding. The method uses the same file format as the ExportStrings method. Refer to Localization Support on page 103 of the GLG User's Guide and Builder Reference Manual for information about the file format. The method returns the number of exported tags or -1 in case of an error.

int ImportTags( GlgObject object, String filename, String encoding )

Replaces tag names and tag sources of tags in the drawing defined by the object parameter with information loaded from a tag translation file using the specified encoding. The method uses the same file format as the ImportStrings method. Refer to Localization Support on page 103 of the GLG User's Guide and Builder Reference Manual for information about the tag translation file format.The method returns the number of imported tags or -1 in case of an error.

public boolean Print( String file, double x, double y, double width, double height, boolean portrait, boolean stretch )

Prints the viewport object's drawing and saves it in a PostScript file. The x, y, width and height parameters define the page layout of the print output in the GLG coordinate system (use x=-1000, y=-1000, width=2000, height = 2000 to use the whole page). The portrait parameter defines the portrait or landscape orientation. If the stretch parameter is false, the aspect ratio of the drawing is preserved. The function returns true if the drawing was successfully printed.

public boolean NativePrint( Graphics graphics )

Prints the viewport object's drawing into a provided graphics object. The origin of graphics is assumed to be (0,0) and clipping to be set the viewport's window width and height. Returns true if the drawing was successfully printed.

public Image CreateImage( String res_name )

Generates an image of the visible area of the viewport's drawing and returns it in a form of the Java Image object. The res_name parameter specifies the resource name of a child viewport whose image to generate, or null to generate the image of the viewport itself. The function returns null if image creation fails.

public Image CreateImageCustom( String res_name, Rectangle image_area, int gap )

Generates an image of the area of the drawing defined by the image_area (in the screen pixels), and returns it in a form of the Java Image object. If image_area is null, the image of the whole drawing is generated, which may be bigger than the visible area of the viewport if the drawing is zoomed in. The gap parameter specifies the padding space between the extent of the drawing and the edge of the image when the image_area is null. The viewport's zoom factor defines the scaling factor for objects in the drawing when the image is saved. The res_name parameter specifies the resource name of a child viewport whose image to generate, or null to generate the image of the viewport itself. The function returns null if image creation fails.

public static String CreateIndexedName( String template_name, int resource_index )

Creates and returns a resource name string by inserting the given number ( resource_index ) to the template_name string. The index is inserted at the position indicated by the "%" character, or at the end of the template name if it does not contain the "%" character.

public static String ConcatResNames( String resource_name1, String resource_name2 )

Creates a "/"- separated resource name by appending the second resource name to the first one, and inserting the "/" separator is necessary.

public Double GetDResource( String resource_name )

public Double GetDTag( String tag_source )

Return the value of a scalar resource or tag.

public GlgPoint GetGResource( String resource_name )

public GlgPoint GetGTag( String tag_source )

Return the value of a G-type resource or tag.

public String GetSResource( String resource_name )

public String GetSTag( String tag_source )

Return the value of a string resource or tag.

public boolean SetDResource( String resource_name, double d_value )

public boolean SetDResource( String resource_name, Double d_value )

public boolean SetDResource( String resource_name, double d_value, boolean if_changed )

public boolean SetDResource( String resource_name, Double d_value, boolean if_changed )

public boolean SetDTag( String tag_source, double d_value, boolean if_changed )

public boolean SetDTag( String tag_source, Double d_value, boolean if_changed )

Set the value of scalar resource or tag. Returns true if the value of the resource or tag was successfully changed.

public boolean SetGResource( String resource_name, double g_value1, double g_value2,
double g_value3 )

public boolean SetGResource( String resource_name, GlgPoint g_value )

public boolean SetGResource( String resource_name, double g_value1, double g_value2,
double g_value3, boolean if_changed )

public boolean SetGResource( String resource_name, GlgPoint g_value, boolean if_changed )

public boolean SetGTag( String tag_source, double g_value1, double g_value2, double g_value3, boolean if_changed )

public boolean SetGTag( String tag_source, GlgPoint g_value, boolean if_changed )

Set the value of a G-type resource or tag. Returns true if the value of the resource or tag was successfully changed.

public boolean SetSResource( String resource_name, String s_value )

public boolean SetSResource( String resource_name, String s_value, boolean if_changed )

public boolean SetSTag( String tag_source, String s_value, boolean if_changed )

Set the value of a string resource or tag. Returns true if the value of the resource or tag was successfully changed.

public boolean SetSResourceFromD( String resource_name, String format, double d_value )
public boolean SetSResourceFromD( String resource_name, String format, Double d_value )
public boolean SetSResourceFromD( String resource_name, String format, double d_value,
boolean if_changed )
public boolean SetSResourceFromD( String resource_name, String format, Double d_value,
boolean if_changed )
public boolean SetSTagFromD( String tag_source, String format, double d_value, boolean if_changed )
public boolean SetSTagFromD( String tag_source, String format, Double d_value, boolean if_changed )

Set the value of a string resource or tag to a string obtained by converting the supplied double value according to the specified format. The format parameter is a C-like format string. Returns true if the value of the resource or tag was successfully changed.

public boolean SetResourceFromObject( String resource_name, GlgObject o_value )

Sets the new value of the resource object defined by the resource name to the value of the o_value object. The resource types should match. Returns true if the value of the resource was successfully changed.

public GlgObject CreateTagList( boolean unique_tags )

Returns a list of all object's tags.

public boolean HasResourceObject( String resource_name )

Returns true if a named resource exists.

public boolean HasTagName( String tag_name )

public boolean HasTagSource( String tag_source )

Return true if a tag with a specified tag name or tag source exists.

public boolean GISConvert( String res_name, int coord_type, boolean coord_to_lat_lon,
GlgPoint in_point, GlgPoint out_point )

Converts coordinates between the GIS coordinate system of the GIS Object and GLG coordinate system of the drawing. If the res_name parameter is NULL, the coordinate system of this object is used for conversion. If the res_name parameter is not NULL, it specifies the resource name of the GIS Object inside of this object whose coordinate system will be used for conversion. The coord_type parameter specifies the type of the GLG coordinate system type to convert to or from: SCREEN_COORD for screen coordinates or OBJECT_COORD for world coordinates. If the coord_to_lat_lon parameter is true, coordinates are converted from GLG to GIS coordinate system. If it is false, the coordinates are converted from GIS to GLG coordinate system. When converting from GLG to GIS coordinates, the Z coordinate is set to a negative GLG_GIS_OUTSIDE_VALUE value for points on the invisible part of the globe.

public boolean GlmConvert( int projection, boolean stretch, int coord_type, boolean coord_to_lat_lon, GlgPoint center, GlgPoint extent, double angle,
double min_x, double max_x, double min_y, double max_y,
GlgPoint in_point, GlgPoint out_point )

Low-level function similar to GISConvert, but without the use of the GIS Object. The projection, stretch, center, extent and angle parameters provide information about the GIS Object's attributes, and min_x, max_x, min_y and max_y parameters provide information about the extent of the GIS Object in the drawing using a coordinate system (screen or object) matching the coord_type parameter. Refer to the GlmConvert function description in the GLG Map Server Reference Manual for details.

public Double GISGetElevation( String res_name, String layer_name, double lon, double lat )

Return an elevation of a lat/lon point on a map. If the res_name parameter is NULL, the coordinate system of this object is used for conversion. If the res_name parameter is not NULL, it specifies the resource name of the GIS Object inside of this object whose coordinate system will be used for conversion. The layer_name parameter specifies the name of the layer with elevation data to query.

The method returns null if the point is outside of the map in the ORTHOGRAPHIC projection or if there is no elevation data for the specified location. Otherwise, the method returns the elevation value in the units (such as meters or feet) defined by the elevation data file.

public static void Init()

Initializes the GLG Toolkit. If a GlgBean is not used, this method must be invoke before using any other GLG methods. If the GlgBean is used, it'll invoke this method automatically in its constructor.

public static void Terminate()

May be used to free internal structures allocated by the Toolkit if the Toolkit will not be used any more by the program.

public static boolean Sync()

Synchronizes the Toolkit's graphical state by flushing any buffered graphics events.

public void AddListener( int type, Object callback )

Adds an input, selection or event listener depending on the type parameter (INPUT_CB, SELECT_CB, TRACE_CB or TRACE2_CB). The listener should implement the GlgInputListener , GlgSelectListener or GlgTraceListener interface, depending on the specified type. Only one listener of a particular type may be added to one viewport. The listeners must be added before setting the drawing hierarchy or displaying the drawing for the first time.

The GlgBean implements all GLG listener interfaces. If the GlgBean is used, the listener's callbacks are added automatically and may be overwritten by the bean's subclass.

public static void Lock() (JSP Servlet only)

public static void Unlock() (JSP Servlet only)

Locks and unlocks the object for synchronization of object access in the JSP Servlets. These methods may be used to lock an object to avoid an access to object's components while it is being manipulated. The locking may also be used to prevent a thread being killed in the middle of the object manipulation, which would result in an unpredictable object state.

The calls to the Lock and Unlock methods must be balanced. If a thread was locked with a several calls to the Lock method, an equal number of calls to the Unlock method must be used to unlock the thread.

In Swing applications, asynchronous access is not allowed and these functions should not be used.

public static void UnlockThread() (JSP Servlet only)

Unconditionally unlocks the current tread regardless of the number of the Lock calls made to lock the thread. It may be used at the end of the JSP Servlet's doGet method to unlock the thread after an exception that interrupts the normal flow of control, or to ensure that the thread is unlocked even if there was an unbalanced number of the Lock nd Unlock calls due to a programming error.

public static GlgErrorHandler SetErrorHandler( GlgErrorHandler new_handler )

Replaces a default GLG error handler with a custom one. If the new_handler parameter is null, the method restores the default error handler. The default error handler prints an error message to the stdout and generates a beep.

public static String GetStackTraceAsString()

Returns the stack trace information as a string which may be used for logging.

public static void Bell()

Emits an audio beep.

public static double Rand( double low, double high )

Returns a random number in the defined range.

public static void SetBrowserObject( GlgObject browser, GlgObject object )

Sets an object to be browsed by the GLG Resource or Tag Browser widget.

public void SetImageSize( int width, int height ) (JSP Servlet only)

Sets the size of the image to be generated for the drawing represented by a viewport object.

Extended API Methods

public GlgObject CopyObject()

Creates and returns a copy of the object.

public GlgObject CloneObject( int clone_type )

Creates and returns a full or constrained copy of an object according to the clone_type (WEAK_CLONE, STRONG_CLONE, FULL_CLONE or CONSTRAINED_CLONE).

public boolean SaveObject( String filename )

Saves the object into a file. Returns true if the object was successfully saved.

public boolean AddObjectToTop( Object object )

Adds the object to the beginning of this container. Returns true if the object was successfully added.

public boolean AddObjectToBottom( Object object )

Adds the object to the end of this container. Returns true if the object was successfully added.

public boolean AddObjectAt( Object object, int index )

Adds the object to the container at the position specified by index . Returns true if the object was successfully added.

public boolean AddObject( Object object, int access_type, int position_modifier )

Adds the object to this container at the position indicated by the access type (BOTTOM, TOP or CURRENT). If access_type is CURRENT, adds before or after the element indicated by the container's current position, as indicated by the position_modifier parameter (BEFORE or AFTER). Sets the container's current position to point to the added object. Returns true if the object was successfully added.

public boolean DeleteTopObject()

Deletes the first object of this container. Returns true if the object was successfully deleted.

public boolean DeleteBottomObject()

Deletes the last object of this container. Returns true if the object was successfully deleted.

public boolean DeleteObjectAt( int index )

Deletes an object at the specified position in this container.

public boolean DeleteObject( Object object )

Deletes the given object from this container. Returns true if the object was successfully deleted.

public boolean DeleteObject( int access_type, int pos_modifier )

Deletes an object from this container and adjusts the current position according to the pos_modifier (BEFORE or AFTER). The object is deleted from the position indicated by the access_type (BOTTOM, TOP or CURRENT). Returns true if the object was successfully deleted.

public boolean ContainsObject( Object object )

Returns true if the object is contained in this container.

public Object GetElement( int index )

Returns the element of this container indicated by index or null if index is invalid.

public boolean SetElement( int index, GlgObject new_object )

Replaces the element of this container indicated by index . Returns false if index is invalid.

public int GetIndex( Object object )

Returns the index of the first occurrence of the object in the container or -1 if the object wasn't found in the container.

public int GetStringIndex( String string )

Returns the index of the first occurrence of the string in the container or -1 if the string wasn't found in the container.

public GlgObject GetNamedObject( String name )

Returns the named element of this container defined by the name parameter.

public boolean ReorderElement( int old_index, int new_index )

Moves an element of this container from the position specified by old_index to the position defined by new_index . Returns false if indexes are out of range.

public void SetStart()

Initializes this container for traversing, should be called before invoking the container's Iterate method.

public Object Iterate()

Returns the next element of this container.

public int GetSize()

Returns the size of this container.

public void Inverse()

Reverses the order of the objects in this container.

public boolean SetXform( GlgObject xform )

Sets this object's transformation to a constrained copy of the xform parameter. If the object has already been drawn, it has to be suspended with the SuspendObject method before setting its transformation. If the xform parameter is null, this function removes any object transformations. The CopyObject and CloneObject methods may be used in conjunction with the SetXform to add unconstrained copies of the same transformation to several objects.

public boolean SetResource( String resource_name, int type, Object value, boolean if_changed_only, boolean is_attribute )

ADVANCED: Sets the value of a generic resource of a type defined by the type parameter (D, S, G or O). The value parameter must be of the Double type for D resources, String type for S resources, GlgPoint for G resources and Object type for O (object) resources. If the if_changed_only parameter is true , the value change event will be generated only if value of the resource was different. The is_attribute parameter may be set to true to speed up setting default attributes of an object. Returns null if the resource can't be set.

public boolean SetResourceObject( String resource_name, GlgObject value )

Sets the new value of the object's attribute specified by the resource_name . It is used for attaching Custom Property objects and aliases .

public GlgObject GetResourceObject( String resource_name )

Finds and returns a named resource or an attribute of this object. The resource or attribute must be of the GlgObject type.

public Object GetResource( String resource_name )

Finds and returns a named resource or an attribute of this object. The resource or attribute must be of the Object type.

public Object GetResource( String resource_name, int type, boolean mandatory, boolean is_attribute, boolean dont_cache )

ADVANCED: Gets the value of a generic resource of a type defined by the type parameter. (D, S, G or O). The type of the returned value is Double for D resources, String for S resources, GlgPoint for G resources and Object for O (object) resources. Returns null if the resource can't be found.

public GlgObject GetTagObject( String search_string, boolean by_name, boolean unique_tags, boolean single_tag )

Finds a single tag with a given tag name or tag source, or creates a list of tags matching the wildcard. The search_string specifies either the exact tag name or tag source to search for, or a search pattern which may contain the ? and * wildcards. The by_name parameter defines the search mode: by a tag name or tag source. In the single tag mode, the first tag matching the search criteria is returned. The unique_tags controls if only one tag is included in case there are multiple tags with the same tag name or tag source. The unique_tags flag is ignored in the single tag mode.

In a single tag mode, the function returns the first attribute that has a tag matching the search criteria. In the multiple tag mode, a list containing all attributes with matching tags will be returned.

public boolean ConstrainObject( GlgObject to_attribute )

Constrains this attribute object to the object defined by the to_attribute parameter. The attribute object being costrained must be obtained by using either a default attribute name at the end of the resource path name, or using the container access functions. If the object has already been drawn, a SuspendObject method should be invoked on either the attribute object or its parent before constraining.

public boolean UnconstrainObject()

Unconstrain this attribute object. The attribute object being unconstrained must be obtained by using either a default attribute name at the end of the resource path name, or using container access functions. If the object has already been drawn, a SuspendObject method should be invoked on either the attribute object or its parent before constraining.

public boolean UnconstrainObject( int clone_type )

ADVANCED: Unconstrain this attribute object using clone_type parameter (WEAK_CLONE, STRONG_CLONE, FULL_CLONE or CONSTRAINED_CLONE) to unconstrain the transformation attached to the object, if any. The attribute object being unconstrained must be obtained by using either a default attribute name at the end of the resource path name, or using container access functions. If the object has already been drawn, a SuspendObject method should be invoked on either the attribute object or its parent before constraining.

public GlgObject SuspendObject()

Suspends this object for editing. It must be called before adding a transformation or constraining attributes of the object whose object hierarchy has been setup (the object has been drawn). The method returns a GlgObject , which can be used as the suspend_info argument to the ReleaseObject method.

public void ReleaseObject( GlgObject suspend_info )

Releases this object after suspending for editing. The suspend_info parameter is a returned value of a previous call to SuspendObject.

public int GetNumParents()

ADVANCED: Returns the number of parents of this object. Used to determine the type of the return value of the GetParent method.

public GlgObject GetParent()

ADVANCED: Returns the objects' parent if this object has one parent. If object has more than one parent, returns an array of parents. The type of the return value may be determined with the GetNumParents method.

public GlgCube GetBox()

ADVANCED: Returns a 3D bounding box of the object that can be used for collision detection. The coordinates of the bounding box are valid only after the object has been drawn.

public GlgObject GetDrawingMatrix()

ADVANCED: Returns a matrix object of the transformation used to draw the object on the screen.

public GlgObject CreateInversedMatrix()

ADVANCED: Creates and returns an matrix inversed relative to this one.

public void GetMatrixData( GlgMatrixData matrix_data );

ADVANCED: Queries matrix coefficients.

public void SetMatrixData( GlgMatrixData matrix_data );

ADVANCED: Sets matrix coefficients.

public void TransformPoint( GlgPoint in_point, GlgPoint out_point )

ADVANCED: Transforms the in_point with this matrix and places the result into the out_point .

public boolean MoveObject( GlgCoordType coord_type, GlgPoint start_point, GlgPoint end_point );

Moves an object by the specified vector in the specified coordinate system (SCREEN_COORD or WORLD_COORD). If start_point is null, (0,0,0) is used as the start point of the move vector.

public boolean MoveObjectBy( GlgCoordType coord_type, double x, double y, double z );

Moves an object by the specified X, Y and Z distances in the specified coordinate system (SCREEN_COORD or WORLD_COORD).

public boolean ScaleObject( GlgCoordType coord_type, GlgPoint * center, double x, double y,
double z );

Scales an object relative to the specified center in the specified coordinate system (SCREEN_COORD or WORLD_COORD) by the specified X, Y and Z scale factors.

public boolean RotateObject( GlgCoordType coord_type, GlgPoint * center, double x, double y,
double z );

Rotates an object around the specified center in the specified coordinate system (SCREEN_COORD or WORLD_COORD) by the specified X, Y and Z angles.

public boolean PositionObject( GlgCoordType coord_type, int anchoring, double x, double y,
double z );

Positions an object at the specified location in the specified coordinate system (SCREEN_COORD or WORLD_COORD) using the specified anchoring. The value of anchoring is formed as a bitwise "or" of the horizontal anchoring constant (HLEFT, HCENTER or HRIGHT) with the vertical anchoring constants (VTOP, VCENTER or VBOTTOM). The object's bounding box is used to anchor an object's edges.

public boolean FitObject( GlgCoordType coord_type, GlgCube box, boolean keep_ratio );

Fits the object to the specified area in the specified coordinate system (SCREEN_COORD or WORLD_COORD).

public boolean LayoutObjects( GlgObject sel_elem, int type, double distance, boolean use_box, boolean process_subobjects )

Performs a requested layout operation. Refer to The GLG Extended API on page 99 for more details.

public void TransformObject( GlgObject xform, int coord_type, GlgObject parent )

ADVANCED: Transforms all control points of an object with the transformation, calculating new control points values.The coord_type specifies the coordinate system to interpret the transformation in. If SCREEN_COORD is used, the parameters of the transformation are considered to be in screen pixels. For example, this may be used to move the object by the number of screen pixels as defined by the mouse move. If OBJECT_COORD is used, the transformation parameters are interpreted as GLG world coordinates. The parent parameter specifies the object's parent in the OBJECT_COORD mode, null may be used in the SCREEN_COORD mode. The object's hierarchy must be set to use this method.

public boolean ScreenToWorld( boolean inside_vp, GlgPoint in_point, GlgPoint out_point );

ADVANCED: Converts a point coordinates from the screen to the GLG world coordinate system. The inside_vp flag must be set to true for viewport objects to convert to the world coordinate system inside the viewport.

public boolean WorldToScreen( boolean inside_vp, GlgPoint in_point, GlgPoint out_point );

ADVANCED: Converts a point coordinates from the GLG world to the screen coordinate system. The inside_vp flag must be set to true for viewport objects to convert from the world coordinate system inside the viewport.

public static GlgObject CreateSelectionNames( GlgObject top_vp, GlgCube rectangle,
GlgObject selected_vp )

ADVANCED: Given the top viewport of the drawing, and a screen coordinates rectangle in a selected viewport, returns an array of names of all objects within the rectangle. This method may be used inside of the TraceListener to implement custom selection logic based on the mouse events.

public static GlgObject CreateSelectionNames( MouseEvent event, int delta, GlgObject top_vp, GlgObject selected_vp )

ADVANCED: Given the top viewport of the drawing, a mouse event, a viewport in which the mouse event occurred and the selection distance ( delta ), returns an array of names of all objects selected by the mouse event. This method may be used inside of the TraceListener to implement custom selection logic based on the mouse events.

public static GlgObject CreateSelectionMessage( GlgObject top_vp, GlgCube rectangle,
GlgObject selected_vp, in selection_type, int button )

ADVANCED: This method is a programming API for the custom events. It may be used in the trace callback to retrieve a custom event which would be triggered by a specified mouse action in the rectangular area.

Given the top viewport of the drawing and a screen coordinates rectangle in a selected viewport, the method searches all objects inside the rectangle for the custom event of the specified type attached to an object. The method returns a selection message for the first matching custom event it finds. The selection message is a custom event message equivalent to the message received in the input callback. The selection_type parameter may specify one of the following predefined selection types: MOVE_SELECTION, CLICK_SELECTION or TOOLTIP_SELECTION.

public static GlgObject CreateSelection( GlgObject top_vp, GlgCube rectangle,
GlgObject selected_vp )

ADVANCED: This is the same as the corresponding CreateSelectionNames, but returns an array of selected objects on the bottom of the hierarchy instead of an array of names.

public static GlgObject CreateSelection( MouseEvent event, int delta, GlgObject top_vp,
GlgObject selected_vp )

ADVANCED: Same as the corresponding CreateSelectionNames, but returns an array of selected objects on the bottom of the hierarchy instead of an array of names.

public GlgObject CreateResourceList( boolean list_named_res, boolean list_def_attr,
boolean list_aliases )

ADVANCED: Creates an array of all resource names of this object on one level of hierarchy. If list_def_attr is true , the default attributes are included. The list_aliases parameter is reserved for the future use and must be false .

public GlgObject CreatePointArray( int type )

ADVANCED: Creates and returns an array containing all of an object's control points. The type parameter is reserved for future use, must be 0.

GLG Utility Classes

These classes are used for incidental tasks associated with the GlgBean and GlgObject classes.

GlgPoint class

public class GlgPoint

Variables
public double x, y, z;

X, Y and Z values of the point.

Constructors
public GlgPoint()

Creates a new point with a default (0;0;0) value.

public GlgPoint( double x, double y, double z )

public GlgPoint( GlgPoint point )

Create a new point with a defined value.

Methods
public void CopyFrom( GlgPoint point )

Copies x, y and z values from the point defined by the point parameter to this point.

GlgCube class

public class GlgCube

Used to store an object's bounding box in 3D space.

Variables
public GlgPoint p1;

The first corner of the cube. Always has the lowest X, Y and Z.

public GlgPoint p2;

The second corner of the cube. Always has the biggest X, Y and Z.

Constructors
public GlgCube()

Creates a new bounding box with default (0;0;0) values for both corner points.

public GlgCube( GlgCube cube )

Creates a copy of a cube.

GlgMatrixData class

public class GlgMatrixData

Variables
public byte type;

Matrix type.

public double matrix[4][4];

Matrix coefficients.

Constructors
public GlgMatrixData()

Creates an empty matrix data object.

public GlgMatrixData( GlgMatrixData matrix_data )

Create a new matrix data fills it with data from another matrix data object.

Methods
public void CopyFrom( GlgMatrixData )

Copies matrix data from another matrix data object.

GlgTraceData class

public class GlgTraceData

This class is used to pass information for the GlgTraceCallback.

Variables:
public GlgObject viewport;

The viewport object that received the event.

public Object widget;

The AWT widget of the viewport.

public AWTEvent event;

The AWT event that caused GlgTraceCallback to be invoked.

GLG objects classes

Overview

GLG objects classes provide the actual implementation for specific drawing primitives used in the Toolkit. However, these classes are rarely used by the end user, since the GlgObject superclass delivers most of the GLG API. Unless you are dealing with some advanced uses of the Toolkit, you can skip this section of the manual. For details regarding a particular type of a GLG object, refer to GLG Objects.

The GLG objects classes are used only to create objects using their public constructors. After they are created, you use the GlgObject superclass methods for any further processing.

Most of the time the drawing and objects in it will be created interactively using the GLG Graphics Builder. These object classes are provided for the advanced users who may want to build the drawing programmatically for applications that generate objects in the drawing based on some kind of a configuration file or table.

When the constructors are used, the objects are initially created with default attributes (attribute values set to 0). The values may later be set using the GlgObject SetResource methods.

Most of the constructors may be called with null parameters to create an object instance with default attribute values. Where the non-null parameter are required, it will be explicitly mentioned.

All constants used by these classes are defined in the GlgObject superclass.

GlgArc class

public class GlgArc extends GlgObject

An arc object.

Constructor
public GlgArc()

Creates an arc object.

GlgBoxAttr class

public class GlgBoxAttr extends GlgObject

A text box attributes object.

Constructor
public GlgBoxAttr()

Creates an text box attributes object.

GlgDynArray class

public class GlgDynArray extends GlgObject

A dynamic array. The array automatically increase its size when new elements are added.

Constructor
public GlgDynArray( int type, int n_slots, int increment )

Creates a dynamic array.

The type parameter defines the type of objects that will be stored in the array and may be one of GLG_OBJECT, STRING, INT_VALUE or JAVA_OBJECT. The GLG_OBJECT default value is used if the value of 0 is passed.

The n_slots parameter defines the initial size of the array. A default value is used if the value 0 is passed.

The increment parameter specifies the initial increment to be used when the size of the array has to be increased. A default value is used if the value 0 is passed.

GlgFont class

public class GlgFont extends GlgObject

A GLG font object.

Constructor
public GlgFont( String font_name, String ps_name )

Creates a font object. The font_name parameter defines the name of the font to use, while ps_name defines the name to use for the font when producing a PostScript output. If these parameters are null, default names are used.

GlgFontTable class

public class GlgFontTable extends GlgObject

A font table object.

Constructor
public GlgFontTable( int num_types, int num_sizes, GlgObject font_array )

Creates a font table. The num_types parameter specifies the number of font types in the table, and num_sizes specifies the number of font sizes. The font_array parameter may specify a GLG group object containing an array of strings to be used as font names. If the length of the array is less than the product of the first two parameters, default font names will be used for the remaining fonts. If null values are passed for the number of font types, sizes, or the font_array, the default values will be used.

GlgFrame class

public class GlgFrame extends GlgObject

A GLG frame object.

Constructor
public GlgFrame( int type, int factor, GlgObject reserved )

Creates a frame object. The type parameter specifies a type of frame to create and must be FRAME_1D, FRAME_2D or FRAME_3D. The factor parameter must specify the number of intervals the frame uses to create frame points. The last parameter is reserved and a null value must be used.

GlgFunction class

public class GlgFunction extends GlgObject

A helper class for implementing GLG interaction handlers.

Constructors:
public GlgFunction( String name, GlgHandler reserved, String arguments )

Creates an interaction handler that can be attached to a viewport object. The name parameter specifies a name of one of Glg's interaction handlers (GlgButton, GlgKnob, etc.). The second and third parameters are reserved and a null value must be used.

GlgHistory class

public class GlgHistory extends GlgObject

A history object that implements a scrolling behavior of the GLG graphs.

Constructor
public GlgHistory( String var_name, GlgObject reserved1, int reserved2 )

Creates a history object. The var_name parameter specifies the name of the resource to scroll. The second and third parameters are reserved and null values (null and 0 ) must be used.

GlgImage class

public class GlgImage extends GlgObject

An image object, integrates GIF images into a GLG drawing.

Constructors
public GlgImage( int image_type, String filename, String load_path )

Creates a GLG image object. The image_type parameter defines the type of image: FIXED_IMAGE or SCALED_IMAGE. The filename defines the GIF file to use and may be a local file or a URL. The load_path parameter is reserved for future use and must be null.

GlgList class

public class GlgList extends GlgObject

A linked list object.

Constructors
public GlgList( int type )

Creates a GLG list object. The type parameter defines the type of objects that will be stored in the array and may be one of GLG_OBJECT, STRING, INT_VALUE or JAVA_OBJECT. The GLG_OBJECT default value is used if the value of 0 is passed.

GlgLight class

public class GlgLight extends GlgObject

A light object.

Constructors
public GlgLight()

Creates a light object.

GlgMarker class

public class GlgMarker extends GlgObject

A GLG marker object.

Constructor
public GlgMarker()

Creates a marker object.

GlgParallelogram class

public class GlgParallelogram extends GlgObject

A parallelogram object.

Constructor
public GlgParallelogram()

Creates a parallelogram object.

GlgPolySurface class

public class GlgPolySurface extends GlgObject

A polysurface object.

Constructor
public GlgPolySurface( GlgObject marker, GlgObject polygon, GlgObject reserved )

Creates a polysurface object. The first two parameters are optional and null values may be used, the last parameter is reserved and a null value must be used. The marker parameter specifies a template marker object to use, and the polygon parameter specifies a template polygon.

GlgPolygon class

public class GlgPolygon extends GlgObject

A polygon object.

Constructor
public GlgPolygon( int size, GlgObject reserved )

Creates a polygon object. The optional size parameter specifies the number of points in the polygon. If the values of 0 or 1 are used, a default polygon with two points is created. After the polygon is created, more points may be added or existing points may be deleted by using Add and Delete methods of the GlgObject superclass. The value of -1 may be used to create a polygon with no points. The second parameter is reserved and a null value must be used.

GlgPolyline class

public class GlgPolyline extends GlgObject

A polyline object.

Constructor
public GlgPolyline( GlgObject marker, GlgObject polygon, GlgObject reserved )

Creates a polyline object. The first two parameters are optional and null values may be used, the last parameter is reserved and a null value must be used. The marker parameter specifies a template marker object to use, and the polygon parameter specifies a template polygon.

GlgReference class

public class GlgReference extends GlgObject

A reference object.

Constructor
public GlgReference( GlgObject template, GlgObject reserved )

Creates a reference object. A mandatory template parameter specifies the object to be used as the reference's template. The second parameter is reserved and a null value must be used.

GlgRenderingAttr class

public class GlgRenderingAttr extends GlgObject

A rendering attributes object.

Constructor
public GlgRenderingAttr()

Creates a rendering attributes object.

GlgResourceReference class

public class GlgResourceReference extends GlgObject

An alias object.

Constructor
public GlgResourceReference( String from_name, String to_name, GlgObject reserved )

Creates an alias object. The from_name parameter specifies the new logical name for the resource hierarchy pointed to by the alias. The to_name specifies the resource path to the aliased resource. The third parameter is reserved and a null value must be used.

GlgScreen

abstract class GlgScreen extends GlgObject

This class implements AWT-related properties of the viewport object. The class is never created directly. Instead, it is created by the viewport object.

GlgSeries class

public class GlgSeries extends GlgObject

A series object.

Constructor
public GlgSeries( GlgObject template, GlgObject reserved )

Creates a series object. A mandatory template parameter specifies the object to be used as the series template. The second parameter is reserved and a null value must be used.

GlgSpline class

public class GlgSpline extends GlgObject

A spline object.

Constructor
public GlgSpline( int size, GlgObject reserved )

Creates a spline object. The size parameter specifies the number of control points. The second parameter is reserved and a null value must be used.

GlgSquareSeries class

public class GlgSquareSeries extends GlgObject

A square series object.

Constructor
public GlgSquareSeries( GlgObject template )

Creates a square series object. A mandatory template parameter specifies the object to be used as the series template.

GlgTag class

public class GlgTag extends GlgObject

A tag object which is attached to object attributes to hold data connectivity information.

Constructor
public GlgTag( String tag_name, String tag_source, String tag_comment )

Creates a tag object. Optional String parameters supply tag name, tag source and tag comment. The default value for these parameters is null .

GlgText class

public class GlgText extends GlgObject

A text object.

Constructor
public GlgText( String string, int type )

Creates a text object. An optional string parameter defines the string to display in the text object. If this parameter is null, an empty string is used as a default. The type parameter defines the type of the text object to create and may be FIXED_TEXT, AUTOSCALED_TEXT or SPACED_TEXT. If the value of 0 is passed, the AUTOSCALED_TEXT type is used as a default.

GlgViewport class

public class GlgViewport extends GlgObject

A viewport object.

Constructor
public GlgViewport( GlgObject reserved )

Creates a viewport object. The constructor's parameter is reserved and a null value must be used.

GlgXform class

public class GlgXform extends GlgObject

A transformation object.

Constructor
public GlgXform( int role, int type, GlgObject reserved1, GlgObject reserved2 )

Creates a transformation object used to animate objects.

The role parameter specifies the role transformation plays and may have the value of one of the transformation role constants defined in the GlgObject superclass. POINT_XR is the most common value of this parameter that is used to transform geometrical points in 3D space.

The type parameter specifies the type of the transformation to create and may have the value of one of the transformation type constants defined in the GlgObject superclass, for example: TRANSLATE_XF, SCALE_XYZ_XF, ROTATE_Z_XF, and so on.

After the transformation of a desired type is created, its parameters (such as the scale, rotation angle and others) may be set by using SetResource methods of the GlgObject superclass.

The last two parameters are reserved and null values must be used.

Attribute classes

GlgDataPoint class

abstract class GlgDataPoint extends GlgObject

GlgDDataPoint class

class GlgDDataPoint extends GlgDataPoint

GlgGDataPoint class

class GlgSDataPoint extends GlgDataPoint

GlgSDataPoint class

class GlgGDataPoint extends GlgDataPoint

These classes implement object attributes. These classes are not used by the end user and are listed here for the sake of completeness, so that they can be used in the instanceof operator.

Data Value classes

These classes implement an atomic data value holder. The data object may be used in user applications to hold D, S, or G data. One of the GLG containers may be used to hold a collection of data objects. The data may be assigned or queried using the GetResource and SetResource methods using null as a resource name. The type of the Get/Set method to use (D, S or G) is defined by the type of the data value.

GlgDataValue class

abstract class GlgDataValue extends GlgObject

An abstract superclass for all data value classes

GlgDDataValue class

public class GlgDDataValue extends GlgDataValue

Holds one double data value

Constructors
public GlgDDataValue( double value )

public GlgDDataValue( GlgObject ddatavalue )

Creates a D data value from a double or another GlgDDataValue object. If created from a null GlgDDataValue, the values of 0 is used as a default value.

GlgGDataValue class

public class GlgGDataValue extends GlgDataValue

Hold one triplet of X, Y, Z or R, G and B values.

Constructors
public GlgGDataValue( double x, double y, double z )

public GlgGDataValue( GlgObject gdatavalue)

Creates a G data value from X, Y and Z values or another GlgGDataValue object. If created from null GlgGDataValue, the values of 0 are used for X, Y and Z.

GlgSDataValue class

public class GlgSDataValue extends GlgDataValue

Holds one string value as a GLG object

Constructors
public GlgSDataValue( GlgObject sdatavalue )

public GlgSDataValue( String value )

Creates an S data value from a sting or another GlgSDataValue object. If created with null parameters, holds an empty string.

GlgMatrix class

abstract class GlgMatrix extends GlgObject

The GlgMatrix class implements a matrix object that is used for 3D transformations. The matrix holds the "value" of the transformation and is considered to be a data object. The matrix is never created directly by a user application. To create a matrix, a GlgXform transformation object of a required type is created with the required transformation parameters, and then either the xform object or its matrix is used.

Graph Layout Classes

Overview

The GLG Graph Layout package implements the spring embedder graph layout algorithm used for automatic layout of graphs containing nodes connected with edges. The spring embedder algorithm performs a series of iterations optimizing the graph layout and minimizing the number of node intersections. The GLG Graph Layout Demo shows an example of an application that creates and automatically lays out a graph containing connected nodes of a network. The demo's source code may be used as an example of using the Graph Layout module.

As seen in the demo, GLG Graph Layout may be used together with the GLG graphical engine, using GLG to display the graph and its nodes. In this case, the GLG Graphics Builder may be used to define a palette of graphical objects containing icons for the graph's nodes.

The Graph Layout may also be used to lay out non-GLG objects, for example, AWT or Swing components representing an application's objects. In this case, the application uses the Graph Layout's relative node position output (in the range from 0 to 1) to position an application's objects on the page.

The Graph Layout Component is provided with the GLG Extended API for Java.

GlgGraphNode class

Fields:
public int type;

Node type (0-based index used to associate the node with the node icon from the palette).

public Object data;

Data object associated with the node.

public GlgPoint display_position;

Node's display position in GLG coordinates.

public GlgPoint position;

Node's position in normalized coordinates (in the range from 0 to 1).

public GlgObject graphics;

GlgObject actually used to display the node.

public GlgObject template;

Custom GlgObject used to display the node. If the template is null, an icon from the palette is used.

public GlgObject link_array;

A group (GlgObject) containing the list of links (of the GlgGraphEdge type) attached to this node.

public boolean anchor;

The node's anchor flag. Setting this flag to true anchors the node: the node does not move, the rest move around this node.

Methods:
public GlgGraphNode();

Default constructor.

GlgGraphEdge class

Fields:
public int type;

Edge type (0-based index used to associate the node with the edge icon from the palette). It is 0 in the current implementation.

public Object data;

Data object associated with the edge.

public GlgObject graphics;

GlgObject actually used to display the edge.

public GlgObject template;

Custom GlgObject used to display the edge. If the template null, an icon from the palette is used.

public GlgGraphNode start_node;

The node the start of the edge is connected to.

public GlgGraphNode end_node;

The node the end of the edge is connected to.

Methods:
public GlgGraphEdge();

Default constructor.

GlgGraphLayout class

Fields:
public static CIRCULAR_GRAPH;

Graph type constant for creating circular demo graphs.

public static RANDOM_GRAPH;

Graph type constant for creating random demo graphs.

public static STAR_GRAPH;

Graph type constant for creating demo graphs with a star shape.

public static GlgObject DefNodeIcon;

A group of node icons to use if no palette is defined.

public static GlgObject DefEdgeIcon;

An edge icon to use if no palette is defined.

public static GlgObject DefViewportIcon;

A default viewport to use to render the graph.

public GlgObject palette;

The graph's palette.

public GlgPoint dimensions;

The extent of the graph's drawing, [-800;800] by default.

public GlgObject node_array;

A group containing all graph nodes (GlgGraphNode).

public GlgObject edge_array;

A group containing all graph edges (GlgGraphEdge).

public double end_temperature;

The final "temperature" of the graph (in the range from 0 to 1) defining the end of the layout process, 0.2 by default. A higher value will result in the process finishing faster but with less precision. A lower value will cause the layout process to last longer, trying to produce a finer layout.

public boolean finished;

Is set to true when the graph layout finishes positioning the nodes.

public boolean iteration;

The current iteration number.

public int update_rate;

The graph's update rate: the graph is redrawn after each update_rate iterations.

Methods:
public GlgGraphLayout();

Constructor.

public void GlgGraphDestroy();

Destroys all internal structures used by the instance of the graph:

public void GlgGraphSetPalette( GlgObject palette_drawing )

Sets the graph's icon palette. The palette drawing must contain node icons named Node0, Node1, Node2, etc. Each node must contain a G-type resource named Position, which is used by the graph layout to position the node. The palette must also contain an edge icon (a polygon named Edge), which is used to define the edges' attributes.

Parameters:
palette_drawing

Specifies the palette to use for the graph.

public void SetDefaultPalette( GlgObject palette_drawing );

Sets the default palette to be used by all graphs:

Parameters:
palette_drawing

Specifies the palette to use as a default palette.

public void UnloadDefaultPalette();

Resets the default palette to null and destroys any stored objects.

public void CreateGraphics( GlgObject viewport );

Loads icons from the palette and creates a GLG drawing to render the graph.

Parameters:
viewport

An optional viewport. If it is not null, it is used as a container for the graph's drawing, rendering the graph in the existing object hierarchy. If it is null, the graph will create a new viewport to render the graph.

public void DestroyGraphics();

Destroys the graph's drawing and all graphical objects used to render nodes and edges.

public GlgObject GetViewport();

Returns the viewport of the graph's drawing.

public void SpringIterate();

Performs one iteration of the spring embedder layout, returns true if the layout process has finished.

public void Update();

Updates the display to show the results of the spring layout. There is no need to update the display after every iteration: it may be updated every N iterations, or just once when the layout is finished.

public void AddNode( GlgObject graphics, int node_type, Object data );

Creates a new node and adds it to the graph.

Parameters:
graphics

An optional custom node icon to override the icon from the palette.

node_type

The palette index, specifies what icon to use from the node palette if no custom icons are specified.

data

Custom data to attach to the node.

public void AddEdge( GlgGraphNode start_node, GlgGraphNode end_node, GlgObject graphics, int edge_type, Object data );

Creates a new edge and adds it to the graph.

Parameters:
graph

Specifies the graph.

graphics

An optional custom edge icon to override the icon from the palette.

edge_type

The palette index, specifies what icon to use from the edge palette if no custom graphics are specified (reserved for future use).

data

Custom data to attach to the edge.

public void DeleteNode();

Deletes node from the graph.

Parameters:
node

Node to delete.

public void DeleteEdge();

Deletes edge from the graph.

Parameters:
edge

Edge to delete.

public GlgPoint GetNodePosition( GlgGraphNode node );

Returns the node position in GLG coordinates (in the range from -1000 to 1000).

Parameters:
node

Node object

public void SetNodePosition() GlgGraphNode node, double x, double y, double z );

Sets the node position in GLG coordinates (in the range from -1000 to 1000).

Parameters:
node

Node object.

x, y, z

New coordinate values.

public GlgGraphNode FindNode( GlgObject node_graphics );

Finds the node object by its graphics and is used to handle mouse selection.

Parameters:
node_graphics

The graphical object used to render the node in the drawing.

public GlgGraphEdge FindEdge( GlgObject edge_graphics );

Finds the edge object by its graphics and is used to handle mouse selection.

Parameters:
edge_graphics

The graphical object used to render the edge in the drawing.

public boolean NodesConnected( GlgGraphNode node1, GlgGraphNode node2 );

Connectivity test, returns true if there is an edge connecting the two nodes.

Parameters:
node1, node2

Node objects.

public void IncreaseTemperature( boolean init );

Forces the graph to continue layout after it is finished by increasing the temperature of the graph by a small increment.

Parameters:
init

Specifies if large increment should be used to re-layout the graph if true.

public boolean GetUntangle();

Returns true if the untangling algorithm is enabled. The untangling algorithm helps the graph layout to avoid local minima in the form of intersecting edges. Using this algorithm roughly doubles the time it takes to finish the layout.

public void SetUntangle( boolean untangle );

Enables or disables the untangling algorithm.

Parameters:
untangle

Specifies whether untangling should be used.

public void Error( String string );

Prints an error message.

Parameters:
string

Error message to print.

public void Scramble();

Randomly scrambles the graph's nodes and is mostly used by demo programs.

public static GlgGraphLayout CreateRandom( int num_nodes, int num_node_types, int graph_type );

The demo constructor, creates and returns a graph layout, populating it with nodes and edges.

Parameters:
num_nodes

Number of graph nodes to create.

num_node_types

Number of node types to use for rendering.

type

Graph type constant: RANDOM_GRAPH, CIRCULAR_GRAPH or STAR_GRAPH.