Class TitleBarBorder

All Implemented Interfaces:
Border, LabeledBorder

public class TitleBarBorder extends AbstractLabeledBorder
Border provides a title bar on the Figure for which this is the border of. Generally used in conjunction with other borders to create window-like effects. Also provides for alignment of the text in the bar.
See Also:
  • Constructor Details

    • TitleBarBorder

      public TitleBarBorder()
      Constructs a TitleBarBorder with its label set to the name of this class.
      Since:
      2.0
    • TitleBarBorder

      public TitleBarBorder(String s)
      Constructs a TitleBarBorder with its label set to the passed String.
      Parameters:
      s - text of the label
      Since:
      2.0
  • Method Details

    • calculateInsets

      protected Insets calculateInsets(IFigure figure)
      Calculates and returns the Insets for this border.
      Specified by:
      calculateInsets in class AbstractLabeledBorder
      Parameters:
      figure - the figure on which Insets calculations are based
      Returns:
      the calculated Insets
      Since:
      2.0
    • getBackgroundColor

      protected Color getBackgroundColor()
      Returns the background Color of this TitleBarBorder.
      Returns:
      the background color
      Since:
      2.0
    • getPadding

      protected Insets getPadding()
      Returns this TitleBarBorder's padding. Padding provides spacing along the sides of the TitleBarBorder. The default value is no padding along all sides.
      Returns:
      the Insets representing the space along the sides of the TitleBarBorder
      Since:
      2.0
    • getPreferredSize

      public Dimension getPreferredSize(IFigure fig)
      Overwritten to handle padding appropriately.
      Specified by:
      getPreferredSize in interface Border
      Overrides:
      getPreferredSize in class AbstractLabeledBorder
      Parameters:
      fig - The figure
      Returns:
      The preferred size
      See Also:
    • getTextAlignment

      public int getTextAlignment()
      Returns the alignment of the text in the title bar. Possible values are PositionConstants.LEFT, PositionConstants.CENTER and PositionConstants.RIGHT.
      Returns:
      the text alignment
      Since:
      2.0
    • isOpaque

      public boolean isOpaque()
      Returns true thereby filling up all the contents within its boundaries, eleminating the need by the figure to clip the boundaries and do the same.
      Specified by:
      isOpaque in interface Border
      Overrides:
      isOpaque in class AbstractBorder
      Returns:
      true if this border is opaque
      See Also:
    • paint

      public void paint(IFigure figure, Graphics g, Insets insets)
      Description copied from interface: Border
      Paints the border. The border should paint inside figure's IFigure.getBounds(), inset by the parameter insets. The border generally should not paint inside its own insets. More specifically, Border b should paint inside the rectangle: figure.getBounds().getCropped(insets) and outside of the rectangle: figure.getBounds().getCropped(insets).getCropped(getInsets()) where inside is defined as Rectangle.contains(int, int).
      Parameters:
      figure - The figure this border belongs to
      g - The graphics object used for painting
      insets - The insets
      See Also:
    • setBackgroundColor

      public void setBackgroundColor(Color color)
      Sets the background color of the area within the boundaries of this border. This is required as this border takes responsibility for filling up the region, as TitleBarBorders are always opaque.
      Parameters:
      color - the background color
      Since:
      2.0
    • setPadding

      public void setPadding(int all)
      Sets the padding space to be applied on all sides of the border. The default value is no padding on all sides.
      Parameters:
      all - the value of the padding on all sides
      Since:
      2.0
    • setPadding

      public void setPadding(Insets pad)
      Sets the padding space of this TitleBarBorder to the passed value. The default value is no padding on all sides.
      Parameters:
      pad - the padding
      Since:
      2.0
    • setTextAlignment

      public void setTextAlignment(int align)
      Sets the alignment of the text in the title bar. Possible values are PositionConstants.LEFT, PositionConstants.CENTER and PositionConstants.RIGHT.
      Parameters:
      align - the new text alignment
      Since:
      2.0