707b244b12664aa04a2c691cb73cfa3973d06e27
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]
36 public final class Color
{
39 * The color value. Default is SGRWHITE.
41 private int value
= SGRWHITE
;
44 * Get color value. Note that these deliberately match the color values
45 * of the ECMA-48 / ANSI X3.64 / VT100-ish SGR function ("ANSI colors").
49 public int getValue() {
54 * Private constructor used to make the static Color instances.
56 * @param value the integer Color value
58 private Color(final int value
) {
63 * Public constructor returns one of the static Color instances.
65 * @param colorName "red", "blue", etc.
66 * @return Color.RED, Color.BLUE, etc.
68 static Color
getColor(final String colorName
) {
69 switch (colorName
.toLowerCase()) {
89 // Let unknown strings become white
95 * SGR black value = 0.
97 private static final int SGRBLACK
= 0;
102 private static final int SGRRED
= 1;
105 * SGR green value = 2.
107 private static final int SGRGREEN
= 2;
110 * SGR yellow value = 3.
112 private static final int SGRYELLOW
= 3;
115 * SGR blue value = 4.
117 private static final int SGRBLUE
= 4;
120 * SGR magenta value = 5.
122 private static final int SGRMAGENTA
= 5;
125 * SGR cyan value = 6.
127 private static final int SGRCYAN
= 6;
130 * SGR white value = 7.
132 private static final int SGRWHITE
= 7;
135 * Black. Bold + black = dark grey
137 public static final Color BLACK
= new Color(SGRBLACK
);
142 public static final Color RED
= new Color(SGRRED
);
147 public static final Color GREEN
= new Color(SGRGREEN
);
150 * Yellow. Sometimes not-bold yellow is brown.
152 public static final Color YELLOW
= new Color(SGRYELLOW
);
157 public static final Color BLUE
= new Color(SGRBLUE
);
162 public static final Color MAGENTA
= new Color(SGRMAGENTA
);
167 public static final Color CYAN
= new Color(SGRCYAN
);
172 public static final Color WHITE
= new Color(SGRWHITE
);
175 * Invert a color in the same way as (CGA/VGA color XOR 0x7).
177 * @return the inverted color
179 public Color
invert() {
190 return Color
.MAGENTA
;
198 throw new IllegalArgumentException("Invalid Color value: " + value
);
203 * Comparison check. All fields must match to return true.
205 * @param rhs another Color instance
206 * @return true if all fields are equal
209 public boolean equals(final Object rhs
) {
210 if (!(rhs
instanceof Color
)) {
214 Color that
= (Color
) rhs
;
215 return (value
== that
.value
);
219 * Make human-readable description of this Color.
221 * @return displayable String "red", "blue", etc.
224 public String
toString() {
243 throw new IllegalArgumentException("Invalid Color value: " + value
);