load properties files using UTF-8 instead of ISO 8859-1 (issue #1031)

This commit is contained in:
Karl Tauber
2025-09-06 12:45:40 +02:00
parent d388158de7
commit 6f63982054
7 changed files with 40 additions and 7 deletions

View File

@@ -8,6 +8,16 @@ FlatLaf Change Log
- Tree and List: Fixed painting of rounded drop backgrounds. (issue #1023)
#### Incompatibilities
- FlatLaf properties files are now loaded using the UTF-8 character encoding
instead of ISO 8859-1. In usual properties files you will not notice any
difference because they use only ASCII characters, but if you've put localized
(non-English) texts (e.g. German umlauts) into your properties files, you need
to convert them to UTF-8. Properties files created with the FlatLaf Theme
Editor already use UTF-8, including in older versions. (issue #1031)
## 3.6.1
- Extras: Support JSVG 2.0.0. Minimum JSVG version is now 1.6.0. (issue #997)

View File

@@ -20,6 +20,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;
@@ -62,8 +65,8 @@ public class FlatPropertiesLaf
throws IOException
{
Properties properties = new Properties();
try( InputStream in2 = in ) {
properties.load( in2 );
try( Reader reader = new InputStreamReader( in, StandardCharsets.UTF_8 )) {
properties.load( reader );
}
return properties;
}

View File

@@ -25,12 +25,15 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -112,6 +115,14 @@ class UIDefaultsLoader
Set<String> specialPrefixes = FlatLaf.getUIKeySpecialPrefixes();
return new Properties() {
@Override
public void load( InputStream in ) throws IOException {
// use UTF-8 to load properties file
try( Reader reader = new InputStreamReader( in, StandardCharsets.UTF_8 )) {
super.load( reader );
}
}
@Override
public synchronized Object put( Object k, Object value ) {
// process key prefixes (while loading properties files)

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -177,7 +178,7 @@ class FlatCompletionProvider
try {
try( InputStream in = getClass().getResourceAsStream( "/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt" ) ) {
if( in != null ) {
try( BufferedReader reader = new BufferedReader( new InputStreamReader( in, "UTF-8" ) ) ) {
try( BufferedReader reader = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 ) ) ) {
String key;
while( (key = reader.readLine()) != null ) {
if( !isIgnored( key ) )

View File

@@ -23,6 +23,7 @@ import java.awt.Window;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.InputMap;
@@ -211,7 +212,7 @@ class FlatThemeEditorPane
void load( File file ) throws IOException {
this.file = file;
textArea.load( FileLocation.create( file ), "UTF-8" );
textArea.load( FileLocation.create( file ), StandardCharsets.UTF_8 );
}
boolean reloadIfNecessary() {

View File

@@ -39,6 +39,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.Year;
import java.util.ArrayList;
import java.util.Arrays;
@@ -675,7 +676,7 @@ class FlatThemeFileEditor
{
try(
FileOutputStream out = new FileOutputStream( file );
Writer writer = new OutputStreamWriter( out, "UTF-8" );
Writer writer = new OutputStreamWriter( out, StandardCharsets.UTF_8 );
) {
writer.write( content );
}

View File

@@ -19,6 +19,9 @@ package com.formdev.flatlaf.themeeditor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -109,8 +112,11 @@ class FlatThemePropertiesBaseManager
String propertiesName = '/' + lafClass.getName().replace( '.', '/' ) + ".properties";
try( InputStream in = lafClass.getResourceAsStream( propertiesName ) ) {
Properties properties = new Properties();
if( in != null )
properties.load( in );
if( in != null ) {
try( Reader reader = new InputStreamReader( in, StandardCharsets.UTF_8 )) {
properties.load( in );
}
}
coreThemes.put( lafClass.getSimpleName(), properties );
} catch( IOException ex ) {
ex.printStackTrace();