edu.neu.ccs.gui
Interface Paintable

All Known Subinterfaces:
MutatablePaintable
All Known Implementing Classes:
AbstractMutatablePaintable, AbstractPaintable, PaintableSequenceComposite

public interface Paintable

Paintable describes an object that can paint onto a graphics context.

Since:
2.3

Method Summary
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the paintable.
 boolean contains(Point2D p)
          Tests if a specified point is inside the paintable.
 Rectangle2D getBounds2D()
          Returns a copy of the 2-dimensional bounds of the paint region affected by the paint method.
 Point2D getCenter()
          Returns a copy of the center of the paint region affected by the paint method.
 float getOpacity()
          Returns the opacity value of this paintable between 0 and 1.
 Graphics2D getPreparedGraphics2D(Graphics g)
          Returns a copy of the given graphics context after modifying the copy to set anti-aliasing on, to clip to within the bounds region, and to apply the opacity of the paintable if needed.
 boolean isVisible()
          Returns the current visibility property of this paintable.
 void paint(Graphics g)
          Paints onto a Graphics context g using information from this object provided that the visibility property of the object is set to true.
 void setOpacity(float opacity)
          Sets the opacity value of this paintable between 0 and 1.
 void setVisible(boolean visible)
          Sets the visibility property of this paintable.
 

Method Detail

paint

public void paint(Graphics g)

Paints onto a Graphics context g using information from this object provided that the visibility property of the object is set to true.

After this method call is complete, the internal state of g should be unchanged. In addition, this method should not paint outside of the region returned by getBounds2D.

Implementation recommendation:

To achieve the above goals, it is recommended that the graphics context g be copied to a new graphics context h and that the clip region of h be intersected with the Bounds2D rectangle. This may be done directly or may be achieved in one step by using the method getPreparedGraphics2D which also takes care of other issues.

Parameters:
g - the graphics context on which to paint

getBounds2D

public Rectangle2D getBounds2D()
Returns a copy of the 2-dimensional bounds of the paint region affected by the paint method.

Returns:
a copy of the 2-dimensional bounds of the paint region

getCenter

public Point2D getCenter()

Returns a copy of the center of the paint region affected by the paint method.

By default, this method may be implemented to return the center of the rectangle returned by getBounds2D(). However, a different result is permitted if the object geometry so dictates.

Returns:
a copy of the center of the paint region

contains

public boolean contains(double x,
                        double y)

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

This method must return false if one or more of the following conditions occurs:

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 paintable

contains

public boolean contains(Point2D p)

Tests if a specified point is inside the paintable.

This method must return false if one or more of the following conditions occurs:

Parameters:
p - a specified Point2D
Returns:
whether or not a specified point is inside the paintable

setVisible

public void setVisible(boolean visible)

Sets the visibility property of this paintable.

The default for the visibility property should be true

.

Parameters:
visible - the visibility setting
See Also:
isVisible()

isVisible

public boolean isVisible()
Returns the current visibility property of this paintable.

See Also:
setVisible(boolean)

setOpacity

public void setOpacity(float opacity)
Sets the opacity value of this paintable between 0 and 1.

Parameters:
opacity - the opacity value of this paintable between 0 and 1
See Also:
getOpacity()

getOpacity

public float getOpacity()
Returns the opacity value of this paintable between 0 and 1.

Returns:
the opacity value of this paintable between 0 and 1
See Also:
setOpacity(float)

getPreparedGraphics2D

public Graphics2D getPreparedGraphics2D(Graphics g)

Returns a copy of the given graphics context after modifying the copy to set anti-aliasing on, to clip to within the bounds region, and to apply the opacity of the paintable if needed.

For convenience, return the graphics context as a Graphics2D object.

Parameters:
g - the given graphics context to copy
Returns:
a suitably prepared copy of the given graphics context