cz.cuni.jagrlib
Class DefaultGraphicsViewer

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.DefaultGraphicsViewer
All Implemented Interfaces:
Breakable, GraphicsViewer, Property, Trigger, Template
Direct Known Subclasses:
AWTWindow, RasterImagePreview

public abstract class DefaultGraphicsViewer
extends Piece
implements GraphicsViewer

Default implementation of GraphicsViewer.

Since:
0.25
See Also:
DefaultGraphicsViewer.java

Nested Class Summary
protected static class DefaultGraphicsViewer.HudLine
          Line for HUD drawing.
protected static interface DefaultGraphicsViewer.HudPrimitive
          Protocol for HUD drawable primitives.
protected  class DefaultGraphicsViewer.LocalComponentListener
           
protected  class DefaultGraphicsViewer.LocalKeyListener
           
protected  class DefaultGraphicsViewer.LocalMouseListener
           
protected  class DefaultGraphicsViewer.LocalMouseMotionListener
           
protected  class DefaultGraphicsViewer.LocalMouseWheelListener
           
protected  class DefaultGraphicsViewer.LocalWindowListener
          Inner class responsible for window-close event handling (by user interaction).
 
Nested classes/interfaces inherited from interface cz.cuni.jagrlib.iface.GraphicsViewer
GraphicsViewer.PreviewThread
 
Field Summary
protected  boolean autoStart
          Force automatic start of preview window.
protected  javax.swing.JComponent canvas
          Custom component - drawing target.
protected static java.lang.String CATEGORY
          Object category.
protected  boolean continueRepaintLoop
          Breaks the repaint loop from outside the repaintLoop() call.
protected  javax.swing.JFrame frame
          Swing frame window to show graphic output in.
protected  java.lang.String frameTitle
          Frame title (in order that Frame.setTitle(java.lang.String) works every time).
protected  IntMap<DefaultGraphicsViewer.HudPrimitive> hudSet
          Set of HUD primitives.
protected  InputListener listener
          InputListener connected through "direct" plug.
protected  java.util.List<InputListener> listeners
          Set of actual input listeners.
protected  int nextFreeId
          Next free HUD id (or id from which a future search will start).
protected  java.util.List<Semaphore> semaphores
          Semaphores that will be signaled after the viewer window is closed.
protected  boolean userBreak
          Has the user-break occurred?
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, reg, 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
DefaultGraphicsViewer()
           
 
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.
protected abstract  javax.swing.JComponent getCanvas()
          Returns drawing component or null if failed.
 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].
 int init(int phase)
          Module initialization - called before any Runnable.run().
 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.
 boolean stopRepaintLoop()
          Stops the running repaint loop.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplate, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, get, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, 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, get, set
 
Methods inherited from interface cz.cuni.jagrlib.Breakable
setProgressListener, stop
 

Field Detail

autoStart

protected boolean autoStart
Force automatic start of preview window.


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.


frameTitle

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


frame

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


canvas

protected javax.swing.JComponent canvas
Custom component - drawing target.


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.


hudSet

protected IntMap<DefaultGraphicsViewer.HudPrimitive> hudSet
Set of HUD primitives.


nextFreeId

protected int nextFreeId
Next free HUD id (or id from which a future search will start).


CATEGORY

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

See Also:
Constant Field Values
Constructor Detail

DefaultGraphicsViewer

public DefaultGraphicsViewer()
Method Detail

doRepaint

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

See Also:
repaintLoop()

getCanvas

protected abstract javax.swing.JComponent getCanvas()
Returns drawing component or null if failed.


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()

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()

destroy

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

Specified by:
destroy in interface GraphicsViewer

repaintAll

public void repaintAll()
Causes the instant repainting of the whole graphic output (regardless of the actual invalid region). Trigger.fire(int) 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()
Removes all HUD primitives.

Specified by:
hudClear in interface GraphicsViewer

hudGetFreeId

public int hudGetFreeId()
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)
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)
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.

init

public int init(int phase)
Module initialization - called before any Runnable.run(). Individual phases (starting at 0) will be called until maximum requested phase number is reached.

Overrides:
init in class Piece
Parameters:
phase - Current phase number.
Returns:
Number of phases needed to initialize this module.