- java.lang.Object
-
- com.googlecode.lanterna.graphics.BasicTextImage
-
- All Implemented Interfaces:
Scrollable
,TextImage
public class BasicTextImage extends java.lang.Object implements TextImage
Simple implementation of TextImage that keeps the content as a two-dimensional TextCharacter array. Copy operations between two BasicTextImage classes are semi-optimized by using System.arraycopy instead of iterating over each character and copying them over one by one.
-
-
Field Summary
Fields Modifier and Type Field Description private TextCharacter[][]
buffer
private TerminalSize
size
-
Constructor Summary
Constructors Modifier Constructor Description BasicTextImage(int columns, int rows)
Creates a new BasicTextImage with the specified size and fills it initially with space characters using the default foreground and background colorBasicTextImage(TerminalSize size)
Creates a new BasicTextImage with the specified size and fills it initially with space characters using the default foreground and background colorBasicTextImage(TerminalSize size, TextCharacter initialContent)
Creates a new BasicTextImage with a given size and a TextCharacter to initially fill it withprivate
BasicTextImage(TerminalSize size, TextCharacter[][] toCopy, TextCharacter initialContent)
Creates a new BasicTextImage by copying a region of a two-dimensional array of TextCharacter:s.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyTo(TextImage destination)
Copies this TextImage's content to another TextImage.void
copyTo(TextImage destination, int startRowIndex, int rows, int startColumnIndex, int columns, int destinationRowOffset, int destinationColumnOffset)
Copies this TextImage's content to another TextImage.TextCharacter
getCharacterAt(int column, int row)
Returns the character stored at a particular position in this imageTextCharacter
getCharacterAt(TerminalPosition position)
Returns the character stored at a particular position in this imageTerminalSize
getSize()
Returns the dimensions of this TextImage, in columns and rowsprivate TextCharacter[]
newBlankLine()
TextGraphics
newTextGraphics()
Creates a TextGraphics object that targets this TextImage for all its drawing operations.BasicTextImage
resize(TerminalSize newSize, TextCharacter filler)
Returns a copy of this image resized to a new size and using a specified filler character if the new size is larger than the old and we need to fill in empty areas.void
scrollLines(int firstLine, int lastLine, int distance)
Scroll a range of lines of this TextImage according to given distance.void
setAll(TextCharacter character)
Sets the text image content to one specified character (including color and style)void
setCharacterAt(int column, int row, TextCharacter character)
Sets the character at a specific position in the image to a particular TextCharacter.void
setCharacterAt(TerminalPosition position, TextCharacter character)
Sets the character at a specific position in the image to a particular TextCharacter.java.lang.String
toString()
-
-
-
Field Detail
-
size
private final TerminalSize size
-
buffer
private final TextCharacter[][] buffer
-
-
Constructor Detail
-
BasicTextImage
public BasicTextImage(int columns, int rows)
Creates a new BasicTextImage with the specified size and fills it initially with space characters using the default foreground and background color- Parameters:
columns
- Size of the image in number of columnsrows
- Size of the image in number of rows
-
BasicTextImage
public BasicTextImage(TerminalSize size)
Creates a new BasicTextImage with the specified size and fills it initially with space characters using the default foreground and background color- Parameters:
size
- Size to make the image
-
BasicTextImage
public BasicTextImage(TerminalSize size, TextCharacter initialContent)
Creates a new BasicTextImage with a given size and a TextCharacter to initially fill it with- Parameters:
size
- Size of the imageinitialContent
- What character to set as the initial content
-
BasicTextImage
private BasicTextImage(TerminalSize size, TextCharacter[][] toCopy, TextCharacter initialContent)
Creates a new BasicTextImage by copying a region of a two-dimensional array of TextCharacter:s. If the area to be copied to larger than the source array, a filler character is used.- Parameters:
size
- Size to create the new BasicTextImage as (and size to copy from the array)toCopy
- Array to copy initial data frominitialContent
- Filler character to use if the source array is smaller than the requested size
-
-
Method Detail
-
getSize
public TerminalSize getSize()
Description copied from interface:TextImage
Returns the dimensions of this TextImage, in columns and rows
-
setAll
public void setAll(TextCharacter character)
Description copied from interface:TextImage
Sets the text image content to one specified character (including color and style)
-
resize
public BasicTextImage resize(TerminalSize newSize, TextCharacter filler)
Description copied from interface:TextImage
Returns a copy of this image resized to a new size and using a specified filler character if the new size is larger than the old and we need to fill in empty areas. The copy will be independent from the one this method is invoked on, so modifying one will not affect the other.
-
setCharacterAt
public void setCharacterAt(TerminalPosition position, TextCharacter character)
Description copied from interface:TextImage
Sets the character at a specific position in the image to a particular TextCharacter. If the position is outside of the image's size, this method does nothing.- Specified by:
setCharacterAt
in interfaceTextImage
- Parameters:
position
- Coordinates of the charactercharacter
- What TextCharacter to assign at the specified position
-
setCharacterAt
public void setCharacterAt(int column, int row, TextCharacter character)
Description copied from interface:TextImage
Sets the character at a specific position in the image to a particular TextCharacter. If the position is outside of the image's size, this method does nothing.- Specified by:
setCharacterAt
in interfaceTextImage
- Parameters:
column
- Column coordinate of the characterrow
- Row coordinate of the charactercharacter
- What TextCharacter to assign at the specified position
-
getCharacterAt
public TextCharacter getCharacterAt(TerminalPosition position)
Description copied from interface:TextImage
Returns the character stored at a particular position in this image- Specified by:
getCharacterAt
in interfaceTextImage
- Parameters:
position
- Coordinates of the character- Returns:
- TextCharacter stored at the specified position
-
getCharacterAt
public TextCharacter getCharacterAt(int column, int row)
Description copied from interface:TextImage
Returns the character stored at a particular position in this image- Specified by:
getCharacterAt
in interfaceTextImage
- Parameters:
column
- Column coordinate of the characterrow
- Row coordinate of the character- Returns:
- TextCharacter stored at the specified position
-
copyTo
public void copyTo(TextImage destination)
Description copied from interface:TextImage
Copies this TextImage's content to another TextImage. If the destination TextImage is larger than this ScreenBuffer, the areas outside of the area that is written to will be untouched.
-
copyTo
public void copyTo(TextImage destination, int startRowIndex, int rows, int startColumnIndex, int columns, int destinationRowOffset, int destinationColumnOffset)
Description copied from interface:TextImage
Copies this TextImage's content to another TextImage. If the destination TextImage is larger than this TextImage, the areas outside of the area that is written to will be untouched.- Specified by:
copyTo
in interfaceTextImage
- Parameters:
destination
- TextImage to copy tostartRowIndex
- Which row in this image to copy fromrows
- How many rows to copystartColumnIndex
- Which column in this image to copy fromcolumns
- How many columns to copydestinationRowOffset
- Offset (in number of rows) in the target image where we want to first copied row to bedestinationColumnOffset
- Offset (in number of columns) in the target image where we want to first copied column to be
-
newTextGraphics
public TextGraphics newTextGraphics()
Description copied from interface:TextImage
Creates a TextGraphics object that targets this TextImage for all its drawing operations.- Specified by:
newTextGraphics
in interfaceTextImage
- Returns:
- TextGraphics object for this TextImage
-
newBlankLine
private TextCharacter[] newBlankLine()
-
scrollLines
public void scrollLines(int firstLine, int lastLine, int distance)
Description copied from interface:TextImage
Scroll a range of lines of this TextImage according to given distance. TextImage implementations of this method do not throw IOException.- Specified by:
scrollLines
in interfaceScrollable
- Specified by:
scrollLines
in interfaceTextImage
- Parameters:
firstLine
- first line of the range to be scrolled (top line is 0)lastLine
- last (inclusive) line of the range to be scrolleddistance
- if > 0: move lines up, else if < 0: move lines down.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-