Test commit from within Eclipse
[fanfix.git] / src / jexer / bits / CellAttributes.java
CommitLineData
624ce48e
KL
1/**
2 * Jexer - Java Text User Interface
3 *
624ce48e
KL
4 * License: LGPLv3 or later
5 *
7b5261bc
KL
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.
624ce48e
KL
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
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.
16 *
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.
21 *
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
26 * 02110-1301 USA
7b5261bc
KL
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
624ce48e
KL
30 */
31package jexer.bits;
32
33/**
34 * The attributes used by a Cell: color, bold, blink, etc.
35 */
36public class CellAttributes {
37
38 /**
7b5261bc
KL
39 * Bold attribute.
40 */
41 private boolean bold;
42
43 /**
44 * Getter for bold.
45 *
46 * @return bold value
47 */
48 public final boolean getBold() {
49 return bold;
50 }
51
52 /**
53 * Setter for bold.
54 *
55 * @param bold new bold value
56 */
57 public final void setBold(final boolean bold) {
58 this.bold = bold;
59 }
60
61 /**
62 * Blink attribute.
63 */
64 private boolean blink;
65
66 /**
67 * Getter for blink.
68 *
69 * @return blink value
70 */
71 public final boolean getBlink() {
72 return blink;
73 }
74
75 /**
76 * Setter for blink.
77 *
78 * @param blink new blink value
79 */
80 public final void setBlink(final boolean blink) {
81 this.blink = blink;
82 }
83
84 /**
85 * Reverse attribute.
86 */
87 private boolean reverse;
88
89 /**
90 * Getter for reverse.
91 *
92 * @return reverse value
93 */
94 public final boolean getReverse() {
95 return reverse;
96 }
97
98 /**
99 * Setter for reverse.
100 *
101 * @param reverse new reverse value
102 */
103 public final void setReverse(final boolean reverse) {
104 this.reverse = reverse;
105 }
106
107 /**
108 * Underline attribute.
624ce48e 109 */
7b5261bc 110 private boolean underline;
624ce48e
KL
111
112 /**
7b5261bc
KL
113 * Getter for underline.
114 *
115 * @return underline value
624ce48e 116 */
7b5261bc
KL
117 public final boolean getUnderline() {
118 return underline;
119 }
624ce48e
KL
120
121 /**
7b5261bc
KL
122 * Setter for underline.
123 *
124 * @param underline new underline value
624ce48e 125 */
7b5261bc
KL
126 public final void setUnderline(final boolean underline) {
127 this.underline = underline;
128 }
624ce48e
KL
129
130 /**
7b5261bc 131 * Protected attribute.
624ce48e 132 */
7b5261bc 133 private boolean protect;
624ce48e
KL
134
135 /**
7b5261bc
KL
136 * Getter for protect.
137 *
138 * @return protect value
624ce48e 139 */
7b5261bc
KL
140 public final boolean getProtect() {
141 return protect;
142 }
143
144 /**
145 * Setter for protect.
146 *
147 * @param protect new protect value
148 */
149 public final void setProtect(final boolean protect) {
150 this.protect = protect;
151 }
624ce48e
KL
152
153 /**
154 * Foreground color. Color.WHITE, Color.RED, etc.
155 */
7b5261bc
KL
156 private Color foreColor;
157
158 /**
159 * Getter for foreColor.
160 *
161 * @return foreColor value
162 */
163 public final Color getForeColor() {
164 return foreColor;
165 }
166
167 /**
168 * Setter for foreColor.
169 *
170 * @param foreColor new foreColor value
171 */
172 public final void setForeColor(final Color foreColor) {
173 this.foreColor = foreColor;
174 }
624ce48e
KL
175
176 /**
177 * Background color. Color.WHITE, Color.RED, etc.
178 */
7b5261bc
KL
179 private Color backColor;
180
181 /**
182 * Getter for backColor.
183 *
184 * @return backColor value
185 */
186 public final Color getBackColor() {
187 return backColor;
188 }
189
190 /**
191 * Setter for backColor.
192 *
193 * @param backColor new backColor value
194 */
195 public final void setBackColor(final Color backColor) {
196 this.backColor = backColor;
197 }
624ce48e
KL
198
199 /**
7b5261bc
KL
200 * Set to default: white foreground on black background, no
201 * bold/underline/blink/rever/protect.
624ce48e
KL
202 */
203 public void reset() {
7b5261bc
KL
204 bold = false;
205 blink = false;
206 reverse = false;
207 underline = false;
208 protect = false;
209 foreColor = Color.WHITE;
210 backColor = Color.BLACK;
624ce48e
KL
211 }
212
213 /**
7b5261bc
KL
214 * Public constructor sets default values of the cell to white-on-black,
215 * no bold/blink/reverse/underline/protect.
216 *
217 * @see #reset()
624ce48e
KL
218 */
219 public CellAttributes() {
7b5261bc 220 reset();
624ce48e
KL
221 }
222
223 /**
7b5261bc
KL
224 * Comparison check. All fields must match to return true.
225 *
226 * @param rhs another CellAttributes instance
227 * @return true if all fields are equal
624ce48e
KL
228 */
229 @Override
7b5261bc
KL
230 public boolean equals(final Object rhs) {
231 if (!(rhs instanceof CellAttributes)) {
232 return false;
233 }
624ce48e 234
7b5261bc
KL
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));
624ce48e
KL
243 }
244
e826b451
KL
245 /**
246 * Hashcode uses all fields in equals().
247 *
248 * @return the hash
249 */
250 @Override
251 public int hashCode() {
252 int A = 13;
253 int B = 23;
254 int hash = A;
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();
262 return hash;
263 }
264
624ce48e 265 /**
7b5261bc
KL
266 * Set my field values to that's field.
267 *
268 * @param rhs another CellAttributes instance
624ce48e 269 */
e826b451 270 public void setTo(final Object rhs) {
7b5261bc
KL
271 CellAttributes that = (CellAttributes) rhs;
272
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;
280 }
281
282 /**
283 * Make human-readable description of this CellAttributes.
284 *
285 * @return displayable String
624ce48e
KL
286 */
287 @Override
288 public String toString() {
7b5261bc
KL
289 if (bold) {
290 return String.format("bold %s on %s",
291 foreColor, backColor);
292 } else {
293 return String.format("%s on %s", foreColor, backColor);
294 }
624ce48e
KL
295 }
296
297}