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 * The attributes used by a Cell: color, bold, blink, etc.
34 public class CellAttributes
{
36 // ------------------------------------------------------------------------
37 // Variables --------------------------------------------------------------
38 // ------------------------------------------------------------------------
48 private boolean blink
;
53 private boolean reverse
;
56 * Underline attribute.
58 private boolean underline
;
61 * Protected attribute.
63 private boolean protect
;
66 * Foreground color. Color.WHITE, Color.RED, etc.
68 private Color foreColor
;
71 * Background color. Color.WHITE, Color.RED, etc.
73 private Color backColor
;
75 // ------------------------------------------------------------------------
76 // Constructors -----------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * Public constructor sets default values of the cell to white-on-black,
81 * no bold/blink/reverse/underline/protect.
85 public CellAttributes() {
90 * Public constructor makes a copy from another instance.
92 * @param that another CellAttributes instance
95 public CellAttributes(final CellAttributes that
) {
99 // ------------------------------------------------------------------------
100 // CellAttributes ---------------------------------------------------------
101 // ------------------------------------------------------------------------
108 public final boolean isBold() {
115 * @param bold new bold value
117 public final void setBold(final boolean bold
) {
124 * @return blink value
126 public final boolean isBlink() {
133 * @param blink new blink value
135 public final void setBlink(final boolean blink
) {
140 * Getter for reverse.
142 * @return reverse value
144 public final boolean isReverse() {
149 * Setter for reverse.
151 * @param reverse new reverse value
153 public final void setReverse(final boolean reverse
) {
154 this.reverse
= reverse
;
158 * Getter for underline.
160 * @return underline value
162 public final boolean isUnderline() {
167 * Setter for underline.
169 * @param underline new underline value
171 public final void setUnderline(final boolean underline
) {
172 this.underline
= underline
;
176 * Getter for protect.
178 * @return protect value
180 public final boolean isProtect() {
185 * Setter for protect.
187 * @param protect new protect value
189 public final void setProtect(final boolean protect
) {
190 this.protect
= protect
;
194 * Getter for foreColor.
196 * @return foreColor value
198 public final Color
getForeColor() {
203 * Setter for foreColor.
205 * @param foreColor new foreColor value
207 public final void setForeColor(final Color foreColor
) {
208 this.foreColor
= foreColor
;
212 * Getter for backColor.
214 * @return backColor value
216 public final Color
getBackColor() {
221 * Setter for backColor.
223 * @param backColor new backColor value
225 public final void setBackColor(final Color backColor
) {
226 this.backColor
= backColor
;
230 * Set to default: white foreground on black background, no
231 * bold/underline/blink/rever/protect.
233 public void reset() {
239 foreColor
= Color
.WHITE
;
240 backColor
= Color
.BLACK
;
244 * Comparison check. All fields must match to return true.
246 * @param rhs another CellAttributes instance
247 * @return true if all fields are equal
250 public boolean equals(final Object rhs
) {
251 if (!(rhs
instanceof CellAttributes
)) {
255 CellAttributes that
= (CellAttributes
) rhs
;
256 return ((foreColor
== that
.foreColor
)
257 && (backColor
== that
.backColor
)
258 && (bold
== that
.bold
)
259 && (reverse
== that
.reverse
)
260 && (underline
== that
.underline
)
261 && (blink
== that
.blink
)
262 && (protect
== that
.protect
));
266 * Hashcode uses all fields in equals().
271 public int hashCode() {
275 hash
= (B
* hash
) + (bold ?
1 : 0);
276 hash
= (B
* hash
) + (blink ?
1 : 0);
277 hash
= (B
* hash
) + (underline ?
1 : 0);
278 hash
= (B
* hash
) + (reverse ?
1 : 0);
279 hash
= (B
* hash
) + (protect ?
1 : 0);
280 hash
= (B
* hash
) + foreColor
.hashCode();
281 hash
= (B
* hash
) + backColor
.hashCode();
286 * Set my field values to that's field.
288 * @param rhs another CellAttributes instance
290 public void setTo(final Object rhs
) {
291 CellAttributes that
= (CellAttributes
) rhs
;
293 this.bold
= that
.bold
;
294 this.blink
= that
.blink
;
295 this.reverse
= that
.reverse
;
296 this.underline
= that
.underline
;
297 this.protect
= that
.protect
;
298 this.foreColor
= that
.foreColor
;
299 this.backColor
= that
.backColor
;
303 * Make human-readable description of this CellAttributes.
305 * @return displayable String
308 public String
toString() {
309 return String
.format("%s%s%s on %s", (bold
== true ?
"bold " : ""),
310 (blink
== true ?
"blink " : ""), foreColor
, backColor
);