- java.lang.Object
-
- com.googlecode.lanterna.TextCharacter
-
- All Implemented Interfaces:
java.io.Serializable
public class TextCharacter extends java.lang.Object implements java.io.Serializable
Represents a single character with additional metadata such as colors and modifiers. This class is immutable and cannot be modified after creation.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private TextColor
backgroundColor
private java.lang.String
character
The "character" might not fit in a Java 16-bit char (emoji and other types) so we store it in a String as of 3.1 instead.static TextCharacter
DEFAULT_CHARACTER
private TextColor
foregroundColor
private java.util.EnumSet<SGR>
modifiers
-
Constructor Summary
Constructors Modifier Constructor Description TextCharacter(char character)
Deprecated.Use fromCharacter insteadTextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, SGR... styles)
Deprecated.Use fromCharacter insteadTextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
Deprecated.Use fromCharacter insteadTextCharacter(TextCharacter character)
Deprecated.TextCharacters are immutable so you shouldn't need to call thisprivate
TextCharacter(java.lang.String character, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
Creates a newScreenCharacter
based on a physical character, color information and a set of modifiers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
static TextCharacter[]
fromCharacter(char c)
static TextCharacter[]
fromCharacter(char c, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers)
static TextCharacter[]
fromString(java.lang.String string)
static TextCharacter[]
fromString(java.lang.String string, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers)
static TextCharacter[]
fromString(java.lang.String string, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
TextColor
getBackgroundColor()
Background color specified for this TextCharacterchar
getCharacter()
Deprecated.This won't work with advanced characters like emojijava.lang.String
getCharacterString()
Returns the character this TextCharacter represents as a String.TextColor
getForegroundColor()
Foreground color specified for this TextCharacterjava.util.EnumSet<SGR>
getModifiers()
Returns a set of all active modifiers on this TextCharacterint
hashCode()
boolean
is(char otherCharacter)
boolean
isBlinking()
Returns true if this TextCharacter has the blink modifier activeboolean
isBold()
Returns true if this TextCharacter has the bold modifier activeboolean
isBordered()
Returns true if this TextCharacter has the bordered modifier activeboolean
isCrossedOut()
Returns true if this TextCharacter has the crossed-out modifier activeboolean
isDoubleWidth()
private static boolean
isEmoji(java.lang.String s)
boolean
isItalic()
Returns true if this TextCharacter has the italic modifier activeboolean
isReversed()
Returns true if this TextCharacter has the reverse modifier activeboolean
isUnderlined()
Returns true if this TextCharacter has the underline modifier activeprivate static java.util.EnumSet<SGR>
toEnumSet(SGR... modifiers)
java.lang.String
toString()
private void
validateSingleCharacter(java.lang.String character)
TextCharacter
withBackgroundColor(TextColor backgroundColor)
Returns a copy of this TextCharacter with a specified background colorTextCharacter
withCharacter(char character)
Returns a new TextCharacter with the same colors and modifiers but a different underlying characterTextCharacter
withForegroundColor(TextColor foregroundColor)
Returns a copy of this TextCharacter with a specified foreground colorTextCharacter
withModifier(SGR modifier)
Returns a copy of this TextCharacter with an additional SGR modifier.TextCharacter
withModifiers(java.util.Collection<SGR> modifiers)
Returns a copy of this TextCharacter with specified list of SGR modifiers.TextCharacter
withoutModifier(SGR modifier)
Returns a copy of this TextCharacter with an SGR modifier removed.
-
-
-
Field Detail
-
DEFAULT_CHARACTER
public static final TextCharacter DEFAULT_CHARACTER
-
character
private final java.lang.String character
The "character" might not fit in a Java 16-bit char (emoji and other types) so we store it in a String as of 3.1 instead.
-
foregroundColor
private final TextColor foregroundColor
-
backgroundColor
private final TextColor backgroundColor
-
modifiers
private final java.util.EnumSet<SGR> modifiers
-
-
Constructor Detail
-
TextCharacter
@Deprecated public TextCharacter(char character)
Deprecated.Use fromCharacter insteadCreates aScreenCharacter
based on a supplied character, with default colors and no extra modifiers.- Parameters:
character
- Physical character to use
-
TextCharacter
@Deprecated public TextCharacter(TextCharacter character)
Deprecated.TextCharacters are immutable so you shouldn't need to call thisCopies anotherScreenCharacter
- Parameters:
character
- screenCharacter to copy from
-
TextCharacter
@Deprecated public TextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, SGR... styles)
Deprecated.Use fromCharacter insteadCreates a newScreenCharacter
based on a physical character, color information and optional modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasstyles
- Optional list of modifiers to apply when drawing the character
-
TextCharacter
@Deprecated public TextCharacter(char character, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
Deprecated.Use fromCharacter insteadCreates a newScreenCharacter
based on a physical character, color information and a set of modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasmodifiers
- Set of modifiers to apply when drawing the character
-
TextCharacter
private TextCharacter(java.lang.String character, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
Creates a newScreenCharacter
based on a physical character, color information and a set of modifiers.- Parameters:
character
- Physical character to refer toforegroundColor
- Foreground color the character hasbackgroundColor
- Background color the character hasmodifiers
- Set of modifiers to apply when drawing the character
-
-
Method Detail
-
fromCharacter
public static TextCharacter[] fromCharacter(char c)
-
fromString
public static TextCharacter[] fromString(java.lang.String string)
-
fromCharacter
public static TextCharacter[] fromCharacter(char c, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers)
-
fromString
public static TextCharacter[] fromString(java.lang.String string, TextColor foregroundColor, TextColor backgroundColor, SGR... modifiers)
-
fromString
public static TextCharacter[] fromString(java.lang.String string, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)
-
validateSingleCharacter
private void validateSingleCharacter(java.lang.String character)
-
is
public boolean is(char otherCharacter)
-
getCharacter
@Deprecated public char getCharacter()
Deprecated.This won't work with advanced characters like emojiThe actual character this TextCharacter represents- Returns:
- character of the TextCharacter
-
getCharacterString
public java.lang.String getCharacterString()
Returns the character this TextCharacter represents as a String. This is not returning a char- Returns:
-
getForegroundColor
public TextColor getForegroundColor()
Foreground color specified for this TextCharacter- Returns:
- Foreground color of this TextCharacter
-
getBackgroundColor
public TextColor getBackgroundColor()
Background color specified for this TextCharacter- Returns:
- Background color of this TextCharacter
-
getModifiers
public java.util.EnumSet<SGR> getModifiers()
Returns a set of all active modifiers on this TextCharacter- Returns:
- Set of active SGR codes
-
isBold
public boolean isBold()
Returns true if this TextCharacter has the bold modifier active- Returns:
true
if this TextCharacter has the bold modifier active
-
isReversed
public boolean isReversed()
Returns true if this TextCharacter has the reverse modifier active- Returns:
true
if this TextCharacter has the reverse modifier active
-
isUnderlined
public boolean isUnderlined()
Returns true if this TextCharacter has the underline modifier active- Returns:
true
if this TextCharacter has the underline modifier active
-
isBlinking
public boolean isBlinking()
Returns true if this TextCharacter has the blink modifier active- Returns:
true
if this TextCharacter has the blink modifier active
-
isBordered
public boolean isBordered()
Returns true if this TextCharacter has the bordered modifier active- Returns:
true
if this TextCharacter has the bordered modifier active
-
isCrossedOut
public boolean isCrossedOut()
Returns true if this TextCharacter has the crossed-out modifier active- Returns:
true
if this TextCharacter has the crossed-out modifier active
-
isItalic
public boolean isItalic()
Returns true if this TextCharacter has the italic modifier active- Returns:
true
if this TextCharacter has the italic modifier active
-
withCharacter
public TextCharacter withCharacter(char character)
Returns a new TextCharacter with the same colors and modifiers but a different underlying character- Parameters:
character
- Character the copy should have- Returns:
- Copy of this TextCharacter with different underlying character
-
withForegroundColor
public TextCharacter withForegroundColor(TextColor foregroundColor)
Returns a copy of this TextCharacter with a specified foreground color- Parameters:
foregroundColor
- Foreground color the copy should have- Returns:
- Copy of the TextCharacter with a different foreground color
-
withBackgroundColor
public TextCharacter withBackgroundColor(TextColor backgroundColor)
Returns a copy of this TextCharacter with a specified background color- Parameters:
backgroundColor
- Background color the copy should have- Returns:
- Copy of the TextCharacter with a different background color
-
withModifiers
public TextCharacter withModifiers(java.util.Collection<SGR> modifiers)
Returns a copy of this TextCharacter with specified list of SGR modifiers. None of the currently active SGR codes will be carried over to the copy, only those in the passed in value.- Parameters:
modifiers
- SGR modifiers the copy should have- Returns:
- Copy of the TextCharacter with a different set of SGR modifiers
-
withModifier
public TextCharacter withModifier(SGR modifier)
Returns a copy of this TextCharacter with an additional SGR modifier. All of the currently active SGR codes will be carried over to the copy, in addition to the one specified.- Parameters:
modifier
- SGR modifiers the copy should have in additional to all currently present- Returns:
- Copy of the TextCharacter with a new SGR modifier
-
withoutModifier
public TextCharacter withoutModifier(SGR modifier)
Returns a copy of this TextCharacter with an SGR modifier removed. All of the currently active SGR codes will be carried over to the copy, except for the one specified. If the current TextCharacter doesn't have the SGR specified, it will return itself.- Parameters:
modifier
- SGR modifiers the copy should not have- Returns:
- Copy of the TextCharacter without the SGR modifier
-
isDoubleWidth
public boolean isDoubleWidth()
-
isEmoji
private static boolean isEmoji(java.lang.String s)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-