e75680864fb60dc27910a845b27db6c5d7bfb2d1
2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
34 * This class represents a single text cell on the screen.
36 public final class Cell
extends CellAttributes
{
39 * The character at this cell.
44 * Getter for cell character.
46 * @return cell character
48 public char getChar() {
53 * Setter for cell character.
55 * @param ch new cell character
57 public void setChar(final char ch
) {
62 * Reset this cell to a blank.
71 * Check to see if this cell has default attributes: white foreground,
72 * black background, no bold/blink/reverse/underline/protect, and a
73 * character value of ' ' (space).
75 * @return true if this cell has default attributes.
77 public boolean isBlank() {
78 if ((getForeColor().equals(Color
.WHITE
))
79 && (getBackColor().equals(Color
.BLACK
))
94 * Comparison check. All fields must match to return true.
96 * @param rhs another Cell instance
97 * @return true if all fields are equal
100 public boolean equals(final Object rhs
) {
101 if (!(rhs
instanceof Cell
)) {
105 Cell that
= (Cell
) rhs
;
106 return (super.equals(rhs
)
111 * Hashcode uses all fields in equals().
116 public int hashCode() {
120 hash
= (B
* hash
) + super.hashCode();
121 hash
= (B
* hash
) + (int)ch
;
126 * Set my field values to that's field.
128 * @param rhs an instance of either Cell or CellAttributes
131 public void setTo(final Object rhs
) {
132 // Let this throw a ClassCastException
133 CellAttributes thatAttr
= (CellAttributes
) rhs
;
134 super.setTo(thatAttr
);
136 if (rhs
instanceof Cell
) {
137 Cell that
= (Cell
) rhs
;
143 * Set my field attr values to that's field.
145 * @param that a CellAttributes instance
147 public void setAttr(final CellAttributes that
) {
152 * Public constructor sets default values of the cell to blank.
162 * Public constructor sets the character. Attributes are the same as
165 * @param ch character to set to
168 public Cell(final char ch
) {
174 * Make human-readable description of this Cell.
176 * @return displayable String
179 public String
toString() {
180 return String
.format("fore: %d back: %d bold: %s blink: %s ch %c",
181 getForeColor(), getBackColor(), isBold(), isBlink(), ch
);