diff --git a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts index 7e5b2ceb..311d7af4 100644 --- a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts @@ -27,6 +27,10 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { } } + dependencies { + add("java9Compile", sourceSets.main.get().output) + } + tasks { named( "compileJava9Java" ) { sourceCompatibility = "9" diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index d703ea3e..04d73c04 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -101,7 +101,7 @@ public abstract class FlatLaf UIManager.setLookAndFeel( newLookAndFeel ); return true; } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); return false; } } @@ -339,7 +339,7 @@ public abstract class FlatLaf } else aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance(); } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); throw new IllegalStateException(); } @@ -575,7 +575,7 @@ public abstract class FlatLaf .invoke( null, true ); defaults.put( key, value ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -682,7 +682,7 @@ public abstract class FlatLaf // update UI updateUI(); } catch( UnsupportedLookAndFeelException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); } } ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index e3154907..86c443b5 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -76,7 +76,7 @@ public class IntelliJTheme try { return FlatLaf.install( createLaf( in ) ); } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex ); return false; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index 71c8d9a6..d6c585bf 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -173,7 +173,7 @@ class LinuxFontPolicy if( "1".equals( strs.get( 5 ) ) ) style |= Font.ITALIC; } catch( RuntimeException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); } } @@ -187,7 +187,7 @@ class LinuxFontPolicy if( dpi < 50 ) dpi = 50; } catch( NumberFormatException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); } } @@ -226,7 +226,7 @@ class LinuxFontPolicy while( (line = reader.readLine()) != null ) lines.add( line ); } catch( IOException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex ); } return lines; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index d34b3b6a..209723e4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -247,16 +247,16 @@ class UIDefaultsLoader } } } catch( IOException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to load properties files.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load properties files.", ex ); } } static void logParseError( String key, String value, RuntimeException ex, boolean severe ) { String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\''; if (severe) { - LoggingFacade.logSevere( message, ex ); + LoggingFacade.INSTANCE.logSevere( message, ex ); } else { - LoggingFacade.logConfig( message, ex ); + LoggingFacade.INSTANCE.logConfig( message, ex ); } } @@ -445,7 +445,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ).newInstance(); } catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex ); return null; } }; @@ -456,7 +456,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ); } catch( ClassNotFoundException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex ); return null; } }; @@ -933,7 +933,7 @@ class UIDefaultsLoader Object value = UIManager.get( uiKey ); if( value == null && !optional ) - LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); return value; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 97f21724..e79fb165 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -154,7 +154,7 @@ public class JBRCustomDecorations try { return (Boolean) Window_hasCustomDecoration.invoke( window ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); return false; } } @@ -166,7 +166,7 @@ public class JBRCustomDecorations try { Window_setHasCustomDecoration.invoke( window ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); } } @@ -180,7 +180,7 @@ public class JBRCustomDecorations WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots ); WWindowPeer_setCustomDecorationTitleBarHeight.invoke( peer, titleBarHeight ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java index bc177a66..1f94dc55 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java @@ -55,7 +55,7 @@ public class JavaCompatibility ? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class } : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -67,7 +67,7 @@ public class JavaCompatibility else drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -91,7 +91,7 @@ public class JavaCompatibility : "clipStringIfNecessary", new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -100,7 +100,7 @@ public class JavaCompatibility try { return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java index 12172f7f..afdef194 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java @@ -16,48 +16,11 @@ package com.formdev.flatlaf.util; -import com.formdev.flatlaf.FlatLaf; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LoggingFacade +public interface LoggingFacade { - private static final Logger LOG = createLogger(); + LoggingFacade INSTANCE = new LoggingFacadeImpl(); - private static Logger createLogger() { - try { - return Logger.getLogger( FlatLaf.class.getName() ); - } catch( Throwable e ) { - // Module java.logging is not present - return null; - } - } + void logSevere( String message, Throwable t ); - public static void logSevere( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.SEVERE, message, t ); - } else { - if( message != null ) { - System.err.println( message ); - } - if( t != null ) { - t.printStackTrace(); - } - } - } - - public static void logConfig( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.CONFIG, message, t ); - } else { - if (Boolean.getBoolean( "flatLaf.logConfig" )) { - if( message != null ) { - System.err.println( message ); - } - if( t != null ) { - t.printStackTrace(); - } - } - } - } + void logConfig( String message, Throwable t ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java new file mode 100644 index 00000000..5da1655a --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggingFacadeImpl implements LoggingFacade +{ + private static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); + + public void logSevere( String message, Throwable t ) { + LOG.log( Level.SEVERE, message, t ); + } + + public void logConfig( String message, Throwable t ) { + LOG.log( Level.CONFIG, message, t ); + } +} diff --git a/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java new file mode 100644 index 00000000..d7e5902f --- /dev/null +++ b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; + +public class LoggingFacadeImpl implements LoggingFacade +{ + private static final System.Logger LOG = System.getLogger( FlatLaf.class.getName() ); + + public void logSevere( String message, Throwable t ) { + LOG.log( System.Logger.Level.ERROR, message, t ); + } + + public void logConfig( String message, Throwable t ) { + LOG.log( System.Logger.Level.DEBUG, message, t ); + } +} diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java index 0e31e66b..4d37b99b 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java @@ -31,7 +31,7 @@ class Utils "/com/formdev/flatlaf/intellijthemes/themes/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LoggingFacade.logSevere( msg, ex ); + LoggingFacade.INSTANCE.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } } diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java index 2a1558ce..957c2ddc 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java @@ -31,7 +31,7 @@ class Utils "/com/formdev/flatlaf/intellijthemes/themes/material-theme-ui-lite/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LoggingFacade.logSevere( msg, ex ); + LoggingFacade.INSTANCE.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } }