update roadmap
[fanfix.git] / src / jexer / bits / Color.java
CommitLineData
624ce48e
KL
1/**
2 * Jexer - Java Text User Interface
3 *
4 * Version: $Id$
5 *
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
7 *
8 * License: LGPLv3 or later
9 *
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
13 * License Version 3.
14 *
15 * Copyright (C) 2015 Kevin Lamonte
16 *
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.
21 *
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.
26 *
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
31 * 02110-1301 USA
32 */
33package jexer.bits;
34
35/**
36 * A text cell color.
37 */
38public class Color {
39
40 /**
41 * The color value. Default is WHITE.
42 */
43 public int value = 7;
44
45 /**
46 * Public constructor
47 */
48 public Color(int value) {
49 this.value = value;
50 }
51
52 // The color integer values. NOT EXPOSED.
53 static private final int black = 0;
54 static private final int red = 1;
55 static private final int green = 2;
56 static private final int yellow = 3;
57 static private final int blue = 4;
58 static private final int magenta = 5;
59 static private final int cyan = 6;
60 static private final int white = 7;
61
62 /**
63 * Black. Bold + black = dark grey
64 */
65 static public final Color BLACK = new Color(black);
66
67 /**
68 * Red
69 */
70 static public final Color RED = new Color(red);
71
72 /**
73 * Green
74 */
75 static public final Color GREEN = new Color(green);
76
77 /**
78 * Yellow. Sometimes not-bold yellow is brown.
79 */
80 static public final Color YELLOW = new Color(yellow);
81
82 /**
83 * Blue
84 */
85 static public final Color BLUE = new Color(blue);
86
87 /**
88 * Magenta (purple)
89 */
90 static public final Color MAGENTA = new Color(magenta);
91
92 /**
93 * Cyan (blue-green)
94 */
95 static public final Color CYAN = new Color(cyan);
96
97 /**
98 * White
99 */
100 static public final Color WHITE = new Color(white);
101
102 /**
103 * Invert a color in the same way as (CGA/VGA color XOR 0x7).
624ce48e
KL
104 * @return the inverted color
105 */
4328bb42
KL
106 public Color invert() {
107 switch (value) {
624ce48e
KL
108 case black:
109 return Color.WHITE;
110 case white:
111 return Color.BLACK;
112 case red:
113 return Color.CYAN;
114 case cyan:
115 return Color.RED;
116 case green:
117 return Color.MAGENTA;
118 case magenta:
119 return Color.GREEN;
120 case blue:
121 return Color.YELLOW;
122 case yellow:
123 return Color.BLUE;
124 }
125 throw new IllegalArgumentException("Invalid Color value: " +
4328bb42
KL
126 value);
127 }
128
129 /**
130 * Comparison. All fields must match to return true.
131 */
132 @Override
133 public boolean equals(Object rhs) {
134 if (!(rhs instanceof Color)) {
135 return false;
136 }
137
138 Color that = (Color)rhs;
139 return (value == that.value);
624ce48e
KL
140 }
141}