7dce699468562bf3b9f776a79a58eb66ada3f9bd
2 * Jexer - Java Text User Interface
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
8 * License: LGPLv3 or later
10 * Copyright: This module is licensed under the GNU Lesser General
11 * Public License Version 3. Please see the file "COPYING" in this
12 * directory for more information about the GNU Lesser General Public
15 * Copyright (C) 2015 Kevin Lamonte
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation; either version 3 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this program; if not, see
29 * http://www.gnu.org/licenses/, or write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
36 * The attributes used by a Cell: color, bold, blink, etc.
38 public class CellAttributes
{
53 public boolean reverse
;
58 public boolean underline
;
63 public boolean protect
;
66 * Foreground color. Color.WHITE, Color.RED, etc.
68 public Color foreColor
;
71 * Background color. Color.WHITE, Color.RED, etc.
73 public Color backColor
;
76 * Set to default not-bold, white foreground on black background.
84 foreColor
= Color
.WHITE
;
85 backColor
= Color
.BLACK
;
91 public CellAttributes() {
96 * Comparison. All fields must match to return true.
99 public boolean equals(Object rhs
) {
100 if (!(rhs
instanceof CellAttributes
)) {
104 CellAttributes that
= (CellAttributes
)rhs
;
105 return ((bold
== that
.bold
) &&
106 (blink
== that
.blink
) &&
107 (reverse
== that
.reverse
) &&
108 (underline
== that
.underline
) &&
109 (protect
== that
.protect
) &&
110 (foreColor
== that
.foreColor
) &&
111 (backColor
== that
.backColor
));
115 * Set my field values to that's field
117 public void setTo(Object rhs
) {
118 CellAttributes that
= (CellAttributes
)rhs
;
120 this.bold
= that
.bold
;
121 this.blink
= that
.blink
;
122 this.reverse
= that
.reverse
;
123 this.underline
= that
.underline
;
124 this.protect
= that
.protect
;
125 this.foreColor
= that
.foreColor
;
126 this.backColor
= that
.backColor
;
130 * Convert enum to string
132 * @param color Color.RED, Color.BLUE, etc.
133 * @return "red", "blue", etc.
135 static public String
stringFromColor(Color color
) {
136 if (color
.equals(Color
.BLACK
)) {
138 } else if (color
.equals(Color
.WHITE
)) {
140 } else if (color
.equals(Color
.RED
)) {
142 } else if (color
.equals(Color
.CYAN
)) {
144 } else if (color
.equals(Color
.GREEN
)) {
146 } else if (color
.equals(Color
.MAGENTA
)) {
148 } else if (color
.equals(Color
.BLUE
)) {
150 } else if (color
.equals(Color
.YELLOW
)) {
153 throw new IllegalArgumentException("Invalid Color value: " +
158 * Convert string to enum
160 * @param color "red", "blue", etc.
161 * @return Color.RED, Color.BLUE, etc.
163 static public Color
colorFromString(String color
) {
164 switch (color
.toLowerCase()) {
176 return Color
.MAGENTA
;
184 // Let unknown strings become white
190 * Make human-readable description of this CellAttributes
193 public String
toString() {
194 return String
.format("%s%s on %s",
196 stringFromColor(foreColor
),
197 stringFromColor(backColor
));