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 * The attributes used by a Cell: color, bold, blink, etc.
36 public class CellAttributes
{
48 public final boolean getBold() {
55 * @param bold new bold value
57 public final void setBold(final boolean bold
) {
64 private boolean blink
;
71 public final boolean getBlink() {
78 * @param blink new blink value
80 public final void setBlink(final boolean blink
) {
87 private boolean reverse
;
92 * @return reverse value
94 public final boolean getReverse() {
101 * @param reverse new reverse value
103 public final void setReverse(final boolean reverse
) {
104 this.reverse
= reverse
;
108 * Underline attribute.
110 private boolean underline
;
113 * Getter for underline.
115 * @return underline value
117 public final boolean getUnderline() {
122 * Setter for underline.
124 * @param underline new underline value
126 public final void setUnderline(final boolean underline
) {
127 this.underline
= underline
;
131 * Protected attribute.
133 private boolean protect
;
136 * Getter for protect.
138 * @return protect value
140 public final boolean getProtect() {
145 * Setter for protect.
147 * @param protect new protect value
149 public final void setProtect(final boolean protect
) {
150 this.protect
= protect
;
154 * Foreground color. Color.WHITE, Color.RED, etc.
156 private Color foreColor
;
159 * Getter for foreColor.
161 * @return foreColor value
163 public final Color
getForeColor() {
168 * Setter for foreColor.
170 * @param foreColor new foreColor value
172 public final void setForeColor(final Color foreColor
) {
173 this.foreColor
= foreColor
;
177 * Background color. Color.WHITE, Color.RED, etc.
179 private Color backColor
;
182 * Getter for backColor.
184 * @return backColor value
186 public final Color
getBackColor() {
191 * Setter for backColor.
193 * @param backColor new backColor value
195 public final void setBackColor(final Color backColor
) {
196 this.backColor
= backColor
;
200 * Set to default: white foreground on black background, no
201 * bold/underline/blink/rever/protect.
203 public void reset() {
209 foreColor
= Color
.WHITE
;
210 backColor
= Color
.BLACK
;
214 * Public constructor sets default values of the cell to white-on-black,
215 * no bold/blink/reverse/underline/protect.
219 public CellAttributes() {
224 * Comparison check. All fields must match to return true.
226 * @param rhs another CellAttributes instance
227 * @return true if all fields are equal
230 public boolean equals(final Object rhs
) {
231 if (!(rhs
instanceof CellAttributes
)) {
235 CellAttributes that
= (CellAttributes
) rhs
;
236 return ((bold
== that
.bold
)
237 && (blink
== that
.blink
)
238 && (reverse
== that
.reverse
)
239 && (underline
== that
.underline
)
240 && (protect
== that
.protect
)
241 && (foreColor
== that
.foreColor
)
242 && (backColor
== that
.backColor
));
246 * Hashcode uses all fields in equals().
251 public int hashCode() {
255 hash
= (B
* hash
) + (bold ?
1 : 0);
256 hash
= (B
* hash
) + (blink ?
1 : 0);
257 hash
= (B
* hash
) + (underline ?
1 : 0);
258 hash
= (B
* hash
) + (reverse ?
1 : 0);
259 hash
= (B
* hash
) + (protect ?
1 : 0);
260 hash
= (B
* hash
) + foreColor
.hashCode();
261 hash
= (B
* hash
) + backColor
.hashCode();
266 * Set my field values to that's field.
268 * @param rhs another CellAttributes instance
270 public void setTo(final Object rhs
) {
271 CellAttributes that
= (CellAttributes
) rhs
;
273 this.bold
= that
.bold
;
274 this.blink
= that
.blink
;
275 this.reverse
= that
.reverse
;
276 this.underline
= that
.underline
;
277 this.protect
= that
.protect
;
278 this.foreColor
= that
.foreColor
;
279 this.backColor
= that
.backColor
;
283 * Make human-readable description of this CellAttributes.
285 * @return displayable String
288 public String
toString() {
290 return String
.format("bold %s on %s",
291 foreColor
, backColor
);
293 return String
.format("%s on %s", foreColor
, backColor
);