- java.lang.Object
-
- com.googlecode.lanterna.TerminalSize
-
public class TerminalSize extends java.lang.Object
Terminal dimensions in 2-d space, measured in number of rows and columns. This class is immutable and cannot change its internal state after creation.
-
-
Field Summary
Fields Modifier and Type Field Description private int
columns
static TerminalSize
ONE
private int
rows
static TerminalSize
ZERO
-
Constructor Summary
Constructors Constructor Description TerminalSize(int columns, int rows)
Creates a new terminal size representation with a given width (columns) and height (rows)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
int
getColumns()
int
getRows()
int
hashCode()
TerminalSize
max(TerminalSize other)
Takes a different TerminalSize and returns a new TerminalSize that has the largest dimensions of the two, measured separately.TerminalSize
min(TerminalSize other)
Takes a different TerminalSize and returns a new TerminalSize that has the smallest dimensions of the two, measured separately.java.lang.String
toString()
TerminalSize
with(TerminalSize size)
Returns itself if it is equal to the supplied size, otherwise the supplied size.TerminalSize
withColumns(int columns)
Creates a new size based on this size, but with a different widthTerminalSize
withRelative(int deltaColumns, int deltaRows)
Creates a new TerminalSize object representing a size based on this object's size but with a delta applied.TerminalSize
withRelative(TerminalSize delta)
Creates a new TerminalSize object representing a size based on this object's size but with a delta applied.TerminalSize
withRelativeColumns(int delta)
Creates a new TerminalSize object representing a size with the same number of rows, but with a column size offset by a supplied value.TerminalSize
withRelativeRows(int delta)
Creates a new TerminalSize object representing a size with the same number of columns, but with a row size offset by a supplied value.TerminalSize
withRows(int rows)
Creates a new size based on this size, but with a different height
-
-
-
Field Detail
-
ZERO
public static final TerminalSize ZERO
-
ONE
public static final TerminalSize ONE
-
columns
private final int columns
-
rows
private final int rows
-
-
Method Detail
-
getColumns
public int getColumns()
- Returns:
- Returns the width of this size representation, in number of columns
-
withColumns
public TerminalSize withColumns(int columns)
Creates a new size based on this size, but with a different width- Parameters:
columns
- Width of the new size, in columns- Returns:
- New size based on this one, but with a new width
-
getRows
public int getRows()
- Returns:
- Returns the height of this size representation, in number of rows
-
withRows
public TerminalSize withRows(int rows)
Creates a new size based on this size, but with a different height- Parameters:
rows
- Height of the new size, in rows- Returns:
- New size based on this one, but with a new height
-
withRelativeColumns
public TerminalSize withRelativeColumns(int delta)
Creates a new TerminalSize object representing a size with the same number of rows, but with a column size offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal size delta number of columns wider and for negative numbers shorter.- Parameters:
delta
- Column offset- Returns:
- New terminal size based off this one but with an applied transformation
-
withRelativeRows
public TerminalSize withRelativeRows(int delta)
Creates a new TerminalSize object representing a size with the same number of columns, but with a row size offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal size delta number of rows longer and for negative numbers shorter.- Parameters:
delta
- Row offset- Returns:
- New terminal size based off this one but with an applied transformation
-
withRelative
public TerminalSize withRelative(TerminalSize delta)
Creates a new TerminalSize object representing a size based on this object's size but with a delta applied. This is the same as callingwithRelativeColumns(delta.getColumns()).withRelativeRows(delta.getRows())
- Parameters:
delta
- Column and row offset- Returns:
- New terminal size based off this one but with an applied resize
-
withRelative
public TerminalSize withRelative(int deltaColumns, int deltaRows)
Creates a new TerminalSize object representing a size based on this object's size but with a delta applied. This is the same as callingwithRelativeColumns(deltaColumns).withRelativeRows(deltaRows)
- Parameters:
deltaColumns
- How many extra columns the new TerminalSize will have (negative values are allowed)deltaRows
- How many extra rows the new TerminalSize will have (negative values are allowed)- Returns:
- New terminal size based off this one but with an applied resize
-
max
public TerminalSize max(TerminalSize other)
Takes a different TerminalSize and returns a new TerminalSize that has the largest dimensions of the two, measured separately. So calling 3x5 on a 5x3 will return 5x5.- Parameters:
other
- Other TerminalSize to compare with- Returns:
- TerminalSize that combines the maximum width between the two and the maximum height
-
min
public TerminalSize min(TerminalSize other)
Takes a different TerminalSize and returns a new TerminalSize that has the smallest dimensions of the two, measured separately. So calling 3x5 on a 5x3 will return 3x3.- Parameters:
other
- Other TerminalSize to compare with- Returns:
- TerminalSize that combines the minimum width between the two and the minimum height
-
with
public TerminalSize with(TerminalSize size)
Returns itself if it is equal to the supplied size, otherwise the supplied size. You can use this if you have a size field which is frequently recalculated but often resolves to the same size; it will keep the same object in memory instead of swapping it out every cycle.- Parameters:
size
- Size you want to return- Returns:
- Itself if this size equals the size passed in, otherwise the size passed in
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-