cz.cuni.jagrlib.piece
Class GLWindow

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.GLWindow
All Implemented Interfaces:
Breakable, GraphicsViewer, Property, Trigger, Template

public class GLWindow
extends Piece
implements GraphicsViewer

Window able to display GL graphics.

See Also:
GLWindow.java

Nested Class Summary
 
Nested classes/interfaces inherited from interface cz.cuni.jagrlib.iface.GraphicsViewer
GraphicsViewer.PreviewThread
 
Field Summary
protected  javax.media.opengl.GLCanvas canvas
          GL canvas component - drawing target.
static java.lang.String CANVAS_HEIGHT
           
protected static int CANVAS_HEIGHT_MAX
          Maximal canvas height.
protected static int CANVAS_HEIGHT_MIN
          Minimal canvas height.
static java.lang.String CANVAS_WIDTH
           
protected static int CANVAS_WIDTH_MAX
          Maximal canvas width.
protected static int CANVAS_WIDTH_MIN
          Minimal canvas width.
protected static java.lang.String CATEGORY
          Object category.
protected  boolean continueRepaintLoop
          Breaks the repaint loop from outside the repaintLoop() call.
protected static java.lang.String DEFAULT_FRAME_TITLE
          Default window title.
protected static boolean DEFAULT_FULLSCREEN_VALUE
          Default fullscreen value.
protected static int DEFAULT_HEIGHT
          Default canvas height in pixels.
protected static int DEFAULT_WIDTH
          Default canvas width in pixels.
protected static long FPS_PERIOD
          Minimal interval between two FPS-display times.
protected static int FPS_QUEUE_SIZE
          FPS-queue size (maximal number of previous frames used in FPS computation).
protected  long fpsLast
          The last FPS-display time.
protected  int fpsPtr
          Index of actual frame in fpsQueue.
protected  long[] fpsQueue
          The FPS-queue data, actual frame is defined by fpsPtr.
protected  javax.swing.JFrame frame
          Swing frame window to show graphic output in.
protected  java.lang.String frameTitle
          Frame title (in order that setTitle() works every time).
protected  boolean fullscreen
          Current state of fulscreen mode.
static java.lang.String FULLSCREEN
           
protected  GLGraphics gr
          Actual GL graphics module (rendering source).
protected  int height
          Current height of rendering canvas (in pixels).
protected  InputListener listener
          InputListener connected through "direct" plug.
protected  java.util.List<InputListener> listeners
          Set of actual input listeners.
protected  boolean makeSnapshot
          Interthread variable for creating snapshot.
static RegPiece reg
          Static registration instance for this class.
protected  java.util.List<Semaphore> semaphores
          Semaphores that will be signaled after the viewer window is closed.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  boolean userBreak
          Has the user-break occurred?
protected  int width
          Current width of rendering canvas (in pixels).
protected  int x1
          Minimal X coordinate of actual invalid region.
protected  int x2
          Maximal X coordinate (outer bound) of actual invalid region.
protected  int y1
          Minimal Y coordinate of actual invalid region.
protected  int y2
          Maximal Y coordinate (outer bound) of actual invalid region.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE
 
Fields inherited from interface cz.cuni.jagrlib.iface.GraphicsViewer
BLACK_BACKGROUND, WINDOW_TITLE
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
GLWindow()
           
 
Method Summary
 void addInputListener(InputListener list)
          Adds input listener object.
 void addSemaphore(Semaphore s)
          Adds a new semaphore - object which wants to be signaled after the viewer window is closed (by user interaction etc.).
 void destroy()
          Destroys the preview window.
protected  void doRepaint()
          Does the repaint job itself (according the invalid region).
 boolean fire(int type)
          Triggers the (undetermined) action.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 void hudClear()
          Removes all HUD primitives.
 int hudGetFreeId()
          Returns id of any free HUD slot.
 void hudRemove(int id)
          Removes existing HUD primitive.
 void hudSetLine(int id, int x1, int y1, int x2, int y2)
          Replaces the given HUD primitive slot with line from [x1,y1] to [x2,y2].
 void invalidate(int xMin, int xMax, int yMin, int yMax)
          Invalidates the given rectangular region of the graphics output.
 void removeInputListener(InputListener list)
          Removes (previously added) input listener object.
 void removeSemaphore(Semaphore s)
          Removes one of associated semaphores.
 void repaint()
          Causes the instant repainting of actual invalid region of the graphic output.
 void repaintAll()
          Causes the instant repainting of the whole graphic output (regardless of the actual invalid region).
 boolean repaintLoop()
          Start (potentially) infinite repaint loop.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 void setSize()
          Sets size of frame due to fullscreen variable and width and height variables
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 boolean stopRepaintLoop()
          Stops the running repaint loop.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 
Methods inherited from interface cz.cuni.jagrlib.Breakable
setProgressListener, stop
 

Field Detail

DEFAULT_WIDTH

protected static final int DEFAULT_WIDTH
Default canvas width in pixels.

See Also:
Constant Field Values

DEFAULT_HEIGHT

protected static final int DEFAULT_HEIGHT
Default canvas height in pixels.

See Also:
Constant Field Values

width

protected int width
Current width of rendering canvas (in pixels).


height

protected int height
Current height of rendering canvas (in pixels).


fullscreen

protected boolean fullscreen
Current state of fulscreen mode.


x1

protected int x1
Minimal X coordinate of actual invalid region.


x2

protected int x2
Maximal X coordinate (outer bound) of actual invalid region.


y1

protected int y1
Minimal Y coordinate of actual invalid region.


y2

protected int y2
Maximal Y coordinate (outer bound) of actual invalid region.


CANVAS_WIDTH_MIN

protected static final int CANVAS_WIDTH_MIN
Minimal canvas width.

See Also:
Constant Field Values

CANVAS_WIDTH_MAX

protected static final int CANVAS_WIDTH_MAX
Maximal canvas width.

See Also:
Constant Field Values

CANVAS_HEIGHT_MIN

protected static final int CANVAS_HEIGHT_MIN
Minimal canvas height.

See Also:
Constant Field Values

CANVAS_HEIGHT_MAX

protected static final int CANVAS_HEIGHT_MAX
Maximal canvas height.

See Also:
Constant Field Values

DEFAULT_FULLSCREEN_VALUE

protected static final boolean DEFAULT_FULLSCREEN_VALUE
Default fullscreen value.

See Also:
Constant Field Values

DEFAULT_FRAME_TITLE

protected static final java.lang.String DEFAULT_FRAME_TITLE
Default window title.

See Also:
Constant Field Values

frameTitle

protected java.lang.String frameTitle
Frame title (in order that setTitle() works every time).


frame

protected javax.swing.JFrame frame
Swing frame window to show graphic output in.


canvas

protected javax.media.opengl.GLCanvas canvas
GL canvas component - drawing target.


gr

protected GLGraphics gr
Actual GL graphics module (rendering source).


makeSnapshot

protected boolean makeSnapshot
Interthread variable for creating snapshot. Snapshot can be done only in drawing thread. This variable tells drawing thread to make snapshot.

See Also:
GLEventListener.display(javax.media.opengl.GLAutoDrawable)

continueRepaintLoop

protected boolean continueRepaintLoop
Breaks the repaint loop from outside the repaintLoop() call.

See Also:
repaintLoop(), stopRepaintLoop()

userBreak

protected boolean userBreak
Has the user-break occurred?


semaphores

protected java.util.List<Semaphore> semaphores
Semaphores that will be signaled after the viewer window is closed.

See Also:
Semaphore, addSemaphore(cz.cuni.jagrlib.Semaphore), removeSemaphore(cz.cuni.jagrlib.Semaphore)

listeners

protected java.util.List<InputListener> listeners
Set of actual input listeners.

See Also:
addInputListener(cz.cuni.jagrlib.iface.InputListener), removeInputListener(cz.cuni.jagrlib.iface.InputListener)

listener

protected InputListener listener
InputListener connected through "direct" plug.


FPS_PERIOD

protected static final long FPS_PERIOD
Minimal interval between two FPS-display times.

See Also:
Constant Field Values

FPS_QUEUE_SIZE

protected static final int FPS_QUEUE_SIZE
FPS-queue size (maximal number of previous frames used in FPS computation).

See Also:
Constant Field Values

fpsQueue

protected final long[] fpsQueue
The FPS-queue data, actual frame is defined by fpsPtr.


fpsPtr

protected int fpsPtr
Index of actual frame in fpsQueue.


fpsLast

protected long fpsLast
The last FPS-display time.


FULLSCREEN

public static final java.lang.String FULLSCREEN
See Also:
Constant Field Values

CANVAS_WIDTH

public static final java.lang.String CANVAS_WIDTH
See Also:
Constant Field Values

CANVAS_HEIGHT

public static final java.lang.String CANVAS_HEIGHT
See Also:
Constant Field Values

TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

GLWindow

public GLWindow()
Method Detail

doRepaint

protected void doRepaint()
Does the repaint job itself (according the invalid region).

See Also:
repaintLoop()

repaintLoop

public boolean repaintLoop()
Start (potentially) infinite repaint loop. It can be terminated either by a stopRepaintLoop() call or by external user interaction (user break, window close, ..).

Specified by:
repaintLoop in interface GraphicsViewer
Returns:
true if the loop was terminated by a stopRepaintLoop() call.
See Also:
stopRepaintLoop()

destroy

public void destroy()
Destroys the preview window. Stops repaint-loop eventually.

Specified by:
destroy in interface GraphicsViewer

stopRepaintLoop

public boolean stopRepaintLoop()
Stops the running repaint loop.

Specified by:
stopRepaintLoop in interface GraphicsViewer
Returns:
true if the loop was successfully stopped.
See Also:
repaintLoop()

repaintAll

public void repaintAll()
Causes the instant repainting of the whole graphic output (regardless of the actual invalid region). Trigger.fire() call has the same effect..

Specified by:
repaintAll in interface GraphicsViewer
See Also:
invalidate(int, int, int, int), repaint(), Trigger.fire(int)

invalidate

public void invalidate(int xMin,
                       int xMax,
                       int yMin,
                       int yMax)
Invalidates the given rectangular region of the graphics output. Invalid regions will be repainted during the next repaint() call...

Specified by:
invalidate in interface GraphicsViewer
Parameters:
xMin - X coordinate of the upper left corner.
xMax - X coordinate of the lower right corner (outside pixel).
yMin - Y coordinate of the upper left corner.
yMax - Y coordinate of the upper left corner (outside pixel).
See Also:
repaint()

repaint

public void repaint()
Causes the instant repainting of actual invalid region of the graphic output.

Specified by:
repaint in interface GraphicsViewer
See Also:
repaintAll(), invalidate(int, int, int, int)

addSemaphore

public void addSemaphore(Semaphore s)
Adds a new semaphore - object which wants to be signaled after the viewer window is closed (by user interaction etc.).

Specified by:
addSemaphore in interface GraphicsViewer
Parameters:
s - A new semaphore instance.
See Also:
removeSemaphore(cz.cuni.jagrlib.Semaphore)

removeSemaphore

public void removeSemaphore(Semaphore s)
Removes one of associated semaphores.

Specified by:
removeSemaphore in interface GraphicsViewer
Parameters:
s - Semaphore to be removed.
See Also:
addSemaphore(cz.cuni.jagrlib.Semaphore)

addInputListener

public void addInputListener(InputListener list)
Adds input listener object.

Specified by:
addInputListener in interface GraphicsViewer

removeInputListener

public void removeInputListener(InputListener list)
Removes (previously added) input listener object.

Specified by:
removeInputListener in interface GraphicsViewer

hudClear

public void hudClear()
Description copied from interface: GraphicsViewer
Removes all HUD primitives.

Specified by:
hudClear in interface GraphicsViewer

hudGetFreeId

public int hudGetFreeId()
Description copied from interface: GraphicsViewer
Returns id of any free HUD slot.

Specified by:
hudGetFreeId in interface GraphicsViewer

hudSetLine

public void hudSetLine(int id,
                       int x1,
                       int y1,
                       int x2,
                       int y2)
Description copied from interface: GraphicsViewer
Replaces the given HUD primitive slot with line from [x1,y1] to [x2,y2].

Specified by:
hudSetLine in interface GraphicsViewer

hudRemove

public void hudRemove(int id)
Description copied from interface: GraphicsViewer
Removes existing HUD primitive.

Specified by:
hudRemove in interface GraphicsViewer

fire

public boolean fire(int type)
Triggers the (undetermined) action.

Specified by:
fire in interface Trigger
Parameters:
type - The action type (whatever it means..).
Returns:
true if the action was successful.

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

setSize

public void setSize()
Sets size of frame due to fullscreen variable and width and height variables


get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.