- java.lang.Object
-
- com.googlecode.lanterna.TextCharacter
-
- All Implemented Interfaces:
java.io.Serializable
public class TextCharacter extends java.lang.Object implements java.io.SerializableRepresents 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 TextColorbackgroundColorprivate java.lang.StringcharacterThe "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 TextCharacterDEFAULT_CHARACTERprivate TextColorforegroundColorprivate 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 thisprivateTextCharacter(java.lang.String character, TextColor foregroundColor, TextColor backgroundColor, java.util.EnumSet<SGR> modifiers)Creates a newScreenCharacterbased 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 booleanequals(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)TextColorgetBackgroundColor()Background color specified for this TextCharacterchargetCharacter()Deprecated.This won't work with advanced characters like emojijava.lang.StringgetCharacterString()Returns the character this TextCharacter represents as a String.TextColorgetForegroundColor()Foreground color specified for this TextCharacterjava.util.EnumSet<SGR>getModifiers()Returns a set of all active modifiers on this TextCharacterinthashCode()booleanis(char otherCharacter)booleanisBlinking()Returns true if this TextCharacter has the blink modifier activebooleanisBold()Returns true if this TextCharacter has the bold modifier activebooleanisBordered()Returns true if this TextCharacter has the bordered modifier activebooleanisCrossedOut()Returns true if this TextCharacter has the crossed-out modifier activebooleanisDoubleWidth()private static booleanisEmoji(java.lang.String s)booleanisItalic()Returns true if this TextCharacter has the italic modifier activebooleanisReversed()Returns true if this TextCharacter has the reverse modifier activebooleanisUnderlined()Returns true if this TextCharacter has the underline modifier activeprivate static java.util.EnumSet<SGR>toEnumSet(SGR... modifiers)java.lang.StringtoString()private voidvalidateSingleCharacter(java.lang.String character)TextCharacterwithBackgroundColor(TextColor backgroundColor)Returns a copy of this TextCharacter with a specified background colorTextCharacterwithCharacter(char character)Returns a new TextCharacter with the same colors and modifiers but a different underlying characterTextCharacterwithForegroundColor(TextColor foregroundColor)Returns a copy of this TextCharacter with a specified foreground colorTextCharacterwithModifier(SGR modifier)Returns a copy of this TextCharacter with an additional SGR modifier.TextCharacterwithModifiers(java.util.Collection<SGR> modifiers)Returns a copy of this TextCharacter with specified list of SGR modifiers.TextCharacterwithoutModifier(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 aScreenCharacterbased 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 newScreenCharacterbased 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 newScreenCharacterbased 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 newScreenCharacterbased 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:
trueif this TextCharacter has the bold modifier active
-
isReversed
public boolean isReversed()
Returns true if this TextCharacter has the reverse modifier active- Returns:
trueif this TextCharacter has the reverse modifier active
-
isUnderlined
public boolean isUnderlined()
Returns true if this TextCharacter has the underline modifier active- Returns:
trueif this TextCharacter has the underline modifier active
-
isBlinking
public boolean isBlinking()
Returns true if this TextCharacter has the blink modifier active- Returns:
trueif this TextCharacter has the blink modifier active
-
isBordered
public boolean isBordered()
Returns true if this TextCharacter has the bordered modifier active- Returns:
trueif this TextCharacter has the bordered modifier active
-
isCrossedOut
public boolean isCrossedOut()
Returns true if this TextCharacter has the crossed-out modifier active- Returns:
trueif this TextCharacter has the crossed-out modifier active
-
isItalic
public boolean isItalic()
Returns true if this TextCharacter has the italic modifier active- Returns:
trueif 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-