Class JLabelBox

java.lang.Object
org.sm.smtools.swing.util.JLabelBox

public final class JLabelBox extends Object
The JLabelBox class provides static methodes for drawing labels in boxes.

Note that this class cannot be subclassed!

Version:
08/03/2020
Author:
Sven Maerivoet
  • Field Details

    • kViewportOffset

      public static final int kViewportOffset
      A position offset from the viewport boundary.
      See Also:
  • Method Details

    • drawLabel

      public static Rectangle drawLabel(Graphics2D g2D, Color textColor, Color backgroundColor, Color borderColor, double transparency, int posX, int posY, int textInset, Rectangle viewportBounds, String[] text)
      Draws multiple lines of text inside a coloured box.
      Parameters:
      g2D - a handle to the Graphics2D object
      textColor - the text colour
      backgroundColor - the background colour
      borderColor - the border colour
      transparency - the background and border colours' transparency (0.0 is fully opaque, 1.0 is fully transparent)
      posX - the left position of the box
      posY - the top position of the box
      textInset - the inside single-margin between the text and any of the surrounding box's sides
      viewportBounds - the bounds of the viewport in which the label box should fit (it is ignored if the parameter is null)
      text - the label text (specified as new String[] {"String 1","String 2"})
      Returns:
      a Rectangle containing optionally modified (x,y) coordinates to make the label box fit inside the viewport
    • drawLabel

      public static Rectangle drawLabel(Graphics2D g2D, Color textColor, Color backgroundColor, Color borderColor, double transparency, int posX, int posY, int textInset, Rectangle viewportBounds, String text)
      Draws a single line of text inside a coloured box.
      Parameters:
      g2D - a handle to the Graphics2D object
      textColor - the text colour
      backgroundColor - the background colour
      borderColor - the border colour
      transparency - the background and border colours' transparency (0.0 is fully opaque, 1.0 is fully transparent)
      posX - the left position of the box
      posY - the top position of the box
      textInset - the inside single-margin between the text and any of the surrounding box's sides
      viewportBounds - the bounds of the viewport in which the label box should fit (it is ignored if the parameter is null)
      text - the label text
      Returns:
      a Rectangle containing optionally modified (x,y) coordinates to make the label box fit inside the viewport
    • drawLabelCentered

      public static Rectangle drawLabelCentered(Graphics2D g2D, Color textColor, Color backgroundColor, Color borderColor, double transparency, int posX, int posY, int textInset, Rectangle viewportBounds, String[] text)
      Draws multiple lines of text inside a coloured box with its position centred.
      Parameters:
      g2D - a handle to the Graphics2D object
      textColor - the text colour
      backgroundColor - the background colour
      borderColor - the border colour
      transparency - the background and border colours' transparency (0.0 is fully opaque, 1.0 is fully transparent)
      posX - the left position of the box
      posY - the top position of the box
      textInset - the inside single-margin between the text and any of the surrounding box's sides
      viewportBounds - the bounds of the viewport in which the label box should fit (it is ignored if the parameter is null)
      text - the label text
      Returns:
      a Rectangle containing optionally modified (x,y) coordinates to make the label box fit inside the viewport
    • drawLabelCentered

      public static Rectangle drawLabelCentered(Graphics2D g2D, Color textColor, Color backgroundColor, Color borderColor, double transparency, int posX, int posY, int textInset, Rectangle viewportBounds, String text)
      Draws a single line of text inside a coloured box with its position centred.
      Parameters:
      g2D - a handle to the Graphics2D object
      textColor - the text colour
      backgroundColor - the background colour
      borderColor - the border colour
      transparency - the background and border colours' transparency (0.0 is fully opaque, 1.0 is fully transparent)
      posX - the left position of the box
      posY - the top position of the box
      textInset - the inside single-margin between the text and any of the surrounding box's sides
      viewportBounds - the bounds of the viewport in which the label box should fit (it is ignored if the parameter is null)
      text - the label text
      Returns:
      a Rectangle containing optionally modified (x,y) coordinates to make the label box fit inside the viewport