hex color values in .properties files now must start with a # character

This commit is contained in:
Karl Tauber
2019-11-25 19:10:51 +01:00
parent 81f1ebd1db
commit 711c4dd2b5
10 changed files with 417 additions and 361 deletions

View File

@@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.UIDefaults;
@@ -204,8 +205,26 @@ public class IntelliJTheme
Object uiValue = namedColors.get( valueStr );
// parse value
if( uiValue == null )
uiValue = UIDefaultsLoader.parseValue( key, valueStr );
if( uiValue == null ) {
// fix errors (missing '#' for colors)
if( !valueStr.startsWith( "#" ) && (key.endsWith( "ground" ) || key.endsWith( "Color" )) )
valueStr = "#" + valueStr;
else if( key.endsWith( ".border" ) || key.endsWith( "Border" ) ) {
List<String> parts = StringUtils.split( valueStr, ',' );
if( parts.size() == 5 && !parts.get( 4 ).startsWith( "#" ) ) {
parts.set( 4, "#" + parts.get( 4 ) );
valueStr = String.join( ",", parts );
}
}
// parse value
try {
uiValue = UIDefaultsLoader.parseValue( key, valueStr );
} catch( RuntimeException ex ) {
UIDefaultsLoader.logParseError( key, valueStr, ex );
return; // ignore invalid value
}
}
if( key.startsWith( "*." ) ) {
// wildcard

View File

@@ -166,7 +166,7 @@ class UIDefaultsLoader
}
}
private static void logParseError( String key, String value, RuntimeException ex ) {
static void logParseError( String key, String value, RuntimeException ex ) {
System.err.println( "Failed to parse: '" + key + '=' + value + '\'' );
System.err.println( " " + ex.getMessage() );
}
@@ -214,7 +214,9 @@ class UIDefaultsLoader
ValueType valueType = ValueType.UNKNOWN;
// check whether value type is specified in the value
if( value.startsWith( TYPE_PREFIX ) ) {
if( value.startsWith( "#" ) )
valueType = ValueType.COLOR;
else if( value.startsWith( TYPE_PREFIX ) ) {
int end = value.indexOf( TYPE_PREFIX_END );
if( end != -1 ) {
try {
@@ -340,22 +342,12 @@ class UIDefaultsLoader
}
private static ColorUIResource parseColor( String value, boolean reportError ) {
value = StringUtils.removeLeading( value, "#" );
int valueLength = value.length();
if( valueLength != 6 && valueLength != 8 )
return null;
try {
long rgb = Long.parseLong( value, 16 );
if( valueLength == 6 )
return new ColorUIResource( (int) rgb );
if( valueLength == 8 )
return new ColorUIResource( new Color( (int) (((rgb >> 8) & 0xffffff) | ((rgb & 0xff) << 24)), true ) );
if( reportError )
throw new NumberFormatException( value );
} catch( NumberFormatException ex ) {
int rgba = parseColorRGBA( value );
return ((rgba & 0xff000000) == 0xff000000)
? new ColorUIResource( rgba )
: new ColorUIResource( new Color( rgba, true ) );
} catch( IllegalArgumentException ex ) {
if( reportError )
throw new IllegalArgumentException( "invalid color '" + value + "'" );
@@ -364,6 +356,50 @@ class UIDefaultsLoader
return null;
}
/**
* Parses a hex color in {@code #RGB}, {@code #RGBA}, {@code #RRGGBB} or {@code #RRGGBBAA}
* format and returns it as {@code rgba} integer suitable for {@link java.awt.Color},
* which includes alpha component in bits 24-31.
*
* @throws IllegalArgumentException
*/
static int parseColorRGBA( String value ) {
int len = value.length();
if( (len != 4 && len != 5 && len != 7 && len != 9) || value.charAt( 0 ) != '#' )
throw new IllegalArgumentException();
// parse hex
int n = 0;
for( int i = 1; i < len; i++ ) {
char ch = value.charAt( i );
int digit;
if( ch >= '0' && ch <= '9' )
digit = ch - '0';
else if( ch >= 'a' && ch <= 'f' )
digit = ch - 'a' + 10;
else if( ch >= 'A' && ch <= 'F' )
digit = ch - 'A' + 10;
else
throw new IllegalArgumentException();
n = (n << 4) | digit;
}
if( len <= 5 ) {
// double nibbles
int n1 = n & 0xf000;
int n2 = n & 0xf00;
int n3 = n & 0xf0;
int n4 = n & 0xf;
n = (n1 << 16) | (n1 << 12) | (n2 << 12) | (n2 << 8) | (n3 << 8) | (n3 << 4) | (n4 << 4) | n4;
}
return (len == 4 || len == 7)
? (0xff000000 | n) // set alpha to 255
: (((n >> 8) & 0xffffff) | ((n & 0xff) << 24)); // move alpha from lowest to highest byte
}
private static ColorUIResource parseColorFunctions( String value, boolean reportError ) {
int paramsStart = value.indexOf( '(' );
if( paramsStart < 0 ) {

View File

@@ -20,16 +20,16 @@
#---- variables ----
@background=3c3f41
@foreground=bbbbbb
@selectionBackground=4B6EAF
@background=#3c3f41
@foreground=#bbbbbb
@selectionBackground=#4B6EAF
@selectionForeground=@foreground
@selectionInactiveBackground=0D293E
@selectionInactiveBackground=#0D293E
@selectionInactiveForeground=@foreground
@disabledText=777777
@textComponentBackground=45494A
@cellFocusColor=000000
@icon=adadad
@disabledText=#777777
@textComponentBackground=#45494A
@cellFocusColor=#000000
@icon=#adadad
# Button
@buttonHoverBackground=lighten(3%,autoInverse)
@@ -50,7 +50,7 @@
*.disabledBackground=@background
*.disabledForeground=@disabledText
*.disabledText=@disabledText
*.acceleratorForeground=bbbbbb
*.acceleratorForeground=#bbbbbb
*.acceleratorSelectionForeground=@selectionForeground
@@ -66,62 +66,62 @@ window=@background
#---- Button ----
Button.background=4c5052
Button.background=#4c5052
Button.hoverBackground=@buttonHoverBackground
Button.pressedBackground=@buttonPressedBackground
Button.borderColor=5e6060
Button.disabledBorderColor=5e6060
Button.focusedBorderColor=466d94
Button.borderColor=#5e6060
Button.disabledBorderColor=#5e6060
Button.focusedBorderColor=#466d94
Button.hoverBorderColor=@@Button.focusedBorderColor
Button.default.background=365880
Button.default.foreground=bbbbbb
Button.default.background=#365880
Button.default.foreground=#bbbbbb
Button.default.hoverBackground=@buttonHoverBackground
Button.default.pressedBackground=@buttonPressedBackground
Button.default.borderColor=4c708c
Button.default.hoverBorderColor=537699
Button.default.focusedBorderColor=537699
Button.default.focusColor=43688c
Button.default.borderColor=#4c708c
Button.default.hoverBorderColor=#537699
Button.default.focusedBorderColor=#537699
Button.default.focusColor=#43688c
Button.default.boldText=true
Button.toolbar.hoverBackground=4c5052
Button.toolbar.pressedBackground=555a5d
Button.toolbar.hoverBackground=#4c5052
Button.toolbar.pressedBackground=#555a5d
#---- CheckBox ----
CheckBox.icon.borderColor=6B6B6B
CheckBox.icon.disabledBorderColor=545556
CheckBox.icon.selectedBorderColor=6B6B6B
CheckBox.icon.focusedBorderColor=466D94
CheckBox.icon.borderColor=#6B6B6B
CheckBox.icon.disabledBorderColor=#545556
CheckBox.icon.selectedBorderColor=#6B6B6B
CheckBox.icon.focusedBorderColor=#466D94
CheckBox.icon.hoverBorderColor=@@CheckBox.icon.focusedBorderColor
CheckBox.icon.selectedFocusedBorderColor=466D94
CheckBox.icon.background=43494A
CheckBox.icon.selectedFocusedBorderColor=#466D94
CheckBox.icon.background=#43494A
CheckBox.icon.disabledBackground=@background
CheckBox.icon.hoverBackground=@buttonHoverBackground
CheckBox.icon.pressedBackground=@buttonPressedBackground
CheckBox.icon.selectedBackground=43494A
CheckBox.icon.checkmarkColor=A7A7A7
CheckBox.icon.disabledCheckmarkColor=606060
CheckBox.icon.selectedBackground=#43494A
CheckBox.icon.checkmarkColor=#A7A7A7
CheckBox.icon.disabledCheckmarkColor=#606060
#---- ComboBox ----
ComboBox.background=@textComponentBackground
ComboBox.buttonBackground=@textComponentBackground
ComboBox.buttonEditableBackground=404445
ComboBox.buttonArrowColor=9A9DA1
ComboBox.buttonDisabledArrowColor=585858
ComboBox.buttonHoverArrowColor=bbbbbb
ComboBox.buttonEditableBackground=#404445
ComboBox.buttonArrowColor=#9A9DA1
ComboBox.buttonDisabledArrowColor=#585858
ComboBox.buttonHoverArrowColor=#bbbbbb
#---- Component ----
Component.borderColor=646464
Component.disabledBorderColor=646464
Component.focusedBorderColor=466d94
Component.focusColor=3d6185
Component.borderColor=#646464
Component.disabledBorderColor=#646464
Component.focusedBorderColor=#466d94
Component.focusColor=#3d6185
#---- List ----
@@ -131,101 +131,101 @@ List.background=@textComponentBackground
#---- Menu ----
Menu.icon.arrowColor=A7A7A7
Menu.icon.disabledArrowColor=606060
Menu.icon.arrowColor=#A7A7A7
Menu.icon.disabledArrowColor=#606060
#---- MenuBar ----
MenuBar.borderColor=515151
MenuBar.borderColor=#515151
#---- MenuItemCheckBox ----
MenuItemCheckBox.icon.checkmarkColor=A7A7A7
MenuItemCheckBox.icon.disabledCheckmarkColor=606060
MenuItemCheckBox.icon.checkmarkColor=#A7A7A7
MenuItemCheckBox.icon.disabledCheckmarkColor=#606060
#---- PopupMenu ----
PopupMenu.borderColor=515151
PopupMenu.borderColor=#515151
#---- ProgressBar ----
ProgressBar.background=555555
ProgressBar.foreground=a0a0a0
ProgressBar.background=#555555
ProgressBar.foreground=#a0a0a0
ProgressBar.selectionForeground=@background
ProgressBar.selectionBackground=@foreground
#---- ScrollBar ----
ScrollBar.track=3F4244
ScrollBar.thumb=5B5E5F
ScrollBar.hoverTrackColor=434647
ScrollBar.hoverThumbColor=666868
ScrollBar.track=#3F4244
ScrollBar.thumb=#5B5E5F
ScrollBar.hoverTrackColor=#434647
ScrollBar.hoverThumbColor=#666868
#---- Separator ----
Separator.foreground=515151
Separator.foreground=#515151
#---- Slider ----
Slider.trackColor=646464
Slider.thumbColor=A6A6A6
Slider.tickColor=888888
Slider.trackColor=#646464
Slider.thumbColor=#A6A6A6
Slider.tickColor=#888888
Slider.hoverColor=darken(15%,autoInverse)
Slider.disabledForeground=4c5052
Slider.disabledForeground=#4c5052
#---- SplitPane ----
SplitPaneDivider.draggingColor=646464
SplitPaneDivider.oneTouchHoverArrowColor=7A7D81
SplitPaneDivider.draggingColor=#646464
SplitPaneDivider.oneTouchHoverArrowColor=#7A7D81
#---- TabbedPane ----
TabbedPane.disabledForeground=777777
TabbedPane.underlineColor=4A88C7
TabbedPane.disabledUnderlineColor=7a7a7a
TabbedPane.hoverColor=2e3133
TabbedPane.focusColor=3d4b5c
TabbedPane.contentAreaColor=323232
TabbedPane.disabledForeground=#777777
TabbedPane.underlineColor=#4A88C7
TabbedPane.disabledUnderlineColor=#7a7a7a
TabbedPane.hoverColor=#2e3133
TabbedPane.focusColor=#3d4b5c
TabbedPane.contentAreaColor=#323232
#---- Table ----
Table.background=@textComponentBackground
Table.gridColor=4F5152
Table.gridColor=#4F5152
#---- TableHeader ----
TableHeader.background=45494A
TableHeader.separatorColor=585858
TableHeader.bottomSeparatorColor=585858
TableHeader.background=#45494A
TableHeader.separatorColor=#585858
TableHeader.bottomSeparatorColor=#585858
#---- ToggleButton ----
ToggleButton.selectedBackground=64696C
ToggleButton.selectedBackground=#64696C
ToggleButton.selectedForeground=@foreground
ToggleButton.disabledSelectedBackground=525658
ToggleButton.disabledSelectedBackground=#525658
ToggleButton.toolbar.selectedBackground=5c6164
ToggleButton.toolbar.selectedBackground=#5c6164
#---- ToolTip ----
ToolTip.border=4,6,4,6
ToolTip.background=1e2123
ToolTip.background=#1e2123
#---- Tree ----
Tree.background=@textComponentBackground
Tree.hash=505355
Tree.hash=#505355

View File

@@ -22,27 +22,27 @@
Button.focusedBackground=null
Button.default.background=4A86C7
Button.default.foreground=f0f0f0
Button.default.background=#4A86C7
Button.default.foreground=#f0f0f0
Button.default.focusedBackground=null
Button.default.hoverBackground=5B91CC
Button.default.pressedBackground=6E9ED2
Button.default.borderColor=3167ad
Button.default.hoverBorderColor=a8cef6
Button.default.focusedBorderColor=a8cef6
Button.default.focusColor=97c3f3
Button.default.hoverBackground=#5B91CC
Button.default.pressedBackground=#6E9ED2
Button.default.borderColor=#3167ad
Button.default.hoverBorderColor=#a8cef6
Button.default.focusedBorderColor=#a8cef6
Button.default.focusColor=#97c3f3
Button.default.boldText=true
#---- CheckBox ----
CheckBox.icon.selectedBorderColor=4982CC
CheckBox.icon.selectedFocusedBorderColor=ACCFF7
CheckBox.icon.selectedBackground=4D89C9
CheckBox.icon.checkmarkColor=FFFFFF
CheckBox.icon.selectedBorderColor=#4982CC
CheckBox.icon.selectedFocusedBorderColor=#ACCFF7
CheckBox.icon.selectedBackground=#4D89C9
CheckBox.icon.checkmarkColor=#FFFFFF
CheckBox.icon.selectedHoverBackground=5E94CE
CheckBox.icon.selectedPressedBackground=72A1D4
CheckBox.icon.selectedHoverBackground=#5E94CE
CheckBox.icon.selectedPressedBackground=#72A1D4
#---- Component ----

View File

@@ -20,16 +20,16 @@
#---- variables ----
@background=f2f2f2
@foreground=000000
@selectionBackground=4A6EB7
@selectionForeground=ffffff
@selectionInactiveBackground=d4d4d4
@background=#f2f2f2
@foreground=#000000
@selectionBackground=#4A6EB7
@selectionForeground=#ffffff
@selectionInactiveBackground=#d4d4d4
@selectionInactiveForeground=@foreground
@disabledText=999999
@textComponentBackground=ffffff
@cellFocusColor=000000
@icon=afafaf
@disabledText=#999999
@textComponentBackground=#ffffff
@cellFocusColor=#000000
@icon=#afafaf
# Button
@buttonHoverBackground=darken(3%,autoInverse)
@@ -40,23 +40,23 @@
*.background=@background
*.foreground=@foreground
*.textBackground=cccccc
*.textBackground=#cccccc
*.textForeground=@foreground
*.caretForeground=@foreground
*.inactiveBackground=@background
*.inactiveForeground=777777
*.inactiveForeground=#777777
*.selectionBackground=@selectionBackground
*.selectionForeground=@selectionForeground
*.disabledBackground=@background
*.disabledForeground=@disabledText
*.disabledText=@disabledText
*.acceleratorForeground=505050
*.acceleratorForeground=#505050
*.acceleratorSelectionForeground=@selectionForeground
#---- system ----
control=e0e0e0
control=#e0e0e0
controlText=@foreground
infoText=@foreground
text=@foreground
@@ -66,14 +66,14 @@ window=@background
#---- Button ----
Button.background=ffffff
Button.focusedBackground=e3f1fa
Button.background=#ffffff
Button.focusedBackground=#e3f1fa
Button.hoverBackground=@buttonHoverBackground
Button.pressedBackground=@buttonPressedBackground
Button.borderColor=bfbfbf
Button.disabledBorderColor=cfcfcf
Button.focusedBorderColor=87afda
Button.borderColor=#bfbfbf
Button.disabledBorderColor=#cfcfcf
Button.focusedBorderColor=#87afda
Button.hoverBorderColor=@@Button.focusedBorderColor
Button.default.background=@@Button.background
@@ -81,54 +81,54 @@ Button.default.foreground=@foreground
Button.default.focusedBackground=@@Button.focusedBackground
Button.default.hoverBackground=@buttonHoverBackground
Button.default.pressedBackground=@buttonPressedBackground
Button.default.borderColor=4D89C9
Button.default.borderColor=#4D89C9
Button.default.hoverBorderColor=@@Button.hoverBorderColor
Button.default.focusedBorderColor=@@Button.focusedBorderColor
Button.default.focusColor=@@Component.focusColor
Button.default.borderWidth=2
Button.toolbar.hoverBackground=dfdfdf
Button.toolbar.pressedBackground=d8d8d8
Button.toolbar.hoverBackground=#dfdfdf
Button.toolbar.pressedBackground=#d8d8d8
#---- CheckBox ----
CheckBox.icon.borderColor=878787
CheckBox.icon.disabledBorderColor=BDBDBD
CheckBox.icon.selectedBorderColor=878787
CheckBox.icon.focusedBorderColor=7B9FC7
CheckBox.icon.borderColor=#878787
CheckBox.icon.disabledBorderColor=#BDBDBD
CheckBox.icon.selectedBorderColor=#878787
CheckBox.icon.focusedBorderColor=#7B9FC7
CheckBox.icon.hoverBorderColor=@@CheckBox.icon.focusedBorderColor
CheckBox.icon.background=FFFFFF
CheckBox.icon.background=#FFFFFF
CheckBox.icon.disabledBackground=@background
CheckBox.icon.focusedBackground=@@Button.focusedBackground
CheckBox.icon.hoverBackground=@buttonHoverBackground
CheckBox.icon.pressedBackground=@buttonPressedBackground
CheckBox.icon.selectedBackground=FFFFFF
CheckBox.icon.checkmarkColor=4D89C9
CheckBox.icon.disabledCheckmarkColor=ABABAB
CheckBox.icon.selectedBackground=#FFFFFF
CheckBox.icon.checkmarkColor=#4D89C9
CheckBox.icon.disabledCheckmarkColor=#ABABAB
#---- ComboBox ----
ComboBox.background=@textComponentBackground
ComboBox.buttonBackground=@textComponentBackground
ComboBox.buttonEditableBackground=fafafa
ComboBox.buttonArrowColor=666666
ComboBox.buttonDisabledArrowColor=ABABAB
ComboBox.buttonHoverArrowColor=999999
ComboBox.buttonEditableBackground=#fafafa
ComboBox.buttonArrowColor=#666666
ComboBox.buttonDisabledArrowColor=#ABABAB
ComboBox.buttonHoverArrowColor=#999999
#---- Component ----
Component.borderColor=c4c4c4
Component.disabledBorderColor=cfcfcf
Component.focusedBorderColor=87afda
Component.focusColor=97c3f3
Component.borderColor=#c4c4c4
Component.disabledBorderColor=#cfcfcf
Component.focusedBorderColor=#87afda
Component.focusColor=#97c3f3
#---- HelpButton ----
HelpButton.questionMarkColor=4D89C9
HelpButton.questionMarkColor=#4D89C9
#---- List ----
@@ -138,100 +138,100 @@ List.background=@textComponentBackground
#---- Menu ----
Menu.icon.arrowColor=666666
Menu.icon.disabledArrowColor=ABABAB
Menu.icon.arrowColor=#666666
Menu.icon.disabledArrowColor=#ABABAB
#---- MenuBar ----
MenuBar.borderColor=cdcdcd
MenuBar.borderColor=#cdcdcd
#---- MenuItemCheckBox ----
MenuItemCheckBox.icon.checkmarkColor=4D89C9
MenuItemCheckBox.icon.disabledCheckmarkColor=ABABAB
MenuItemCheckBox.icon.checkmarkColor=#4D89C9
MenuItemCheckBox.icon.disabledCheckmarkColor=#ABABAB
#---- PopupMenu ----
PopupMenu.borderColor=cdcdcd
PopupMenu.borderColor=#cdcdcd
#---- ProgressBar ----
ProgressBar.background=c4c4c4
ProgressBar.foreground=808080
ProgressBar.background=#c4c4c4
ProgressBar.foreground=#808080
ProgressBar.selectionForeground=@textComponentBackground
ProgressBar.selectionBackground=@foreground
#---- ScrollBar ----
ScrollBar.track=F5F5F5
ScrollBar.thumb=DBDBDB
ScrollBar.hoverTrackColor=e6e6e6
ScrollBar.hoverThumbColor=c6c6c6
ScrollBar.track=#F5F5F5
ScrollBar.thumb=#DBDBDB
ScrollBar.hoverTrackColor=#e6e6e6
ScrollBar.hoverThumbColor=#c6c6c6
#---- Separator ----
Separator.foreground=cdcdcd
Separator.foreground=#cdcdcd
#---- Slider ----
Slider.trackColor=c4c4c4
Slider.thumbColor=6e6e6e
Slider.tickColor=888888
Slider.trackColor=#c4c4c4
Slider.thumbColor=#6e6e6e
Slider.tickColor=#888888
Slider.hoverColor=lighten(15%,autoInverse)
Slider.disabledForeground=c0c0c0
Slider.disabledForeground=#c0c0c0
#---- SplitPane ----
SplitPaneDivider.draggingColor=c4c4c4
SplitPaneDivider.oneTouchHoverArrowColor=333333
SplitPaneDivider.draggingColor=#c4c4c4
SplitPaneDivider.oneTouchHoverArrowColor=#333333
#---- TabbedPane ----
TabbedPane.disabledForeground=999999
TabbedPane.underlineColor=4083C9
TabbedPane.disabledUnderlineColor=ababab
TabbedPane.hoverColor=d9d9d9
TabbedPane.focusColor=dae4ed
TabbedPane.contentAreaColor=bfbfbf
TabbedPane.disabledForeground=#999999
TabbedPane.underlineColor=#4083C9
TabbedPane.disabledUnderlineColor=#ababab
TabbedPane.hoverColor=#d9d9d9
TabbedPane.focusColor=#dae4ed
TabbedPane.contentAreaColor=#bfbfbf
#---- Table ----
Table.background=@textComponentBackground
Table.gridColor=F7F7F7
Table.gridColor=#F7F7F7
#---- TableHeader ----
TableHeader.background=ffffff
TableHeader.separatorColor=e5e5e5
TableHeader.bottomSeparatorColor=e5e5e5
TableHeader.background=#ffffff
TableHeader.separatorColor=#e5e5e5
TableHeader.bottomSeparatorColor=#e5e5e5
#---- ToggleButton ----
ToggleButton.selectedBackground=cfcfcf
ToggleButton.selectedBackground=#cfcfcf
ToggleButton.selectedForeground=@foreground
ToggleButton.disabledSelectedBackground=dfdfdf
ToggleButton.disabledSelectedBackground=#dfdfdf
ToggleButton.toolbar.selectedBackground=cfcfcf
ToggleButton.toolbar.selectedBackground=#cfcfcf
#---- ToolTip ----
ToolTip.background=fafafa
ToolTip.background=#fafafa
#---- Tree ----
Tree.background=@textComponentBackground
Tree.hash=E6E6E6
Tree.hash=#E6E6E6