edu.neu.ccs.gui
Class PointPaintable

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

public class PointPaintable
extends AbstractPaintable

A PointPaintable creates a Paintable using a point, a PlotMark, and a Paint.

Intuitively, the effect of painting the plotmark at the origin using the paint is translated from the origin to the point.

More precisely, the idea is that the point defines the mutator for the object as a translation whose whose x,y coefficients are those of the point. In fact, in this class, the mutator must be a translation. When the method setPoint is called, the mutator is set at the same time to be the corresponding translation.

In addition, when the method setMutator is called, the linear part of the given mutator is ignored and the object mutator is set to be the translation portion of the given mutator. At the same time, the point associated with this object is set.

The behaviors of the methods setPreMutation and setPostMutation are then determined by the above rules.

Note that, if the plotmark is defined by a paintable, then the property changes of the internal paintable will be sent to the forwarding listener of the point paintable.

Since:
2.4.0
Version:
2.4.0

Field Summary
private static XPoint2D ORIGIN
          The origin for use in originalPaint.
private  Paint paint
          The internal paint for this PointPaintable.
private  PlotMark plotmark
          The internal plotmark for this PointPaintable.
private  XPoint2D point
          The internal point for this PointPaintable.
static String SET_PAINT
          Bound property name for set paint.
static String SET_PLOTMARK
          Bound property name for set plotmark.
 
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
PointPaintable()
          The default constructor.
PointPaintable(double[] data, PlotMark pm, Paint paint)
          Constructor that sets the point from the given data and sets the plotmark and the paint.
PointPaintable(double x, double y, PlotMark pm, Paint paint)
          Constructor that sets the point from the given data and sets the plotmark and the paint.
PointPaintable(float[] data, PlotMark pm, Paint paint)
          Constructor that sets the point from the given data and sets the plotmark and the paint.
PointPaintable(Point2D p, PlotMark pm, Paint paint)
          Constructor that sets the point from the given data and sets the plotmark and the paint.
 
Method Summary
 XRect getActualBounds2D()
          Returns the actual bounds of the original paintable or null if the paintable is effectively empty.
 XPoint2D getOriginalCenter()
          Returns a copy of the original center of the paint region.
 Paint getPaint()
          Returns the current paint of this object.
 PlotMark getPlotMark()
          Returns the current plotmark of this object.
 XPoint2D getPoint()
          Returns a copy of the current point of this object.
static PaintableSequence makePaintableSequence(double[][] points, PlotMark pm, Paint paint)
          Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.
static PaintableSequence makePaintableSequence(float[][] points, PlotMark pm, Paint paint)
          Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.
static PaintableSequence makePaintableSequence(Point2D[] points, PlotMark pm, Paint paint)
          Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.
static PointPaintable[] makePointPaintableArray(double[][] points, PlotMark pm, Paint paint)
          Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.
static PointPaintable[] makePointPaintableArray(float[][] points, PlotMark pm, Paint paint)
          Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.
static PointPaintable[] makePointPaintableArray(Point2D[] points, PlotMark pm, Paint paint)
          Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.
 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.
 void setMutator(AffineTransform M)
          The linear part of the given mutator is ignored and the object mutator is set to the translation portion of the given mutator.
 void setMutator(Mutator.Strategy strategy)
          Calls the super method.
 void setPaint(Paint paint)
          Sets the paint to the given paint.
 void setPlotMark(Paintable paintable)
          Sets the internal plotmark using the given data to call the corresponding PlotMark constructor.
 void setPlotMark(PlotMark pm)
          Sets the internal plotmark using the given data.
 void setPlotMark(PlotMarkAlgorithm algorithm, int size, boolean fill)
          Sets the internal plotmark using the given data to call the corresponding PlotMark constructor.
 void setPoint(double[] data)
          Sets the internal point using the given data.
 void setPoint(double x, double y)
          Sets the internal point using the given data.
 void setPoint(float[] data)
          Sets the internal point using the given data.
 void setPoint(Point2D p)
          Sets the internal point using the given data.
 
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, 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, setOpacity, setVisible, shear, vreflect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGIN

private static final XPoint2D ORIGIN
The origin for use in originalPaint.


SET_PLOTMARK

public static final String SET_PLOTMARK
Bound property name for set plotmark.

See Also:
Constant Field Values

SET_PAINT

public static final String SET_PAINT
Bound property name for set paint.

See Also:
Constant Field Values

point

private XPoint2D point
The internal point for this PointPaintable.


plotmark

private PlotMark plotmark
The internal plotmark for this PointPaintable.


paint

private Paint paint
The internal paint for this PointPaintable.

Constructor Detail

PointPaintable

public PointPaintable()

The default constructor.

Sets the following defaults:


PointPaintable

public PointPaintable(double x,
                      double y,
                      PlotMark pm,
                      Paint paint)

Constructor that sets the point from the given data and sets the plotmark and the paint.

Parameters that are null revert to the defaults listed in the default constructor.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
pm - the plotmark to set
paint - the paint to set

PointPaintable

public PointPaintable(Point2D p,
                      PlotMark pm,
                      Paint paint)

Constructor that sets the point from the given data and sets the plotmark and the paint.

Parameters that are null revert to the defaults listed in the default constructor.

Parameters:
p - the point whose data will set the internal point
pm - the plotmark to set
paint - the paint to set

PointPaintable

public PointPaintable(double[] data,
                      PlotMark pm,
                      Paint paint)

Constructor that sets the point from the given data and sets the plotmark and the paint.

Parameters that are null revert to the defaults listed in the default constructor.

Parameters:
data - the array of size 2 with the x,y data
pm - the plotmark to set
paint - the paint to set

PointPaintable

public PointPaintable(float[] data,
                      PlotMark pm,
                      Paint paint)

Constructor that sets the point from the given data and sets the plotmark and the paint.

Parameters that are null revert to the defaults listed in the default constructor.

Parameters:
data - the array of size 2 with the x,y data
pm - the plotmark to set
paint - the paint to set
Method Detail

originalPaint

public void originalPaint(Graphics g)

Paints onto a Graphics context.

Sets the paint of the graphics context to the internal paint and then uses the plotmark to place a mark at the origin, that is, at (0,0).

When the method call is complete, the internal state of g is unchanged.

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 the original paintable or null if the paintable is effectively empty.

If the plotmark is defined by a paintable, then the actual bounds of that paintable is returned.

Otherwise, if the plotmark is defined by an algorithm and a size, then the actual bounds is computed as follows. The shape algorithm.makeShape(0, 0, size) is constructed. If this is null then null is returned. Otherwise, the bounds of the shape is computed. The width and the height of this rectangle is increased by 1 to account for the decision to always stroke the boundary of an algorithmic plotmark with a stroke of thickness 1.

Specified by:
getActualBounds2D in interface Paintable
Specified by:
getActualBounds2D in class AbstractPaintable

getOriginalCenter

public XPoint2D getOriginalCenter()

Returns a copy of the original center of the paint region.

The method is implemented as follows.

If the value of getDefaultOriginalCenter is non-null, then this center is returned.

Otherwise, if the plotmark is defined by a paintable, then the original center of that paintable is returned.

Otherwise, a copy of the origin is returned, that is, new XPoint2D().

Specified by:
getOriginalCenter in interface Paintable
Overrides:
getOriginalCenter in class AbstractPaintable
Returns:
a copy of the center of the paint region

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

setPoint

public void setPoint(double x,
                     double y)

Sets the internal point using the given data.

Fires property change: SET_MUTATOR.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point

setPoint

public void setPoint(Point2D p)

Sets the internal point using the given data.

Does nothing if the given point data is null.

Fires property change: SET_MUTATOR.

Parameters:
p - the point whose data will set the internal point

setPoint

public void setPoint(double[] data)

Sets the internal point using the given data.

Does nothing if the given array data is null.

Fires property change: SET_MUTATOR.

Parameters:
data - the array of size 2 with the x,y data

setPoint

public void setPoint(float[] data)

Sets the internal point using the given data.

Does nothing if the given array data is null.

Fires property change: SET_MUTATOR.

Parameters:
data - the array of size 2 with the x,y data

setPlotMark

public void setPlotMark(PlotMark pm)

Sets the internal plotmark using the given data.

Does nothing if the given data is null.

Fires property change: SET_PLOTMARK.

For convenience, if the plotmark happens to be defined by a paintable, then property changes from that internal paintable will be sent to the forwarding listener of the point paintable.

Parameters:
pm - the plotmark to set

setPlotMark

public void setPlotMark(PlotMarkAlgorithm algorithm,
                        int size,
                        boolean fill)

Sets the internal plotmark using the given data to call the corresponding PlotMark constructor.

Does nothing if the given algorithm data is null.

Fires property change: SET_PLOTMARK.

Parameters:
algorithm - the plot mark algorithm
size - the plot mark size setting
fill - the plot mark fill setting

setPlotMark

public void setPlotMark(Paintable paintable)

Sets the internal plotmark using the given data to call the corresponding PlotMark constructor.

Does nothing if the given paintable data is null.

Fires property change: SET_PLOTMARK.

For convenience, if the plotmark happens to be defined by a paintable, then property changes from that internal paintable will be sent to the forwarding listener of the point paintable.

Parameters:
paintable - the paintable to define the internal plotmark

setPaint

public void setPaint(Paint paint)

Sets the paint to the given paint.

Does nothing if the given paint is null.

Fires property change: SET_PAINT.

Parameters:
paint - the paint to set

getPoint

public XPoint2D getPoint()
Returns a copy of the current point of this object.


getPlotMark

public PlotMark getPlotMark()
Returns the current plotmark of this object.


getPaint

public Paint getPaint()
Returns the current paint of this object.


setMutator

public void setMutator(AffineTransform M)

The linear part of the given mutator is ignored and the object mutator is set to the translation portion of the given mutator. At the same time, the point associated with this object is set.

Specified by:
setMutator in interface Paintable
Overrides:
setMutator in class AbstractPaintable
Parameters:
M - the transform whose translation will set the mutator

setMutator

public void setMutator(Mutator.Strategy strategy)
Calls the super method.

Specified by:
setMutator in interface Paintable
Overrides:
setMutator in class AbstractPaintable
Parameters:
strategy - the mutator strategy to apply

makePointPaintableArray

public static PointPaintable[] makePointPaintableArray(Point2D[] points,
                                                       PlotMark pm,
                                                       Paint paint)

Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.

Returns null if the given array of points is null or if any point in the array is null.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set

makePointPaintableArray

public static PointPaintable[] makePointPaintableArray(double[][] points,
                                                       PlotMark pm,
                                                       Paint paint)

Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.

Precondition:

Returns null if the precondition fails.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set

makePointPaintableArray

public static PointPaintable[] makePointPaintableArray(float[][] points,
                                                       PlotMark pm,
                                                       Paint paint)

Factory to make an array of point paintable objects from the given point array data and from the given plotmark and paint.

Precondition:

Returns null if the precondition fails.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set

makePaintableSequence

public static PaintableSequence makePaintableSequence(Point2D[] points,
                                                      PlotMark pm,
                                                      Paint paint)

Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.

Returns null if the given array of points is null or if any point in the array is null.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set

makePaintableSequence

public static PaintableSequence makePaintableSequence(double[][] points,
                                                      PlotMark pm,
                                                      Paint paint)

Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.

Precondition:

Returns null if the precondition fails.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set

makePaintableSequence

public static PaintableSequence makePaintableSequence(float[][] points,
                                                      PlotMark pm,
                                                      Paint paint)

Factory to make a PaintableSequence from the given point array data and from the given plotmark and paint.

Precondition:

Returns null if the precondition fails.

Parameters:
points - the point array data
pm - the plotmark to set
paint - the paint to set