Previous ION Java User's Guide: Building ION Applets and Applications Next

Object Graphics in ION

To render IDL Object Graphics in ION Java, you use the following general technique:

  1. Create the IDL objects
  2.  

  3. Create an off-screen buffer (an IDLgrBuffer object)
  4.  

  5. Draw the object to the buffer, then read the contents of the buffer as an image
  6.  

  7. TV the image to the ION device

The following example demonstrates this technique.

First, create your IDL graphic objects, contained in the proper object hierarchy (model and view):

oView=obj_new('IDLgrView', COLOR=[255,255,255]) 
oModel=obj_new('IDLgrModel')   
oText=obj_new('IDLgrText', 'Hello World', COLOR = [255,0,0]) 
oModel->Add, oText   
oView->Add, oModel  

Then, create an off-screen buffer object to which to draw in IDL. Match the dimensions of the ION drawable. For example, suppose your .java file contains the following method:

public void buildGUI()  
    {  
		c_ionDrw = new IONGrDrawable(400,400);  
  
		setLayout(new FlowLayout());  
		add(c_ionDrw);  
    }  

In the above code, the IONGrDrawable is defined with dimensions of (400, 400). Therefore, you would create the IDLgrBuffer object in IDL as follows:

oBuffer=obj_new('IDLgrBuffer',DIMENSIONS=[400,400])  

Next, draw the object to your buffer object:

oBuffer->Draw, oView   

Then get the image object from the buffer:

oImage=oBuffer->Read()   

Now extract the data:

oImage->Getproperty, DATA=image  

Make sure to destroy the image object since it is no longer needed:

OBJ_DESTROY, oImage  

Next, convert the TrueColor image to 8-bit to reduce the bandwidth required to send it to the client:

result=COLOR_QUAN(image,1,r,g,b)   

Load the color table:

TVLCT,r,g,b  

Lastly, TV the image:

TV, result  

The image is then displayed in the current ION Java drawable.


Example Code
For a similar but slightly more complex version of this example, click the Object Graphics link on the page advanced.html. The Java source code resides in objgraphics.java in the IDL63\products\ION63\ion_java\
examples\src
directory. The IDL create_surface.pro in the examples directory contains a draw_buffer procedure that illustrates the coding routine shown above.

Using Object References

When we initially create an object, we get back a reference to that object. Since the IDL session is persistent in ION Java, we can use object references later in event callbacks for the applet. It is not necessary to create Java variables for persistence because the object continues to exist in the persistent IDL session. For instance, you could add a button to our Hello World applet to rotate the text. In the event callback for the button, you would call the rotate method on the model object whose reference you obtained initially. Then you would use the buffer technique to redraw the view.

  IDL Online Help (March 06, 2007)