Class FigureCanvas

All Implemented Interfaces:
Drawable
Direct Known Subclasses:
MultiLineLabel

public class FigureCanvas extends Canvas
A scrolling Canvas that contains Figures viewed through a Viewport. Call setContents(IFigure) to specify the root of the tree of Figures to be viewed through the Viewport.

Normal procedure for using a FigureCanvas:

  1. Create a FigureCanvas.
  2. Create a Draw2d Figure and call setContents(IFigure). This Figure will be the top-level Figure of the Draw2d application.
Required Styles (when using certain constructors):
V_SCROLL, H_SCROLL, NO_REDRAW_RESIZE
Optional Styles:
DOUBLE_BUFFERED, RIGHT_TO_LEFT, LEFT_TO_RIGHT, NO_BACKGROUND, BORDER

Note: Only one of the styles RIGHT_TO_LEFT, LEFT_TO_RIGHT may be specified.

  • Field Details

    • NEVER

      public static int NEVER
      Never show scrollbar
    • AUTOMATIC

      public static int AUTOMATIC
      Automatically show scrollbar when needed
    • ALWAYS

      public static int ALWAYS
      Always show scrollbar
  • Constructor Details

    • FigureCanvas

      public FigureCanvas(Composite parent)
      Creates a new FigureCanvas with the given parent and the DEFAULT_STYLES.
      Parameters:
      parent - the parent
    • FigureCanvas

      public FigureCanvas(Composite parent, int style)
      Constructor which applies the default styles plus any optional styles indicated.
      Parameters:
      parent - the parent composite
      style - see the class javadoc for optional styles
      Since:
      3.1
    • FigureCanvas

      public FigureCanvas(int style, Composite parent)
      Constructor which uses the given styles verbatim. Certain styles must be used with this class. Refer to the class javadoc for more details.
      Parameters:
      style - see the class javadoc for required and optional styles
      parent - the parent composite
      Since:
      3.4
    • FigureCanvas

      public FigureCanvas(Composite parent, LightweightSystem lws)
      Constructs a new FigureCanvas with the given parent and LightweightSystem, using the DEFAULT_STYLES.
      Parameters:
      parent - the parent
      lws - the LightweightSystem
    • FigureCanvas

      public FigureCanvas(int style, Composite parent, LightweightSystem lws)
      Constructor taking a lightweight system and SWT style, which is used verbatim. Certain styles must be used with this class. Refer to the class javadoc for more details.
      Parameters:
      style - see the class javadoc for required and optional styles
      parent - the parent composite
      lws - the LightweightSystem
      Since:
      3.4
    • FigureCanvas

      public FigureCanvas(Composite parent, int style, LightweightSystem lws)
      Constructor
      Parameters:
      parent - the parent composite
      style - look at class javadoc for valid styles
      lws - the lightweight system
      Since:
      3.1
  • Method Details

    • computeSize

      public Point computeSize(int wHint, int hHint, boolean changed)
      Overrides:
      computeSize in class Composite
      See Also:
    • getContents

      public IFigure getContents()
      Returns:
      the contents of the Viewport.
    • getFont

      public Font getFont()
      Overrides:
      getFont in class Control
      See Also:
    • getHorizontalScrollBarVisibility

      public int getHorizontalScrollBarVisibility()
      Returns:
      the horizontal scrollbar visibility.
    • getLightweightSystem

      public LightweightSystem getLightweightSystem()
      Returns:
      the LightweightSystem
    • getVerticalScrollBarVisibility

      public int getVerticalScrollBarVisibility()
      Returns:
      the vertical scrollbar visibility.
    • getViewport

      public Viewport getViewport()
      Returns the Viewport. If it's null, a new one is created.
      Returns:
      the viewport
    • scrollSmoothTo

      public void scrollSmoothTo(int x, int y)
      Scrolls in an animated way to the new x and y location.
      Parameters:
      x - the x coordinate to scroll to
      y - the y coordinate to scroll to
    • scrollTo

      public void scrollTo(int x, int y)
      Scrolls the contents to the new x and y location. If this scroll operation only consists of a vertical or horizontal scroll, a call will be made to scrollToY(int) or scrollToX(int), respectively, to increase performance.
      Parameters:
      x - the x coordinate to scroll to
      y - the y coordinate to scroll to
    • scrollToX

      public void scrollToX(int hOffset)
      Scrolls the contents horizontally so that they are offset by hOffset.
      Parameters:
      hOffset - the new horizontal offset
    • scrollToY

      public void scrollToY(int vOffset)
      Scrolls the contents vertically so that they are offset by vOffset.
      Parameters:
      vOffset - the new vertical offset
    • setBorder

      public void setBorder(Border border)
      Sets the given border on the LightweightSystem's root figure.
      Parameters:
      border - The new border
    • setContents

      public void setContents(IFigure figure)
      Sets the contents of the Viewport.
      Parameters:
      figure - the new contents
    • setFont

      public void setFont(Font font)
      Overrides:
      setFont in class Canvas
      See Also:
    • setHorizontalScrollBarVisibility

      public void setHorizontalScrollBarVisibility(int v)
      Sets the horizontal scrollbar visibility. Possible values are AUTOMATIC, ALWAYS, and NEVER.
      Parameters:
      v - the new visibility
    • setScrollBarVisibility

      public void setScrollBarVisibility(int both)
      Sets both the horizontal and vertical scrollbar visibility to the given value. Possible values are AUTOMATIC, ALWAYS, and NEVER.
      Parameters:
      both - the new visibility
    • setVerticalScrollBarVisibility

      public void setVerticalScrollBarVisibility(int v)
      Sets the vertical scrollbar visibility. Possible values are AUTOMATIC, ALWAYS, and NEVER.
      Parameters:
      v - the new visibility
    • setViewport

      public void setViewport(Viewport vp)
      Sets the Viewport. The given Viewport must use "fake" scrolling. That is, it must be constructed using new Viewport(true).
      Parameters:
      vp - the new viewport