Class ContainerElement<T extends ContainerElement<T>>

java.lang.Object
com.oorian.html.Element<T>
com.oorian.html.ContainerElement<T>

public class ContainerElement<T extends ContainerElement<T>> extends Element<T>
Base class for HTML elements that can contain child elements.

This class makes the container methods from Element publicly accessible. Elements that extend this class allow callers to add, insert, remove, and set child elements and text content. Non-container elements keep these methods protected to prevent misuse.

Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ContainerElement

      public ContainerElement(String tagName)
      Constructs a container element with the specified tag name and a closing tag.
      Parameters:
      tagName - the HTML tag name (e.g., "div", "section")
    • ContainerElement

      public ContainerElement(String tagName, boolean closed)
      Constructs a container element with the specified tag name and closing behavior.
      Parameters:
      tagName - the HTML tag name
      closed - true for elements with closing tags, false for self-closing elements
  • Method Details

    • addElement

      public T addElement(Element child)
      Description copied from class: Element
      Adds a child element to this element.

      The child is removed from its previous parent if it has one, then added to this element's children. If this element is already attached to a page, the child is also attached and registered for DOM addition.

      Overrides:
      addElement in class Element<T extends ContainerElement<T>>
      Parameters:
      child - The child element to add.
      Returns:
      this element for method chaining
    • setElement

      public T setElement(Element child)
      Description copied from class: Element
      Replaces all child elements with a single child element.

      All existing children are removed before adding the new child.

      Overrides:
      setElement in class Element<T extends ContainerElement<T>>
      Parameters:
      child - The child element to set as the only child.
      Returns:
      This element for method chaining.
    • insertElement

      public T insertElement(int index, Element child)
      Description copied from class: Element
      Inserts a child element at the specified index.

      The child is removed from its previous parent if it has one, then inserted at the specified index in this element's children.

      Overrides:
      insertElement in class Element<T extends ContainerElement<T>>
      Parameters:
      index - The index at which to insert the child.
      child - The child element to insert.
      Returns:
      this element for method chaining
    • addText

      public void addText(Text text)
      Description copied from class: Element
      Appends a Text element to this element.
      Overrides:
      addText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The Text element to append.
    • addText

      public void addText(String text, CssStyle style)
      Description copied from class: Element
      Appends text content with a CssStyle to this element.
      Overrides:
      addText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
      style - The CssStyle to apply to the text.
    • addText

      public void addText(String text, String style)
      Description copied from class: Element
      Appends text content with inline CSS styling to this element.
      Overrides:
      addText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
      style - The inline CSS style string to apply to the text.
    • addText

      public void addText(String text)
      Description copied from class: Element
      Appends text content to this element.
      Overrides:
      addText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
    • setText

      public void setText(String text, CssStyle style)
      Description copied from class: Element
      Sets the text content of this element with a CssStyle, replacing any existing content.
      Overrides:
      setText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to set.
      style - The CssStyle to apply to the text.
    • setText

      public void setText(String text, Font font)
      Description copied from class: Element
      Sets the text content of this element with a font, replacing any existing content.
      Overrides:
      setText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to set.
      font - The font to apply to the text.
    • setText

      public void setText(String text, String style)
      Description copied from class: Element
      Sets the text content of this element with inline CSS styling, replacing any existing content.
      Overrides:
      setText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to set.
      style - The inline CSS style string to apply to the text.
    • setText

      public void setText(String text)
      Description copied from class: Element
      Sets the text content of this element, replacing any existing content.
      Overrides:
      setText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to set.
    • addParagraph

      public void addParagraph(String text)
      Description copied from class: Element
      Adds a paragraph element containing the specified text.
      Overrides:
      addParagraph in class Element<T extends ContainerElement<T>>
      Parameters:
      text - the text content for the paragraph
    • addParagraph

      public void addParagraph()
      Description copied from class: Element
      Adds an empty paragraph element.
      Overrides:
      addParagraph in class Element<T extends ContainerElement<T>>
    • addSpacer

      public void addSpacer(int height)
      Description copied from class: Element
      Adds a vertical spacer element with the specified height in pixels.
      Overrides:
      addSpacer in class Element<T extends ContainerElement<T>>
      Parameters:
      height - The height of the spacer in pixels.
    • addLineOfText

      public void addLineOfText(String text, CssStyle style)
      Description copied from class: Element
      Appends text content with a CssStyle followed by a line break to this element.
      Overrides:
      addLineOfText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
      style - The CssStyle to apply to the text.
    • addLineOfText

      public void addLineOfText(String text, String style)
      Description copied from class: Element
      Appends text content with inline CSS styling followed by a line break to this element.
      Overrides:
      addLineOfText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
      style - The inline CSS style string to apply to the text.
    • addLineOfText

      public void addLineOfText(String text)
      Description copied from class: Element
      Appends text content followed by a line break to this element.
      Overrides:
      addLineOfText in class Element<T extends ContainerElement<T>>
      Parameters:
      text - The text content to append.
    • removeAllElements

      public void removeAllElements()
      Description copied from class: Element
      Removes all child elements from this element.

      Each child is unlinked and registered for DOM removal if the element is attached to a page.

      Overrides:
      removeAllElements in class Element<T extends ContainerElement<T>>
    • removeElement

      public void removeElement(String id)
      Description copied from class: Element
      Removes a child element by its ID.
      Overrides:
      removeElement in class Element<T extends ContainerElement<T>>
      Parameters:
      id - The ID of the child element to remove.
    • removeElement

      public void removeElement(Element child)
      Description copied from class: Element
      Removes a child element from this element.

      The child is unlinked from this parent and registered for DOM removal if the element is attached to a page.

      Overrides:
      removeElement in class Element<T extends ContainerElement<T>>
      Parameters:
      child - The child element to remove.