Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / terminal / swing / TerminalEmulatorPalette.java
CommitLineData
a3b510ab
NR
1/*
2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
3 *
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) 2010-2015 Martin
18 */
19
20package com.googlecode.lanterna.terminal.swing;
21
22import com.googlecode.lanterna.TextColor;
23import java.awt.Color;
24
25/**
26 * This class specifies the palette of colors the terminal will use for the normally available 8 + 1 ANSI colors but
27 * also their 'bright' versions with are normally enabled through bold mode. There are several palettes available, all
28 * based on popular terminal emulators. All colors are defined in the AWT format.
29 * @author Martin
30 */
31@SuppressWarnings("WeakerAccess")
32public class TerminalEmulatorPalette {
33 /**
34 * Values taken from gnome-terminal on Ubuntu
35 */
36 public static final TerminalEmulatorPalette GNOME_TERMINAL =
37 new TerminalEmulatorPalette(
38 new java.awt.Color(211, 215, 207),
39 new java.awt.Color(238, 238, 236),
40 new java.awt.Color(46, 52, 54),
41 new java.awt.Color(46, 52, 54),
42 new java.awt.Color(85, 87, 83),
43 new java.awt.Color(204, 0, 0),
44 new java.awt.Color(239, 41, 41),
45 new java.awt.Color(78, 154, 6),
46 new java.awt.Color(138, 226, 52),
47 new java.awt.Color(196, 160, 0),
48 new java.awt.Color(252, 233, 79),
49 new java.awt.Color(52, 101, 164),
50 new java.awt.Color(114, 159, 207),
51 new java.awt.Color(117, 80, 123),
52 new java.awt.Color(173, 127, 168),
53 new java.awt.Color(6, 152, 154),
54 new java.awt.Color(52, 226, 226),
55 new java.awt.Color(211, 215, 207),
56 new java.awt.Color(238, 238, 236));
57
58 /**
59 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
60 * wikipedia</a>, these are supposed to be the standard VGA palette.
61 */
62 public static final TerminalEmulatorPalette STANDARD_VGA =
63 new TerminalEmulatorPalette(
64 new java.awt.Color(170, 170, 170),
65 new java.awt.Color(255, 255, 255),
66 new java.awt.Color(0, 0, 0),
67 new java.awt.Color(0, 0, 0),
68 new java.awt.Color(85, 85, 85),
69 new java.awt.Color(170, 0, 0),
70 new java.awt.Color(255, 85, 85),
71 new java.awt.Color(0, 170, 0),
72 new java.awt.Color(85, 255, 85),
73 new java.awt.Color(170, 85, 0),
74 new java.awt.Color(255, 255, 85),
75 new java.awt.Color(0, 0, 170),
76 new java.awt.Color(85, 85, 255),
77 new java.awt.Color(170, 0, 170),
78 new java.awt.Color(255, 85, 255),
79 new java.awt.Color(0, 170, 170),
80 new java.awt.Color(85, 255, 255),
81 new java.awt.Color(170, 170, 170),
82 new java.awt.Color(255, 255, 255));
83
84 /**
85 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
86 * wikipedia</a>, these are supposed to be what Windows XP cmd is using.
87 */
88 public static final TerminalEmulatorPalette WINDOWS_XP_COMMAND_PROMPT =
89 new TerminalEmulatorPalette(
90 new java.awt.Color(192, 192, 192),
91 new java.awt.Color(255, 255, 255),
92 new java.awt.Color(0, 0, 0),
93 new java.awt.Color(0, 0, 0),
94 new java.awt.Color(128, 128, 128),
95 new java.awt.Color(128, 0, 0),
96 new java.awt.Color(255, 0, 0),
97 new java.awt.Color(0, 128, 0),
98 new java.awt.Color(0, 255, 0),
99 new java.awt.Color(128, 128, 0),
100 new java.awt.Color(255, 255, 0),
101 new java.awt.Color(0, 0, 128),
102 new java.awt.Color(0, 0, 255),
103 new java.awt.Color(128, 0, 128),
104 new java.awt.Color(255, 0, 255),
105 new java.awt.Color(0, 128, 128),
106 new java.awt.Color(0, 255, 255),
107 new java.awt.Color(192, 192, 192),
108 new java.awt.Color(255, 255, 255));
109
110 /**
111 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
112 * wikipedia</a>, these are supposed to be what terminal.app on MacOSX is using.
113 */
114 public static final TerminalEmulatorPalette MAC_OS_X_TERMINAL_APP =
115 new TerminalEmulatorPalette(
116 new java.awt.Color(203, 204, 205),
117 new java.awt.Color(233, 235, 235),
118 new java.awt.Color(0, 0, 0),
119 new java.awt.Color(0, 0, 0),
120 new java.awt.Color(129, 131, 131),
121 new java.awt.Color(194, 54, 33),
122 new java.awt.Color(252,57,31),
123 new java.awt.Color(37, 188, 36),
124 new java.awt.Color(49, 231, 34),
125 new java.awt.Color(173, 173, 39),
126 new java.awt.Color(234, 236, 35),
127 new java.awt.Color(73, 46, 225),
128 new java.awt.Color(88, 51, 255),
129 new java.awt.Color(211, 56, 211),
130 new java.awt.Color(249, 53, 248),
131 new java.awt.Color(51, 187, 200),
132 new java.awt.Color(20, 240, 240),
133 new java.awt.Color(203, 204, 205),
134 new java.awt.Color(233, 235, 235));
135
136 /**
137 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
138 * wikipedia</a>, these are supposed to be what putty is using.
139 */
140 public static final TerminalEmulatorPalette PUTTY =
141 new TerminalEmulatorPalette(
142 new java.awt.Color(187, 187, 187),
143 new java.awt.Color(255, 255, 255),
144 new java.awt.Color(0, 0, 0),
145 new java.awt.Color(0, 0, 0),
146 new java.awt.Color(85, 85, 85),
147 new java.awt.Color(187, 0, 0),
148 new java.awt.Color(255, 85, 85),
149 new java.awt.Color(0, 187, 0),
150 new java.awt.Color(85, 255, 85),
151 new java.awt.Color(187, 187, 0),
152 new java.awt.Color(255, 255, 85),
153 new java.awt.Color(0, 0, 187),
154 new java.awt.Color(85, 85, 255),
155 new java.awt.Color(187, 0, 187),
156 new java.awt.Color(255, 85, 255),
157 new java.awt.Color(0, 187, 187),
158 new java.awt.Color(85, 255, 255),
159 new java.awt.Color(187, 187, 187),
160 new java.awt.Color(255, 255, 255));
161
162 /**
163 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
164 * wikipedia</a>, these are supposed to be what xterm is using.
165 */
166 public static final TerminalEmulatorPalette XTERM =
167 new TerminalEmulatorPalette(
168 new java.awt.Color(229, 229, 229),
169 new java.awt.Color(255, 255, 255),
170 new java.awt.Color(0, 0, 0),
171 new java.awt.Color(0, 0, 0),
172 new java.awt.Color(127, 127, 127),
173 new java.awt.Color(205, 0, 0),
174 new java.awt.Color(255, 0, 0),
175 new java.awt.Color(0, 205, 0),
176 new java.awt.Color(0, 255, 0),
177 new java.awt.Color(205, 205, 0),
178 new java.awt.Color(255, 255, 0),
179 new java.awt.Color(0, 0, 238),
180 new java.awt.Color(92, 92, 255),
181 new java.awt.Color(205, 0, 205),
182 new java.awt.Color(255, 0, 255),
183 new java.awt.Color(0, 205, 205),
184 new java.awt.Color(0, 255, 255),
185 new java.awt.Color(229, 229, 229),
186 new java.awt.Color(255, 255, 255));
187
188 /**
189 * Default colors the SwingTerminal is using if you don't specify anything
190 */
191 public static final TerminalEmulatorPalette DEFAULT = GNOME_TERMINAL;
192
193 private final Color defaultColor;
194 private final Color defaultBrightColor;
195 private final Color defaultBackgroundColor;
196 private final Color normalBlack;
197 private final Color brightBlack;
198 private final Color normalRed;
199 private final Color brightRed;
200 private final Color normalGreen;
201 private final Color brightGreen;
202 private final Color normalYellow;
203 private final Color brightYellow;
204 private final Color normalBlue;
205 private final Color brightBlue;
206 private final Color normalMagenta;
207 private final Color brightMagenta;
208 private final Color normalCyan;
209 private final Color brightCyan;
210 private final Color normalWhite;
211 private final Color brightWhite;
212
213 /**
214 * Creates a new palette with all colors specified up-front
215 * @param defaultColor Default color which no specific color has been selected
216 * @param defaultBrightColor Default color which no specific color has been selected but bold is enabled
217 * @param defaultBackgroundColor Default color to use for the background when no specific color has been selected
218 * @param normalBlack Color for normal black
219 * @param brightBlack Color for bright black
220 * @param normalRed Color for normal red
221 * @param brightRed Color for bright red
222 * @param normalGreen Color for normal green
223 * @param brightGreen Color for bright green
224 * @param normalYellow Color for normal yellow
225 * @param brightYellow Color for bright yellow
226 * @param normalBlue Color for normal blue
227 * @param brightBlue Color for bright blue
228 * @param normalMagenta Color for normal magenta
229 * @param brightMagenta Color for bright magenta
230 * @param normalCyan Color for normal cyan
231 * @param brightCyan Color for bright cyan
232 * @param normalWhite Color for normal white
233 * @param brightWhite Color for bright white
234 */
235 public TerminalEmulatorPalette(
236 Color defaultColor,
237 Color defaultBrightColor,
238 Color defaultBackgroundColor,
239 Color normalBlack,
240 Color brightBlack,
241 Color normalRed,
242 Color brightRed,
243 Color normalGreen,
244 Color brightGreen,
245 Color normalYellow,
246 Color brightYellow,
247 Color normalBlue,
248 Color brightBlue,
249 Color normalMagenta,
250 Color brightMagenta,
251 Color normalCyan,
252 Color brightCyan,
253 Color normalWhite,
254 Color brightWhite) {
255 this.defaultColor = defaultColor;
256 this.defaultBrightColor = defaultBrightColor;
257 this.defaultBackgroundColor = defaultBackgroundColor;
258 this.normalBlack = normalBlack;
259 this.brightBlack = brightBlack;
260 this.normalRed = normalRed;
261 this.brightRed = brightRed;
262 this.normalGreen = normalGreen;
263 this.brightGreen = brightGreen;
264 this.normalYellow = normalYellow;
265 this.brightYellow = brightYellow;
266 this.normalBlue = normalBlue;
267 this.brightBlue = brightBlue;
268 this.normalMagenta = normalMagenta;
269 this.brightMagenta = brightMagenta;
270 this.normalCyan = normalCyan;
271 this.brightCyan = brightCyan;
272 this.normalWhite = normalWhite;
273 this.brightWhite = brightWhite;
274 }
275
276 /**
277 * Returns the AWT color from this palette given an ANSI color and two hints for if we are looking for a background
278 * color and if we want to use the bright version.
279 * @param color Which ANSI color we want to extract
280 * @param isForeground Is this color we extract going to be used as a background color?
281 * @param useBrightTones If true, we should return the bright version of the color
282 * @return AWT color extracted from this palette for the input parameters
283 */
284 public Color get(TextColor.ANSI color, boolean isForeground, boolean useBrightTones) {
285 if(useBrightTones) {
286 switch(color) {
287 case BLACK:
288 return brightBlack;
289 case BLUE:
290 return brightBlue;
291 case CYAN:
292 return brightCyan;
293 case DEFAULT:
294 return isForeground ? defaultBrightColor : defaultBackgroundColor;
295 case GREEN:
296 return brightGreen;
297 case MAGENTA:
298 return brightMagenta;
299 case RED:
300 return brightRed;
301 case WHITE:
302 return brightWhite;
303 case YELLOW:
304 return brightYellow;
305 }
306 }
307 else {
308 switch(color) {
309 case BLACK:
310 return normalBlack;
311 case BLUE:
312 return normalBlue;
313 case CYAN:
314 return normalCyan;
315 case DEFAULT:
316 return isForeground ? defaultColor : defaultBackgroundColor;
317 case GREEN:
318 return normalGreen;
319 case MAGENTA:
320 return normalMagenta;
321 case RED:
322 return normalRed;
323 case WHITE:
324 return normalWhite;
325 case YELLOW:
326 return normalYellow;
327 }
328 }
329 throw new IllegalArgumentException("Unknown text color " + color);
330 }
331
332 @SuppressWarnings({"SimplifiableIfStatement", "ConstantConditions"})
333 @Override
334 public boolean equals(Object obj) {
335 if(obj == null) {
336 return false;
337 }
338 if(getClass() != obj.getClass()) {
339 return false;
340 }
341 final TerminalEmulatorPalette other = (TerminalEmulatorPalette) obj;
342 if(this.defaultColor != other.defaultColor && (this.defaultColor == null || !this.defaultColor.equals(other.defaultColor))) {
343 return false;
344 }
345 if(this.defaultBrightColor != other.defaultBrightColor && (this.defaultBrightColor == null || !this.defaultBrightColor.equals(other.defaultBrightColor))) {
346 return false;
347 }
348 if(this.defaultBackgroundColor != other.defaultBackgroundColor && (this.defaultBackgroundColor == null || !this.defaultBackgroundColor.equals(other.defaultBackgroundColor))) {
349 return false;
350 }
351 if(this.normalBlack != other.normalBlack && (this.normalBlack == null || !this.normalBlack.equals(other.normalBlack))) {
352 return false;
353 }
354 if(this.brightBlack != other.brightBlack && (this.brightBlack == null || !this.brightBlack.equals(other.brightBlack))) {
355 return false;
356 }
357 if(this.normalRed != other.normalRed && (this.normalRed == null || !this.normalRed.equals(other.normalRed))) {
358 return false;
359 }
360 if(this.brightRed != other.brightRed && (this.brightRed == null || !this.brightRed.equals(other.brightRed))) {
361 return false;
362 }
363 if(this.normalGreen != other.normalGreen && (this.normalGreen == null || !this.normalGreen.equals(other.normalGreen))) {
364 return false;
365 }
366 if(this.brightGreen != other.brightGreen && (this.brightGreen == null || !this.brightGreen.equals(other.brightGreen))) {
367 return false;
368 }
369 if(this.normalYellow != other.normalYellow && (this.normalYellow == null || !this.normalYellow.equals(other.normalYellow))) {
370 return false;
371 }
372 if(this.brightYellow != other.brightYellow && (this.brightYellow == null || !this.brightYellow.equals(other.brightYellow))) {
373 return false;
374 }
375 if(this.normalBlue != other.normalBlue && (this.normalBlue == null || !this.normalBlue.equals(other.normalBlue))) {
376 return false;
377 }
378 if(this.brightBlue != other.brightBlue && (this.brightBlue == null || !this.brightBlue.equals(other.brightBlue))) {
379 return false;
380 }
381 if(this.normalMagenta != other.normalMagenta && (this.normalMagenta == null || !this.normalMagenta.equals(other.normalMagenta))) {
382 return false;
383 }
384 if(this.brightMagenta != other.brightMagenta && (this.brightMagenta == null || !this.brightMagenta.equals(other.brightMagenta))) {
385 return false;
386 }
387 if(this.normalCyan != other.normalCyan && (this.normalCyan == null || !this.normalCyan.equals(other.normalCyan))) {
388 return false;
389 }
390 if(this.brightCyan != other.brightCyan && (this.brightCyan == null || !this.brightCyan.equals(other.brightCyan))) {
391 return false;
392 }
393 if(this.normalWhite != other.normalWhite && (this.normalWhite == null || !this.normalWhite.equals(other.normalWhite))) {
394 return false;
395 }
396 return !(this.brightWhite != other.brightWhite && (this.brightWhite == null || !this.brightWhite.equals(other.brightWhite)));
397 }
398
399 @SuppressWarnings("ConstantConditions")
400 @Override
401 public int hashCode() {
402 int hash = 5;
403 hash = 47 * hash + (this.defaultColor != null ? this.defaultColor.hashCode() : 0);
404 hash = 47 * hash + (this.defaultBrightColor != null ? this.defaultBrightColor.hashCode() : 0);
405 hash = 47 * hash + (this.defaultBackgroundColor != null ? this.defaultBackgroundColor.hashCode() : 0);
406 hash = 47 * hash + (this.normalBlack != null ? this.normalBlack.hashCode() : 0);
407 hash = 47 * hash + (this.brightBlack != null ? this.brightBlack.hashCode() : 0);
408 hash = 47 * hash + (this.normalRed != null ? this.normalRed.hashCode() : 0);
409 hash = 47 * hash + (this.brightRed != null ? this.brightRed.hashCode() : 0);
410 hash = 47 * hash + (this.normalGreen != null ? this.normalGreen.hashCode() : 0);
411 hash = 47 * hash + (this.brightGreen != null ? this.brightGreen.hashCode() : 0);
412 hash = 47 * hash + (this.normalYellow != null ? this.normalYellow.hashCode() : 0);
413 hash = 47 * hash + (this.brightYellow != null ? this.brightYellow.hashCode() : 0);
414 hash = 47 * hash + (this.normalBlue != null ? this.normalBlue.hashCode() : 0);
415 hash = 47 * hash + (this.brightBlue != null ? this.brightBlue.hashCode() : 0);
416 hash = 47 * hash + (this.normalMagenta != null ? this.normalMagenta.hashCode() : 0);
417 hash = 47 * hash + (this.brightMagenta != null ? this.brightMagenta.hashCode() : 0);
418 hash = 47 * hash + (this.normalCyan != null ? this.normalCyan.hashCode() : 0);
419 hash = 47 * hash + (this.brightCyan != null ? this.brightCyan.hashCode() : 0);
420 hash = 47 * hash + (this.normalWhite != null ? this.normalWhite.hashCode() : 0);
421 hash = 47 * hash + (this.brightWhite != null ? this.brightWhite.hashCode() : 0);
422 return hash;
423 }
424
425 @Override
426 public String toString() {
427 return "SwingTerminalPalette{" +
428 "defaultColor=" + defaultColor +
429 ", defaultBrightColor=" + defaultBrightColor +
430 ", defaultBackgroundColor=" + defaultBackgroundColor +
431 ", normalBlack=" + normalBlack +
432 ", brightBlack=" + brightBlack +
433 ", normalRed=" + normalRed +
434 ", brightRed=" + brightRed +
435 ", normalGreen=" + normalGreen +
436 ", brightGreen=" + brightGreen +
437 ", normalYellow=" + normalYellow +
438 ", brightYellow=" + brightYellow +
439 ", normalBlue=" + normalBlue +
440 ", brightBlue=" + brightBlue +
441 ", normalMagenta=" + normalMagenta +
442 ", brightMagenta=" + brightMagenta +
443 ", normalCyan=" + normalCyan +
444 ", brightCyan=" + brightCyan +
445 ", normalWhite=" + normalWhite +
446 ", brightWhite=" + brightWhite + '}';
447 }
448}