2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2016 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 * The attributes used by a Cell: color, bold, blink, etc.
34 public class CellAttributes
{
46 public final boolean isBold() {
53 * @param bold new bold value
55 public final void setBold(final boolean bold
) {
62 private boolean blink
;
69 public final boolean isBlink() {
76 * @param blink new blink value
78 public final void setBlink(final boolean blink
) {
85 private boolean reverse
;
90 * @return reverse value
92 public final boolean isReverse() {
99 * @param reverse new reverse value
101 public final void setReverse(final boolean reverse
) {
102 this.reverse
= reverse
;
106 * Underline attribute.
108 private boolean underline
;
111 * Getter for underline.
113 * @return underline value
115 public final boolean isUnderline() {
120 * Setter for underline.
122 * @param underline new underline value
124 public final void setUnderline(final boolean underline
) {
125 this.underline
= underline
;
129 * Protected attribute.
131 private boolean protect
;
134 * Getter for protect.
136 * @return protect value
138 public final boolean isProtect() {
143 * Setter for protect.
145 * @param protect new protect value
147 public final void setProtect(final boolean protect
) {
148 this.protect
= protect
;
152 * Foreground color. Color.WHITE, Color.RED, etc.
154 private Color foreColor
;
157 * Getter for foreColor.
159 * @return foreColor value
161 public final Color
getForeColor() {
166 * Setter for foreColor.
168 * @param foreColor new foreColor value
170 public final void setForeColor(final Color foreColor
) {
171 this.foreColor
= foreColor
;
175 * Background color. Color.WHITE, Color.RED, etc.
177 private Color backColor
;
180 * Getter for backColor.
182 * @return backColor value
184 public final Color
getBackColor() {
189 * Setter for backColor.
191 * @param backColor new backColor value
193 public final void setBackColor(final Color backColor
) {
194 this.backColor
= backColor
;
198 * Set to default: white foreground on black background, no
199 * bold/underline/blink/rever/protect.
201 public void reset() {
207 foreColor
= Color
.WHITE
;
208 backColor
= Color
.BLACK
;
212 * Public constructor sets default values of the cell to white-on-black,
213 * no bold/blink/reverse/underline/protect.
217 public CellAttributes() {
222 * Comparison check. All fields must match to return true.
224 * @param rhs another CellAttributes instance
225 * @return true if all fields are equal
228 public boolean equals(final Object rhs
) {
229 if (!(rhs
instanceof CellAttributes
)) {
233 CellAttributes that
= (CellAttributes
) rhs
;
234 return ((bold
== that
.bold
)
235 && (blink
== that
.blink
)
236 && (reverse
== that
.reverse
)
237 && (underline
== that
.underline
)
238 && (protect
== that
.protect
)
239 && (foreColor
== that
.foreColor
)
240 && (backColor
== that
.backColor
));
244 * Hashcode uses all fields in equals().
249 public int hashCode() {
253 hash
= (B
* hash
) + (bold ?
1 : 0);
254 hash
= (B
* hash
) + (blink ?
1 : 0);
255 hash
= (B
* hash
) + (underline ?
1 : 0);
256 hash
= (B
* hash
) + (reverse ?
1 : 0);
257 hash
= (B
* hash
) + (protect ?
1 : 0);
258 hash
= (B
* hash
) + foreColor
.hashCode();
259 hash
= (B
* hash
) + backColor
.hashCode();
264 * Set my field values to that's field.
266 * @param rhs another CellAttributes instance
268 public void setTo(final Object rhs
) {
269 CellAttributes that
= (CellAttributes
) rhs
;
271 this.bold
= that
.bold
;
272 this.blink
= that
.blink
;
273 this.reverse
= that
.reverse
;
274 this.underline
= that
.underline
;
275 this.protect
= that
.protect
;
276 this.foreColor
= that
.foreColor
;
277 this.backColor
= that
.backColor
;
281 * Make human-readable description of this CellAttributes.
283 * @return displayable String
286 public String
toString() {
288 return String
.format("bold %s on %s",
289 foreColor
, backColor
);
291 return String
.format("%s on %s", foreColor
, backColor
);