Top Description Fields Constructors Methods
io.github.kusoroadeolu.clique.components

public Class Frame

extends Object
implements Component
Class Inheritance
All Implemented Interfaces
io.github.kusoroadeolu.clique.components.Component
Annotations
@Stable
since:3.2.0
Imports
io.github.kusoroadeolu.clique.configuration.BoxType, .FrameAlign, .FrameConfiguration, io.github.kusoroadeolu.clique.internal.BorderChars, .Cell, .FrameNode, io.github.kusoroadeolu.clique.internal.documentation.Stable, io.github.kusoroadeolu.clique.internal.exception.InvalidDimensionException, java.util.ArrayList, .List, .Objects

A bordered, optionally titled container that renders its content as a formatted terminal box. Frames may contain strings or nested Component instances, each independently aligned within the frame.

Width resolution order:

  1. If width(int) has been set, that value is used as the total inner width.
  2. Otherwise, the width is derived from the widest nested node, plus padding on each side. If a title is present and wider than the computed content width, the title width takes precedence.

Content width must not exceed frameWidth - (padding * 2); if it does, io.github.kusoroadeolu.clique.internal.exception.InvalidDimensionException is thrown at render time.

This class is not thread-safe.

Field Summary

Modifier and TypeField and Description
private final BorderChars
private final FrameConfiguration
private static final int
private final List<FrameNode>
private static final String
private String
private FrameAlign
private final BoxType
private int

Constructor Summary

AccessConstructor and Description
public
Frame(FrameConfiguration configuration, BoxType type)

public
public
Frame(BoxType type)

public
Frame(FrameConfiguration configuration)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
align(FrameNode node, int availableWidth, StringBuilder sb)

pack-priv void
appendTitleToBox(Cell parsedTitle, int givenWidth, int titleWidth, StringBuilder sb)

pack-priv void
pack-priv void
public boolean
equals(Object object)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv int
pack-priv static int
findTitleBlockOffset(int givenWidth, int titleWidth, FrameAlign align)

public String

Returns:

the fully rendered frame as a multi-line string, terminated with a newline
get
()

Implements io.github.kusoroadeolu.clique.components.Component.get.

Builds the frame and all its nested nodes to a string.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Frame

Returns:

this frame, for chaining
nest
(String
the string to nest; must not be null
str
)

Appends a string node to this frame using the alignment configured in FrameConfiguration.

public Frame

Returns:

this frame, for chaining
nest
(String
the string to nest; must not be null
str
,
FrameAlign
the horizontal alignment of the string within the frame; must not be null
align
)

Appends a string node to this frame with the specified alignment.

public Frame

Returns:

this frame, for chaining
nest
(Component
the component to nest; must not be null and must not be this frame
component
)

Appends a Component node to this frame using the alignment configured in FrameConfiguration.

public Frame

Returns:

this frame, for chaining
nest
(Component
the component to nest; must not be null and must not be this frame
component
,
FrameAlign
the horizontal alignment within the frame; must not be null
align
)

Appends a Component node to this frame with the specified alignment.

pack-priv boolean
public Frame

Returns:

this frame, for chaining
title
(String
the title text; must not be null
title
,
FrameAlign
the horizontal placement of the title; must not be null
titleAlign
)

Sets the frame title and its horizontal alignment within the top border.

public Frame

Returns:

this frame, for chaining
title
(String
the title text; must not be null
title
)

Sets the frame title with center alignment.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
validateTitleWidth(int titleWidth, int resolvedWidth)

public Frame

Returns:

this frame, for chaining
width
(int
the total inner width; must be greater than zero
width
)

Sets the total inner width of the frame in characters, excluding the border columns.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

borderCharsback to summary
private final BorderChars borderChars
configurationback to summary
private final FrameConfiguration configuration
NO_WIDTH_SETback to summary
private static final int NO_WIDTH_SET
nodesback to summary
private final List<FrameNode> nodes
NULL_FRAME_ALIGNback to summary
private static final String NULL_FRAME_ALIGN
titleback to summary
private String title
titleAlignback to summary
private FrameAlign titleAlign
typeback to summary
private final BoxType type
widthback to summary
private int width

Constructor Detail

Frameback to summary
public Frame(FrameConfiguration configuration, BoxType type)
Frameback to summary
public Frame()
Frameback to summary
public Frame(BoxType type)
Frameback to summary
public Frame(FrameConfiguration configuration)

Method Detail

alignback to summary
pack-priv void align(FrameNode node, int availableWidth, StringBuilder sb)
appendTitleToBoxback to summary
pack-priv void appendTitleToBox(Cell parsedTitle, int givenWidth, int titleWidth, StringBuilder sb)
assertNotSelfback to summary
pack-priv void assertNotSelf(Component component)
colorBordersback to summary
pack-priv void colorBorders(BorderChars borderChar)
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
findNodesMaxWidthback to summary
pack-priv int findNodesMaxWidth()
findTitleBlockOffsetback to summary
pack-priv static int findTitleBlockOffset(int givenWidth, int titleWidth, FrameAlign align)
getback to summary
public String get()

Implements io.github.kusoroadeolu.clique.components.Component.get.

Builds the frame and all its nested nodes to a string.

Width resolution, title placement, content alignment, and border drawing all occur during this call. No state is cached; each invocation performs a full render.

Returns:String

the fully rendered frame as a multi-line string, terminated with a newline

Exceptions
InvalidDimensionException:
if the title width exceeds the resolved frame width, or if any nested node's content width exceeds the available content area
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
nestback to summary
public Frame nest(String str)

Appends a string node to this frame using the alignment configured in FrameConfiguration.

Equivalent to nest(str, configuration.getFrameAlign()).

Parameters
str:String

the string to nest; must not be null

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if str is null
nestback to summary
public Frame nest(String str, FrameAlign align)

Appends a string node to this frame with the specified alignment.

Parameters
str:String

the string to nest; must not be null

align:FrameAlign

the horizontal alignment of the string within the frame; must not be null

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if str or align is null
nestback to summary
public Frame nest(Component component)

Appends a Component node to this frame using the alignment configured in FrameConfiguration.

Equivalent to nest(component, configuration.getFrameAlign()).

Parameters
component:Component

the component to nest; must not be null and must not be this frame

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if component is null
IllegalArgumentException:
if component is this frame instance
nestback to summary
public Frame nest(Component component, FrameAlign align)

Appends a Component node to this frame with the specified alignment.

A frame cannot nest itself. Attempting to do so throws IllegalArgumentException. Circular nesting through intermediate components is not detected and results in a StackOverflowError at render time.

Parameters
component:Component

the component to nest; must not be null and must not be this frame

align:FrameAlign

the horizontal alignment within the frame; must not be null

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if component or align is null
IllegalArgumentException:
if component is this frame instance
noWidthSetback to summary
pack-priv boolean noWidthSet()
titleback to summary
public Frame title(String title, FrameAlign titleAlign)

Sets the frame title and its horizontal alignment within the top border.

The title is rendered inline with the top border line. If a color parser is configured, a reset sequence is automatically appended to prevent color bleed into the border.

Parameters
title:String

the title text; must not be null

titleAlign:FrameAlign

the horizontal placement of the title; must not be null

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if title or titleAlign is null
InvalidDimensionException:
if the title is wider than the resolved frame width, thrown at render time via get()
titleback to summary
public Frame title(String title)

Sets the frame title with center alignment.

Equivalent to title(title, FrameAlign.CENTER).

Parameters
title:String

the title text; must not be null

Returns:Frame

this frame, for chaining

Exceptions
NullPointerException:
if title is null
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
validateTitleWidthback to summary
pack-priv void validateTitleWidth(int titleWidth, int resolvedWidth)
widthback to summary
public Frame width(int width)

Sets the total inner width of the frame in characters, excluding the border columns.

When set, this width overrides auto-sizing. The available content width is width - (padding * 2). Nested node widths must not exceed this value; violations are detected at render time via get().

Parameters
width:int

the total inner width; must be greater than zero

Returns:Frame

this frame, for chaining

Exceptions
InvalidDimensionException:
if width is less than or equal to zero