com.threerings.media
Class AbstractMedia

java.lang.Object
  extended by com.threerings.media.AbstractMedia
All Implemented Interfaces:
Shape
Direct Known Subclasses:
Animation, Sprite

public abstract class AbstractMedia
extends Object
implements Shape

Something that can be rendered on the media panel.


Field Summary
protected  Rectangle _bounds
          The bounds of the media's rendering area.
protected  long _firstTick
          The tick stamp associated with our first call to tick(long).
protected  AbstractMediaManager _mgr
          Our manager.
protected  ObserverList<Object> _observers
          Our observers.
protected  int _renderOrder
          The layer in which to render.
static int HUD_LAYER
          A _renderOrder value at or above which, indicates that this media is in the HUD (heads up display) and should not scroll when the view scrolls.
 
Constructor Summary
AbstractMedia(Rectangle bounds)
          Instantiate an abstract media object.
 
Method Summary
protected  void addObserver(Object obs)
          Add the specified observer to this media element.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(Point2D p)
           
 boolean contains(Rectangle2D r)
           
 void fastForward(long timeDelta)
          Called when the appropriate media manager has been paused for some length of time and is then unpaused.
 Rectangle getBounds()
          Returns a rectangle containing all the pixels rendered by this media.
 Rectangle2D getBounds2D()
           
 PathIterator getPathIterator(AffineTransform at)
           
 PathIterator getPathIterator(AffineTransform at, double flatness)
           
 int getRenderOrder()
          Returns the render order of this media element.
protected  void init()
          Called when the media has had its manager set.
 void init(AbstractMediaManager manager)
          Initialize the media.
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(Rectangle2D r)
           
 void invalidate()
          Invalidate the media's bounding rectangle for later painting.
protected  void invalidateAfterChange(Rectangle obounds)
          If this media's size or location are changing, it should create a new rectangle from its old bounds (new Rectangle(_bounds)), then effect the bounds changes and then call this method with the old bounds.
protected  int naturalCompareTo(AbstractMedia other)
          "Naturally" compares this media with the specified other media (which by definition will have the same render order value).
abstract  void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
 void queueNotification(ObserverList.ObserverOp<Object> amop)
          Queues the supplied notification up to be dispatched to this abstract media's observers.
protected  void removeObserver(Object obs)
          Remove the specified observer from this media element.
 int renderCompareTo(AbstractMedia other)
          Compares this media to the specified media by render order.
 void setLocation(int x, int y)
          Set the location.
 void setRenderOrder(int renderOrder)
          Sets the render order associated with this media.
protected  void shutdown()
          Called by the media manager after the media is removed from service.
abstract  void tick(long tickStamp)
          Called periodically by this media's manager to give it a chance to do its thing.
 String toString()
           
protected  void toString(StringBuilder buf)
          This should be overridden by derived classes (which should be sure to call super.toString()) to append the derived class specific information to the string buffer.
 void viewLocationDidChange(int dx, int dy)
          Called by the AbstractMediaManager when we are in a VirtualMediaPanel that just scrolled.
protected  void willStart(long tickStamp)
          Prior to the first call to tick(long) on an abstract media, this method is called by the AbstractMediaManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HUD_LAYER

public static final int HUD_LAYER
A _renderOrder value at or above which, indicates that this media is in the HUD (heads up display) and should not scroll when the view scrolls.

See Also:
Constant Field Values

_renderOrder

protected int _renderOrder
The layer in which to render.


_bounds

protected Rectangle _bounds
The bounds of the media's rendering area.


_mgr

protected AbstractMediaManager _mgr
Our manager.


_observers

protected ObserverList<Object> _observers
Our observers.


_firstTick

protected long _firstTick
The tick stamp associated with our first call to tick(long). This is set up automatically in willStart(long).

Constructor Detail

AbstractMedia

public AbstractMedia(Rectangle bounds)
Instantiate an abstract media object.

Method Detail

tick

public abstract void tick(long tickStamp)
Called periodically by this media's manager to give it a chance to do its thing.

Parameters:
tickStamp - a time stamp associated with this tick. Note: this is not obtained from a call to System.currentTimeMillis() and cannot be compared to timestamps obtained there from.

paint

public abstract void paint(Graphics2D gfx)
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.


fastForward

public void fastForward(long timeDelta)
Called when the appropriate media manager has been paused for some length of time and is then unpaused. Media should adjust any time stamps that are maintained internally forward by the delta so that time maintains the illusion of flowing smoothly forward.


invalidate

public void invalidate()
Invalidate the media's bounding rectangle for later painting.


setLocation

public void setLocation(int x,
                        int y)
Set the location.


getBounds

public Rectangle getBounds()
Returns a rectangle containing all the pixels rendered by this media.

Specified by:
getBounds in interface Shape

getBounds2D

public Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface Shape

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface Shape

contains

public boolean contains(Point2D p)
Specified by:
contains in interface Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface Shape

intersects

public boolean intersects(Rectangle2D r)
Specified by:
intersects in interface Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface Shape

contains

public boolean contains(Rectangle2D r)
Specified by:
contains in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Specified by:
getPathIterator in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Specified by:
getPathIterator in interface Shape

renderCompareTo

public int renderCompareTo(AbstractMedia other)
Compares this media to the specified media by render order.


setRenderOrder

public void setRenderOrder(int renderOrder)
Sets the render order associated with this media. Media can be rendered in two layers; those with negative render order and those with positive render order. In the same layer, they will be rendered according to their render order's cardinal value (least to greatest). Those with the same render order value will be rendered in arbitrary order.

This method may not be called during a tick.

See Also:
HUD_LAYER

getRenderOrder

public int getRenderOrder()
Returns the render order of this media element.


queueNotification

public void queueNotification(ObserverList.ObserverOp<Object> amop)
Queues the supplied notification up to be dispatched to this abstract media's observers.


viewLocationDidChange

public void viewLocationDidChange(int dx,
                                  int dy)
Called by the AbstractMediaManager when we are in a VirtualMediaPanel that just scrolled.


toString

public String toString()
Overrides:
toString in class Object

init

public final void init(AbstractMediaManager manager)
Initialize the media.


init

protected void init()
Called when the media has had its manager set. Derived classes may override this method, but should be sure to call super.init().


willStart

protected void willStart(long tickStamp)
Prior to the first call to tick(long) on an abstract media, this method is called by the AbstractMediaManager. It is called during the normal tick cycle, immediately prior to the first call to tick(long).

Note: It is imperative that super.willStart() is called by any entity that overrides this method because the AbstractMediaManager depends on the setting of the _firstTick value to know whether or not to call this method.


invalidateAfterChange

protected void invalidateAfterChange(Rectangle obounds)
If this media's size or location are changing, it should create a new rectangle from its old bounds (new Rectangle(_bounds)), then effect the bounds changes and then call this method with the old bounds. This method will either merge the new bounds with the old to create a single dirty rectangle or dirty them separately depending on which is more appropriate. It will also behave properly if this media is not currently managed (not being rendered) by NOOPing. Do not pass _bounds to this method. The rectangle passed in will be modified and then passed on to the region manager which will modify it further.


shutdown

protected void shutdown()
Called by the media manager after the media is removed from service. Derived classes may override this method, but should be sure to call super.shutdown().


addObserver

protected void addObserver(Object obs)
Add the specified observer to this media element.


removeObserver

protected void removeObserver(Object obs)
Remove the specified observer from this media element.


naturalCompareTo

protected int naturalCompareTo(AbstractMedia other)
"Naturally" compares this media with the specified other media (which by definition will have the same render order value). The default behavior, for legacy reasons, is to compare using Object.hashCode() which is not consistent across VM invocations.


toString

protected void toString(StringBuilder buf)
This should be overridden by derived classes (which should be sure to call super.toString()) to append the derived class specific information to the string buffer.