com.wirefusion.player
Class Wob

java.lang.Object
  extended by com.wirefusion.player.Wob
Direct Known Subclasses:
BoolWob, ColorWob, JavaWob, Number2DWob, NumberWob, SceneWobBase, TextWob

public abstract class Wob
extends java.lang.Object

A Wob is the object representing a WireFusion object. Both graphical and non graphical objects should be subclasses of this object. Several methods in this object are meant to be used by graphical subclasses only.


Constructor Summary
Wob()
          It is recommended that you initialize the object in the init method instead of the constructor, if you access the engine in your initialization code.
 
Method Summary
 void addChild(Wob child)
          Adds a child to this object.
 void addFocusListener(java.awt.event.FocusListener l)
          Adds the specified focus listener to receive focus events from this component when this component gains input focus.
 void addInteractiveSceneChild(SceneWob scene)
          Adds a SceneWob object as a child to this object.
 void addKeyListener(java.awt.event.KeyListener l)
          Adds the specified key listener to receive key events from this component.
 void addMouseListener(java.awt.event.MouseListener l)
          Adds the specified mouse listener to receive mouse events from this component.
 void addMouseMotionListener(java.awt.event.MouseMotionListener l)
          Adds the specified mouse motion listener to receive mouse motion events from this component.
 void addMouseWheelListener(java.awt.event.MouseWheelListener l)
          Adds the specified mouse wheel listener to receive mouse wheel events from this component.
 boolean contains(int x, int y)
          Checks whether this component "contains" the specified point, where x and y are defined to be relative to the coordinate system of this component.
 void destroy()
          Called to inform this object that it is being reclaimed and that it should destroy any resources that it has allocated.
 void disableEvents(long eventsToDisable)
          Disables the events defined by the specified event mask parameter from being delivered to this component.
 void enableEvents(long eventsToEnable)
           Enables the events defined by the specified event mask parameter to be delivered to their corresponding processEvent method in this this object.
 void filterPixels(WfImage sceneImage, WfImage processedImage, java.awt.Rectangle targetArea, java.awt.Rectangle areaToProcess)
          Processes the pixels in the sceneImage parameter and writes the result to processedImage.
 java.awt.Component getAwtComponent()
          Each Wob with a target area has an associated AWT Component, from which it receives AWT events for example.
 java.awt.Rectangle getBounds()
          Gets the bounds of this Wob in the form of a Rectangle object.
 Wob getChild(java.lang.String childName)
          Returns a child of this Wob.
 java.util.Enumeration getChildren()
          Returns the children of this Wob, or null if it has no children.
 Core getCore()
          Returns the core player object
 java.awt.Cursor getCursor()
          Gets the cursor set in the component.
 Port getInPort(int portNo)
          Returns the in-port with the specified port number.
 int getMemoryUsage()
          Returns the approximate memory used by this object (in bytes).
 java.lang.String getName()
          Gets the name of the Wob.
 Port getOutPort(int portNo)
          Returns the out-port with the specified port number.
 Wob getParent()
          Gets the parent of this object.
 Resource getResource(java.lang.String filename)
          Tries to located a resource whos filename equals the argument.
 Resource getResourceById(java.lang.String resourceId)
          Tries to located a resource whos "resource ID" equals resourceId.
 java.awt.Dimension getSize()
          Gets the size of this Wob in the form of a Dimension object.
 void init()
          Override this method to initialize this Wob.
 boolean isFocusable()
          Returns whether this Component can be focused.
 boolean isVisible()
          Determines whether this object should be visible when its parent is visible.
 void paint(java.awt.Graphics g)
          Paints this component.
 void prepareForSceneRender()
          This method is called just before the rendering process of each frame starts if this object has a Target Area and is visible (even if this Wob doesn't intersect any areas currently scheduled for repainting).
 void printMemoryUsageInfo(java.io.PrintStream out)
          Prints information about the memory usage to the PrintStream parameter.
protected  void processComponentEvent(java.awt.event.ComponentEvent ev)
          This method is not called unless component events are enabled for this component.
protected  void processEvent(java.awt.AWTEvent e)
          Processes events occurring on this component.
protected  void processFocusEvent(java.awt.event.FocusEvent ev)
          This method is not called unless focus events are enabled for this component.
protected  void processInportEvent(Wob arg, int inport)
          Override to handle inport events sent to your Wob.
protected  void processKeyEvent(java.awt.event.KeyEvent ev)
          This method is not called unless key events are enabled for this component.
protected  void processMouseEvent(java.awt.event.MouseEvent ev)
          This method is not called unless mouse events are enabled for this component.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent ev)
          This method is not called unless mouse motion events are enabled for this component.
protected  void processMouseWheelEvent(java.awt.event.MouseWheelEvent ev)
          This method is not called unless mouse wheel events are enabled for this component.
protected  void processPlayerEvent(PlayerEvent ev)
          This method is not called unless player events are enabled for this component.
 void readData(java.io.DataInputStream dataInputStream)
          Reads the data written by the coresponding WobProperties.writeData method.
 void removeChild(Wob child)
          Removes a child of this object.
 void repaint()
          Repaints this object.
 void repaint(int x, int y, int width, int height)
          Repaints the specified rectangle of this component.
 void requestFocus()
          Requests that this Component get the input focus.
 void send(Wob argument, int sourcePort)
          Sends data through all wires connected to the out-port of this Wob that has the specified port number.
 void sendBoolean(boolean value, int outport)
          Sends the specified value as a Boolean Wob through the specified out-port of this Wob.
 void sendColor(int color, int outport)
          Sends the specified value as a Color Wob through the specified out-port of this Wob.
 void sendNumber(double value, int outport)
          Sends the specified value as a Number Wob through the specified out-port of this Wob.
 void sendNumber2D(double x, double y, int outport)
          Sends the specified x and y values as a Number2D Wob through the specified out-port of this Wob.
 void sendPulse(int outport)
          Sends a pulse through the specified out-port of this Wob.
 void sendText(java.lang.String value, int outport)
          Sends the specified value as a Text Wob through the specified out-port of this Wob.
 void setBounds(int x, int y, int width, int height)
          Moves and resizes this object.
 void setCursor(java.awt.Cursor cursor)
          Sets the cursor image to the specified cursor.
 void setLayer(int layer, int position)
          Sets the layer attribute for this Wob and also sets the position within that layer.
 void setLocation(int x, int y)
          Sets the position of this object
 void setName(java.lang.String name)
          Sets this Wob's name
 void setSize(int width, int height)
          Resizes this component so that it has width width and height height.
 void setVisible(boolean visible)
          Shows or hides this object depending on the value of parameter b.
 java.lang.String toString()
          Returns a string represenation of this objects "value".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Wob

public Wob()
It is recommended that you initialize the object in the init method instead of the constructor, if you access the engine in your initialization code.

Method Detail

init

public void init()
Override this method to initialize this Wob. If the Wob is added inside the WireFusion Designer, init will run at presentation startup. If the Wob is created programatically, init will be called right after you have added the Wob to a parent (SceneWob.addChild).


getAwtComponent

public java.awt.Component getAwtComponent()
Each Wob with a target area has an associated AWT Component, from which it receives AWT events for example. This method returns that Component. Note: SceneWob Wobs without target area are exceptions, they also have AWT Component.

Returns:
the AWT Component of this Wob, or null if this Wob has no target area.

getCore

public Core getCore()
Returns the core player object

Returns:
the core player object

getMemoryUsage

public int getMemoryUsage()
Returns the approximate memory used by this object (in bytes). The returned value is used by the memory profiler. If no more than a few kilobytes is used by the Wob, or if you don't have a need for memory profiling of this object, then you can skip overriding this method. The default value returned is 0.

Returns:
the approximate number of bytes used by this object

printMemoryUsageInfo

public void printMemoryUsageInfo(java.io.PrintStream out)
Prints information about the memory usage to the PrintStream parameter. This method is invoked when you call the memory profiling command "showxd" for this object. Override if you want the memory profiler to be able to display memory information about this object (in addition to the total memory used by the object).


toString

public java.lang.String toString()
Returns a string represenation of this objects "value". An empty string is returned by default. The string is for example shown in the debugger.

Overrides:
toString in class java.lang.Object
Returns:
a string representing the state/value of this object
See Also:
Object.toString()

getInPort

public Port getInPort(int portNo)
Returns the in-port with the specified port number.

Parameters:
portNo - a port number
Returns:
an in-port

getOutPort

public Port getOutPort(int portNo)
Returns the out-port with the specified port number.

Parameters:
portNo - a port number
Returns:
an out-port

prepareForSceneRender

public void prepareForSceneRender()
This method is called just before the rendering process of each frame starts if this object has a Target Area and is visible (even if this Wob doesn't intersect any areas currently scheduled for repainting). Methods that override this method need to call super.prepareForSceneRender().


send

public void send(Wob argument,
                 int sourcePort)
Sends data through all wires connected to the out-port of this Wob that has the specified port number.

Parameters:
argument - the data that will be sent from this object
sourcePort - the port number of the out-port of this object through which the data should be sent

sendPulse

public void sendPulse(int outport)
Sends a pulse through the specified out-port of this Wob.

Parameters:
outport - the out-port number

sendNumber

public void sendNumber(double value,
                       int outport)
Sends the specified value as a Number Wob through the specified out-port of this Wob.

Parameters:
value - the number value
outport - the out-port number

sendBoolean

public void sendBoolean(boolean value,
                        int outport)
Sends the specified value as a Boolean Wob through the specified out-port of this Wob.

Parameters:
value - the boolean value
outport - the out-port number

sendText

public void sendText(java.lang.String value,
                     int outport)
Sends the specified value as a Text Wob through the specified out-port of this Wob.

Parameters:
value - the String value
outport - the out-port number

sendNumber2D

public void sendNumber2D(double x,
                         double y,
                         int outport)
Sends the specified x and y values as a Number2D Wob through the specified out-port of this Wob.

Parameters:
x - the x value
y - the y value
outport - the out-port number

sendColor

public void sendColor(int color,
                      int outport)
Sends the specified value as a Color Wob through the specified out-port of this Wob.

Parameters:
color - the rgb color value (0xRRGGBB)
outport - the out-port number

readData

public void readData(java.io.DataInputStream dataInputStream)
Reads the data written by the coresponding WobProperties.writeData method.

Parameters:
dataInputStream - the input stream of the data file

processInportEvent

protected void processInportEvent(Wob arg,
                                  int inport)
Override to handle inport events sent to your Wob. You must call super.processInportEvent if you override this method.

Parameters:
arg - the argument of an event sent to this object
inport - the in-port number the event has been sent to

destroy

public void destroy()
Called to inform this object that it is being reclaimed and that it should destroy any resources that it has allocated. A subclass of Wob should override this method if it has any operation that it wants to perform before it is destroyed. For example, a Wob with threads would use the init method to create the threads and the destroy method to kill them.


paint

public void paint(java.awt.Graphics g)
Paints this component. This method is called when the contents of the object should be painted; such as when the component is first being shown or is damaged and in need of repair. The method is similar to java.awt.Component.paint(). The graphics parameter can be cast to the class com.wirefusion.player.WFGraphics for access to more functions. If this method is not overridden, it will call the filterPixels() method. Do not call super.paint() in this method.

Parameters:
g - the graphics context to use for painting

filterPixels

public void filterPixels(WfImage sceneImage,
                         WfImage processedImage,
                         java.awt.Rectangle targetArea,
                         java.awt.Rectangle areaToProcess)
Processes the pixels in the sceneImage parameter and writes the result to processedImage. Override this method instead of paint, to directly acess and process/write pixels in the target area. Only applicable to Wobs with a Target Area. (If the paint method has been overridden, this method will not be called unless super.paint is called in overridden paint method, but this is not recommended).

Wobs implementing this method will not display correctly in OpenGL presentations

Parameters:
sceneImage - an RGB image containing the current scene pixels. Do not change pixels in this image.
processedImage - an RGB image, with the same dimension av sceneImage. Write processed pixels to this image.
targetArea - the target area of this Wob in the scene image. May extend outside of the image area.
areaToProcess - equals targetArea or is a sub area of target area. It is completely inside of the scene image area. Only process pixels inside this area.

repaint

public void repaint(int x,
                    int y,
                    int width,
                    int height)
Repaints the specified rectangle of this component. It works in a similar way to java.awt.Component.repaint(x, y, width, height).

Parameters:
x - the x coordinate
y - the y coordinate
width - the width
height - the height

repaint

public void repaint()
Repaints this object. Call this method if this object has changed visually and needs to be repainted. It works in a similar way to java.awt.Component.repaint().


setLocation

public void setLocation(int x,
                        int y)
Sets the position of this object

Parameters:
x - the x position
y - the y position

setSize

public void setSize(int width,
                    int height)
Resizes this component so that it has width width and height height.

Parameters:
width - the new width
height - the new height

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Moves and resizes this object. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Parameters:
x - the new x-coordinate of this object
y - the new y-coordinate of this object
width - the new width of this object
height - the new height of this object

setLayer

public void setLayer(int layer,
                     int position)

Sets the layer attribute for this Wob and also sets the position within that layer.

The following layers are supported:
PlayerConstants.DEFAULT_LAYER (the bottommost layer)
PlayerConstants.POPUP_LAYER (is between the default layer and the drag layer))
PlayerConstants.DRAG_LAYER (the topmost layer)

Parameters:
layer - an int specifying the layer to set, where lower numbers are closer to the bottom
position - an int specifying the position within the layer, where 0 is the topmost position and -1 is the bottommost position

getChild

public Wob getChild(java.lang.String childName)
Returns a child of this Wob. If the child was configured in WireFusion, then the childName parameter should be equal to the same used as object label inside WireFusion.

Parameters:
childName - the name of the child.
Returns:
a child Wob

getChildren

public java.util.Enumeration getChildren()
Returns the children of this Wob, or null if it has no children.

Returns:
the children of this Wob, or null if it has no children.

addInteractiveSceneChild

public void addInteractiveSceneChild(SceneWob scene)
Adds a SceneWob object as a child to this object. It will be added to the "AWT system", so that it for example can receive mouse events. This method should only be called if this Wob has a target area or is a SceneWob.

Parameters:
scene - a Wob

addChild

public void addChild(Wob child)
Adds a child to this object. If child already has a parent, it si removed from the parent before it is added.

Parameters:
child - a Wob

removeChild

public void removeChild(Wob child)
Removes a child of this object. The child is also removed from the "AWT System" if previously added.

Parameters:
child - a child

enableEvents

public final void enableEvents(long eventsToEnable)

Enables the events defined by the specified event mask parameter to be delivered to their corresponding processEvent method in this this object. Event types are automatically enabled when a listener for that event type is added to the component (using for example addMouseListener()). This method only needs to be invoked by subclasses of Wob who desire to have the specified event types delivered to its corresponding processEvent method, regardless of whether or not a listener is registered.

The following event masks are supported:
AWTEvent.MOUSE_EVENT_MASK
AWTEvent.MOUSE_MOTION_EVENT_MASK
AWTEvent.MOUSE_WHEEL_EVENT_MASK
AWTEvent.COMPONENT_EVENT_MASK
AWTEvent.FOCUS_EVENT_MASK
AWTEvent.KEY_EVENT_MASK
PlayerEvent.PLAYER_EVENT_MASK

Example:
enableEvents(PlayerEvent.PLAYER_EVENT_MASK) will cause the player to send player events to processPlayerEvent() (until disableEvents(PlayerEvent.PLAYER_EVENT_MASK) is called).

Note: PlayerEvents and Component events doesn't have no associated "add listener" methods.
Note2: Using Mouse Wheel events could break Java 1.1 compatibility if not carefully implemented.

Parameters:
eventsToEnable - the event mask defining the event types

disableEvents

public final void disableEvents(long eventsToDisable)
Disables the events defined by the specified event mask parameter from being delivered to this component.

Parameters:
eventsToDisable - the event mask defining the event types

processEvent

protected void processEvent(java.awt.AWTEvent e)
Processes events occurring on this component. By default this method calls the appropriate processEvent method for the given class of event. You must call super.processEvent if you override this method.

Parameters:
e - the event

processComponentEvent

protected void processComponentEvent(java.awt.event.ComponentEvent ev)
This method is not called unless component events are enabled for this component. Component events are enabled enabled via enableEvents.

Parameters:
ev - the event

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent ev)
This method is not called unless focus events are enabled for this component. Focus events are enabled when one of the following occurs:

Parameters:
ev - the event

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent ev)
This method is not called unless key events are enabled for this component. Key events are enabled when one of the following occurs:

Parameters:
ev - the event

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent ev)
This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:

Parameters:
ev - the event

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent ev)
This method is not called unless mouse motion events are enabled for this component. Mouse motion events are enabled when one of the following occurs:

Parameters:
ev - the event

processMouseWheelEvent

protected void processMouseWheelEvent(java.awt.event.MouseWheelEvent ev)
This method is not called unless mouse wheel events are enabled for this component. Mouse wheel events are enabled when one of the following occurs:

Parameters:
ev - the event

processPlayerEvent

protected void processPlayerEvent(PlayerEvent ev)
This method is not called unless player events are enabled for this component. Component events are enabled enabled via enableEvents. A subclass of Wob overriding this method must call super.processPlayerEvent().

Parameters:
ev - the event

addFocusListener

public void addFocusListener(java.awt.event.FocusListener l)
Adds the specified focus listener to receive focus events from this component when this component gains input focus.

Parameters:
l - the focus listener

addKeyListener

public void addKeyListener(java.awt.event.KeyListener l)
Adds the specified key listener to receive key events from this component.

Parameters:
l - the key listener

addMouseListener

public void addMouseListener(java.awt.event.MouseListener l)
Adds the specified mouse listener to receive mouse events from this component.

Parameters:
l - the mouse listener

addMouseWheelListener

public void addMouseWheelListener(java.awt.event.MouseWheelListener l)
Adds the specified mouse wheel listener to receive mouse wheel events from this component.

Parameters:
l - the mouse wheel listener

addMouseMotionListener

public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component.

Parameters:
l - the mouse motion listener

setVisible

public void setVisible(boolean visible)
Shows or hides this object depending on the value of parameter b.

Parameters:
visible - if true, shows this object; otherwise, hides this object

isVisible

public final boolean isVisible()
Determines whether this object should be visible when its parent is visible. Objects are initially visible.

Returns:
true if the object is visible, false otherwise

requestFocus

public void requestFocus()
Requests that this Component get the input focus.


isFocusable

public boolean isFocusable()
Returns whether this Component can be focused.

Returns:
true if this Component is focusable; false otherwise.

getBounds

public java.awt.Rectangle getBounds()
Gets the bounds of this Wob in the form of a Rectangle object. The bounds specify this Wob's width, height, and location relative to its parent.

Returns:
rectangle indicating this objects bounds

getSize

public java.awt.Dimension getSize()
Gets the size of this Wob in the form of a Dimension object. The height field of the Dimension object contains this Wob's height, and the width field of the Dimension object contains this Wob's width.

Returns:
a Dimension object that indicates the size of this Wob

contains

public boolean contains(int x,
                        int y)
Checks whether this component "contains" the specified point, where x and y are defined to be relative to the coordinate system of this component. The function is similar to java.awt.Componet.contains(). Note: Do not call methods from contains that locks the Component monitor. It may result in deadlocks.

Parameters:
x - The x value of the mouse position.
y - The y value of the mouse position.
Returns:
true if the event was inside, otherwise false.

getName

public java.lang.String getName()
Gets the name of the Wob.

Returns:
this Wob's name

setName

public void setName(java.lang.String name)
Sets this Wob's name

Parameters:
name - a name

setCursor

public void setCursor(java.awt.Cursor cursor)
Sets the cursor image to the specified cursor. This cursor image is displayed when the contains method for this object returns true for the current cursor location, and this object is visible. Setting the cursor of a SceneWob causes that cursor to be displayed within all of the scene's subcomponents, except for those that have a non-null cursor.

Parameters:
cursor - the cursor

getCursor

public java.awt.Cursor getCursor()
Gets the cursor set in the component. If the component does not have a cursor set, the cursor of its parent is returned. If no cursor is set in the entire hierarchy, Cursor.DEFAULT_CURSOR is returned.

Returns:
the cursor

getParent

public Wob getParent()
Gets the parent of this object.

Returns:
the parent container of this object

getResource

public Resource getResource(java.lang.String filename)
Tries to located a resource whos filename equals the argument. If no resource is found with that filename, a search will be made for a resource whos filename, with the checksum removed from the filename, equals filename.

Parameters:
filename - a resource filename
Returns:
a Resource object

getResourceById

public Resource getResourceById(java.lang.String resourceId)
Tries to located a resource whos "resource ID" equals resourceId.

Parameters:
resourceId - a resource ID
Returns:
a Resource object if found, otherwise null.