edu.neu.ccs.gui
Class Tile

java.lang.Object
  extended byedu.neu.ccs.gui.AbstractPaintable
      extended byedu.neu.ccs.gui.Tile
All Implemented Interfaces:
JPTConstants, Paintable, SupportsPropertyChange, SwingConstants
Direct Known Subclasses:
TileBox

public class Tile
extends AbstractPaintable

The class Tile will wrap a Paintable object to obtain to a copy that may be subject to mutation that does not affect the data in the encapsulated paintable.

As of 2.4.0, the class will actually accept an arbitrary object and use the method makePaintable if needed to create the Paintable to be wrapped. This generality turns out to be convenient at times.

The original purpose of this class is to permit multiple copies of one source paintable to exist at once and be mutated independently.

The following principles should be observed:

Normally, the least confusing way to work with Tile objects is to mutate only the Tile objects and leave the paintable alone.

This class is a generalization of the class MutatableWrapper which has been removed from JPT.

In 2.4.0, this class was also updated to be consistent with refinements to the Paintable interface.

In 2.5.0, this class added fields row and col that permit the user to tag a tile with a row,col position in a user-defined structure. Usage of this facility is entirely optional.

In 2.6.0, the notion of a background paint was refactored into required “set” and “get” methods in the Paintable interface and implemented in the base class AbstractPaintable.

In 2.7.0, fixed some documentation.

Since:
2.3.5
Version:
2.7.0

Field Summary
protected  int col
          The optional col.
protected  Paintable paintable
          The wrapped paintable.
protected  int row
          The optional row.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_BACKGROUND_PAINT, SET_BACKGROUND_TILE
 
Fields inherited from interface edu.neu.ccs.gui.Paintable
REMOVE_PAINTABLE, SET_CLIPPING_SHAPE, SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_DEFAULT_ORIGINAL_BOUNDS2D, SET_DEFAULT_ORIGINAL_CENTER, SET_MUTATOR, SET_OPACITY, SET_PAINTABLE, SET_VISIBLE, SHIFT_PAINTABLE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
Tile()
          The constructor that leaves the paintable unspecified; the background paint is set to null.
Tile(Object o)
          The constructor to specify the object to be wrapped; the background paint is set to null.
Tile(Object o, AffineTransform m)
          The constructor to specify the object to be wrapped and the initial mutator; the background paint is set to null.
Tile(Object o, Paint background)
          The constructor to specify the object to be wrapped and the background paint.
Tile(Object o, Paint background, AffineTransform m)
          The constructor to specify the object to be wrapped, the background paint, and the initial mutator.
 
Method Summary
 XRect getActualBounds2D()
          Returns the actual bounds of this tile or null if the tile is effectively empty.
 int getCol()
          Returns the optional col tag for this tile.
 Paintable getPaintable()
          Returns the wrapped paintable.
 int getRow()
          Returns the optional row tag for this tile.
 void initializeTile(Object o, Paint background, AffineTransform m)
          The common initialization method.
 Paintable makePaintable(Object o)
          Returns a Paintable constructed from the given Object.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates is inside the original paintable without mutation.
 void originalPaint(Graphics g)
          Paints onto a Graphics context using the wrapped paintable object but without the use of the mutator transform.
 void setCol(int col)
          Sets the optional col tag for this tile.
 void setPaintable(Object o)
          Sets the object to be wrapped.
 void setRow(int row)
          Sets the optional row tag for this tile.
 void setRowCol(int row, int col)
          Sets the optional row and col tags for this tile.
 
Methods inherited from class edu.neu.ccs.gui.AbstractPaintable
addForwardingListener, addPostMutation, addPostMutation, addPreMutation, addPreMutation, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, affinetransform, applyOpacity, clearBackgroundPaint, clearBackgroundTile, clearBothBackgrounds, contains, contains, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundPaint, getBackgroundTile, getBounds2D, getCenter, getCorner, getDefaultBounds2D, getDefaultCenter, getDefaultOriginalBounds2D, getDefaultOriginalCenter, getForwardingListener, getMutator, getMutatorInverse, getOpacity, getOriginalBounds2D, getOriginalCenter, getPreparedGraphics2D, getPropertyChangeListeners, getPropertyChangeListeners, glide, glidereflect, hasListeners, hreflect, isVisible, lineartransform, makeSnapshot, move, move, moveCenterTo, moveCenterTo, moveCornerTo, moveCornerTo, mutate, mutate, originalContains, paint, paintAsTiles, paintAsTiles, paintAsTiles, paintAt, paintAt, paintAt, paintAt, possiblyContains, reflect, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener, rotate, scale, scale, setBackgroundPaint, setBackgroundTile, setDefaultBounds2D, setDefaultCenter, setDefaultOriginalBounds2D, setDefaultOriginalCenter, setMutator, setMutator, setOpacity, setVisible, shear, vreflect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

paintable

protected Paintable paintable
The wrapped paintable.


row

protected int row
The optional row.


col

protected int col
The optional col.

Constructor Detail

Tile

public Tile()
The constructor that leaves the paintable unspecified; the background paint is set to null.


Tile

public Tile(Object o)
The constructor to specify the object to be wrapped; the background paint is set to null.

Parameters:
o - the object to convert to a paintable to wrap in this tile

Tile

public Tile(Object o,
            Paint background)
The constructor to specify the object to be wrapped and the background paint.

Parameters:
o - the object to convert to a paintable to wrap in this tile
background - the background paint for the tile

Tile

public Tile(Object o,
            AffineTransform m)
The constructor to specify the object to be wrapped and the initial mutator; the background paint is set to null.

Parameters:
o - the object to convert to a paintable to wrap in this tile
m - the initial mutator

Tile

public Tile(Object o,
            Paint background,
            AffineTransform m)
The constructor to specify the object to be wrapped, the background paint, and the initial mutator.

Parameters:
o - the object to convert to a paintable to wrap in this tile
background - the background paint for the tile
m - the initial mutator
Method Detail

initializeTile

public void initializeTile(Object o,
                           Paint background,
                           AffineTransform m)

The common initialization method.

Because this method is public, the caller can reset the key properties of a tile after construction.

Parameters:
o - the object to convert to a paintable to wrap in this tile
background - the background paint for the tile
m - the initial mutator

originalPaint

public void originalPaint(Graphics g)

Paints onto a Graphics context using the wrapped paintable object but without the use of the mutator transform.

Specified by:
originalPaint in interface Paintable
Specified by:
originalPaint in class AbstractPaintable
Parameters:
g - the graphics context on which to paint

getActualBounds2D

public XRect getActualBounds2D()

Returns the actual bounds of this tile or null if the tile is effectively empty.

If the internal paintable is non-null, then returns a copy of the 2-dimensional bounds of the internal paintable prior to any mutation of this object.

Since the internal paintable may have a mutation or defaults this method calls getBounds2D on the internal paintable. Hence any mutation or defaults set for the internal paintable are respected.

Specified by:
getActualBounds2D in interface Paintable
Specified by:
getActualBounds2D in class AbstractPaintable
Returns:
a copy of the 2-dimensional bounds of the original paintable

originalContains

public boolean originalContains(double x,
                                double y)

Tests if a point specified by coordinates is inside the original paintable without mutation.

Specified by:
originalContains in interface Paintable
Specified by:
originalContains in class AbstractPaintable
Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
whether or not a specified point is inside the original paintable

makePaintable

public Paintable makePaintable(Object o)

Returns a Paintable constructed from the given Object.

By default, uses ComponentFactory.makePaintable.

May be overridden in a derived class if the designer has a more sophisticated way to construct a Paintable.

Any override should respect the convention that if the object is already a Paintable then it is returned as is.

Parameters:
o - the object to make into a Paintable

setPaintable

public void setPaintable(Object o)

Sets the object to be wrapped. If the object is a paintable, then it is wrapped as is. Otherwise the makePaintable method is called to create the paintable that will be wrapped in this tile.

The given object may be set to null to eliminate the paintable. The method originalPaint will then paint nothing. However, if the caller has set some form of default bounds and if a background paint or background tile has also been set, then these will be painted by the paint method.

Fires property change: SET_PAINTABLE.

Parameters:
o - the object to convert to a paintable to wrap in this tile

getPaintable

public Paintable getPaintable()
Returns the wrapped paintable.

Returns:
the wrapped paintable

setRowCol

public void setRowCol(int row,
                      int col)
Sets the optional row and col tags for this tile.

Parameters:
row - the row tag for this tile
col - the col tag for this tile

setRow

public void setRow(int row)
Sets the optional row tag for this tile.

Parameters:
row - the row tag for this tile

setCol

public void setCol(int col)
Sets the optional col tag for this tile.

Parameters:
col - the col tag for this tile

getRow

public int getRow()
Returns the optional row tag for this tile.


getCol

public int getCol()
Returns the optional col tag for this tile.