Class ImageFigure

All Implemented Interfaces:
IFigure, IImageFigure

public class ImageFigure extends AbstractImageFigure
A Figure that simply contains an Image. Use this Figure, instead of a Label, when displaying Images without any accompanying text. This figure is not intended to have a layout mananger or children.

Note that it is the client's responsibility to dispose the given image. There is no "free" resource management in draw2d.

  • Constructor Details

    • ImageFigure

      public ImageFigure()
      Constructor
      The default alignment is PositionConstants.CENTER.
    • ImageFigure

      public ImageFigure(Image image)
      Constructor
      The default alignment is PositionConstants.CENTER.
      Parameters:
      image - The Image to be displayed
    • ImageFigure

      public ImageFigure(Image image, int alignment)
      Constructor
      Parameters:
      image - The Image to be displayed
      alignment - A PositionConstant indicating the alignment
      See Also:
  • Method Details

    • getImage

      public Image getImage()
      Description copied from interface: IImageFigure
      Returns the SWT Image contained by the figure
      Returns:
      The Image that this Figure displays
    • getPreferredSize

      public Dimension getPreferredSize(int wHint, int hHint)
      Calculates the necessary size to display the Image within the figure's client area.
      Specified by:
      getPreferredSize in interface IFigure
      Overrides:
      getPreferredSize in class Figure
      Parameters:
      wHint - a width hint
      hHint - a height hint
      Returns:
      The preferred size
      See Also:
    • paintFigure

      protected void paintFigure(Graphics graphics)
      Description copied from class: Figure
      Paints this Figure's primary representation, or background. Changes made to the graphics to the graphics current state will not affect the subsequent calls to Figure.paintClientArea(Graphics) and Figure.paintBorder(Graphics). Furthermore, it is safe to call graphics.restoreState() within this method, and doing so will restore the graphics to its original state upon entry.
      Overrides:
      paintFigure in class Figure
      Parameters:
      graphics - The Graphics used to paint
      See Also:
    • setAlignment

      public void setAlignment(int flag)
      Sets the alignment of the Image within this Figure. The alignment comes into play when the ImageFigure is larger than the Image. The alignment could be any valid combination of the following:
      • PositionConstants.NORTH
      • PositionConstants.SOUTH
      • PositionConstants.EAST
      • PositionConstants.WEST
      • PositionConstants.CENTER or PositionConstants.NONE
      Parameters:
      flag - A constant indicating the alignment
    • setImage

      public void setImage(Image image)
      Sets the Image that this ImageFigure displays.

      IMPORTANT: Note that it is the client's responsibility to dispose the given image.

      Parameters:
      image - The Image to be displayed. It can be null.