edu.neu.ccs.gui
Class PaintableTools

java.lang.Object
  extended byedu.neu.ccs.gui.PaintableTools

public class PaintableTools
extends Object

The class PaintableTools collects static methods that construct objects of other types from Paintable objects.

Class PaintableTools cannot be instantiated.

In 2.3.5, the class was refactored to be consistent with the new Paintable interface and the new AbstractPaintable class.

In 2.6.0c, adjusted makeBufferedImage to ensure that the constructed image is at least 1-by-1 (unless the given paintable is null in which case the method continues to return null).

Since:
2.3
Version:
2.6.0c

Constructor Summary
private PaintableTools()
          Private constructor to prevent instantiation.
 
Method Summary
static BufferedImage makeBufferedImage(Paintable paintable)
          Constructs a BufferedImage object that is the same size as the bounding box of the given paintable and then paints the given paintable onto the buffered image with a suitable translation back to the origin.
static JButton makeButton(Paintable paintable)
          Returns a JButton using the given Paintable to construct the button icon, no specified action for the button behavior, the Java default background color, and insets of 2, 2, 2, 2.
static JButton makeButton(Paintable paintable, Action action)
          Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the Java default background color, and insets of 2, 2, 2, 2.
static JButton makeButton(Paintable paintable, Action action, Color color)
          Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the given background color, and insets of 2, 2, 2, 2.
static JButton makeButton(Paintable paintable, Action action, Color color, Insets insets)
          Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the given background color, and the given insets.
static JPTComponent makeComponent(Paintable paintable)
          Returns a JPTComponent using the given Paintable to define its location and paint behavior.
static JPTComponent makeComponent(Paintable paintable, Color color)
          Returns a JPTComponent using the given Paintable to define its location and paint behavior and the optional background color.
static JPTComponent makeComponent(Paintable paintable, Color color, boolean opaque)
          Returns a JPTComponent using the given Paintable to define its location and paint behavior, the optional background color, and the opacity setting.
static JPTComponent makeComponent(Paintable paintable, Color color, boolean opaque, Border border)
          Returns a JPTComponent using the given Paintable to define its location and paint behavior, the optional background color, the opacity setting, and the component border.
static Icon makeIcon(Paintable paintable)
          Returns an Icon constructed using the paint operation and bounds of the given Paintable object.
static TexturePaint makeTexturePaint(Paintable paintable)
          Returns a TexturePaint whose BufferedImage is constructed using the method makeBufferedImage and whose anchor rectangle is the bounds rectangle of the given paintable.
static Paintable wrapPaintable(Paintable object)
          Returns a Paintable that wraps the given object in a Tile object if needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaintableTools

private PaintableTools()
Private constructor to prevent instantiation.

Method Detail

wrapPaintable

public static Paintable wrapPaintable(Paintable object)

Returns a Paintable that wraps the given object in a Tile object if needed.

If the given object is non-null, then it is returned as is.

If the given object is null, it is wrapped in a Tile.

Since 2.3.5, the code is basically trivial but it does avoid breaking certain existing code.

Parameters:
object - the object to wrap as a paintable
Returns:
the associated paintable

makeIcon

public static Icon makeIcon(Paintable paintable)

Returns an Icon constructed using the paint operation and bounds of the given Paintable object.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableComponent, viewed as an Icon, or null.

Parameters:
paintable - the paintable used in the construction
Returns:
the Icon constructed from the paintable
See Also:
makeButton(Paintable, Action), makeButton(Paintable, Action, Color)

makeBufferedImage

public static BufferedImage makeBufferedImage(Paintable paintable)

Constructs a BufferedImage object that is the same size as the bounding box of the given paintable and then paints the given paintable onto the buffered image with a suitable translation back to the origin.

This method creates a snapshot of the current visual state of the given paintable.

The BufferedImage returned will have size at least 1-by-1 even if the given paintable has 0 width or height.

If the given paintable is null, then returns null.

Parameters:
paintable - the paintable used in the construction
Returns:
the BufferedImage constructed from the paintable
See Also:
makeTexturePaint(Paintable)

makeTexturePaint

public static TexturePaint makeTexturePaint(Paintable paintable)

Returns a TexturePaint whose BufferedImage is constructed using the method makeBufferedImage and whose anchor rectangle is the bounds rectangle of the given paintable.

If the given paintable is null, then returns null.

Parameters:
paintable - the paintable used in the construction
Returns:
the TexturePaint constructed from the paintable
See Also:
makeBufferedImage(Paintable)

makeButton

public static JButton makeButton(Paintable paintable)

Returns a JButton using the given Paintable to construct the button icon, no specified action for the button behavior, the Java default background color, and insets of 2, 2, 2, 2.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableButton or null.

Parameters:
paintable - the paintable that defines the button
Returns:
the button constructed from the paintable
See Also:
makeIcon(Paintable), makeButton(Paintable, Action), makeButton(Paintable, Action, Color), makeButton(Paintable, Action, Color, Insets)

makeButton

public static JButton makeButton(Paintable paintable,
                                 Action action)

Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the Java default background color, and insets of 2, 2, 2, 2.

The action is used only to supply behavior not to set the button icon or text.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableButton or null.

Parameters:
paintable - the paintable that defines the button
action - the action to define the button behavior
Returns:
the button constructed from the paintable
See Also:
makeIcon(Paintable), makeButton(Paintable), makeButton(Paintable, Action, Color), makeButton(Paintable, Action, Color, Insets)

makeButton

public static JButton makeButton(Paintable paintable,
                                 Action action,
                                 Color color)

Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the given background color, and insets of 2, 2, 2, 2.

The action is used only to supply behavior not to set the button icon or text.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableButton or null.

Parameters:
paintable - the paintable that defines the button
action - the action to define the button behavior
color - the button background color
Returns:
the button constructed from the paintable
See Also:
makeIcon(Paintable), makeButton(Paintable), makeButton(Paintable, Action), makeButton(Paintable, Action, Color, Insets)

makeButton

public static JButton makeButton(Paintable paintable,
                                 Action action,
                                 Color color,
                                 Insets insets)

Returns a JButton using the given Paintable to construct the button icon, the given Action for the button behavior, the given background color, and the given insets.

The action is used only to supply behavior not to set the button icon or text.

If the given insets is null, then the insets are set to 2, 2, 2, 2.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableButton or null.

Parameters:
paintable - the paintable that defines the button
action - the action to define the button behavior
color - the button background color
insets - the button insets
Returns:
the button constructed from the paintable
See Also:
makeIcon(Paintable), makeButton(Paintable), makeButton(Paintable, Action), makeButton(Paintable, Action, Color)

makeComponent

public static JPTComponent makeComponent(Paintable paintable)

Returns a JPTComponent using the given Paintable to define its location and paint behavior.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableComponent or null.

Parameters:
paintable - the paintable to encapsulate
Returns:
the component constructed from the paintable
See Also:
makeComponent(Paintable, Color), makeComponent(Paintable, Color, boolean), makeComponent(Paintable, Color, boolean, Border)

makeComponent

public static JPTComponent makeComponent(Paintable paintable,
                                         Color color)

Returns a JPTComponent using the given Paintable to define its location and paint behavior and the optional background color.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableComponent or null.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
Returns:
the component constructed from the paintable
See Also:
makeComponent(Paintable), makeComponent(Paintable, Color, boolean), makeComponent(Paintable, Color, boolean, Border)

makeComponent

public static JPTComponent makeComponent(Paintable paintable,
                                         Color color,
                                         boolean opaque)

Returns a JPTComponent using the given Paintable to define its location and paint behavior, the optional background color, and the opacity setting.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableComponent or null.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
opaque - whether or not to paint the component background
Returns:
the component constructed from the paintable
See Also:
makeComponent(Paintable), makeComponent(Paintable, Color), makeComponent(Paintable, Color, boolean, Border)

makeComponent

public static JPTComponent makeComponent(Paintable paintable,
                                         Color color,
                                         boolean opaque,
                                         Border border)

Returns a JPTComponent using the given Paintable to define its location and paint behavior, the optional background color, the opacity setting, and the component border.

If the given paintable is null, then returns null.

As of 2.3.2, this method returns a PaintableComponent or null.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
opaque - whether or not to paint the component background
border - the border for the component
Returns:
the component constructed from the paintable
See Also:
makeComponent(Paintable), makeComponent(Paintable, Color), makeComponent(Paintable, Color, boolean)