Class HTMLTag
java.lang.Object
com.amalgamasimulation.desktop.html.HTMLTag
- All Implemented Interfaces:
HTMLConvertable
- Direct Known Subclasses:
HTMLChart,HTMLHeader,HTMLHeatmapChart,HTMLImage,HTMLLink,HTMLLinkAction,HTMLTable,HTMLTextBlock
The HTMLTag class represents an HTML tag that can contain children, styles, and attributes.
It implements the
HTMLConvertable interface, providing a method to convert the tag
and its contents to an HTML string.- Author:
- Alexey Glazyrin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(HTMLConvertable... children) Appends one or more children to this HTML tag.Adds an attribute to this HTML tag.backgroundColor(Color color) Sets the background color using AWT Color converted to RGBA format.static StringcolorToRGBA(Color color) Converts an AWT color to an RGBA string.Creates a deep copy of this HTMLConvertable element, preserving the element's structure while substituting text content using the provided translation mapping.protected voidfont(FontDescriptor fontDescriptor) Sets the font of this HTML tag using the specified font descriptor.Sets the font color of this HTML tag using the specified AWT color.fontFamily(String fontFamily) Sets the font family of this HTML tag using the specified font family names.fontSizeInPx(double size) Sets the font size of this HTML tag using the specified size in pixels.fontStyle(FontPosture posture) Sets the font style of this HTML tag using the specified FontPosture.fontWeight(String weight) Sets the font weight of this HTML tag using the specified weight value.Returns attributes of this HTML tag.Returns the children of this HTML tag.lineHeight(double lineHeight) Sets the line height of this HTML tag as a multiple of the font size.marginInPx(Side side, int marginPx) Sets the margin of this HTML tag for the specified side in pixels.maxHeightInPx(int maxHeightPx) Sets the maximum height of this HTML tag in pixels.maxWidthInPx(int maxWidthPx) Sets the maximum width of this HTML tag in pixels.paddingInPx(Side side, int paddingPx) Sets the padding of this HTML tag for the specified side in pixels.relativeHeight(double height) Sets the relative height of this HTML tag as a percentage.relativeWidth(double width) Sets the relative width of this HTML tag as a percentage.protected voidremoveChildren(Collection<HTMLConvertable> children) Adds a CSS style to this HTML tag.tag()Returns the tag name of this HTML tag.Sets the HTML tag name.textAlignment(TextAlignment textAlignment) Sets the text alignment of this HTML tag.static StringtoCSS(FontDescriptor fontDescriptor) Converts FontDescriptor to a CSS string.Converts the object to an HTML string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.amalgamasimulation.desktop.html.HTMLConvertable
copy, toHTML
-
Constructor Details
-
HTMLTag
Constructs a new HTMLTag instance with the specified tag name.- Parameters:
tag- the name of the HTML tag (e.g., "div", "span")
-
-
Method Details
-
tag
Sets the HTML tag name.- Parameters:
tag- new tag name to use- Returns:
- this HTMLTag instance for method chaining
-
append
Appends one or more children to this HTML tag.- Parameters:
children- the children to append- Returns:
- this HTMLTag instance for method chaining
-
removeChildren
-
style
Adds a CSS style to this HTML tag.- Parameters:
style- the CSS style to add- Returns:
- this HTMLTag instance for method chaining
-
attr
Adds an attribute to this HTML tag.- Parameters:
key- the attribute key (e.g., "id", "class")value- the attribute value- Returns:
- this HTMLTag instance for method chaining
-
relativeWidth
Sets the relative width of this HTML tag as a percentage.- Parameters:
width- the width as a percentage (e.g., 0.5 for 50%)- Returns:
- this HTMLTag instance for method chaining
-
relativeHeight
Sets the relative height of this HTML tag as a percentage.- Parameters:
height- the height as a percentage (e.g., 0.5 for 50%)- Returns:
- this HTMLTag instance for method chaining
-
font
Sets the font of this HTML tag using the specified font descriptor.- Parameters:
fontDescriptor- the font descriptor to use- Returns:
- this HTMLTag instance for method chaining
-
fontColor
Sets the font color of this HTML tag using the specified AWT color.- Parameters:
color- the AWT color to use- Returns:
- this HTMLTag instance for method chaining
-
fontWeight
Sets the font weight of this HTML tag using the specified weight value. Accepts predefined values or numeric values between 100 and 900.- Parameters:
weight- the font weight value- Returns:
- this HTMLTag instance for method chaining
- Throws:
IllegalArgumentException- if the weight value is invalid
-
lineHeight
Sets the line height of this HTML tag as a multiple of the font size.- Parameters:
lineHeight- the line height as a double (e.g., 1.5 for 150% of the font size)- Returns:
- this HTMLTag instance for method chaining
-
fontSizeInPx
Sets the font size of this HTML tag using the specified size in pixels.- Parameters:
size- the font size in pixels (must be positive)- Returns:
- this HTMLTag instance for method chaining
- Throws:
IllegalArgumentException- if the size is not positive
-
fontFamily
Sets the font family of this HTML tag using the specified font family names.- Parameters:
fontFamily- the font family name(s) to use- Returns:
- this HTMLTag instance for method chaining
-
fontStyle
Sets the font style of this HTML tag using the specified FontPosture.- Parameters:
posture- the FontPosture to use- Returns:
- this HTMLTag instance for method chaining
-
backgroundColor
Sets the background color using AWT Color converted to RGBA format.- Parameters:
color- the background color to apply- Returns:
- this HTMLTag instance for method chaining
-
marginInPx
Sets the margin of this HTML tag for the specified side in pixels.- Parameters:
side- the side to set the margin formarginPx- the margin in pixels- Returns:
- this HTMLTag instance for method chaining
-
paddingInPx
Sets the padding of this HTML tag for the specified side in pixels.- Parameters:
side- the side to set the padding forpaddingPx- the padding in pixels- Returns:
- this HTMLTag instance for method chaining
-
maxWidthInPx
Sets the maximum width of this HTML tag in pixels.- Parameters:
maxWidthPx- the maximum width in pixels- Returns:
- this HTMLTag instance for method chaining
-
maxHeightInPx
Sets the maximum height of this HTML tag in pixels.- Parameters:
maxHeightPx- the maximum height in pixels- Returns:
- this HTMLTag instance for method chaining
-
textAlignment
Sets the text alignment of this HTML tag.- Parameters:
textAlignment- the text alignment to use- Returns:
- this HTMLTag instance for method chaining
-
getChildren
Returns the children of this HTML tag.- Returns:
- a collection of children, or an empty collection if no children are present
-
tag
Returns the tag name of this HTML tag.- Returns:
- the tag name
-
toHTML
Description copied from interface:HTMLConvertableConverts the object to an HTML string.- Specified by:
toHTMLin interfaceHTMLConvertable- Parameters:
outStrings- set of unique strings of text content- Returns:
-
copy
Description copied from interface:HTMLConvertableCreates a deep copy of this HTMLConvertable element, preserving the element's structure while substituting text content using the provided translation mapping.- Specified by:
copyin interfaceHTMLConvertable- Parameters:
stringsSubstitutionMap- a map where keys are original text strings (as collected byHTMLConvertable.toHTML(Set)) and values are their translations. During copying, any encountered text content present in this map will be replaced with its translated version.- Returns:
- a new independent copy of this HTMLConvertable instance with translated content
-
fillCopy
-
colorToRGBA
Converts an AWT color to an RGBA string.- Parameters:
color- the AWT color to convert- Returns:
- the RGBA string representation of the color
-
getAttributes
Returns attributes of this HTML tag.- Returns:
- a collection of attributes
-
toCSS
Converts FontDescriptor to a CSS string.- Parameters:
fontDescriptor- font descriptor to convert- Returns:
- the CSS string representation of the font descriptor
-