Class HTMLTag
java.lang.Object
com.amalgamasimulation.desktop.html.HTMLTag
- All Implemented Interfaces:
HTMLConvertable
- Direct Known Subclasses:
HTMLChart,HTMLHeader,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.copy()Creates a deep copy of this HTMLTag including its children, styles, and attributes.font(org.eclipse.swt.graphics.Font font) Sets the font of this HTML tag using the specified SWT font.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(javafx.scene.text.FontPosture posture) Sets the font style of this HTML tag using the specified JavaFX FontPosture.fontWeight(String weight) Sets the font weight of this HTML tag using the specified weight value.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(javafx.geometry.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(javafx.geometry.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.Sets the HTML tag name.textAlignment(javafx.scene.text.TextAlignment textAlignment) Sets the text alignment of this HTML tag.static StringtoCSS(org.eclipse.swt.graphics.Font font, boolean includeName) Converts an SWT font to a CSS string.toHTML()Converts this HTML tag and its contents to an HTML string.
-
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
-
copy
Creates a deep copy of this HTMLTag including its children, styles, and attributes.- Returns:
- new independent copy of this HTMLTag instance
-
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 SWT font.- Parameters:
font- the SWT font 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 JavaFX FontPosture.- Parameters:
posture- the JavaFX 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
-
toHTML
Converts this HTML tag and its contents to an HTML string.- Specified by:
toHTMLin interfaceHTMLConvertable- Returns:
- the HTML representation of this tag and its contents
-
colorToRGBA
Converts an AWT color to an RGBA string.- Parameters:
color- the AWT color to convert- Returns:
- the RGBA string representation of the color
-
toCSS
Converts an SWT font to a CSS string.- Parameters:
font- the SWT font to convertincludeName- whether to include the font name in the CSS string- Returns:
- the CSS string representation of the font
-