GLG Toolkit, Java Class Library  Version 4.5

An Input listener is used to handle user interaction with input objects, as well as to perform object selection and action processing. More...

Detailed Description

An Input listener is used to handle user interaction with input objects, as well as to perform object selection and action processing.

The listener is installed via AddListener with the listener type=INPUT_CB.

See InputCallback for more information.

Inherited by GlgJBean.

Public Member Functions

void InputCallback (GlgObject glg_object, GlgObject message)
 Input handler method. More...
 

Member Function Documentation

◆ InputCallback()

void InputCallback ( GlgObject  glg_object,
GlgObject  message 
)

Input handler method.

This method is invoked on any user interaction with GLG drawing and its input objects.

Parameters
glg_objectThe viewport the listener is attached to.
messageThe message object containing information about the event or action that triggered the callback.

See the Appendix B: Message Object Resources section of the Appendices chapter of the GLG Programming Reference Manual for a description of data contained in the message object.

The example below demonstrates a very simple input listener which terminates the application when a Quit button is pressed. The example demonstrates how to handle the default input object events and process attached command actions.

public void InputCallback( GlgObject viewport, GlgObject message_obj )
{
String format = message_obj.GetSResource( "Format" ); // Query message type.
// Handle default input object events.
if( format.equals( "Button" ) ) // A message from a push button.
{
// Query the name of the input object.
String origin = message_obj.GetSResource( "Origin" );
// Query the action that triggered the callback.
String action = message_obj.GetSResource( "Action" );
// Check is the button was pressed (<i>Activate</i> action) and the button name was "Quit".
if( action.equals( "Activate" ) && origin.equals( "Quit" ) )
System.exit( 0 );
}
// Handle command actions attached to a button or an object.
else if( format.equals( "Command" ) ) // <i>Command</i> action was triggered.
{
// Query the command to be executed for <i>Command</i> action types.
String command_type = message_object.GetSResource( "ActionObject/Command/CommandType" );
// Act based on the command type.
if( command_type.equals( "Quit" ) )
System.exit( 0 );
}
}
void InputCallback(GlgObject glg_object, GlgObject message)
Input handler method.

The DEMOS_JAVA/GlgRealTimeChart.java file in the GLG installation directory provides an elaborate example of using the Input listener. Other GLG Demos and Examples also provide coding examples of using the listener.

Implemented in GlgJBean.