diff --git a/src/examples/java/com/googlecode/lanterna/examples/DrawRectangle.java b/src/examples/java/com/googlecode/lanterna/examples/DrawRectangle.java index b370a76d8..becf8a972 100644 --- a/src/examples/java/com/googlecode/lanterna/examples/DrawRectangle.java +++ b/src/examples/java/com/googlecode/lanterna/examples/DrawRectangle.java @@ -29,8 +29,7 @@ public static void main(String[] args) throws IOException { screen.startScreen(); screen.clear(); - tGraphics.drawRectangle( - new TerminalPosition(3,3), new TerminalSize(10,10), '*'); + tGraphics.drawRectangle(TerminalPosition.of(3,3), TerminalSize.of(10,10), '*'); screen.refresh(); screen.readInput(); diff --git a/src/main/java/com/googlecode/lanterna/TerminalPosition.java b/src/main/java/com/googlecode/lanterna/TerminalPosition.java index b65af79db..4c63fae86 100644 --- a/src/main/java/com/googlecode/lanterna/TerminalPosition.java +++ b/src/main/java/com/googlecode/lanterna/TerminalPosition.java @@ -28,17 +28,49 @@ public class TerminalPosition implements Comparable { /** - * Constant for the top-left corner (0x0) + * Constants for less objects memory churn, these are from the top-left corner (column x row) */ - public static final TerminalPosition TOP_LEFT_CORNER = new TerminalPosition(0, 0); - /** - * Constant for the 1x1 position (one offset in both directions from top-left) - */ - public static final TerminalPosition OFFSET_1x1 = new TerminalPosition(1, 1); + public static final TerminalPosition OF_0x0 = new TerminalPosition(0, 0); + public static final TerminalPosition OF_0x1 = new TerminalPosition(0, 1); + public static final TerminalPosition OF_1x0 = new TerminalPosition(1, 0); + public static final TerminalPosition OF_1x1 = new TerminalPosition(1, 1); - private final int row; private final int column; - + private final int row; + + public int x() { return column; } + public int y() { return row; } + + /** + * @return a TerminalPosition instance with the supplied column and row + */ + public static final TerminalPosition of(int column, int row) { + if (OF_0x0.equals(column, row)) { return OF_0x0; } + if (OF_0x1.equals(column, row)) { return OF_0x1; } + if (OF_1x0.equals(column, row)) { return OF_1x0; } + if (OF_1x1.equals(column, row)) { return OF_1x1; } + + return new TerminalPosition(column, row); + } + /** + * Returns a TerminalPosition with the column and row supplied. + * If either the column or row supplied is different than this instances column or row, then a new instance is returned. + * If both column and row are the same as this instance's column and row, then this instance is returned. + * @return Either this instance, or a new instance if column/row are different than this instance's column/row. + */ + public TerminalPosition as(int column, int row) { + return equals(column, row) ? this : of(column, row); + } + /** + * Returns itself if it is equal to the supplied position, otherwise the supplied position. You can use this if you + * have a position field which is frequently recalculated but often resolves to the same; it will keep the same + * object in memory instead of swapping it out every cycle. + * @param position Position you want to return + * @return Itself if this position equals the position passed in, otherwise the position passed in + */ + public TerminalPosition as(TerminalPosition position) { + return position == null ? null : as(position.column, position.row); + } /** * Creates a new TerminalPosition object, which represents a location on the screen. There is no check to verify * that the position you specified is within the size of the current terminal and you can specify negative positions @@ -48,10 +80,9 @@ public class TerminalPosition implements Comparable { * @param row Row of the location, or the "y" coordinate, zero indexed (the first row is 0) */ public TerminalPosition(int column, int row) { - this.row = row; this.column = column; + this.row = row; } - /** * Returns the index of the column this position is representing, zero indexed (the first column has index 0). * @return Index of the column this position has @@ -59,7 +90,6 @@ public TerminalPosition(int column, int row) { public int getColumn() { return column; } - /** * Returns the index of the row this position is representing, zero indexed (the first row has index 0) * @return Index of the row this position has @@ -67,84 +97,64 @@ public int getColumn() { public int getRow() { return row; } - /** - * Creates a new TerminalPosition object representing a position with the same column index as this but with a - * supplied row index. - * @param row Index of the row for the new position - * @return A TerminalPosition object with the same column as this but with a specified row index + * Obtain a TerminalPosition with the supplied column and the same row as this instance. + * @param column Index of the column for the resulting TerminalPosition + * @return a TerminalPosition object with the same row as this but with a specified column index */ - public TerminalPosition withRow(int row) { - if(row == 0 && this.column == 0) { - return TOP_LEFT_CORNER; - } - return new TerminalPosition(this.column, row); + public TerminalPosition withColumn(int column) { + return as(column, row); } - /** - * Creates a new TerminalPosition object representing a position with the same row index as this but with a - * supplied column index. - * @param column Index of the column for the new position - * @return A TerminalPosition object with the same row as this but with a specified column index + * Obtain a TerminalPosition object with this instance's column and the supplied row. + * @param row Index of the row for the new position + * @return a TerminalPosition object with the same column as this but with a specified row index */ - public TerminalPosition withColumn(int column) { - if(column == 0 && this.row == 0) { - return TOP_LEFT_CORNER; - } - return new TerminalPosition(column, this.row); + public TerminalPosition withRow(int row) { + return as(column, row); } - /** - * Creates a new TerminalPosition object representing a position on the same row, but with a column offset by a - * supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return - * a terminal position delta number of columns to the right and for negative numbers the same to the left. + * Obtain a TerminalPosition with a column offset by the supplied delta and the same row as this instance. + * Calling this method with delta 0 will return this, calling it with a positive delta will return + * a TerminalPosition delta number of columns to the right and for negative numbers the same to the left. * @param delta Column offset - * @return New terminal position based off this one but with an applied offset + * @return a TerminalPosition based off this one but with an applied offset */ public TerminalPosition withRelativeColumn(int delta) { - if(delta == 0) { - return this; - } - return withColumn(column + delta); + return plus(delta, 0); } - /** - * Creates a new TerminalPosition object representing a position on the same column, but with a row offset by a - * supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return - * a terminal position delta number of rows to the down and for negative numbers the same up. + * Obtain a TerminalPosition with the same column as this instance and a row which is this instance's row offset + * by the supplied delta. + * Calling this method with delta 0 will return this, calling it with a positive delta will return + * a TerminalPosition delta number of rows to the down and for negative numbers the same up. * @param delta Row offset - * @return New terminal position based off this one but with an applied offset + * @return a TerminalPosition based off this one but with an applied offset */ public TerminalPosition withRelativeRow(int delta) { - if(delta == 0) { - return this; - } - return withRow(row + delta); + return plus(0, delta); } - /** - * Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by another + * Obtain a TerminalPosition that is 'translated' by an amount of rows and columns specified by another * TerminalPosition. Same as calling * withRelativeRow(translate.getRow()).withRelativeColumn(translate.getColumn()) * @param translate How many columns and rows to translate - * @return New TerminalPosition that is the result of the original with added translation + * @return a TerminalPosition that is the result of the original with added translation */ public TerminalPosition withRelative(TerminalPosition translate) { - return withRelative(translate.getColumn(), translate.getRow()); + return plus(translate); } - /** - * Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by the two + * Obtain a TerminalPosition that is 'translated' by an amount of rows and columns specified by the two * parameters. Same as calling * withRelativeRow(deltaRow).withRelativeColumn(deltaColumn) - * @param deltaColumn How many columns to move from the current position in the new TerminalPosition - * @param deltaRow How many rows to move from the current position in the new TerminalPosition - * @return New TerminalPosition that is the result of the original position with added translation + * @param deltaColumn How many columns to move from the current position in the resulting TerminalPosition + * @param deltaRow How many rows to move from the current position in the resulting TerminalPosition + * @return a TerminalPosition that is the result of the original position with added translation */ public TerminalPosition withRelative(int deltaColumn, int deltaRow) { - return withRelativeRow(deltaRow).withRelativeColumn(deltaColumn); + return plus(deltaColumn, deltaRow); } - /** * Returns itself if it is equal to the supplied position, otherwise the supplied position. You can use this if you * have a position field which is frequently recalculated but often resolves to the same; it will keep the same @@ -153,60 +163,53 @@ public TerminalPosition withRelative(int deltaColumn, int deltaRow) { * @return Itself if this position equals the position passed in, otherwise the position passed in */ public TerminalPosition with(TerminalPosition position) { - if(equals(position)) { - return this; - } - return position; + return as(position); } - - public TerminalPosition plus(TerminalPosition position) { - return withRelative(position); + public TerminalPosition plus(TerminalPosition other) { + return plus(other.column, other.row); } - - public TerminalPosition minus(TerminalPosition position) { - return withRelative(-position.getColumn(), -position.getRow()); + public TerminalPosition minus(TerminalPosition other) { + return minus(other.column, other.row); } - - public TerminalPosition multiply(TerminalPosition position) { - return new TerminalPosition(column * position.column, row * position.row); + public TerminalPosition multiply(TerminalPosition other) { + return multiply(other.column, other.row); } - public TerminalPosition divide(TerminalPosition denominator) { - return new TerminalPosition(column / denominator.column, row / denominator.row); + return divide(denominator.column, denominator.row); } + public TerminalPosition plus(int column, int row) { + return as(this.column + column, this.row + row); + } + public TerminalPosition minus(int column, int row) { + return as(this.column - column, this.row - row); + } + public TerminalPosition multiply(int column, int row) { + return as(this.column * column, this.row * row); + } + public TerminalPosition divide(int columnsDenominator, int rowsDenominator) { + return as(column / columnsDenominator, row / rowsDenominator); + } + public TerminalPosition plus(int amount) { return plus(amount, amount); } + public TerminalPosition minus(int amount) { return minus(amount, amount); } + public TerminalPosition multiply(int amount) { return multiply(amount, amount); } + public TerminalPosition divide(int denominator) { return divide(denominator, denominator); } public TerminalPosition abs() { - int x = Math.abs(column); - int y = Math.abs(row); - return new TerminalPosition(x, y); + return as(Math.abs(column), Math.abs(row)); } public TerminalPosition min(TerminalPosition position) { - int x = Math.min(column, position.column); - int y = Math.min(row, position.row); - return new TerminalPosition(x, y); + return as(Math.min(column, position.column), Math.min(row, position.row)); } public TerminalPosition max(TerminalPosition position) { - int x = Math.max(column, position.column); - int y = Math.max(row, position.row); - return new TerminalPosition(x, y); + return as(Math.max(column, position.column), Math.max(row, position.row)); } @Override - public int compareTo(TerminalPosition o) { - if(row < o.row) { - return -1; - } - else if(row == o.row) { - if(column < o.column) { - return -1; - } - else if(column == o.column) { - return 0; - } - } - return 1; + public int compareTo(TerminalPosition other) { + int result = Integer.compare(row, other.row); + return result != 0 ? result : Integer.compare(column, other.column); } @Override @@ -217,25 +220,21 @@ public String toString() { @Override public int hashCode() { int hash = 3; - hash = 23 * hash + this.row; hash = 23 * hash + this.column; + hash = 23 * hash + this.row; return hash; } - public boolean equals(int columnIndex, int rowIndex) { - return this.column == columnIndex && - this.row == rowIndex; + public boolean equals(int column, int row) { + return this.column == column && this.row == row; } @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final TerminalPosition other = (TerminalPosition) obj; - return this.row == other.row && this.column == other.column; + return obj != null + && obj.getClass() == getClass() + && ((TerminalPosition) obj).column == column + && ((TerminalPosition) obj).row == row + ; } } diff --git a/src/main/java/com/googlecode/lanterna/TerminalRectangle.java b/src/main/java/com/googlecode/lanterna/TerminalRectangle.java index 2dd12f609..c775f88e7 100644 --- a/src/main/java/com/googlecode/lanterna/TerminalRectangle.java +++ b/src/main/java/com/googlecode/lanterna/TerminalRectangle.java @@ -27,86 +27,148 @@ */ public class TerminalRectangle { - // one of the benefits of immutable: ease of usage - public final TerminalPosition position; - public final TerminalSize size; - public final int x; - public final int y; - public final int width; - public final int height; + /** + * Constants for less objects memory churn, these are from the top-left corner (column x row) + */ + public static final TerminalRectangle OF_0x0 = new TerminalRectangle(TerminalPosition.of(0, 0), TerminalSize.of(0, 0)); + public static final TerminalRectangle OF_0x1 = new TerminalRectangle(TerminalPosition.of(0, 0), TerminalSize.of(0, 1)); + public static final TerminalRectangle OF_1x0 = new TerminalRectangle(TerminalPosition.of(0, 0), TerminalSize.of(1, 0)); + public static final TerminalRectangle OF_1x1 = new TerminalRectangle(TerminalPosition.of(0, 0), TerminalSize.of(1, 1)); + + private final TerminalPosition position; + private final TerminalSize size; - public final int xAndWidth; - public final int yAndHeight; + public TerminalPosition position() { return position; } + public TerminalSize size() { return size; } + public int x() { return position.x(); } + public int y() { return position.y(); } + public int width() { return size.width(); } + public int height() { return size.height(); } /** - * Creates a new terminal rect representation at the supplied x y position with the supplied width and height. + * Obtain a TerminalRectangle with the supplied x y position and the supplied width and height. * * Both width and height must be at least zero (non negative) as checked in TerminalSize. - * + * @param x column index of top left corner of the TerminalRectangle + * @param y row index of the top left corner of the TerminalRectangle * @param width number of columns * @param height number of rows */ - public TerminalRectangle(int x, int y, int width, int height) { - position = new TerminalPosition(x, y); - size = new TerminalSize(width, height); + public static final TerminalRectangle of(int x, int y, int width, int height) { + return of(TerminalPosition.of(x, y), TerminalSize.of(width, height)); + } + public static final TerminalRectangle of(TerminalPosition position, TerminalSize size) { + if (OF_0x0.equals(position, size)) { return OF_0x0; } + if (OF_0x1.equals(position, size)) { return OF_0x1; } + if (OF_1x0.equals(position, size)) { return OF_1x0; } + if (OF_1x1.equals(position, size)) { return OF_1x1; } - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.xAndWidth = x + width; - this.yAndHeight = y + height; + return new TerminalRectangle(position, size); + } + public TerminalRectangle as(int x, int y, int width, int height) { + return equals(x, y, width, height) ? this : of(x, y, width, height); + } + public TerminalRectangle as(TerminalPosition position, TerminalSize size) { + return equals(position, size) ? this : of(position, size); + } + public TerminalRectangle as(TerminalRectangle rectangle) { + return rectangle == null ? null : as(rectangle.position, rectangle.size); + } + protected TerminalRectangle(TerminalPosition position, TerminalSize size) { + this.position = position; + this.size = size; } - /** - * @return Returns the width of this rect, in number of columns + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied x position + * @param x position of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied x position */ - public int getColumns() { - return width; + public TerminalRectangle withX(int x) { + return TerminalRectangle.of(position.withColumn(x), size); } - /** - * @return Returns the height of this rect representation, in number of rows + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied y position + * @param y position of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied y position */ - public int getRows() { - return height; + public TerminalRectangle withY(int y) { + return TerminalRectangle.of(position.withRow(y), size); } - + /** - * Creates a new rect based on this rect, but with a different width - * @param columns Width of the new rect, in columns - * @return New rect based on this one, but with a new width + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied width + * @param Width of the resulting TerminalRectangle, in columns + * @return a TerminalRectangle based on this one, but with the supplied width */ - public TerminalRectangle withColumns(int columns) { - return new TerminalRectangle(x, y, columns, height); + public TerminalRectangle withWidth(int width) { + return TerminalRectangle.of(position, size.withColumns(width)); + } + /** + * Obtain a TerminalRectangle based on this rect, but with the supplied height + * @param Height of the resulting rect, in rows + * @return a TerminalRectangle based on this one, but with the supplied height + */ + public TerminalRectangle withHeight(int height) { + return TerminalRectangle.of(position, size.withRows(height)); } - /** - * Creates a new rect based on this rect, but with a different height - * @param rows Height of the new rect, in rows - * @return New rect based on this one, but with a new height + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied position + * @param position of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied position */ - public TerminalRectangle withRows(int rows) { - return new TerminalRectangle(x, y, width, rows); + public TerminalRectangle withPosition(TerminalPosition position) { + return TerminalRectangle.of(position, size); + } + /** + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied position + * @param x position of the resulting TerminalRectangle + * @param y position of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied position + */ + public TerminalRectangle withPosition(int x, int y) { + return TerminalRectangle.of(x, y, size.width(), size.height()); + } + /** + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied size + * @param size of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied size + */ + public TerminalRectangle withSize(TerminalSize size) { + return TerminalRectangle.of(position, size); + } + /** + * Obtain a TerminalRectangle based on this TerminalRectangle, but with the supplied size + * @param width number of columns of the resulting TerminalRectangle + * @param height number of rows of the resulting TerminalRectangle + * @return a TerminalRectangle based on this one, but with the supplied size + */ + public TerminalRectangle withSize(int width, int height) { + return TerminalRectangle.of(position.x(), position.y(), width, height); } public boolean whenContains(TerminalPosition p, Runnable op) { - return whenContains(p.getColumn(), p.getRow(), op); + return whenContains(p.x(), p.y(), op); } public boolean whenContains(int x, int y, Runnable op) { - if (this.x <= x && x < this.xAndWidth && this.y <= y && y < this.yAndHeight) { + return whenContains(x(), y(), width(), height(), x, y, op); + } + public static final boolean whenContains(int rx, int ry, int rw, int rh, int x, int y, Runnable op) { + if (rx <= x && x < (rx + rw) && ry <= y && y < (ry + rh)) { op.run(); return true; } return false; } - - @Override public String toString() { - return "{x: " + x + ", y: " + y + ", width: " + width + ", height: " + height + "}"; + return "{x: " + x() + ", y: " + y() + ", width: " + width() + ", height: " + height() + "}"; + } + public boolean equals(int x, int y, int width, int height) { + return position.equals(x, y) && size.equals(width, height); + } + public boolean equals(TerminalPosition position, TerminalSize size) { + return this.position.equals(position) && this.size.equals(size); } - @Override public boolean equals(Object obj) { return obj != null @@ -114,7 +176,6 @@ public boolean equals(Object obj) { && Objects.equals(position, ((TerminalRectangle)obj).position) && Objects.equals(size, ((TerminalRectangle)obj).size); } - @Override public int hashCode() { return Objects.hash(position, size); diff --git a/src/main/java/com/googlecode/lanterna/TerminalSize.java b/src/main/java/com/googlecode/lanterna/TerminalSize.java index 5b5b0afdb..319bd2a73 100644 --- a/src/main/java/com/googlecode/lanterna/TerminalSize.java +++ b/src/main/java/com/googlecode/lanterna/TerminalSize.java @@ -24,147 +24,164 @@ * * @author Martin */ -public class TerminalSize { - public static final TerminalSize ZERO = new TerminalSize(0, 0); - public static final TerminalSize ONE = new TerminalSize(1, 1); +public class TerminalSize implements Comparable { + + public static final TerminalSize OF_0x0 = new TerminalSize(0, 0); + public static final TerminalSize OF_0x1 = new TerminalSize(0, 1); + public static final TerminalSize OF_1x0 = new TerminalSize(1, 0); + public static final TerminalSize OF_1x1 = new TerminalSize(1, 1); private final int columns; private final int rows; - + + public int width() { return columns; } + public int height() { return rows; } + + public static final TerminalSize of(int columns, int rows) { + if (OF_0x0.equals(columns, rows)) { return OF_0x0; } + if (OF_0x1.equals(columns, rows)) { return OF_0x1; } + if (OF_1x0.equals(columns, rows)) { return OF_1x0; } + if (OF_1x1.equals(columns, rows)) { return OF_1x1; } + + return new TerminalSize(columns, rows); + } + public TerminalSize as(int columns, int rows) { + return equals(columns, rows) ? this : of(columns, rows); + } + public TerminalSize as(TerminalSize size) { + return size == null ? null : as(size.columns, size.rows); + } /** * Creates a new terminal size representation with a given width (columns) and height (rows) - * @param columns Width, in number of columns - * @param rows Height, in number of columns + * @param columns Width as number of columns + * @param rows Height as number or rows */ public TerminalSize(int columns, int rows) { if (columns < 0 || rows < 0) { throw new IllegalArgumentException("TerminalSize dimensions cannot be less than 0: [columns: " + columns + ", rows: " + rows + "]"); } - this.columns = columns; this.rows = rows; } - /** - * @return Returns the width of this size representation, in number of columns + * @return Width, the number of columns of this TerminalSize */ public int getColumns() { return columns; } - /** - * Creates a new size based on this size, but with a different width - * @param columns Width of the new size, in columns - * @return New size based on this one, but with a new width + * @return Height, the number of rows of this TerminalSize */ - public TerminalSize withColumns(int columns) { - if(this.columns == columns) { - return this; - } - if(columns == 0 && this.rows == 0) { - return ZERO; - } - return new TerminalSize(columns, this.rows); + public int getRows() { + return rows; } - - /** - * @return Returns the height of this size representation, in number of rows + * Obtain a TerminalSize with the supplied number of columns and this instance's number of rows + * @param columns, the number of columns, or Width, of the resulting TerminalSize + * @return a TerminalSize with the supplied number of columns and this instance's number of rows */ - public int getRows() { - return rows; + public TerminalSize withColumns(int columns) { + return as(columns, rows); } - /** - * Creates a new size based on this size, but with a different height - * @param rows Height of the new size, in rows - * @return New size based on this one, but with a new height + * Obtain a TerminalSize with this instance's number of columns and the supplied number of rows + * @param rows, the number or rows, or Height, of the resulting TerminalSize + * @return a TerminalSize with this instance's number of columns and the supplied number of rows */ public TerminalSize withRows(int rows) { - if(this.rows == rows) { - return this; - } - if(rows == 0 && this.columns == 0) { - return ZERO; - } - return new TerminalSize(this.columns, rows); + return as(columns, rows); } - /** - * Creates a new TerminalSize object representing a size with the same number of rows, but with a column size offset by a + * Obtain a TerminalSize with the same number of rows, but with a columns 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. + * a TerminalSize delta number of columns wider and for negative numbers shorter. * @param delta Column offset - * @return New terminal size based off this one but with an applied transformation + * @return a TerminalSize based off this one but with an applied translation */ public TerminalSize withRelativeColumns(int delta) { - if(delta == 0) { - return this; - } // Prevent going below 0 (which would throw an exception) return withColumns(Math.max(0, columns + delta)); } - /** - * Creates a new TerminalSize object representing a size with the same number of columns, but with a row size offset by a + * Obtain a TerminalSize 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. + * a TerminalSize delta number of rows longer and for negative numbers shorter. * @param delta Row offset - * @return New terminal size based off this one but with an applied transformation + * @return a TerminalSize resulting from translating this instance by the supplied delta rows */ public TerminalSize withRelativeRows(int delta) { - if(delta == 0) { - return this; - } // Prevent going below 0 (which would throw an exception) return withRows(Math.max(0, rows + delta)); } - /** - * Creates a new TerminalSize object representing a size based on this object's size but with a delta applied. + * Obtain a TerminalSize based on this object's size but with a delta applied. * This is the same as calling * withRelativeColumns(delta.getColumns()).withRelativeRows(delta.getRows()) * @param delta Column and row offset - * @return New terminal size based off this one but with an applied resize + * @return a TerminalSize based off this one but with an applied resize */ public TerminalSize withRelative(TerminalSize delta) { - return withRelative(delta.getColumns(), delta.getRows()); + return plus(delta); } - /** - * Creates a new TerminalSize object representing a size based on this object's size but with a delta applied. + * Obtain a TerminalSize based on this object's size but with a delta applied. * This is the same as calling * withRelativeColumns(deltaColumns).withRelativeRows(deltaRows) - * @param deltaColumns How many extra columns the new TerminalSize will have (negative values are allowed) - * @param deltaRows How many extra rows the new TerminalSize will have (negative values are allowed) - * @return New terminal size based off this one but with an applied resize + * @param deltaColumns How many extra columns the resulting TerminalSize will have (negative delta values are allowed) + * @param deltaRows How many extra rows the resulting TerminalSize will have (negative delta values are allowed) + * @return a TerminalSize based off this one but with an applied resize */ public TerminalSize withRelative(int deltaColumns, int deltaRows) { - return withRelativeRows(deltaRows).withRelativeColumns(deltaColumns); + return plus(deltaColumns, deltaRows); } - /** - * 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. - * @param other Other TerminalSize to compare with - * @return TerminalSize that combines the maximum width between the two and the maximum height + * Obtain a TerminalSize having the max columns and max rows of this instance and the supplied one. + * Example: calling 3x5 on a 5x3 will return 5x5. + * @param other TerminalSize to compare with + * @return a TerminalSize that combines the maximum width and maximum height between the two */ public TerminalSize max(TerminalSize other) { - return withColumns(Math.max(columns, other.columns)) - .withRows(Math.max(rows, other.rows)); + return as(Math.max(columns, other.columns), Math.max(rows, other.rows)); } - /** - * 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. - * @param other Other TerminalSize to compare with - * @return TerminalSize that combines the minimum width between the two and the minimum height + * Obtain a TerminalSize having the min columns and min rows of this instance and the supplied one. + * Example: calling 3x5 on a 5x3 will return 3x3. + * @param other TerminalSize to compare with + * @return a TerminalSize that combines the minimum width and minimum height between the two */ public TerminalSize min(TerminalSize other) { - return withColumns(Math.min(columns, other.columns)) - .withRows(Math.min(rows, other.rows)); + return as(Math.min(columns, other.columns), Math.min(rows, other.rows)); } + public TerminalSize plus(TerminalSize other) { + return plus(other.columns, other.rows); + } + public TerminalSize minus(TerminalSize other) { + return minus(other.columns, other.rows); + } + public TerminalSize multiply(TerminalSize other) { + return multiply(other.columns, other.rows); + } + public TerminalSize divide(TerminalSize denominator) { + return divide(denominator.columns, denominator.rows); + } + public TerminalSize plus(int columns, int rows) { + return as(this.columns + columns, this.rows + rows); + } + public TerminalSize minus(int columns, int rows) { + return as(this.columns - columns, this.rows - rows); + } + public TerminalSize multiply(int columns, int rows) { + return as(this.columns * columns, this.rows * rows); + } + public TerminalSize divide(int columnsDenominator, int rowsDenominator) { + return as(columns / columnsDenominator, rows / rowsDenominator); + } + public TerminalSize plus(int amount) { return plus(amount, amount); } + public TerminalSize minus(int amount) { return minus(amount, amount); } + public TerminalSize multiply(int amount) { return multiply(amount, amount); } + public TerminalSize divide(int denominator) { return divide(denominator, denominator); } + /** * 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 @@ -173,10 +190,16 @@ public TerminalSize min(TerminalSize other) { * @return Itself if this size equals the size passed in, otherwise the size passed in */ public TerminalSize with(TerminalSize size) { - if(equals(size)) { - return this; - } - return size; + return as(size); + } + + @Override + public int compareTo(TerminalSize other) { + return Integer.compare(columns * rows, other.columns * other.rows); + } + + public boolean equals(int columns, int rows) { + return this.columns == columns && this.rows == rows; } @Override @@ -186,16 +209,11 @@ public String toString() { @Override public boolean equals(Object obj) { - if(this == obj) { - return true; - } - if (!(obj instanceof TerminalSize)) { - return false; - } - - TerminalSize other = (TerminalSize) obj; - return columns == other.columns - && rows == other.rows; + return obj != null + && obj.getClass() == getClass() + && ((TerminalSize) obj).columns == columns + && ((TerminalSize) obj).rows == rows + ; } @Override diff --git a/src/main/java/com/googlecode/lanterna/graphics/AbstractTextGraphics.java b/src/main/java/com/googlecode/lanterna/graphics/AbstractTextGraphics.java index ecf641192..ce38da024 100644 --- a/src/main/java/com/googlecode/lanterna/graphics/AbstractTextGraphics.java +++ b/src/main/java/com/googlecode/lanterna/graphics/AbstractTextGraphics.java @@ -120,7 +120,7 @@ public TextGraphics setTabBehaviour(TabBehaviour tabBehaviour) { @Override public TextGraphics fill(char c) { - fillRectangle(TerminalPosition.TOP_LEFT_CORNER, getSize(), c); + fillRectangle(TerminalPosition.OF_0x0, getSize(), c); return this; } @@ -158,7 +158,7 @@ public TextGraphics drawLine(int fromX, int fromY, int toX, int toY, char charac @Override public TextGraphics drawLine(int fromX, int fromY, int toX, int toY, TextCharacter character) { - return drawLine(new TerminalPosition(fromX, fromY), new TerminalPosition(toX, toY), character); + return drawLine(TerminalPosition.of(fromX, fromY), TerminalPosition.of(toX, toY), character); } @Override @@ -207,7 +207,7 @@ public TextGraphics fillRectangle(TerminalPosition topLeft, TerminalSize size, T @Override public TextGraphics drawImage(TerminalPosition topLeft, TextImage image) { - return drawImage(topLeft, image, TerminalPosition.TOP_LEFT_CORNER, image.getSize()); + return drawImage(topLeft, image, TerminalPosition.OF_0x0, image.getSize()); } @Override diff --git a/src/main/java/com/googlecode/lanterna/graphics/BasicTextImage.java b/src/main/java/com/googlecode/lanterna/graphics/BasicTextImage.java index 79febeff0..ea6889a7c 100644 --- a/src/main/java/com/googlecode/lanterna/graphics/BasicTextImage.java +++ b/src/main/java/com/googlecode/lanterna/graphics/BasicTextImage.java @@ -42,7 +42,7 @@ public class BasicTextImage implements TextImage { * @param rows Size of the image in number of rows */ public BasicTextImage(int columns, int rows) { - this(new TerminalSize(columns, rows)); + this(TerminalSize.of(columns, rows)); } /** diff --git a/src/main/java/com/googlecode/lanterna/graphics/DefaultShapeRenderer.java b/src/main/java/com/googlecode/lanterna/graphics/DefaultShapeRenderer.java index 563d567ce..05f778e9f 100644 --- a/src/main/java/com/googlecode/lanterna/graphics/DefaultShapeRenderer.java +++ b/src/main/java/com/googlecode/lanterna/graphics/DefaultShapeRenderer.java @@ -162,20 +162,20 @@ public void fillTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosit startY = points[0].getRow(); if (dx1 > dx2) { for (; startY <= points[1].getRow(); startY++, startX += dx2, endX += dx1) { - drawLine(new TerminalPosition((int)startX, (int)startY), new TerminalPosition((int)endX, (int)startY), character); + drawLine(TerminalPosition.of((int)startX, (int)startY), TerminalPosition.of((int)endX, (int)startY), character); } endX = points[1].getColumn(); for (; startY <= points[2].getRow(); startY++, startX += dx2, endX += dx3) { - drawLine(new TerminalPosition((int)startX, (int)startY), new TerminalPosition((int)endX, (int)startY), character); + drawLine(TerminalPosition.of((int)startX, (int)startY), TerminalPosition.of((int)endX, (int)startY), character); } } else { for (; startY <= points[1].getRow(); startY++, startX += dx1, endX += dx2) { - drawLine(new TerminalPosition((int)startX, (int)startY), new TerminalPosition((int)endX, (int)startY), character); + drawLine(TerminalPosition.of((int)startX, (int)startY), TerminalPosition.of((int)endX, (int)startY), character); } startX = points[1].getColumn(); startY = points[1].getRow(); for (; startY <= points[2].getRow(); startY++, startX += dx3, endX += dx2) { - drawLine(new TerminalPosition((int)startX, (int)startY), new TerminalPosition((int)endX, (int)startY), character); + drawLine(TerminalPosition.of((int)startX, (int)startY), TerminalPosition.of((int)endX, (int)startY), character); } } } diff --git a/src/main/java/com/googlecode/lanterna/graphics/TextGraphics.java b/src/main/java/com/googlecode/lanterna/graphics/TextGraphics.java index 72d824e17..ad00560f6 100644 --- a/src/main/java/com/googlecode/lanterna/graphics/TextGraphics.java +++ b/src/main/java/com/googlecode/lanterna/graphics/TextGraphics.java @@ -54,7 +54,7 @@ public interface TextGraphics extends StyleSet { /** * Creates a new TextGraphics of the same type as this one, using the same underlying subsystem. Using this method, * you need to specify a section of the current TextGraphics valid area that this new TextGraphic shall be - * restricted to. If you call newTextGraphics(TerminalPosition.TOP_LEFT_CORNER, textGraphics.getSize()) + * restricted to. If you call newTextGraphics(TerminalPosition.of(0, 0), textGraphics.getSize()) * then the resulting object will be identical to this one, but having a separated state for colors, position and * modifiers. * @param topLeftCorner Position of this TextGraphics's writable area that is to become the top-left corner (0x0) of @@ -281,7 +281,7 @@ public interface TextGraphics extends StyleSet { /** * Takes a TextImage and draws it on the surface this TextGraphics is targeting, given the coordinates on the target * that is specifying where the top-left corner of the image should be drawn. This is equivalent of calling - * {@code drawImage(topLeft, image, TerminalPosition.TOP_LEFT_CORNER, image.getSize()}. + * {@code drawImage(topLeft, image, TerminalPosition.of(0, 0), image.getSize()}. * @param topLeft Position of the top-left corner of the image on the target * @param image Image to draw * @return Itself diff --git a/src/main/java/com/googlecode/lanterna/graphics/TextGraphicsWriter.java b/src/main/java/com/googlecode/lanterna/graphics/TextGraphicsWriter.java index d8885c61c..f84f2801f 100644 --- a/src/main/java/com/googlecode/lanterna/graphics/TextGraphicsWriter.java +++ b/src/main/java/com/googlecode/lanterna/graphics/TextGraphicsWriter.java @@ -24,7 +24,7 @@ public class TextGraphicsWriter implements StyleSet { public TextGraphicsWriter(TextGraphics backend) { this.backend = backend; setStyleFrom( backend ); - cursorPosition = new TerminalPosition(0, 0); + cursorPosition = TerminalPosition.OF_0x0; } public TextGraphicsWriter putString(String string) { diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbsoluteLayout.java b/src/main/java/com/googlecode/lanterna/gui2/AbsoluteLayout.java index a4a87b414..5810f9729 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbsoluteLayout.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbsoluteLayout.java @@ -32,10 +32,9 @@ public class AbsoluteLayout implements LayoutManager { @Override public TerminalSize getPreferredSize(List components) { - TerminalSize size = TerminalSize.ZERO; + TerminalSize size = TerminalSize.OF_0x0; for(Component component: components) { - size = size.max( - new TerminalSize( + size = size.max(TerminalSize.of( component.getPosition().getColumn() + component.getSize().getColumns(), component.getPosition().getRow() + component.getSize().getRows())); diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractBasePane.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractBasePane.java index 6fdeebc92..1251f76e5 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractBasePane.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractBasePane.java @@ -50,7 +50,7 @@ public abstract class AbstractBasePane implements BasePane { protected AbstractBasePane() { this.contentHolder = new ContentHolder(); this.listeners = new CopyOnWriteArrayList<>(); - this.interactableLookupMap = new InteractableLookupMap(new TerminalSize(80, 25)); + this.interactableLookupMap = new InteractableLookupMap(TerminalSize.of(80, 25)); this.invalid = false; this.strictFocusChange = false; this.enableDirectionBasedMovements = true; @@ -452,7 +452,7 @@ protected ComponentRenderer createDefaultRenderer() { public TerminalSize getPreferredSize(Container component) { Component subComponent = getComponent(); if(subComponent == null) { - return TerminalSize.ZERO; + return TerminalSize.OF_0x0; } return subComponent.getPreferredSize(); } @@ -461,9 +461,9 @@ public TerminalSize getPreferredSize(Container component) { public void drawComponent(TextGUIGraphics graphics, Container component) { if (!(menuBar instanceof EmptyMenuBar)) { int menuBarHeight = menuBar.getPreferredSize().getRows(); - TextGUIGraphics menuGraphics = graphics.newTextGraphics(TerminalPosition.TOP_LEFT_CORNER, graphics.getSize().withRows(menuBarHeight)); + TextGUIGraphics menuGraphics = graphics.newTextGraphics(TerminalPosition.OF_0x0, graphics.getSize().withRows(menuBarHeight)); menuBar.draw(menuGraphics); - graphics = graphics.newTextGraphics(TerminalPosition.TOP_LEFT_CORNER.withRelativeRow(menuBarHeight), graphics.getSize().withRelativeRows(-menuBarHeight)); + graphics = graphics.newTextGraphics(TerminalPosition.of(0, menuBarHeight), graphics.getSize().withRelativeRows(-menuBarHeight)); } Component subComponent = getComponent(); diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractBorder.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractBorder.java index 781f6fee4..52c1c60e5 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractBorder.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractBorder.java @@ -32,7 +32,7 @@ public abstract class AbstractBorder extends AbstractComposite implement public void setComponent(Component component) { super.setComponent(component); if(component != null) { - component.setPosition(TerminalPosition.TOP_LEFT_CORNER); + component.setPosition(TerminalPosition.OF_0x0); } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractComponent.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractComponent.java index 369c30459..33283d70b 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractComponent.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractComponent.java @@ -76,8 +76,8 @@ public abstract class AbstractComponent implements Componen * Default constructor */ public AbstractComponent() { - size = TerminalSize.ZERO; - position = TerminalPosition.TOP_LEFT_CORNER; + size = TerminalSize.OF_0x0; + position = TerminalPosition.OF_0x0; explicitPreferredSize = null; layoutData = null; visible = true; @@ -233,7 +233,7 @@ public TerminalPosition getPosition() { @Override public TerminalPosition getGlobalPosition() { - return toGlobal(TerminalPosition.TOP_LEFT_CORNER); + return toGlobal(TerminalPosition.OF_0x0); } @Override diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractComposite.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractComposite.java index debad26a6..940f33d83 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractComposite.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractComposite.java @@ -60,9 +60,9 @@ public void setComponent(Component component) { if (getBasePane() != null) { MenuBar menuBar = getBasePane().getMenuBar(); if (menuBar == null || menuBar.isEmptyMenuBar()) { - component.setPosition(TerminalPosition.TOP_LEFT_CORNER); + component.setPosition(TerminalPosition.OF_0x0); } else { - component.setPosition(TerminalPosition.TOP_LEFT_CORNER.withRelativeRow(1)); + component.setPosition(TerminalPosition.OF_0x1); } } invalidate(); diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractListBox.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractListBox.java index 44c158b13..17b0b4753 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractListBox.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractListBox.java @@ -39,7 +39,7 @@ public abstract class AbstractListBox> extend private final List items; private int selectedIndex; private ListItemRenderer listItemRenderer; - protected TerminalPosition scrollOffset = new TerminalPosition(0, 0); + protected TerminalPosition scrollOffset = TerminalPosition.OF_0x0; /** * This constructor sets up the component so it has no preferred size but will ask to be as big as the list is. If @@ -403,7 +403,7 @@ public TerminalPosition getCursorLocation(T listBox) { if(columnAccordingToRenderer == -1) { return null; } - return new TerminalPosition(columnAccordingToRenderer, selectedIndex - scrollTopIndex); + return TerminalPosition.of(columnAccordingToRenderer, selectedIndex - scrollTopIndex); } @Override @@ -417,7 +417,7 @@ public TerminalSize getPreferredSize(T listBox) { maxWidth = stringLengthInColumns; } } - return new TerminalSize(maxWidth + 1, listBox.getItemCount()); + return TerminalSize.of(maxWidth + 1, listBox.getItemCount()); } @Override @@ -445,7 +445,7 @@ else if(selectedIndex >= componentHeight + scrollTopIndex) scrollTopIndex = items.size() - componentHeight; } - listBox.scrollOffset = new TerminalPosition(0, -scrollTopIndex); + listBox.scrollOffset = TerminalPosition.of(0, -scrollTopIndex); graphics.applyThemeStyle(themeDefinition.getNormal()); graphics.fill(' '); @@ -456,7 +456,7 @@ else if(selectedIndex >= componentHeight + scrollTopIndex) break; } listItemRenderer.drawItem( - graphics.newTextGraphics(new TerminalPosition(0, i - scrollTopIndex), itemSize), + graphics.newTextGraphics(TerminalPosition.of(0, i - scrollTopIndex), itemSize), listBox, i, items.get(i), @@ -471,8 +471,8 @@ else if(selectedIndex >= componentHeight + scrollTopIndex) verticalScrollBar.setScrollMaximum(items.size()); verticalScrollBar.setScrollPosition(scrollTopIndex); verticalScrollBar.draw(graphics.newTextGraphics( - new TerminalPosition(graphics.getSize().getColumns() - 1, 0), - new TerminalSize(1, graphics.getSize().getRows()))); + TerminalPosition.of(graphics.getSize().getColumns() - 1, 0), + TerminalSize.of(1, graphics.getSize().getRows()))); } } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/AbstractWindow.java b/src/main/java/com/googlecode/lanterna/gui2/AbstractWindow.java index 3d7ac5fde..fb67650ab 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AbstractWindow.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AbstractWindow.java @@ -60,7 +60,7 @@ public AbstractWindow(String title) { this.title = title; this.textGUI = null; this.visible = true; - this.contentOffset = TerminalPosition.TOP_LEFT_CORNER; + this.contentOffset = TerminalPosition.OF_0x0; this.lastKnownPosition = null; this.lastKnownSize = null; this.lastKnownDecoratedSize = null; diff --git a/src/main/java/com/googlecode/lanterna/gui2/AnimatedLabel.java b/src/main/java/com/googlecode/lanterna/gui2/AnimatedLabel.java index 31bbdd37b..7eef79726 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/AnimatedLabel.java +++ b/src/main/java/com/googlecode/lanterna/gui2/AnimatedLabel.java @@ -68,7 +68,7 @@ public AnimatedLabel(String firstFrameText) { super(firstFrameText); frames = new ArrayList<>(); currentFrame = 0; - combinedMaximumPreferredSize = TerminalSize.ZERO; + combinedMaximumPreferredSize = TerminalSize.OF_0x0; String[] lines = splitIntoMultipleLines(firstFrameText); frames.add(lines); diff --git a/src/main/java/com/googlecode/lanterna/gui2/BorderLayout.java b/src/main/java/com/googlecode/lanterna/gui2/BorderLayout.java index dc301af1b..cc6f32379 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/BorderLayout.java +++ b/src/main/java/com/googlecode/lanterna/gui2/BorderLayout.java @@ -98,7 +98,7 @@ public TerminalSize getPreferredSize(List components) { Math.max( layout.containsKey(Location.TOP) ? layout.get(Location.TOP).getPreferredSize().getColumns() : 0, layout.containsKey(Location.BOTTOM) ? layout.get(Location.BOTTOM).getPreferredSize().getColumns() : 0)); - return new TerminalSize(preferredWidth, preferredHeight); + return TerminalSize.of(preferredWidth, preferredHeight); } @Override @@ -115,8 +115,8 @@ public void doLayout(TerminalSize area, List components) { if(layout.containsKey(Location.TOP)) { Component topComponent = layout.get(Location.TOP); topComponentHeight = Math.min(topComponent.getPreferredSize().getRows(), availableVerticalSpace); - topComponent.setPosition(TerminalPosition.TOP_LEFT_CORNER); - topComponent.setSize(new TerminalSize(availableHorizontalSpace, topComponentHeight)); + topComponent.setPosition(TerminalPosition.OF_0x0); + topComponent.setSize(TerminalSize.of(availableHorizontalSpace, topComponentHeight)); availableVerticalSpace -= topComponentHeight; } @@ -124,8 +124,8 @@ public void doLayout(TerminalSize area, List components) { if(layout.containsKey(Location.BOTTOM)) { Component bottomComponent = layout.get(Location.BOTTOM); int bottomComponentHeight = Math.min(bottomComponent.getPreferredSize().getRows(), availableVerticalSpace); - bottomComponent.setPosition(new TerminalPosition(0, area.getRows() - bottomComponentHeight)); - bottomComponent.setSize(new TerminalSize(availableHorizontalSpace, bottomComponentHeight)); + bottomComponent.setPosition(TerminalPosition.of(0, area.getRows() - bottomComponentHeight)); + bottomComponent.setSize(TerminalSize.of(availableHorizontalSpace, bottomComponentHeight)); availableVerticalSpace -= bottomComponentHeight; } @@ -133,28 +133,28 @@ public void doLayout(TerminalSize area, List components) { if(layout.containsKey(Location.LEFT)) { Component leftComponent = layout.get(Location.LEFT); leftComponentWidth = Math.min(leftComponent.getPreferredSize().getColumns(), availableHorizontalSpace); - leftComponent.setPosition(new TerminalPosition(0, topComponentHeight)); - leftComponent.setSize(new TerminalSize(leftComponentWidth, availableVerticalSpace)); + leftComponent.setPosition(TerminalPosition.of(0, topComponentHeight)); + leftComponent.setSize(TerminalSize.of(leftComponentWidth, availableVerticalSpace)); availableHorizontalSpace -= leftComponentWidth; } if(layout.containsKey(Location.RIGHT)) { Component rightComponent = layout.get(Location.RIGHT); int rightComponentWidth = Math.min(rightComponent.getPreferredSize().getColumns(), availableHorizontalSpace); - rightComponent.setPosition(new TerminalPosition(area.getColumns() - rightComponentWidth, topComponentHeight)); - rightComponent.setSize(new TerminalSize(rightComponentWidth, availableVerticalSpace)); + rightComponent.setPosition(TerminalPosition.of(area.getColumns() - rightComponentWidth, topComponentHeight)); + rightComponent.setSize(TerminalSize.of(rightComponentWidth, availableVerticalSpace)); availableHorizontalSpace -= rightComponentWidth; } if(layout.containsKey(Location.CENTER)) { Component centerComponent = layout.get(Location.CENTER); - centerComponent.setPosition(new TerminalPosition(leftComponentWidth, topComponentHeight)); - centerComponent.setSize(new TerminalSize(availableHorizontalSpace, availableVerticalSpace)); + centerComponent.setPosition(TerminalPosition.of(leftComponentWidth, topComponentHeight)); + centerComponent.setSize(TerminalSize.of(availableHorizontalSpace, availableVerticalSpace)); } //Set the remaining components to 0x0 for(Component component: components) { if(component.isVisible() && !layout.containsValue(component)) { - component.setPosition(TerminalPosition.TOP_LEFT_CORNER); - component.setSize(TerminalSize.ZERO); + component.setPosition(TerminalPosition.OF_0x0); + component.setSize(TerminalSize.OF_0x0); } } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/Borders.java b/src/main/java/com/googlecode/lanterna/gui2/Borders.java index 632ab2d6f..05822eabd 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/Borders.java +++ b/src/main/java/com/googlecode/lanterna/gui2/Borders.java @@ -186,18 +186,18 @@ public TerminalSize getPreferredSize(Border component) { Component wrappedComponent = border.getComponent(); TerminalSize preferredSize; if (wrappedComponent == null) { - preferredSize = TerminalSize.ZERO; + preferredSize = TerminalSize.OF_0x0; } else { preferredSize = wrappedComponent.getPreferredSize(); } preferredSize = preferredSize.withRelativeColumns(2).withRelativeRows(2); String borderTitle = border.getTitle(); - return preferredSize.max(new TerminalSize((borderTitle.isEmpty() ? 2 : TerminalTextUtils.getColumnWidth(borderTitle) + 4), 2)); + return preferredSize.max(TerminalSize.of((borderTitle.isEmpty() ? 2 : TerminalTextUtils.getColumnWidth(borderTitle) + 4), 2)); } @Override public TerminalPosition getWrappedComponentTopLeftOffset() { - return TerminalPosition.OFFSET_1x1; + return TerminalPosition.OF_1x1; } @Override @@ -234,11 +234,11 @@ public void drawComponent(TextGUIGraphics graphics, Border component) { } graphics.setCharacter(0, drawableArea.getRows() - 1, bottomLeftCorner); if(drawableArea.getRows() > 2) { - graphics.drawLine(new TerminalPosition(0, drawableArea.getRows() - 2), new TerminalPosition(0, 1), verticalLine); + graphics.drawLine(TerminalPosition.of(0, drawableArea.getRows() - 2), TerminalPosition.OF_0x1, verticalLine); } graphics.setCharacter(0, 0, topLeftCorner); if(drawableArea.getColumns() > 2) { - graphics.drawLine(new TerminalPosition(1, 0), new TerminalPosition(drawableArea.getColumns() - 2, 0), horizontalLine); + graphics.drawLine(TerminalPosition.OF_1x0, TerminalPosition.of(drawableArea.getColumns() - 2, 0), horizontalLine); } if(borderStyle == BorderStyle.ReverseBevel) { @@ -249,14 +249,14 @@ public void drawComponent(TextGUIGraphics graphics, Border component) { } graphics.setCharacter(drawableArea.getColumns() - 1, 0, topRightCorner); if(drawableArea.getRows() > 2) { - graphics.drawLine(new TerminalPosition(drawableArea.getColumns() - 1, 1), - new TerminalPosition(drawableArea.getColumns() - 1, drawableArea.getRows() - 2), + graphics.drawLine(TerminalPosition.of(drawableArea.getColumns() - 1, 1), + TerminalPosition.of(drawableArea.getColumns() - 1, drawableArea.getRows() - 2), verticalLine); } graphics.setCharacter(drawableArea.getColumns() - 1, drawableArea.getRows() - 1, bottomRightCorner); if(drawableArea.getColumns() > 2) { - graphics.drawLine(new TerminalPosition(1, drawableArea.getRows() - 1), - new TerminalPosition(drawableArea.getColumns() - 2, drawableArea.getRows() - 1), + graphics.drawLine(TerminalPosition.of(1, drawableArea.getRows() - 1), + TerminalPosition.of(drawableArea.getColumns() - 2, drawableArea.getRows() - 1), horizontalLine); } diff --git a/src/main/java/com/googlecode/lanterna/gui2/Button.java b/src/main/java/com/googlecode/lanterna/gui2/Button.java index 001ae7961..d2e9a4ea7 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/Button.java +++ b/src/main/java/com/googlecode/lanterna/gui2/Button.java @@ -160,7 +160,7 @@ public static class DefaultButtonRenderer implements ButtonRenderer { @Override public TerminalPosition getCursorLocation(Button button) { if(button.getThemeDefinition().isCursorVisible()) { - return new TerminalPosition(1 + getLabelShift(button, button.getSize()), 0); + return TerminalPosition.of(1 + getLabelShift(button, button.getSize()), 0); } else { return null; @@ -169,7 +169,7 @@ public TerminalPosition getCursorLocation(Button button) { @Override public TerminalSize getPreferredSize(Button button) { - return new TerminalSize(Math.max(8, TerminalTextUtils.getColumnWidth(button.getLabel()) + 2), 1); + return TerminalSize.of(Math.max(8, TerminalTextUtils.getColumnWidth(button.getLabel()) + 2), 1); } @Override @@ -231,7 +231,7 @@ public TerminalPosition getCursorLocation(Button component) { @Override public TerminalSize getPreferredSize(Button component) { - return new TerminalSize(TerminalTextUtils.getColumnWidth(component.getLabel()), 1); + return TerminalSize.of(TerminalTextUtils.getColumnWidth(component.getLabel()), 1); } @Override @@ -262,7 +262,7 @@ public TerminalPosition getCursorLocation(Button component) { @Override public TerminalSize getPreferredSize(Button component) { - return new TerminalSize(TerminalTextUtils.getColumnWidth(component.getLabel()) + 5, 4); + return TerminalSize.of(TerminalTextUtils.getColumnWidth(component.getLabel()) + 5, 4); } @Override diff --git a/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java b/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java index a2b45354a..df56a00aa 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java +++ b/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java @@ -175,7 +175,7 @@ public static abstract class CheckBoxRenderer implements InteractableRenderer comboBox) { if(comboBox.isDropDownFocused()) { if(comboBox.getThemeDefinition().isCursorVisible()) { - return new TerminalPosition(comboBox.getSize().getColumns() - 1, 0); + return TerminalPosition.of(comboBox.getSize().getColumns() - 1, 0); } else { return null; @@ -636,19 +636,19 @@ public TerminalPosition getCursorLocation(ComboBox comboBox) { else { int textInputPosition = comboBox.getTextInputPosition(); int textInputColumn = TerminalTextUtils.getColumnWidth(comboBox.getText().substring(0, textInputPosition)); - return new TerminalPosition(textInputColumn - textVisibleLeftPosition, 0); + return TerminalPosition.of(textInputColumn - textVisibleLeftPosition, 0); } } @Override public TerminalSize getPreferredSize(final ComboBox comboBox) { - TerminalSize size = TerminalSize.ONE.withColumns( + TerminalSize size = TerminalSize.OF_1x1.withColumns( (comboBox.getItemCount() == 0 ? TerminalTextUtils.getColumnWidth(comboBox.getText()) : 0) + 2); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized(comboBox) { for(int i = 0; i < comboBox.getItemCount(); i++) { V item = comboBox.getItem(i); - size = size.max(new TerminalSize(TerminalTextUtils.getColumnWidth(item.toString()) + 2 + 1, 1)); // +1 to add a single column of space + size = size.max(TerminalSize.of(TerminalTextUtils.getColumnWidth(item.toString()) + 2 + 1, 1)); // +1 to add a single column of space } } return size; diff --git a/src/main/java/com/googlecode/lanterna/gui2/Component.java b/src/main/java/com/googlecode/lanterna/gui2/Component.java index 9234536e3..27d3d24fe 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/Component.java +++ b/src/main/java/com/googlecode/lanterna/gui2/Component.java @@ -18,6 +18,7 @@ */ package com.googlecode.lanterna.gui2; +import com.googlecode.lanterna.TerminalRectangle; import com.googlecode.lanterna.TerminalPosition; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.graphics.Theme; @@ -30,6 +31,14 @@ * @author Martin */ public interface Component extends TextGUIElement { + + /** + * + * @return the TerminalPosition and TerminalSize as a TerminalRectangle + */ + default TerminalRectangle getBounds() { + return TerminalRectangle.of(getPosition(), getSize()); + } /** * Returns the top-left corner of this component, measured from its parent. * @return Position of this component @@ -38,7 +47,7 @@ public interface Component extends TextGUIElement { /** * Returns the top-left corner of this component in global coordinates space - * using {@link TerminalPosition#TOP_LEFT_CORNER} with + * using {@link TerminalPosition#OF_0x0} with * {@link #toGlobal(TerminalPosition)} * * @return global position of this component diff --git a/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowDecorationRenderer.java b/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowDecorationRenderer.java index d26988a03..f1ebbd5c0 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowDecorationRenderer.java +++ b/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowDecorationRenderer.java @@ -69,8 +69,8 @@ public TextGUIGraphics draw(WindowBasedTextGUI textGUI, TextGUIGraphics graphics else { graphics.applyThemeStyle(themeDefinition.getPreLight()); } - graphics.drawLine(new TerminalPosition(0, drawableArea.getRows() - 2), new TerminalPosition(0, 1), verticalLine); - graphics.drawLine(new TerminalPosition(1, 0), new TerminalPosition(drawableArea.getColumns() - 2, 0), horizontalLine); + graphics.drawLine(TerminalPosition.of(0, drawableArea.getRows() - 2), TerminalPosition.OF_0x1, verticalLine); + graphics.drawLine(TerminalPosition.OF_1x0, TerminalPosition.of(drawableArea.getColumns() - 2, 0), horizontalLine); graphics.setCharacter(0, 0, topLeftCorner); graphics.setCharacter(0, drawableArea.getRows() - 1, bottomLeftCorner); @@ -87,12 +87,12 @@ public TextGUIGraphics draw(WindowBasedTextGUI textGUI, TextGUIGraphics graphics graphics.applyThemeStyle(themeDefinition.getNormal()); graphics.drawLine( - new TerminalPosition(drawableArea.getColumns() - 1, 1), - new TerminalPosition(drawableArea.getColumns() - 1, drawableArea.getRows() - 2), + TerminalPosition.of(drawableArea.getColumns() - 1, 1), + TerminalPosition.of(drawableArea.getColumns() - 1, drawableArea.getRows() - 2), verticalLine); graphics.drawLine( - new TerminalPosition(1, drawableArea.getRows() - 1), - new TerminalPosition(drawableArea.getColumns() - 2, drawableArea.getRows() - 1), + TerminalPosition.of(1, drawableArea.getRows() - 1), + TerminalPosition.of(drawableArea.getColumns() - 2, drawableArea.getRows() - 1), horizontalLine); graphics.setCharacter(drawableArea.getColumns() - 1, 0, topRightCorner); @@ -109,7 +109,7 @@ public TextGUIGraphics draw(WindowBasedTextGUI textGUI, TextGUIGraphics graphics } return graphics.newTextGraphics( - new TerminalPosition(1, 1), + TerminalPosition.OF_1x1, drawableArea // Make sure we don't make the new graphic's area smaller than 0 .withRelativeColumns(-(Math.min(2, drawableArea.getColumns()))) @@ -130,13 +130,11 @@ public TerminalSize getDecoratedSize(Window window, TerminalSize contentAreaSize return contentAreaSize .withRelativeColumns(2) .withRelativeRows(2) - .max(new TerminalSize(titleWidth + minPadding, 1)); //Make sure the title fits! + .max(TerminalSize.of(titleWidth + minPadding, 1)); //Make sure the title fits! } - private static final TerminalPosition OFFSET = new TerminalPosition(1, 1); - @Override public TerminalPosition getOffset(Window window) { - return OFFSET; + return TerminalPosition.OF_1x1; } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowManager.java b/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowManager.java index a9dacd6f9..797110000 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowManager.java +++ b/src/main/java/com/googlecode/lanterna/gui2/DefaultWindowManager.java @@ -72,7 +72,7 @@ public DefaultWindowManager(WindowDecorationRenderer windowDecorationRenderer, T this.lastKnownScreenSize = initialScreenSize; } else { - this.lastKnownScreenSize = new TerminalSize(80, 24); + this.lastKnownScreenSize = TerminalSize.of(80, 24); } } @@ -108,18 +108,18 @@ public void onAdded(WindowBasedTextGUI textGUI, Window window, List allW //Don't place the window, assume the position is already set } else if(allWindows.isEmpty()) { - window.setPosition(TerminalPosition.OFFSET_1x1); + window.setPosition(TerminalPosition.OF_1x1); } else if(window.getHints().contains(Window.Hint.CENTERED)) { int left = (lastKnownScreenSize.getColumns() - expectedDecoratedSize.getColumns()) / 2; int top = (lastKnownScreenSize.getRows() - expectedDecoratedSize.getRows()) / 2; - window.setPosition(new TerminalPosition(left, top)); + window.setPosition(TerminalPosition.of(left, top)); } else { TerminalPosition nextPosition = allWindows.get(allWindows.size() - 1).getPosition().withRelative(2, 1); if(nextPosition.getColumn() + expectedDecoratedSize.getColumns() > lastKnownScreenSize.getColumns() || nextPosition.getRow() + expectedDecoratedSize.getRows() > lastKnownScreenSize.getRows()) { - nextPosition = TerminalPosition.OFFSET_1x1; + nextPosition = TerminalPosition.of(1, 1); } window.setPosition(nextPosition); } @@ -164,11 +164,11 @@ protected void prepareWindow(TerminalSize screenSize, Window window) { TerminalPosition position = window.getPosition(); if(window.getHints().contains(Window.Hint.FULL_SCREEN)) { - position = TerminalPosition.TOP_LEFT_CORNER; + position = TerminalPosition.OF_0x0; size = screenSize; } else if(window.getHints().contains(Window.Hint.EXPANDED)) { - position = TerminalPosition.OFFSET_1x1; + position = TerminalPosition.OF_1x1; size = screenSize.withRelative( -Math.min(4, screenSize.getColumns()), -Math.min(3, screenSize.getRows())); @@ -195,7 +195,7 @@ else if(window.getHints().contains(Window.Hint.FIT_TERMINAL_WINDOW) || if(window.getHints().contains(Window.Hint.CENTERED)) { int left = (lastKnownScreenSize.getColumns() - size.getColumns()) / 2; int top = (lastKnownScreenSize.getRows() - size.getRows()) / 2; - position = new TerminalPosition(left, top); + position = TerminalPosition.of(left, top); } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/EmptySpace.java b/src/main/java/com/googlecode/lanterna/gui2/EmptySpace.java index f13694b94..5cfaaa617 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/EmptySpace.java +++ b/src/main/java/com/googlecode/lanterna/gui2/EmptySpace.java @@ -35,7 +35,7 @@ public class EmptySpace extends AbstractComponent { * Creates an EmptySpace with size 1x1 and a default color chosen from the theme */ public EmptySpace() { - this(null, TerminalSize.ONE); + this(null, TerminalSize.OF_1x1); } /** @@ -43,7 +43,7 @@ public EmptySpace() { * @param color Color to use (null will make it use the theme) */ public EmptySpace(TextColor color) { - this(color, TerminalSize.ONE); + this(color, TerminalSize.OF_1x1); } /** diff --git a/src/main/java/com/googlecode/lanterna/gui2/EmptyWindowDecorationRenderer.java b/src/main/java/com/googlecode/lanterna/gui2/EmptyWindowDecorationRenderer.java index 0220ed6e1..7d0d2d53f 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/EmptyWindowDecorationRenderer.java +++ b/src/main/java/com/googlecode/lanterna/gui2/EmptyWindowDecorationRenderer.java @@ -38,6 +38,6 @@ public TerminalSize getDecoratedSize(Window window, TerminalSize contentAreaSize @Override public TerminalPosition getOffset(Window window) { - return TerminalPosition.TOP_LEFT_CORNER; + return TerminalPosition.OF_0x0; } } diff --git a/src/main/java/com/googlecode/lanterna/gui2/FatWindowDecorationRenderer.java b/src/main/java/com/googlecode/lanterna/gui2/FatWindowDecorationRenderer.java index bc3c3e86c..cb0182ac3 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/FatWindowDecorationRenderer.java +++ b/src/main/java/com/googlecode/lanterna/gui2/FatWindowDecorationRenderer.java @@ -109,18 +109,18 @@ public TerminalSize getDecoratedSize(Window window, TerminalSize contentAreaSize return contentAreaSize .withRelativeColumns(2) .withRelativeRows(4) - .max(new TerminalSize(TerminalTextUtils.getColumnWidth(window.getTitle()) + 4, 1)); //Make sure the title fits! + .max(TerminalSize.of(TerminalTextUtils.getColumnWidth(window.getTitle()) + 4, 1)); //Make sure the title fits! } else { return contentAreaSize .withRelativeColumns(2) .withRelativeRows(2) - .max(new TerminalSize(3, 1)); + .max(TerminalSize.of(3, 1)); } } - private static final TerminalPosition OFFSET_WITH_TITLE = new TerminalPosition(1, 3); - private static final TerminalPosition OFFSET_WITHOUT_TITLE = new TerminalPosition(1, 1); + private static final TerminalPosition OFFSET_WITH_TITLE = TerminalPosition.of(1, 3); + private static final TerminalPosition OFFSET_WITHOUT_TITLE = TerminalPosition.of(1, 1); @Override public TerminalPosition getOffset(Window window) { diff --git a/src/main/java/com/googlecode/lanterna/gui2/GUIBackdrop.java b/src/main/java/com/googlecode/lanterna/gui2/GUIBackdrop.java index cbf12f1e2..d66bd7e5f 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/GUIBackdrop.java +++ b/src/main/java/com/googlecode/lanterna/gui2/GUIBackdrop.java @@ -32,7 +32,7 @@ protected ComponentRenderer createDefaultRenderer() { @Override public TerminalSize getPreferredSize(EmptySpace component) { - return TerminalSize.ONE; + return TerminalSize.OF_1x1; } @Override diff --git a/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java b/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java index 4bc220f2e..8f524537b 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java +++ b/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java @@ -386,7 +386,7 @@ public boolean hasChanged() { @Override public TerminalSize getPreferredSize(List components) { - TerminalSize preferredSize = TerminalSize.ZERO; + TerminalSize preferredSize = TerminalSize.OF_0x0; if(components.isEmpty()) { return preferredSize.withRelative( leftMarginSize + rightMarginSize, @@ -417,7 +417,7 @@ public void doLayout(TerminalSize area, List components) { Component[][] table = buildTable(components); table = eliminateUnusedRowsAndColumns(table); - if(area.equals(TerminalSize.ZERO) || + if(area.equals(TerminalSize.OF_0x0) || table.length == 0 || area.getColumns() <= leftMarginSize + rightMarginSize + ((table[0].length - 1) * horizontalSpacing) || area.getRows() <= bottomMarginSize + topMarginSize + ((table.length - 1) * verticalSpacing)) { @@ -458,7 +458,7 @@ public void doLayout(TerminalSize area, List components) { //Ok, all constraints are in place, we can start placing out components. To simplify, do it horizontally first //and vertically after - TerminalPosition tableCellTopLeft = TerminalPosition.TOP_LEFT_CORNER; + TerminalPosition tableCellTopLeft = TerminalPosition.OF_0x0; for(int y = 0; y < table.length; y++) { tableCellTopLeft = tableCellTopLeft.withColumn(0); for(int x = 0; x < table[y].length; x++) { diff --git a/src/main/java/com/googlecode/lanterna/gui2/ImageComponent.java b/src/main/java/com/googlecode/lanterna/gui2/ImageComponent.java index fc43dabcc..e48df73cc 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/ImageComponent.java +++ b/src/main/java/com/googlecode/lanterna/gui2/ImageComponent.java @@ -44,7 +44,7 @@ public InteractableRenderer createDefaultRenderer() { return new InteractableRenderer() { @Override public void drawComponent(TextGUIGraphics graphics, ImageComponent panel) { - graphics.drawImage(TerminalPosition.TOP_LEFT_CORNER, textImage); + graphics.drawImage(TerminalPosition.OF_0x0, textImage); } @Override public TerminalSize getPreferredSize(ImageComponent panel) { diff --git a/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java b/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java index a67d6981e..f8af12029 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java +++ b/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java @@ -48,8 +48,8 @@ void reset() { } TerminalSize getSize() { - if (lookupMap.length==0) { return TerminalSize.ZERO; } - return new TerminalSize(lookupMap[0].length, lookupMap.length); + if (lookupMap.length==0) { return TerminalSize.OF_0x0; } + return TerminalSize.of(lookupMap[0].length, lookupMap.length); } /** @@ -57,7 +57,7 @@ TerminalSize getSize() { * @param interactable Interactable to add to the lookup map */ public synchronized void add(Interactable interactable) { - TerminalPosition topLeft = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER); + TerminalPosition topLeft = interactable.toBasePane(TerminalPosition.OF_0x0); TerminalSize size = interactable.getSize(); interactables.add(interactable); int index = interactables.size() - 1; @@ -121,10 +121,10 @@ private Interactable findNextUpOrDown(Interactable interactable, boolean isDown) // If the currently active interactable component is not showing the cursor, use the top-left position // instead if we're going up, or the bottom-left position if we're going down if(isDown) { - startPosition = new TerminalPosition(0, interactable.getSize().getRows() - 1); + startPosition = TerminalPosition.of(0, interactable.getSize().getRows() - 1); } else { - startPosition = TerminalPosition.TOP_LEFT_CORNER; + startPosition = TerminalPosition.OF_0x0; } } else { @@ -144,9 +144,9 @@ private Interactable findNextUpOrDown(Interactable interactable, boolean isDown) } Set disqualified = getDisqualifiedInteractables(startPosition, true); TerminalSize size = getSize(); - int maxShiftLeft = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER).getColumn(); + int maxShiftLeft = interactable.toBasePane(TerminalPosition.OF_0x0).getColumn(); maxShiftLeft = Math.max(maxShiftLeft, 0); - int maxShiftRight = interactable.toBasePane(new TerminalPosition(interactable.getSize().getColumns() - 1, 0)).getColumn(); + int maxShiftRight = interactable.toBasePane(TerminalPosition.of(interactable.getSize().getColumns() - 1, 0)).getColumn(); maxShiftRight = Math.min(maxShiftRight, size.getColumns() - 1); int maxShift = Math.max(startPosition.getColumn() - maxShiftLeft, maxShiftRight - startPosition.getRow()); for (int searchRow = startPosition.getRow() + directionTerm; @@ -201,10 +201,10 @@ private Interactable findNextLeftOrRight(Interactable interactable, boolean isRi // If the currently active interactable component is not showing the cursor, use the top-left position // instead if we're going left, or the top-right position if we're going right if(isRight) { - startPosition = new TerminalPosition(interactable.getSize().getColumns() - 1, 0); + startPosition = TerminalPosition.of(interactable.getSize().getColumns() - 1, 0); } else { - startPosition = TerminalPosition.TOP_LEFT_CORNER; + startPosition = TerminalPosition.OF_0x0; } } else { @@ -224,9 +224,9 @@ private Interactable findNextLeftOrRight(Interactable interactable, boolean isRi } Set disqualified = getDisqualifiedInteractables(startPosition, false); TerminalSize size = getSize(); - int maxShiftUp = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER).getRow(); + int maxShiftUp = interactable.toBasePane(TerminalPosition.OF_0x0).getRow(); maxShiftUp = Math.max(maxShiftUp, 0); - int maxShiftDown = interactable.toBasePane(new TerminalPosition(0, interactable.getSize().getRows() - 1)).getRow(); + int maxShiftDown = interactable.toBasePane(TerminalPosition.of(0, interactable.getSize().getRows() - 1)).getRow(); maxShiftDown = Math.min(maxShiftDown, size.getRows() - 1); int maxShift = Math.max(startPosition.getRow() - maxShiftUp, maxShiftDown - startPosition.getRow()); for(int searchColumn = startPosition.getColumn() + directionTerm; diff --git a/src/main/java/com/googlecode/lanterna/gui2/Label.java b/src/main/java/com/googlecode/lanterna/gui2/Label.java index 1a0450407..ae461d219 100644 --- a/src/main/java/com/googlecode/lanterna/gui2/Label.java +++ b/src/main/java/com/googlecode/lanterna/gui2/Label.java @@ -45,7 +45,7 @@ public class Label extends AbstractComponent