megamek.client.ui.AWT.widget
Class BackGroundDrawer

java.lang.Object
  extended by megamek.client.ui.AWT.widget.BackGroundDrawer

public class BackGroundDrawer
extends java.lang.Object

Background drawer is a class which keeps reference to a single Image and draws it according specified rules. For example, we can order to draw image by fully tiling it over all area, or tile it in a single row or column with desired alignment, or draw it just once. Alignment of drawing can be

  • logical (top, bottom, center for vertical alignment and left, right, center for horizontal one)
  • or given by exact number of pixels from top or left borders of area

  • Field Summary
    static int HALIGN_CENTER
              Alignment to the center in case of Vertical or single tiling.
    static int HALIGN_EXACT
              Shift right from left border of area by exact number of pixels.
    static int HALIGN_LEFT
              Alignment to the left in case of Vertical or single tiling.
    static int HALIGN_RIGHT
              Alignment to the right in case of Vertical or single tiling.
    static int NO_TILING
              Single copy of image will be drawn.
    static int TILING_BOTH
              Image will be tiled over all drawing area.
    static int TILING_HORIZONTAL
              Image will be tiled into single row over drawing area.
    static int TILING_VERTICAL
              Image will be tiled into single column over drawing area.
    static int VALIGN_BOTTOM
              Alignment to the bottom in case of Horizontal or single tiling.
    static int VALIGN_CENTER
              Alignment to the centre in case of Horizontal or single tiling.
    static int VALIGN_EXACT
              Shift down from top border of area by exact number of pixels.
    static int VALIGN_TOP
              Alignment to the top in case of Horizontal or single tiling.
     
    Constructor Summary
    BackGroundDrawer(java.awt.Image mainImage)
              Tiling style is set to NO_TILING | VALIGN_CENTER | HALIGN_CENTER.
    BackGroundDrawer(java.awt.Image mainImage, int behavior)
               
     
    Method Summary
     void drawInto(java.awt.Graphics g, int width, int height)
              Draws image into Graphics with custom tiling type and alignment.
     int getBehavior()
              Returns integer describing behavior of BackgroundDrawer
     java.awt.Image getImage()
              Gets image to draw by BackGroundDrawer
     void setHalign(int hAlign)
              Sets horizontal align of tiling
     void setHalignExactAt(int x)
              Sets exact horizontal alignment exactly at "x" pixels
     void setImage(java.awt.Image mainImage)
              Sets image to draw by BackGroundDrawer
     void setTilingType(int type)
              Sets type of tiling.
     void setValign(int vAlign)
              Sets vertical align of tiling
     void setValignExactAt(int y)
              Sets exact vertical alignment exactly at "y" pixels
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    NO_TILING

    public static final int NO_TILING
    Single copy of image will be drawn.

    See Also:
    Constant Field Values

    TILING_VERTICAL

    public static final int TILING_VERTICAL
    Image will be tiled into single column over drawing area.

    See Also:
    Constant Field Values

    TILING_HORIZONTAL

    public static final int TILING_HORIZONTAL
    Image will be tiled into single row over drawing area.

    See Also:
    Constant Field Values

    TILING_BOTH

    public static final int TILING_BOTH
    Image will be tiled over all drawing area.

    See Also:
    Constant Field Values

    VALIGN_TOP

    public static final int VALIGN_TOP
    Alignment to the top in case of Horizontal or single tiling.

    See Also:
    Constant Field Values

    VALIGN_CENTER

    public static final int VALIGN_CENTER
    Alignment to the centre in case of Horizontal or single tiling.

    See Also:
    Constant Field Values

    VALIGN_BOTTOM

    public static final int VALIGN_BOTTOM
    Alignment to the bottom in case of Horizontal or single tiling.

    See Also:
    Constant Field Values

    VALIGN_EXACT

    public static final int VALIGN_EXACT
    Shift down from top border of area by exact number of pixels. (default 0 pixels)

    See Also:
    Constant Field Values

    HALIGN_LEFT

    public static final int HALIGN_LEFT
    Alignment to the left in case of Vertical or single tiling.

    See Also:
    Constant Field Values

    HALIGN_CENTER

    public static final int HALIGN_CENTER
    Alignment to the center in case of Vertical or single tiling.

    See Also:
    Constant Field Values

    HALIGN_RIGHT

    public static final int HALIGN_RIGHT
    Alignment to the right in case of Vertical or single tiling.

    See Also:
    Constant Field Values

    HALIGN_EXACT

    public static final int HALIGN_EXACT
    Shift right from left border of area by exact number of pixels. (default 0 pixels)

    See Also:
    Constant Field Values
    Constructor Detail

    BackGroundDrawer

    public BackGroundDrawer(java.awt.Image mainImage,
                            int behavior)
    Parameters:
    mainImage - image to draw by BackGroundDrawer.
    behavior - Integer value specifying way of tiling and alignment. For exapmple: BackGroundDrawer(myImage, BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_RIGHT);

    BackGroundDrawer

    public BackGroundDrawer(java.awt.Image mainImage)
    Tiling style is set to NO_TILING | VALIGN_CENTER | HALIGN_CENTER.

    Parameters:
    mainImage - image to draw by BackGroundDrawer.
    Method Detail

    setImage

    public void setImage(java.awt.Image mainImage)
    Sets image to draw by BackGroundDrawer


    getImage

    public java.awt.Image getImage()
    Gets image to draw by BackGroundDrawer


    setTilingType

    public void setTilingType(int type)
    Sets type of tiling.

    Parameters:
    type - Possible values: NO_TILING, TILING_BOTH, TILING_VERTICAL, TILING_HORIZONTAL.

    setValign

    public void setValign(int vAlign)
    Sets vertical align of tiling

    Parameters:
    type - Must be VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM

    setHalign

    public void setHalign(int hAlign)
    Sets horizontal align of tiling

    Parameters:
    type - Must be HALIGN_LEFT, HALIGN_CENTER, HALIGN_RIGHT

    setValignExactAt

    public void setValignExactAt(int y)
    Sets exact vertical alignment exactly at "y" pixels


    setHalignExactAt

    public void setHalignExactAt(int x)
    Sets exact horizontal alignment exactly at "x" pixels


    getBehavior

    public int getBehavior()
    Returns integer describing behavior of BackgroundDrawer


    drawInto

    public void drawInto(java.awt.Graphics g,
                         int width,
                         int height)
    Draws image into Graphics with custom tiling type and alignment.

    Parameters:
    g - Graphics to which draw to.
    width - Width of the drawing area.
    height - Height of the drawing area.