Make AbstractMedia implement Comparable instead of using a comparator. Added

naturalOrder() which allows media to use a more consistent "same render order"
order resolution value than Object.hashCode().


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@248 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2007-05-15 17:45:18 +00:00
parent f7dfe51a9c
commit acea29604d
4 changed files with 41 additions and 33 deletions
@@ -37,7 +37,7 @@ import com.samskivert.util.StringUtil;
* Something that can be rendered on the media panel.
*/
public abstract class AbstractMedia
implements Shape
implements Shape, Comparable<AbstractMedia>
{
/** A {@link #_renderOrder} value at or above which, indicates that this
* media is in the HUD (heads up display) and should not scroll when the
@@ -118,54 +118,62 @@ public abstract class AbstractMedia
return _bounds;
}
// documentation inherited from interface Shape
// from interface Shape
public boolean contains (double x, double y)
{
return _bounds.contains(x, y);
}
// documentation inherited from interface Shape
// from interface Shape
public boolean contains (Point2D p)
{
return _bounds.contains(p);
}
// documentation inherited from interface Shape
// from interface Shape
public boolean intersects (double x, double y, double w, double h)
{
return _bounds.intersects(x, y, w, h);
}
// documentation inherited from interface Shape
// from interface Shape
public boolean intersects (Rectangle2D r)
{
return _bounds.intersects(r);
}
// documentation inherited from interface Shape
// from interface Shape
public boolean contains (double x, double y, double w, double h)
{
return _bounds.contains(x, y, w, h);
}
// documentation inherited from interface Shape
// from interface Shape
public boolean contains (Rectangle2D r)
{
return _bounds.contains(r);
}
// documentation inherited from interface Shape
// from interface Shape
public PathIterator getPathIterator (AffineTransform at)
{
return _bounds.getPathIterator(at);
}
// documentation inherited from interface Shape
// from interface Shape
public PathIterator getPathIterator (AffineTransform at, double flatness)
{
return _bounds.getPathIterator(at, flatness);
}
// from interface Comparable<AbstractMedia>
public int compareTo (AbstractMedia other)
{
int result = _renderOrder - other._renderOrder;
// if render order is same, use their natural order
return (result != 0) ? result : naturalOrder() - other.naturalOrder();
}
/**
* Sets the render order associated with this media. Media
* can be rendered in two layers; those with negative render order and
@@ -336,6 +344,16 @@ public abstract class AbstractMedia
}
}
/**
* Returns a value used to "naturally" order media within the same render order layer. The
* default behavior, for legacy reasons is {@link #hashCode} which is not consistent across
* sessions.
*/
protected int naturalOrder ()
{
return hashCode();
}
/**
* This should be overridden by derived classes (which should be sure
* to call <code>super.toString()</code>) to append the derived class