com.hermetica.magician
Class GLComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--com.hermetica.magician.GLComponent

public abstract class GLComponent
extends java.awt.Canvas
implements java.lang.Runnable, GLDrawable, java.awt.image.ImageProducer

A GLComponent object is a generic AWT Component that allows OpenGL commands to be rendered directly onto it. The benefit here is that standard Java AWT methods such as repaint() and resize() may be invoked against this Component and it will affect an associated OpenGL pipeline accordingly.

The main feature of the GLComponent class is that GLComponent objects can be parented into AWT Container objects and treated identically to the more standard AWT objects such as a Button or a Label. The GLComponent object is also subject to the same event handling mechanisms as other AWT classes.

GLComponents are never directly instantiated within Magician applications but are created by using the GLComponentFactory class which provides an abstracted way to create GLComponents straddling differences in Java implementations. This ensures that Magician applications remain portable across as many systems as possible.

Version:
$Id: GLComponent.java,v 1.2 1999/06/03 23:11:48 descarte Exp $
Author:
Alligator Descartes <descarte@arcana.co.uk>, Jason Osgood
See Also:
Serialized Form

Field Summary
protected static int DISPLAY_EVENT
           
protected static int INITIALIZE_EVENT
          Event types this component can deal with
protected static int RESHAPE_EVENT
           
static java.lang.String VERSION
          Version information
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
GLComponent()
           
 
Method Summary
 void addConsumer(java.awt.image.ImageConsumer ic)
          Registers an ImageConsumer with this GLComponent as the target to which image data will be sent
 void addGLEventListener(GLEventListener listener)
          This method registers a component listener with this component.
 void addNotify()
          Handles peer-notification
protected  void createChoke()
          Creates a new mutex for this component.
 void destroy()
          Destroys the component completely.
protected  void generateID()
          Generates a new unique id for the component.
protected  CriticalSection getChoke()
          Returns the mutex associated with this component
 GLContext getContext()
          Returns the rendering context associated with this component
 int getDesktopHeight()
          Native method that returns the desktop height
 int getDesktopWidth()
          Native method that returns the desktop width
 boolean getFlushOnRepaint()
          Returns the current status of whether or not flushing the buffers after each listener display() method has been called will occur.
 int getGLContext()
          Method used to fetch the OpenGL rendering context from this component's associated GLContext.
protected  int getID()
          Returns the internal ID of a particular component
 GLEventListener getListener()
          Returns the listener chain
 java.awt.Dimension getMinimumSize()
          Gets the preferred size of the component
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of the component
 int getReadBuffer()
          Returns the buffer from which pixel data reading will take place for image production.
protected  GLDrawable getSharedComponent()
          Returns the shared component.
 boolean getTraceStatus()
          Returns the warning level that a component is running at.
 int getWidget()
          Method used to fetch the Widget / device context for this GLComponent.
 int getWindow()
          Method used to fetch the window information of this component.
protected abstract  void init(GLDrawable component, GLContext context, int width, int height)
          Overridden method to allow deferred initialization
 boolean initialize()
          Initializes the component.
 boolean isConsumer(java.awt.image.ImageConsumer ic)
          Determines if a given ImageConsumer object is currently registered with this ImageProducer as one of its consumers.
 boolean isInitialized()
          Tests to see whether the component is initialized
 boolean isOffscreen()
          Specifies this component is onscreen
 boolean isRunning()
          Returns whether or not the internal thread is running
 boolean isSuspended()
          Returns whether or not the GLComponent is suspended
 boolean needsHeavyPeer()
          Microsoft-VM-specific thing required to specify that a native window is required to render onto...
 void paint(java.awt.Graphics g)
          Invokes the ``display()'' method within a class implementing GLEventListener.
 void postRedisplay()
          Signals that a repaint event should take place as soon as possible.
 void processDisplayEvent(GLEventListener listener)
          Processes a display event
 void processInitializeEvent(GLEventListener listener)
          Processes an initialize event
 void processReshapeEvent(GLEventListener listener)
          Processes a reshape event
 void removeConsumer(java.awt.image.ImageConsumer ic)
          Removes the given consumer from the list of consumers currently registered to receive image data from this ImageProducer
 void removeGLEventListener(GLEventListener listener)
          This method removes a GLEventListener from the listener chain
 void repaint()
          Handles repainting the screen by directly using GL buffer control instead of the standard AWT refresh handling which causes flickering
 void requestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)
          This method, used by an ImageConsumer, requests that the data be resent as soon as possible in TOPDOWNLEFTRIGHT order so that high quality image conversion might occur
 void reshape(int width, int height)
          This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
 void reshape(int x, int y, int width, int height)
          This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
 void resize(java.awt.Dimension dim)
          This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
 void resize(int width, int height)
          This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
 void restart()
          Reinitializes the component completely.
 void resume()
          Resumes the component allowing it to process reshape, repaint and initialize events.
 void run()
          The main driving thread of the GLComponent
 void setContext(GLContext context)
          Sets the OpenGL context associated with this component.
 void setFlushOnRepaint(boolean mode)
          Specifies whether or not the component should flush its buffers after all the pending repainting calls have been made in each listener.
protected  void setInitialized(boolean initializedStatus)
          Sets the value of whether or not a component is initialized.
protected  void setListener(GLEventListener listener)
          Sets the listener.
 void setReadBuffer(int buffer)
          Sets the buffer from which pixel data should be read for image production
protected  void setRunning(boolean runningStatus)
          Sets the running status of this component.
protected  void setSharedComponent(GLDrawable component)
          Sets the shared Component, if necessary.
 void setSleepDuration(int ms)
          Sets the sleep duration of the thread between iterations
protected  void setSuspended(boolean suspendedStatus)
          Sets the status of whether or not the component is suspended.
 void setTraceStatus(boolean mode)
          Sets the verbosity of Exception warning.
 void start()
          Starts up the GLComponent handling.
 void startProduction(java.awt.image.ImageConsumer ic)
          This method registers the given ImageConsumer as a consumer of pixel data produced by this ImageProducer and starts delivering data in pixel blocks to the registered ImageConsumers
 void stop()
          Shuts down the internal thread safely.
 void suspend()
          Stops the component from processing reshape, repaint and initialize events.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Version information

INITIALIZE_EVENT

protected static final int INITIALIZE_EVENT
Event types this component can deal with

RESHAPE_EVENT

protected static final int RESHAPE_EVENT

DISPLAY_EVENT

protected static final int DISPLAY_EVENT
Constructor Detail

GLComponent

public GLComponent()
Method Detail

getDesktopWidth

public int getDesktopWidth()
Native method that returns the desktop width

getDesktopHeight

public int getDesktopHeight()
Native method that returns the desktop height

init

protected abstract void init(GLDrawable component,
                             GLContext context,
                             int width,
                             int height)
Overridden method to allow deferred initialization

setTraceStatus

public final void setTraceStatus(boolean mode)
Sets the verbosity of Exception warning. The default is false, ie, if there are any internal exceptions caught by the component, it won't tell you about them. Set this to true if you want the message of each caught Exception printed to System.err and the internal locks traced.

Parameters:
mode - The new mode for verbose warnings or not

getTraceStatus

public final boolean getTraceStatus()
Returns the warning level that a component is running at. The return value is either true signifying that debugging is on, or false signifying that it's not

setContext

public final void setContext(GLContext context)
Sets the OpenGL context associated with this component.

Parameters:
context - The context to associate with the component

getContext

public final GLContext getContext()
Returns the rendering context associated with this component
Specified by:
getContext in interface GLDrawable

createChoke

protected void createChoke()
Creates a new mutex for this component. Internal use only.

getChoke

protected CriticalSection getChoke()
Returns the mutex associated with this component

generateID

protected void generateID()
Generates a new unique id for the component. Used internally only.

getID

protected int getID()
Returns the internal ID of a particular component

initialize

public final boolean initialize()
Initializes the component. This MUST be called before anything will happen with the component.
Specified by:
initialize in interface GLDrawable

isInitialized

public final boolean isInitialized()
Tests to see whether the component is initialized
Specified by:
isInitialized in interface GLDrawable

setInitialized

protected final void setInitialized(boolean initializedStatus)
Sets the value of whether or not a component is initialized. This is used internally only...

restart

public final void restart()
Reinitializes the component completely. This leaves the component in the same state as if the constructor had just been called.
Specified by:
restart in interface GLDrawable

isRunning

public final boolean isRunning()
Returns whether or not the internal thread is running
Specified by:
isRunning in interface GLDrawable

setRunning

protected final void setRunning(boolean runningStatus)
Sets the running status of this component. Used internally only.

start

public final void start()
Starts up the GLComponent handling. Without calling start(), no reshape, repaint or initialize events will be processed.
Specified by:
start in interface GLDrawable

suspend

public final void suspend()
Stops the component from processing reshape, repaint and initialize events. This is useful in cases where you might have minimised the component and do not wish it to continue processing.
Specified by:
suspend in interface GLDrawable

isSuspended

public final boolean isSuspended()
Returns whether or not the GLComponent is suspended
Specified by:
isSuspended in interface GLDrawable

setSuspended

protected final void setSuspended(boolean suspendedStatus)
Sets the status of whether or not the component is suspended. This is to be used internally only....

resume

public final void resume()
Resumes the component allowing it to process reshape, repaint and initialize events.
Specified by:
resume in interface GLDrawable

destroy

public final void destroy()
Destroys the component completely. This has the effect of freeing up all internal resources of this component.
Specified by:
destroy in interface GLDrawable

stop

public final void stop()
Shuts down the internal thread safely. This is used when both stopping the component ( if you wished to change its mode of operation from dynamic to static ) and when destroying the component completely
Specified by:
stop in interface GLDrawable

getListener

public final GLEventListener getListener()
Returns the listener chain
Specified by:
getListener in interface GLDrawable

setListener

protected final void setListener(GLEventListener listener)
Sets the listener. This is to be used internally only....

setSharedComponent

protected void setSharedComponent(GLDrawable component)
Sets the shared Component, if necessary. This is used internally only...

getSharedComponent

protected GLDrawable getSharedComponent()
Returns the shared component. This is used internally only.

setFlushOnRepaint

public void setFlushOnRepaint(boolean mode)
Specifies whether or not the component should flush its buffers after all the pending repainting calls have been made in each listener. By default, flushing will occur.

Parameters:
mode - Specifies whether flushing should or should not occur

getFlushOnRepaint

public boolean getFlushOnRepaint()
Returns the current status of whether or not flushing the buffers after each listener display() method has been called will occur. By default, flushing will occur.

setSleepDuration

public void setSleepDuration(int ms)
Sets the sleep duration of the thread between iterations

run

public void run()
The main driving thread of the GLComponent
Specified by:
run in interface java.lang.Runnable

processInitializeEvent

public void processInitializeEvent(GLEventListener listener)
Processes an initialize event
Specified by:
processInitializeEvent in interface GLDrawable

processReshapeEvent

public void processReshapeEvent(GLEventListener listener)
Processes a reshape event
Specified by:
processReshapeEvent in interface GLDrawable

processDisplayEvent

public void processDisplayEvent(GLEventListener listener)
Processes a display event
Specified by:
processDisplayEvent in interface GLDrawable

addGLEventListener

public void addGLEventListener(GLEventListener listener)
This method registers a component listener with this component. The GLEventListener is used to route any resizing and refreshing events through to the main program which handles them accordingly
Specified by:
addGLEventListener in interface GLDrawable

removeGLEventListener

public void removeGLEventListener(GLEventListener listener)
This method removes a GLEventListener from the listener chain
Specified by:
removeGLEventListener in interface GLDrawable

postRedisplay

public void postRedisplay()
Signals that a repaint event should take place as soon as possible. This is basically a GLUT-like cosmetic function.

repaint

public void repaint()
Handles repainting the screen by directly using GL buffer control instead of the standard AWT refresh handling which causes flickering
Overrides:
repaint in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Invokes the ``display()'' method within a class implementing GLEventListener. This class acquires a context lock and handles appropriate buffer swapping for you, ie, glFlush() is called for single-buffered contexts and swapBuffers() is called for double-buffered contexts.

This method should never be invoked directly. If you wish to refresh the display, call ``repaint()'' instead.

Overrides:
paint in class java.awt.Canvas

resize

public void resize(int width,
                   int height)
This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
Overrides:
resize in class java.awt.Component

resize

public void resize(java.awt.Dimension dim)
This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes.
Overrides:
resize in class java.awt.Component

reshape

public void reshape(int width,
                    int height)
This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes. Before it does so, it will acquire a context lock for you and release it after the ``reshape()'' method has been invoked.

reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
This method traps window resizing events from AWT and invokes the ``reshape()'' method implemented in GLEventListener-based classes. Before it does so, it will acquire a context lock for you and release it after the ``reshape()'' method has been invoked.
Overrides:
reshape in class java.awt.Component

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of the component
Overrides:
getPreferredSize in class java.awt.Component

getMinimumSize

public java.awt.Dimension getMinimumSize()
Gets the preferred size of the component
Overrides:
getMinimumSize in class java.awt.Component

addNotify

public void addNotify()
Handles peer-notification
Overrides:
addNotify in class java.awt.Canvas

needsHeavyPeer

public boolean needsHeavyPeer()
Microsoft-VM-specific thing required to specify that a native window is required to render onto...

setReadBuffer

public void setReadBuffer(int buffer)
Sets the buffer from which pixel data should be read for image production
Parameters:
buffer - The OpenGL buffer to read from

getReadBuffer

public int getReadBuffer()
Returns the buffer from which pixel data reading will take place for image production.

getWindow

public int getWindow()
Method used to fetch the window information of this component. This method should not be called directly from Java and should only be used within the context of the Extension Developer's Kit. This method is subject to change name or functionality between releases.

getGLContext

public int getGLContext()
Method used to fetch the OpenGL rendering context from this component's associated GLContext. This method should not be called directly from Java and should only be used within the context of the Extension Developer's Kit. This method is subject to change name or functionality between releases.

getWidget

public int getWidget()
Method used to fetch the Widget / device context for this GLComponent. This method should not be called directly from Java and should only be used within the context of the Extension Developer's Kit. This method is subject to change name or functionality between releases.

addConsumer

public void addConsumer(java.awt.image.ImageConsumer ic)
Registers an ImageConsumer with this GLComponent as the target to which image data will be sent
Specified by:
addConsumer in interface java.awt.image.ImageProducer

isConsumer

public boolean isConsumer(java.awt.image.ImageConsumer ic)
Determines if a given ImageConsumer object is currently registered with this ImageProducer as one of its consumers.
Specified by:
isConsumer in interface java.awt.image.ImageProducer

removeConsumer

public void removeConsumer(java.awt.image.ImageConsumer ic)
Removes the given consumer from the list of consumers currently registered to receive image data from this ImageProducer
Specified by:
removeConsumer in interface java.awt.image.ImageProducer

requestTopDownLeftRightResend

public void requestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)
This method, used by an ImageConsumer, requests that the data be resent as soon as possible in TOPDOWNLEFTRIGHT order so that high quality image conversion might occur
Specified by:
requestTopDownLeftRightResend in interface java.awt.image.ImageProducer

startProduction

public void startProduction(java.awt.image.ImageConsumer ic)
This method registers the given ImageConsumer as a consumer of pixel data produced by this ImageProducer and starts delivering data in pixel blocks to the registered ImageConsumers
Specified by:
startProduction in interface java.awt.image.ImageProducer

isOffscreen

public boolean isOffscreen()
Specifies this component is onscreen
Specified by:
isOffscreen in interface GLDrawable