Class GraphicsUtils


  • public final class GraphicsUtils
    extends Object
    This class contains utility methods for drawing graphics
    See Also:
    GC snippets
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.eclipse.swt.graphics.Image createRotatedImage​(org.eclipse.swt.graphics.Image image, int style)
      Creates a rotated image (plus or minus 90 degrees) Styles: UP, DOWN
      static org.eclipse.swt.graphics.Image createRotatedText​(String text, org.eclipse.swt.graphics.Font font, org.eclipse.swt.graphics.Color foreground, org.eclipse.swt.graphics.Color background, int style)
      Creates an image containing the specified text, rotated either plus or minus 90 degrees.
      static void drawLineHorizontal​(org.eclipse.swt.graphics.GC gc, int x, int y, int width)
      Draws a horizontal line starting at (x, y) and having the given width.
      static void drawLineHorizontal​(org.eclipse.swt.graphics.GC gc, int x, int y, int width, boolean drawLeftCorner, boolean drawRightCorner)
      The difference between this method and drawLineHorizontal(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g.
      static void drawLineHorizontalBorderBottom​(org.eclipse.swt.graphics.GC gc, int x, int y, int width)
      Draws a horizontal line starting at (x, y) and having the given width.
      static void drawLineHorizontalBorderBottom​(org.eclipse.swt.graphics.GC gc, int x, int y, int width, boolean drawLeftCorner, boolean drawRightCorner)
      The difference between this method and drawLineHorizontalBorderBottom(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g.
      static void drawLineHorizontalBorderTop​(org.eclipse.swt.graphics.GC gc, int x, int y, int width)
      Draws a horizontal line starting at (x, y) and having the given width.
      static void drawLineHorizontalBorderTop​(org.eclipse.swt.graphics.GC gc, int x, int y, int width, boolean drawLeftCorner, boolean drawRightCorner)
      The difference between this method and drawLineHorizontalBorderTop(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g.
      static void drawLineVertical​(org.eclipse.swt.graphics.GC gc, int x, int y, int height)
      Draws a vertical line starting at (x, y) and having the given height.
      static void drawLineVertical​(org.eclipse.swt.graphics.GC gc, int x, int y, int height, boolean drawTopCorner, boolean drawBottomCorner)
      The difference between this method and drawLineVertical(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g.
      static void drawLineVerticalBorderLeft​(org.eclipse.swt.graphics.GC gc, int x, int y, int height)
      Draws a vertical line starting at (x, y) and having the given height.
      static void drawLineVerticalBorderLeft​(org.eclipse.swt.graphics.GC gc, int x, int y, int height, boolean drawTopCorner, boolean drawBottomCorner)
      The difference between this method and drawLineVerticalBorderLeft(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g.
      static void drawLineVerticalBorderRight​(org.eclipse.swt.graphics.GC gc, int x, int y, int height)
      Draws a vertical line starting at (x, y) and having the given height.
      static void drawLineVerticalBorderRight​(org.eclipse.swt.graphics.GC gc, int x, int y, int height, boolean drawTopCorner, boolean drawBottomCorner)
      The difference between this method and drawLineVerticalBorderRight(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g.
      static void drawRectangle​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect)
      Draws a rectangle.
      static void drawRectangle​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect, BorderStyle borderStyle)
      Draws a rectangle with the given border style.
      static void drawRectangleBorderExternal​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect)
      Draws a rectangle.
      static void drawRectangleBorderInternal​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect)
      Draws a rectangle.
      static void drawVerticalImage​(org.eclipse.swt.graphics.Image image, int x, int y, boolean paintBackground, org.eclipse.swt.graphics.GC gc, int style)
      Draws an image vertically (rotates plus or minus 90 degrees) Styles: UP, DOWN
      static void drawVerticalImage​(org.eclipse.swt.graphics.Image image, int x, int y, org.eclipse.swt.graphics.GC gc, int style)
      Draws an image vertically (rotates plus or minus 90 degrees) Styles: UP, DOWN
      static void drawVerticalText​(String string, int x, int y, boolean underline, boolean strikethrough, boolean paintBackground, org.eclipse.swt.graphics.GC gc, int style)
      Draws text vertically (rotates plus or minus 90 degrees).
      static void drawVerticalText​(String string, int x, int y, org.eclipse.swt.graphics.GC gc, int style)
      Draws text vertically (rotates plus or minus 90 degrees).
      static void fillRectangle​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect)
      Draws a filled rectangle.
      static org.eclipse.swt.graphics.Rectangle getResultingExternalBounds​(org.eclipse.swt.graphics.Rectangle rectangle, BorderStyle borderStyle)
      Returns the external bounds of the rectangle that would be obtained by painting rectangle with borderStyle using one of the GraphicsUtils.drawRectangle... methods.
    • Method Detail

      • drawVerticalText

        public static void drawVerticalText​(String string,
                                            int x,
                                            int y,
                                            org.eclipse.swt.graphics.GC gc,
                                            int style)
        Draws text vertically (rotates plus or minus 90 degrees). Uses the current font, color, and background.
        Styles:
        UP, DOWN
        Parameters:
        string - the text to draw
        x - the x coordinate of the top left corner of the drawing rectangle
        y - the y coordinate of the top left corner of the drawing rectangle
        gc - the GC on which to draw the text
        style - the style (SWT.UP or SWT.DOWN)

        Note: Only one of the style UP or DOWN may be specified.

      • drawVerticalText

        public static void drawVerticalText​(String string,
                                            int x,
                                            int y,
                                            boolean underline,
                                            boolean strikethrough,
                                            boolean paintBackground,
                                            org.eclipse.swt.graphics.GC gc,
                                            int style)
        Draws text vertically (rotates plus or minus 90 degrees). Uses the current font, color, and background.
        Styles:
        UP, DOWN
        Parameters:
        string - the text to draw
        x - the x coordinate of the top left corner of the drawing rectangle
        y - the y coordinate of the top left corner of the drawing rectangle
        underline - set to true to render the text underlined
        strikethrough - set to true to render the text strikethrough
        paintBackground - set to false to render the background transparent. Needed for example to render the background with an image or gradient with another painter so the text drawn here should have no background.
        gc - the GC on which to draw the text
        style - the style (SWT.UP or SWT.DOWN)

        Note: Only one of the style UP or DOWN may be specified.

      • drawVerticalImage

        public static void drawVerticalImage​(org.eclipse.swt.graphics.Image image,
                                             int x,
                                             int y,
                                             org.eclipse.swt.graphics.GC gc,
                                             int style)
        Draws an image vertically (rotates plus or minus 90 degrees)
        Styles:
        UP, DOWN
        Parameters:
        image - the image to draw
        x - the x coordinate of the top left corner of the drawing rectangle
        y - the y coordinate of the top left corner of the drawing rectangle
        gc - the GC on which to draw the image
        style - the style (SWT.UP or SWT.DOWN)

        Note: Only one of the style UP or DOWN may be specified.

      • drawVerticalImage

        public static void drawVerticalImage​(org.eclipse.swt.graphics.Image image,
                                             int x,
                                             int y,
                                             boolean paintBackground,
                                             org.eclipse.swt.graphics.GC gc,
                                             int style)
        Draws an image vertically (rotates plus or minus 90 degrees)
        Styles:
        UP, DOWN
        Parameters:
        image - the image to draw
        x - the x coordinate of the top left corner of the drawing rectangle
        y - the y coordinate of the top left corner of the drawing rectangle
        paintBackground - set to false to render the background transparent. Needed for example to render the background with an image or gradient with another painter so the text drawn here should have no background.
        gc - the GC on which to draw the image
        style - the style (SWT.UP or SWT.DOWN)

        Note: Only one of the style UP or DOWN may be specified.

      • createRotatedText

        public static org.eclipse.swt.graphics.Image createRotatedText​(String text,
                                                                       org.eclipse.swt.graphics.Font font,
                                                                       org.eclipse.swt.graphics.Color foreground,
                                                                       org.eclipse.swt.graphics.Color background,
                                                                       int style)
        Creates an image containing the specified text, rotated either plus or minus 90 degrees.
        Styles:
        UP, DOWN
        Parameters:
        text - the text to rotate
        font - the font to use
        foreground - the color for the text
        background - the background color
        style - direction to rotate (up or down)
        Returns:
        Image

        Note: Only one of the style UP or DOWN may be specified.

      • createRotatedImage

        public static org.eclipse.swt.graphics.Image createRotatedImage​(org.eclipse.swt.graphics.Image image,
                                                                        int style)
        Creates a rotated image (plus or minus 90 degrees)
        Styles:
        UP, DOWN
        Parameters:
        image - the image to rotate
        style - direction to rotate (up or down)
        Returns:
        Image

        Note: Only one of the style UP or DOWN may be specified.

      • drawLineHorizontal

        public static void drawLineHorizontal​(org.eclipse.swt.graphics.GC gc,
                                              int x,
                                              int y,
                                              int width,
                                              boolean drawLeftCorner,
                                              boolean drawRightCorner)
        The difference between this method and drawLineHorizontal(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        width - the width of the line to draw
        drawLeftCorner - to draw the left corner
        drawRightCorner - to draw the right corner
        Since:
        1.5
        See Also:
        drawLineHorizontal(GC, int, int, int)
      • drawLineVertical

        public static void drawLineVertical​(org.eclipse.swt.graphics.GC gc,
                                            int x,
                                            int y,
                                            int height,
                                            boolean drawTopCorner,
                                            boolean drawBottomCorner)
        The difference between this method and drawLineVertical(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        height - the height of the line to draw
        drawTopCorner - to draw the top corner
        drawBottomCorner - to draw the bottom corner
        Since:
        1.5
        See Also:
        drawLineVertical(GC, int, int, int)
      • drawLineHorizontalBorderBottom

        public static void drawLineHorizontalBorderBottom​(org.eclipse.swt.graphics.GC gc,
                                                          int x,
                                                          int y,
                                                          int width)
        Draws a horizontal line starting at (x, y) and having the given width. The increased thickness resulting from GC.getLineWidth() will be strictly drawn below the line.

        Unlike GC.drawLine(int, int, int, int), this method guarantees that the line will always start at the given coordinates and will always have the given width.

        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        width - the width of the line to draw
        Since:
        1.5
        See Also:
        drawLineHorizontal(GC, int, int, int), drawLineHorizontalBorderTop(GC, int, int, int), drawLineHorizontalBorderBottom(GC, int, int, int, boolean, boolean)
      • drawLineHorizontalBorderBottom

        public static void drawLineHorizontalBorderBottom​(org.eclipse.swt.graphics.GC gc,
                                                          int x,
                                                          int y,
                                                          int width,
                                                          boolean drawLeftCorner,
                                                          boolean drawRightCorner)
        The difference between this method and drawLineHorizontalBorderBottom(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        width - the width of the line to draw
        drawLeftCorner - to draw the left corner
        drawRightCorner - to draw the right corner
        Since:
        1.5
        See Also:
        drawLineHorizontalBorderBottom(GC, int, int, int)
      • drawLineHorizontalBorderTop

        public static void drawLineHorizontalBorderTop​(org.eclipse.swt.graphics.GC gc,
                                                       int x,
                                                       int y,
                                                       int width)
        Draws a horizontal line starting at (x, y) and having the given width. The increased thickness resulting from GC.getLineWidth() will be strictly drawn above the line.

        Unlike GC.drawLine(int, int, int, int), this method guarantees that the line will always start at the given coordinates and will always have the given width.

        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        width - the width of the line to draw
        Since:
        1.5
        See Also:
        drawLineHorizontal(GC, int, int, int), drawLineHorizontalBorderBottom(GC, int, int, int), drawLineHorizontalBorderTop(GC, int, int, int, boolean, boolean)
      • drawLineHorizontalBorderTop

        public static void drawLineHorizontalBorderTop​(org.eclipse.swt.graphics.GC gc,
                                                       int x,
                                                       int y,
                                                       int width,
                                                       boolean drawLeftCorner,
                                                       boolean drawRightCorner)
        The difference between this method and drawLineHorizontalBorderTop(GC, int, int, int) is that the line could be extended to draw left and/or right corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        width - the width of the line to draw
        drawLeftCorner - to draw the left corner
        drawRightCorner - to draw the right corner
        Since:
        1.5
        See Also:
        drawLineHorizontalBorderTop(GC, int, int, int)
      • drawLineVerticalBorderRight

        public static void drawLineVerticalBorderRight​(org.eclipse.swt.graphics.GC gc,
                                                       int x,
                                                       int y,
                                                       int height)
        Draws a vertical line starting at (x, y) and having the given height. The increased thickness resulting from GC.getLineWidth() will be strictly drawn to the right of the line.

        Unlike GC.drawLine(int, int, int, int), this method guarantees that the line will always start at the given coordinates and will always have the given height.

        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        height - the height of the line to draw
        Since:
        1.5
        See Also:
        drawLineVertical(GC, int, int, int), drawLineVerticalBorderLeft(GC, int, int, int), drawLineVerticalBorderRight(GC, int, int, int, boolean, boolean)
      • drawLineVerticalBorderRight

        public static void drawLineVerticalBorderRight​(org.eclipse.swt.graphics.GC gc,
                                                       int x,
                                                       int y,
                                                       int height,
                                                       boolean drawTopCorner,
                                                       boolean drawBottomCorner)
        The difference between this method and drawLineVerticalBorderRight(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        height - the height of the line to draw
        drawTopCorner - to draw the top corner
        drawBottomCorner - to draw the bottom corner
        Since:
        1.5
        See Also:
        drawLineVerticalBorderRight(GC, int, int, int)
      • drawLineVerticalBorderLeft

        public static void drawLineVerticalBorderLeft​(org.eclipse.swt.graphics.GC gc,
                                                      int x,
                                                      int y,
                                                      int height)
        Draws a vertical line starting at (x, y) and having the given height. The increased thickness resulting from GC.getLineWidth() will be strictly drawn to the left of the line.

        Unlike GC.drawLine(int, int, int, int), this method guarantees that the line will always start at the given coordinates and will always have the given height.

        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        height - the height of the line to draw
        Since:
        1.5
        See Also:
        drawLineVertical(GC, int, int, int), drawLineVerticalBorderRight(GC, int, int, int), drawLineVerticalBorderLeft(GC, int, int, int, boolean, boolean)
      • drawLineVerticalBorderLeft

        public static void drawLineVerticalBorderLeft​(org.eclipse.swt.graphics.GC gc,
                                                      int x,
                                                      int y,
                                                      int height,
                                                      boolean drawTopCorner,
                                                      boolean drawBottomCorner)
        The difference between this method and drawLineVerticalBorderLeft(GC, int, int, int) is that the line could be extended to draw top and/or bottom corners (e.g. the corners of a rectangle).
        Parameters:
        gc - the GC to use to draw
        x - the starting point's x coordinate
        y - the starting point's y coordinate
        height - the height of the line to draw
        drawTopCorner - to draw the top corner
        drawBottomCorner - to draw the bottom corner
        Since:
        1.5
        See Also:
        drawLineVerticalBorderLeft(GC, int, int, int)
      • fillRectangle

        public static void fillRectangle​(org.eclipse.swt.graphics.GC gc,
                                         org.eclipse.swt.graphics.Rectangle rect)
        Draws a filled rectangle.

        Unlike GC.fillRectangle(Rectangle), this method guarantees that the rectangle will always start at the given coordinates even in case of negative width/height.

        Parameters:
        gc - the GC to use to draw
        rect - the rectangle to draw
        Since:
        1.5
      • drawRectangle

        public static void drawRectangle​(org.eclipse.swt.graphics.GC gc,
                                         org.eclipse.swt.graphics.Rectangle rect,
                                         BorderStyle borderStyle)
        Draws a rectangle with the given border style.

        Unlike GC.drawRectangle(Rectangle):

        • the width and height of the resulting rectangle will be always exactly rect.width and rect.height
        • the rectangle will always start at the given coordinates even in case of negative width/height
        Parameters:
        gc - the GC to use to draw
        rect - the rectangle to draw
        borderStyle - the border style of the rectangle
        Since:
        1.5
      • drawRectangleBorderInternal

        public static void drawRectangleBorderInternal​(org.eclipse.swt.graphics.GC gc,
                                                       org.eclipse.swt.graphics.Rectangle rect)
        Draws a rectangle. The increased border thickness resulting from GC.getLineWidth() will be strictly drawn inside of the rectangle.

        Unlike GC.drawRectangle(Rectangle):

        • the width and height of the resulting rectangle will be always exactly rect.width and rect.height
        • the rectangle will always start at the given coordinates even in case of negative width/height
        Parameters:
        gc - the GC to use to draw
        rect - the rectangle to draw
        Since:
        1.5
        See Also:
        drawRectangle(GC, Rectangle), drawRectangleBorderExternal(org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle)
      • drawRectangleBorderExternal

        public static void drawRectangleBorderExternal​(org.eclipse.swt.graphics.GC gc,
                                                       org.eclipse.swt.graphics.Rectangle rect)
        Draws a rectangle. The increased border thickness resulting from GC.getLineWidth() will be strictly drawn outside of the rectangle.

        Unlike GC.drawRectangle(Rectangle):

        • the width and height of the resulting rectangle will be always exactly rect.width and rect.height
        • the rectangle will always start at the given coordinates even in case of negative width/height
        Parameters:
        gc - the GC to use to draw
        rect - the rectangle to draw
        Since:
        1.5
        See Also:
        drawRectangle(GC, Rectangle), drawRectangleBorderInternal(org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle)
      • getResultingExternalBounds

        public static org.eclipse.swt.graphics.Rectangle getResultingExternalBounds​(org.eclipse.swt.graphics.Rectangle rectangle,
                                                                                    BorderStyle borderStyle)
        Returns the external bounds of the rectangle that would be obtained by painting rectangle with borderStyle using one of the GraphicsUtils.drawRectangle... methods.
        Parameters:
        rectangle - the rectangle to consider
        borderStyle - the border style to consider
        Returns:
        the external bounds of what would be the resulting rectangle
        Since:
        1.5