2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
32 * This class represents a single text cell on the screen.
34 public final class Cell
extends CellAttributes
{
37 * The character at this cell.
42 * Getter for cell character.
44 * @return cell character
46 public char getChar() {
51 * Setter for cell character.
53 * @param ch new cell character
55 public void setChar(final char ch
) {
60 * Reset this cell to a blank.
69 * Check to see if this cell has default attributes: white foreground,
70 * black background, no bold/blink/reverse/underline/protect, and a
71 * character value of ' ' (space).
73 * @return true if this cell has default attributes.
75 public boolean isBlank() {
76 if ((getForeColor().equals(Color
.WHITE
))
77 && (getBackColor().equals(Color
.BLACK
))
92 * Comparison check. All fields must match to return true.
94 * @param rhs another Cell instance
95 * @return true if all fields are equal
98 public boolean equals(final Object rhs
) {
99 if (!(rhs
instanceof Cell
)) {
103 Cell that
= (Cell
) rhs
;
106 return super.equals(rhs
);
112 * Hashcode uses all fields in equals().
117 public int hashCode() {
121 hash
= (B
* hash
) + super.hashCode();
122 hash
= (B
* hash
) + (int)ch
;
127 * Set my field values to that's field.
129 * @param rhs an instance of either Cell or CellAttributes
132 public void setTo(final Object rhs
) {
133 // Let this throw a ClassCastException
134 CellAttributes thatAttr
= (CellAttributes
) rhs
;
135 super.setTo(thatAttr
);
137 if (rhs
instanceof Cell
) {
138 Cell that
= (Cell
) rhs
;
144 * Set my field attr values to that's field.
146 * @param that a CellAttributes instance
148 public void setAttr(final CellAttributes that
) {
153 * Public constructor sets default values of the cell to blank.
163 * Public constructor sets the character. Attributes are the same as
166 * @param ch character to set to
169 public Cell(final char ch
) {
175 * Make human-readable description of this Cell.
177 * @return displayable String
180 public String
toString() {
181 return String
.format("fore: %s back: %s bold: %s blink: %s ch %c",
182 getForeColor(), getBackColor(), isBold(), isBlink(), ch
);