edu.neu.ccs.gui
Class TileBox

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

public class TileBox
extends Tile

The class TileBox will wrap an object by converting it to a Paintable if it is not one already.

This class extends Tile to add two features:

Because of the second feature, it is much easier to drag a TileBox using the mouse than to drag a corresponding Tile since less accuracy is required of the user.

As of 2.6.0c, fixed a bug in the code that tests if a point is contained in the paintable represented by the tile as a whole. It was our intention that a point would be contained in the tile if it was in the bounding box of the tile after mutation. To achieve this, it is necessary to override contains. This was not done in prior versions of this class. Moreover, it was also our intention that originalContains test if the point was in the original bounding box before mutation. This was not done correctly in prior versions of this class. The bounding box before mutation is the rectangle returned by the method getOriginalBounds2D. This method first checks to see if a default original bounds has been set and if so returns it. Only if no such default has been set is the method getActualBounds2D called.

The method getActualBounds2D is the correct method to apply a border setting. This method expands the bounding box of the internal paintable by the border as long as the internal paintable is not null. Otherwise, this method returns null.

A consequence of these relationships is that if the caller has set a default original bounds then the border value is ignored.

Since:
2.4.0
Version:
2.6.0c

Field Summary
protected  int border
          The border size.
static String SET_BORDER_SIZE
          Bound property name for set border size.
 
Fields inherited from class edu.neu.ccs.gui.Tile
col, paintable, 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
TileBox()
          The constructor that leaves the paintable unspecified; the background paint is set to null; the border is set to 0.
TileBox(Object o)
          The constructor to specify the object to be wrapped; the background paint is set to null; the border is set to 0.
TileBox(Object o, AffineTransform m)
          The constructor to specify the object to be wrapped and the initial mutator; the background paint is set to null; the border is set to 0.
TileBox(Object o, AffineTransform m, int border)
          The constructor to specify the object to be wrapped and the initial mutator; the background paint is set to null; the border is set to the given border.
TileBox(Object o, int border)
          The constructor to specify the object to be wrapped; the background paint is set to null; the border is set to the given border.
TileBox(Object o, Paint background)
          The constructor to specify the object to be wrapped and the background paint; the border is set to 0.
TileBox(Object o, Paint background, AffineTransform m)
          The constructor to specify the object to be wrapped, the background paint, and the initial mutator; the border is set to 0.
TileBox(Object o, Paint background, AffineTransform m, int border)
          The constructor to specify the object to be wrapped, the background paint, and the initial mutator; the border is set to the given border.
TileBox(Object o, Paint background, int border)
          The constructor to specify the object to be wrapped and the background paint; the border is set to the given border.
 
Method Summary
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the bounding box of the tile box after mutation.
 XRect getActualBounds2D()
          Returns the actual bounds of this tile box with border added or null if the tile box is effectively empty because there is no internal paintable installed.
 int getBorderSize()
          Gets the border for the tile box, that is, the extra amount to add to the bounding box on all sides.
 void initializeTileBox(Object o, Paint background, AffineTransform m, int border)
          The common initialization method.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates is inside the bounding box of the tile box before mutation.
 void setBorderSize(int border)
          Sets the border for the tile box, that is, the extra amount to add to the bounding box on all sides.
 
Methods inherited from class edu.neu.ccs.gui.Tile
getCol, getPaintable, getRow, initializeTile, makePaintable, originalPaint, setCol, setPaintable, setRow, setRowCol
 
Methods inherited from class edu.neu.ccs.gui.AbstractPaintable
addForwardingListener, addPostMutation, addPostMutation, addPreMutation, addPreMutation, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, affinetransform, applyOpacity, clearBackgroundPaint, clearBackgroundTile, clearBothBackgrounds, 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

SET_BORDER_SIZE

public static final String SET_BORDER_SIZE
Bound property name for set border size.

See Also:
Constant Field Values

border

protected int border
The border size.

Constructor Detail

TileBox

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


TileBox

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

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

TileBox

public TileBox(Object o,
               Paint background)
The constructor to specify the object to be wrapped and the background paint; the border is set to 0.

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

TileBox

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

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

TileBox

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

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

TileBox

public TileBox(Object o,
               int border)
The constructor to specify the object to be wrapped; the background paint is set to null; the border is set to the given border.

Parameters:
o - the object to convert to a paintable to wrap in this tile
border - the border size for the tile box

TileBox

public TileBox(Object o,
               Paint background,
               int border)
The constructor to specify the object to be wrapped and the background paint; the border is set to the given border.

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

TileBox

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

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

TileBox

public TileBox(Object o,
               Paint background,
               AffineTransform m,
               int border)
The constructor to specify the object to be wrapped, the background paint, and the initial mutator; the border is set to the given border.

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
border - the border size for the tile box
Method Detail

initializeTileBox

public void initializeTileBox(Object o,
                              Paint background,
                              AffineTransform m,
                              int border)
The common initialization method.

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

getActualBounds2D

public XRect getActualBounds2D()

Returns the actual bounds of this tile box with border added or null if the tile box is effectively empty because there is no internal paintable installed.

If the internal paintable is non-null, then returns a copy of the 2-dimensional bounds of the internal paintable expanded by the border but prior to any mutation of this tile 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.

This method is bypassed if a default original bounds has been set.

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

contains

public boolean contains(double x,
                        double y)

Tests if a point specified by coordinates is inside the bounding box of the tile box after mutation. Calls the method getBounds2D() to do the test.

Specified by:
contains in interface Paintable
Overrides:
contains 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 bounding box after mutation

originalContains

public boolean originalContains(double x,
                                double y)

Tests if a point specified by coordinates is inside the bounding box of the tile box before mutation. Calls the method getOriginalBounds2D() to do the test.

Specified by:
originalContains in interface Paintable
Overrides:
originalContains in class Tile
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 bounding box before mutation

setBorderSize

public void setBorderSize(int border)

Sets the border for the tile box, that is, the extra amount to add to the bounding box on all sides.

Forces the border to be >= 0.

Fires property change: SET_BORDER_SIZE.

Parameters:
border - the border size for the tile box

getBorderSize

public int getBorderSize()

Gets the border for the tile box, that is, the extra amount to add to the bounding box on all sides.