X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FColorTheme.java;h=3efce633243c9f82433d0212ad13e6caefe4922c;hb=c4cefaa04ec122fc02efb6542451a31fdf722c32;hp=baf7685b4ef2331a2cb07a41e67700bc745a4c00;hpb=a0d734e68fc28e441d74075e4d8d0166bbcde180;p=nikiroo-utils.git diff --git a/src/jexer/bits/ColorTheme.java b/src/jexer/bits/ColorTheme.java index baf7685..3efce63 100644 --- a/src/jexer/bits/ColorTheme.java +++ b/src/jexer/bits/ColorTheme.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -44,13 +44,21 @@ import java.util.TreeMap; * ColorTheme is a collection of colors keyed by string. A default theme is * also provided that matches the blue-and-white theme used by Turbo Vision. */ -public final class ColorTheme { +public class ColorTheme { + + // ------------------------------------------------------------------------ + // Variables -------------------------------------------------------------- + // ------------------------------------------------------------------------ /** * The current theme colors. */ private SortedMap colors; + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Public constructor sets the theme to the default. */ @@ -59,6 +67,10 @@ public final class ColorTheme { setDefaultTheme(); } + // ------------------------------------------------------------------------ + // ColorTheme ------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Retrieve the CellAttributes for a named theme color. * @@ -66,7 +78,7 @@ public final class ColorTheme { * @return color associated with name, e.g. bold yellow on blue */ public CellAttributes getColor(final String name) { - CellAttributes attr = (CellAttributes) colors.get(name); + CellAttributes attr = colors.get(name); return attr; } @@ -134,8 +146,43 @@ public final class ColorTheme { StringTokenizer tokenizer = new StringTokenizer(text); token = tokenizer.nextToken(); - while (token.equals("bold") || token.equals("blink")) { - if (token.equals("bold")) { + + if (token.toLowerCase().equals("rgb:")) { + // Foreground + int foreColorRGB = -1; + try { + foreColorRGB = Integer.parseInt(tokenizer.nextToken(), 16); + } catch (NumberFormatException e) { + // Default to white on black + foreColorRGB = 0xFFFFFF; + } + + // "on" + if (!tokenizer.nextToken().toLowerCase().equals("on")) { + // Invalid line. + return; + } + + // Background + int backColorRGB = -1; + try { + backColorRGB = Integer.parseInt(tokenizer.nextToken(), 16); + } catch (NumberFormatException e) { + backColorRGB = 0; + } + + CellAttributes color = new CellAttributes(); + color.setForeColorRGB(foreColorRGB); + color.setBackColorRGB(backColorRGB); + colors.put(key, color); + return; + } + + while (token.equals("bold") + || token.equals("bright") + || token.equals("blink") + ) { + if (token.equals("bold") || token.equals("bright")) { bold = true; token = tokenizer.nextToken(); } @@ -187,8 +234,8 @@ public final class ColorTheme { // Invalid line. continue; } - String key = line.substring(0, line.indexOf(':')).trim(); - String text = line.substring(line.indexOf(':') + 1); + String key = line.substring(0, line.indexOf('=')).trim(); + String text = line.substring(line.indexOf('=') + 1); setColorFromString(key, text); } // All done. @@ -318,6 +365,11 @@ public final class ColorTheme { color.setBackColor(Color.BLUE); color.setBold(true); colors.put("tlabel", color); + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.BLUE); + color.setBold(true); + colors.put("tlabel.mnemonic", color); // TText text color = new CellAttributes(); @@ -328,17 +380,17 @@ public final class ColorTheme { // TField text color = new CellAttributes(); - color.setForeColor(Color.WHITE); - color.setBackColor(Color.BLUE); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); color.setBold(false); colors.put("tfield.inactive", color); color = new CellAttributes(); - color.setForeColor(Color.YELLOW); - color.setBackColor(Color.BLACK); - color.setBold(true); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.CYAN); + color.setBold(false); colors.put("tfield.active", color); - // TCheckbox + // TCheckBox color = new CellAttributes(); color.setForeColor(Color.WHITE); color.setBackColor(Color.BLUE); @@ -349,6 +401,67 @@ public final class ColorTheme { color.setBackColor(Color.BLACK); color.setBold(true); colors.put("tcheckbox.active", color); + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.BLUE); + color.setBold(true); + colors.put("tcheckbox.mnemonic", color); + color = new CellAttributes(); + color.setForeColor(Color.RED); + color.setBackColor(Color.BLACK); + color.setBold(true); + colors.put("tcheckbox.mnemonic.highlighted", color); + + // TComboBox + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tcombobox.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLUE); + color.setBackColor(Color.CYAN); + color.setBold(false); + colors.put("tcombobox.active", color); + + // TSpinner + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tspinner.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLUE); + color.setBackColor(Color.CYAN); + color.setBold(false); + colors.put("tspinner.active", color); + + // TCalendar + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("tcalendar.background", color); + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("tcalendar.day", color); + color = new CellAttributes(); + color.setForeColor(Color.RED); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tcalendar.day.selected", color); + color = new CellAttributes(); + color.setForeColor(Color.BLUE); + color.setBackColor(Color.CYAN); + color.setBold(false); + colors.put("tcalendar.arrow", color); + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(true); + colors.put("tcalendar.title", color); // TRadioButton color = new CellAttributes(); @@ -361,6 +474,16 @@ public final class ColorTheme { color.setBackColor(Color.BLACK); color.setBold(true); colors.put("tradiobutton.active", color); + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.BLUE); + color.setBold(true); + colors.put("tradiobutton.mnemonic", color); + color = new CellAttributes(); + color.setForeColor(Color.RED); + color.setBackColor(Color.BLACK); + color.setBold(true); + colors.put("tradiobutton.mnemonic.highlighted", color); // TRadioGroup color = new CellAttributes(); @@ -454,6 +577,11 @@ public final class ColorTheme { color.setBackColor(Color.BLUE); color.setBold(false); colors.put("ttreeview.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("ttreeview.selected.inactive", color); // TList color = new CellAttributes(); @@ -479,6 +607,11 @@ public final class ColorTheme { color.setBackColor(Color.BLUE); color.setBold(false); colors.put("tlist.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tlist.selected.inactive", color); // TStatusBar color = new CellAttributes(); @@ -503,6 +636,92 @@ public final class ColorTheme { color.setBackColor(Color.BLUE); color.setBold(false); colors.put("teditor", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.CYAN); + color.setBold(false); + colors.put("teditor.selected", color); + + // TTable + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("ttable.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.CYAN); + color.setBold(false); + colors.put("ttable.active", color); + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.CYAN); + color.setBold(true); + colors.put("ttable.selected", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("ttable.label", color); + color = new CellAttributes(); + color.setForeColor(Color.BLUE); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("ttable.label.selected", color); + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("ttable.border", color); + + // TSplitPane + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("tsplitpane", color); + + // THelpWindow border - during window movement + color = new CellAttributes(); + color.setForeColor(Color.GREEN); + color.setBackColor(Color.CYAN); + color.setBold(true); + colors.put("thelpwindow.windowmove", color); + + // THelpWindow border + color = new CellAttributes(); + color.setForeColor(Color.GREEN); + color.setBackColor(Color.CYAN); + color.setBold(true); + colors.put("thelpwindow.border", color); + + // THelpWindow background + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.CYAN); + color.setBold(true); + colors.put("thelpwindow.background", color); + + // THelpWindow text + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("thelpwindow.text", color); + + // THelpWindow link + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.BLUE); + color.setBold(true); + colors.put("thelpwindow.link", color); + + // THelpWindow link - active + color = new CellAttributes(); + color.setForeColor(Color.YELLOW); + color.setBackColor(Color.CYAN); + color.setBold(true); + colors.put("thelpwindow.link.active", color); }