edu.neu.ccs.gui
Class PaintBar

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

public class PaintBar
extends PaintableSequenceComposite

Class PaintBar implements a Paintable that paints a one or two dimensional array of disks. The constructor supplies an array of Paint objects, one for each disk. The user can choose the diameter of the disks and the gap between the disks.

As an application, an object of this class may be embedded in a PaintableComponent and used to implement a custom paint selector control.

Since:
2.3.2
Version:
2.3.2

Field Summary
private  int base
          The x and y coordinate of the corner of disk (0, 0).
private  Rectangle2D.Double bounds
          The bounds of the paint bar.
private  int center
          The x and y coordinate of the center of disk (0, 0).
private  int diameter
          The diameter of the disks.
private  int gap
          The gap between the disks.
private  int number
          The number of distinct paint disks.
private  int skip
          The skip between the disk centers.
 
Fields inherited from class edu.neu.ccs.gui.PaintableSequenceComposite
 
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
PaintBar(Paint[][] paints, int diameter, int gap)
          This contructor builds a Paintable that will paint an array of disks using the given two dimensional Paint array, the given disk diameter, and the given gap between disks.
PaintBar(Paint[] paints, int diameter, int gap, int orientation)
          This contructor builds a Paintable that will paint a sequence of disks using the given one dimensional Paint array, the given disk diameter, the given gap between disks, and the given orientation for the bar (HORIZONTAL or VERTICAL).
 
Method Summary
 int diameter()
          Returns the diameter.
 int gap()
          Returns the gap.
 Paint getPaint(int row, int col)
          Returns the paint of the disk at the given row and col.
 int getPaintCount()
          Returns the number of paint disks.
protected  ShapePaintable getShapePaintable(int index)
          This protected method returns the ShapePaintable that implements the paint disk at the given index.
 Paint hitsPaint(double x, double y)
          If the given position is within one of the paint disks, then returns the paint of that disk, otherwise returns null.
 Paint hitsPaint(Point2D p)
          If the given position is within one of the paint disks, then returns the paint of that disk, otherwise returns null.
private  void installPaint(Paint paint, int x, int y, int diameter)
          Installs the given paint at the given position with the given diameter.
 void setPaint(int row, int col, Paint paint)
          Sets the paint of the disk at the given row and col.
 int xCenter(int col)
          Returns the x-center of a disk in the given col.
 int xCorner(int col)
          Returns the x-corner of a disk in the given col.
 int yCenter(int row)
          Returns the y-center of a disk in the given row.
 int yCorner(int row)
          Returns the y-corner of a disk in the given row.
 
Methods inherited from class edu.neu.ccs.gui.PaintableSequenceComposite
clearBothInnerBackgrounds, clearInnerBackgroundPaint, clearInnerBackgroundTile, getActualBounds2D, getInnerBackgroundPaint, getInnerBackgroundTile, getPaintableSequence, originalContains, originalPaint, setInnerBackgroundPaint, setInnerBackgroundTile
 
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

number

private int number
The number of distinct paint disks.


diameter

private int diameter
The diameter of the disks.


gap

private int gap
The gap between the disks.


base

private int base
The x and y coordinate of the corner of disk (0, 0).


center

private int center
The x and y coordinate of the center of disk (0, 0).


skip

private int skip
The skip between the disk centers.


bounds

private Rectangle2D.Double bounds
The bounds of the paint bar.

Constructor Detail

PaintBar

public PaintBar(Paint[] paints,
                int diameter,
                int gap,
                int orientation)

This contructor builds a Paintable that will paint a sequence of disks using the given one dimensional Paint array, the given disk diameter, the given gap between disks, and the given orientation for the bar (HORIZONTAL or VERTICAL).

Throws NullPointerException if the array of paints is null or if all entries in the array of paints are null. On the other hand, if an individual paint item is null, then its position is simply skipped.

If the diameter is less than 5, it is set to 5.

If the gap is less than 0, it is set to 0.

If the orientation is not equal to HORIZONAL, it is set to VERTICAL.

Parameters:
paints - the set of paints for the disks in the paint bar
diameter - the diameter of each disk
gap - the gap between disks
orientation - the orientation of the paint bar

PaintBar

public PaintBar(Paint[][] paints,
                int diameter,
                int gap)

This contructor builds a Paintable that will paint an array of disks using the given two dimensional Paint array, the given disk diameter, and the given gap between disks.

Throws NullPointerException if the array of paints is null or if all entries in the array of paints are null. On the other hand, if an individual paint item is null, then its position is simply skipped.

If the diameter is less than 5, it is set to 5.

If the gap is less than 0, it is set to 0.

Parameters:
paints - the set of paints for the disks in the paint bar
diameter - the diameter of each disk
gap - the gap between disks
Method Detail

getPaintCount

public int getPaintCount()

Returns the number of paint disks.

Returns:
the number of paint disks

getPaint

public Paint getPaint(int row,
                      int col)

Returns the paint of the disk at the given row and col.

If the paint bar is HORIZONTAL, row should be 0.

If the paint bar is VERTICAL, col should be 0.

Returns null if no paint disk was installed at the given row and col.

Parameters:
row - the row of a paint disk
col - the col of a paint disk
Returns:
the paint of the disk at the given row and col

setPaint

public void setPaint(int row,
                     int col,
                     Paint paint)

Sets the paint of the disk at the given row and col.

Does nothing if the row and col are out of bounds or the paint is null.

This method will install a paint disk at a valid row and col if none was installed at construction.

Parameters:
row - the row of a paint disk
col - the col of a paint disk
paint - the new paint for the disk at the given index

hitsPaint

public Paint hitsPaint(double x,
                       double y)

If the given position is within one of the paint disks, then returns the paint of that disk, otherwise returns null.

This method may be used to implement a control.

Parameters:
x - the x-coordinate of the position
y - the y-coordinate of the position
Returns:
the paint of the disk at x,y or null

hitsPaint

public Paint hitsPaint(Point2D p)

If the given position is within one of the paint disks, then returns the paint of that disk, otherwise returns null.

This method may be used to implement a control.

Parameters:
p - the position
Returns:
the paint of the disk at p or null

diameter

public int diameter()
Returns the diameter.


gap

public int gap()
Returns the gap.


xCorner

public int xCorner(int col)
Returns the x-corner of a disk in the given col.


yCorner

public int yCorner(int row)
Returns the y-corner of a disk in the given row.


xCenter

public int xCenter(int col)
Returns the x-center of a disk in the given col.


yCenter

public int yCenter(int row)
Returns the y-center of a disk in the given row.


getShapePaintable

protected ShapePaintable getShapePaintable(int index)

This protected method returns the ShapePaintable that implements the paint disk at the given index.

If the index is out of bounds, returns null.

Parameters:
index - the index of a paint disk
Returns:
the shape paintable for the disk at the given index

installPaint

private void installPaint(Paint paint,
                          int x,
                          int y,
                          int diameter)
Installs the given paint at the given position with the given diameter.