2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
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.
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.
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/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.terminal
.swing
;
21 import com
.googlecode
.lanterna
.TextColor
;
22 import java
.awt
.Color
;
25 * Color configuration settings to be using with SwingTerminal. This class contains color-related settings that is used
26 * by SwingTerminal when it renders the component.
29 public class TerminalEmulatorColorConfiguration
{
32 * This is the default settings that is used when you create a new SwingTerminal without specifying any color
33 * configuration. It will use classic VGA colors for the ANSI palette and bright colors on bold text.
35 public static TerminalEmulatorColorConfiguration
getDefault() {
36 return newInstance(TerminalEmulatorPalette
.STANDARD_VGA
);
40 * Creates a new color configuration based on a particular palette and with using brighter colors on bold text.
41 * @param colorPalette Palette to use for this color configuration
42 * @return The resulting color configuration
44 @SuppressWarnings("SameParameterValue")
45 public static TerminalEmulatorColorConfiguration
newInstance(TerminalEmulatorPalette colorPalette
) {
46 return new TerminalEmulatorColorConfiguration(colorPalette
, true);
49 private final TerminalEmulatorPalette colorPalette
;
50 private final boolean useBrightColorsOnBold
;
52 private TerminalEmulatorColorConfiguration(TerminalEmulatorPalette colorPalette
, boolean useBrightColorsOnBold
) {
53 this.colorPalette
= colorPalette
;
54 this.useBrightColorsOnBold
= useBrightColorsOnBold
;
58 * Given a TextColor and a hint as to if the color is to be used as foreground or not and if we currently have
59 * bold text enabled or not, it returns the closest AWT color that matches this.
60 * @param color What text color to convert
61 * @param isForeground Is the color intended to be used as foreground color
62 * @param inBoldContext Is the color intended to be used for on a character this is bold
63 * @return The AWT color that represents this text color
65 public Color
toAWTColor(TextColor color
, boolean isForeground
, boolean inBoldContext
) {
66 if(color
instanceof TextColor
.ANSI
) {
67 return colorPalette
.get((TextColor
.ANSI
)color
, isForeground
, inBoldContext
&& useBrightColorsOnBold
);
69 return color
.toColor();