added Error Prone (https://errorprone.info/) and fixed reported errors and warnings

- CI runs Error Prone with Java 11
- use Gradle task `errorprone` to run it on development machine
- fixes are mostly cosmetic except:
  - use Locale.ENGLISH for String.toLowerCase()
  - use explicit character encoding when reading/writing files
  - TabbedPane: wrong logic in mouse-wheel scrolling
  - SplitPane: simplified property change listener (fixes hiding field `propertyChangeListener` of superclass)
This commit is contained in:
Karl Tauber
2023-05-19 22:58:12 +02:00
parent 9d84501bc8
commit 97018df2f9
46 changed files with 167 additions and 86 deletions

View File

@@ -43,6 +43,10 @@ jobs:
distribution: adopt # Java 8 and 11 are pre-installed on ubuntu-latest distribution: adopt # Java 8 and 11 are pre-installed on ubuntu-latest
cache: gradle cache: gradle
- name: Check with Error Prone
if: matrix.java == '11'
run: ./gradlew errorprone clean -Dtoolchain=${{ matrix.toolchain }}
- name: Build with Gradle - name: Build with Gradle
run: ./gradlew build -Dtoolchain=${{ matrix.toolchain }} run: ./gradlew build -Dtoolchain=${{ matrix.toolchain }}

View File

@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import net.ltgt.gradle.errorprone.errorprone
val releaseVersion = "3.1.1" val releaseVersion = "3.1.1"
val developmentVersion = "3.2-SNAPSHOT" val developmentVersion = "3.2-SNAPSHOT"
@@ -43,6 +45,10 @@ if( !toolchainJavaVersion.isNullOrEmpty() )
println() println()
plugins {
alias( libs.plugins.errorprone ) apply false
}
allprojects { allprojects {
tasks { tasks {
withType<JavaCompile>().configureEach { withType<JavaCompile>().configureEach {
@@ -81,4 +87,55 @@ allprojects {
isFailOnError = false isFailOnError = false
} }
} }
//---- Error Prone ----
tasks.register( "errorprone" ) {
group = "verification"
tasks.withType<JavaCompile>().forEach {
dependsOn( it )
}
}
val useErrorProne = gradle.startParameter.taskNames.contains( "errorprone" )
if( useErrorProne ) {
plugins.withType<JavaPlugin> {
apply( plugin = libs.plugins.errorprone.get().pluginId )
dependencies {
"errorprone"( libs.errorprone )
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add( "-Werror" )
options.errorprone {
disable(
"ReferenceEquality", // reports usage of '==' for objects
"StringSplitter", // reports String.split()
"JavaTimeDefaultTimeZone", // reports Year.now()
"MissingSummary", // reports `/** @since 2 */`
"InvalidBlockTag", // reports @uiDefault in javadoc
"AlreadyChecked", // reports false positives
"InlineMeSuggester", // suggests using Error Prone annotations for deprecated methods
"TypeParameterUnusedInFormals",
"UnsynchronizedOverridesSynchronized",
)
when( project.name ) {
"flatlaf-intellij-themes" -> disable(
"MutablePublicArray", // reports FlatAllIJThemes.INFOS
)
"flatlaf-theme-editor" -> disable(
"CatchAndPrintStackTrace",
)
"flatlaf-testing" -> disable(
"CatchAndPrintStackTrace",
"JdkObsolete", // reports Hashtable used for JSlider.setLabelTable()
"JavaUtilDate", // reports usage of class Date
)
}
}
}
}
}
} }

View File

@@ -391,7 +391,7 @@ public abstract class FlatLaf
Method m = UIManager.class.getMethod( "createLookAndFeel", String.class ); Method m = UIManager.class.getMethod( "createLookAndFeel", String.class );
aquaLaf = (BasicLookAndFeel) m.invoke( null, "Mac OS X" ); aquaLaf = (BasicLookAndFeel) m.invoke( null, "Mac OS X" );
} else } else
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).getDeclaredConstructor().newInstance(); aquaLaf = Class.forName( aquaLafClassName ).asSubclass( BasicLookAndFeel.class ).getDeclaredConstructor().newInstance();
} catch( Exception ex ) { } catch( Exception ex ) {
LoggingFacade.INSTANCE.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(); throw new IllegalStateException();
@@ -581,10 +581,13 @@ public abstract class FlatLaf
Object activeFont = new ActiveFont( null, null, -1, 0, 0, 0, 0 ); Object activeFont = new ActiveFont( null, null, -1, 0, 0, 0, 0 );
// override fonts // override fonts
List<String> fontKeys = new ArrayList<>( 50 );
for( Object key : defaults.keySet() ) { for( Object key : defaults.keySet() ) {
if( key instanceof String && (((String)key).endsWith( ".font" ) || ((String)key).endsWith( "Font" )) ) if( key instanceof String && (((String)key).endsWith( ".font" ) || ((String)key).endsWith( "Font" )) )
defaults.put( key, activeFont ); fontKeys.add( (String) key );
} }
for( String key : fontKeys )
defaults.put( key, activeFont );
// add fonts that are not set in BasicLookAndFeel // add fonts that are not set in BasicLookAndFeel
defaults.put( "RootPane.font", activeFont ); defaults.put( "RootPane.font", activeFont );
@@ -1541,7 +1544,7 @@ public abstract class FlatLaf
int newStyle = (style != -1) int newStyle = (style != -1)
? style ? style
: (styleChange != 0) : (styleChange != 0)
? baseStyle & ~((styleChange >> 16) & 0xffff) | (styleChange & 0xffff) ? (baseStyle & ~((styleChange >> 16) & 0xffff)) | (styleChange & 0xffff)
: baseStyle; : baseStyle;
// new size // new size

View File

@@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
/** /**
@@ -96,7 +97,7 @@ public class FlatPropertiesLaf
protected ArrayList<Class<?>> getLafClassesForDefaultsLoading() { protected ArrayList<Class<?>> getLafClassesForDefaultsLoading() {
ArrayList<Class<?>> lafClasses = new ArrayList<>(); ArrayList<Class<?>> lafClasses = new ArrayList<>();
lafClasses.add( FlatLaf.class ); lafClasses.add( FlatLaf.class );
switch( baseTheme.toLowerCase() ) { switch( baseTheme.toLowerCase( Locale.ENGLISH ) ) {
default: default:
case "light": case "light":
lafClasses.add( FlatLightLaf.class ); lafClasses.add( FlatLightLaf.class );

View File

@@ -23,11 +23,14 @@ import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import javax.swing.text.StyleContext; import javax.swing.text.StyleContext;
import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.LoggingFacade;
@@ -68,7 +71,7 @@ class LinuxFontPolicy
if( word.endsWith( "," ) ) if( word.endsWith( "," ) )
word = word.substring( 0, word.length() - 1 ).trim(); word = word.substring( 0, word.length() - 1 ).trim();
String lword = word.toLowerCase(); String lword = word.toLowerCase( Locale.ENGLISH );
if( lword.equals( "italic" ) || lword.equals( "oblique" ) ) if( lword.equals( "italic" ) || lword.equals( "oblique" ) )
style |= Font.ITALIC; style |= Font.ITALIC;
else if( lword.equals( "bold" ) ) else if( lword.equals( "bold" ) )
@@ -104,7 +107,7 @@ class LinuxFontPolicy
size = 1; size = 1;
// handle logical font names // handle logical font names
String logicalFamily = mapFcName( family.toLowerCase() ); String logicalFamily = mapFcName( family.toLowerCase( Locale.ENGLISH ) );
if( logicalFamily != null ) if( logicalFamily != null )
family = logicalFamily; family = logicalFamily;
@@ -143,7 +146,7 @@ class LinuxFontPolicy
return createFont( Font.DIALOG, style, size, dsize ); return createFont( Font.DIALOG, style, size, dsize );
// check whether last work contains some font weight (e.g. Ultra-Bold or Heavy) // check whether last work contains some font weight (e.g. Ultra-Bold or Heavy)
String lastWord = family.substring( index + 1 ).toLowerCase(); String lastWord = family.substring( index + 1 ).toLowerCase( Locale.ENGLISH );
if( lastWord.contains( "bold" ) || lastWord.contains( "heavy" ) || lastWord.contains( "black" ) ) if( lastWord.contains( "bold" ) || lastWord.contains( "heavy" ) || lastWord.contains( "black" ) )
style |= Font.BOLD; style |= Font.BOLD;
@@ -257,6 +260,7 @@ class LinuxFontPolicy
return createFont( family, style, size, dsize ); return createFont( family, style, size, dsize );
} }
@SuppressWarnings( "MixedMutabilityReturnType" ) // Error Prone
private static List<String> readConfig( String filename ) { private static List<String> readConfig( String filename ) {
File userHome = new File( System.getProperty( "user.home" ) ); File userHome = new File( System.getProperty( "user.home" ) );
@@ -277,7 +281,9 @@ class LinuxFontPolicy
// read config file // read config file
ArrayList<String> lines = new ArrayList<>( 200 ); ArrayList<String> lines = new ArrayList<>( 200 );
try( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) { try( BufferedReader reader = new BufferedReader( new InputStreamReader(
new FileInputStream( file ), StandardCharsets.US_ASCII ) ) )
{
String line; String line;
while( (line = reader.readLine()) != null ) while( (line = reader.readLine()) != null )
lines.add( line ); lines.add( line );

View File

@@ -348,8 +348,11 @@ class UIDefaultsLoader
// convert binary color to string // convert binary color to string
if( newValue instanceof Color ) { if( newValue instanceof Color ) {
Color color = (Color) newValue; Color color = (Color) newValue;
int rgb = color.getRGB() & 0xffffff;
int alpha = color.getAlpha(); int alpha = color.getAlpha();
return String.format( (alpha != 255) ? "#%06x%02x" : "#%06x", color.getRGB() & 0xffffff, alpha ); return (alpha != 255)
? String.format( "#%06x%02x", rgb, alpha )
: String.format( "#%06x", rgb );
} }
throw new IllegalArgumentException( "property value type '" + newValue.getClass().getName() + "' not supported in references" ); throw new IllegalArgumentException( "property value type '" + newValue.getClass().getName() + "' not supported in references" );
@@ -702,8 +705,6 @@ class UIDefaultsLoader
/** /**
* Parses a hex color in {@code #RGB}, {@code #RGBA}, {@code #RRGGBB} or {@code #RRGGBBAA} * Parses a hex color in {@code #RGB}, {@code #RGBA}, {@code #RRGGBB} or {@code #RRGGBBAA}
* format and returns it as color object. * format and returns it as color object.
*
* @throws IllegalArgumentException
*/ */
static ColorUIResource parseColor( String value ) { static ColorUIResource parseColor( String value ) {
int rgba = parseColorRGBA( value ); int rgba = parseColorRGBA( value );
@@ -716,8 +717,6 @@ class UIDefaultsLoader
* Parses a hex color in {@code #RGB}, {@code #RGBA}, {@code #RRGGBB} or {@code #RRGGBBAA} * 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}, * format and returns it as {@code rgba} integer suitable for {@link java.awt.Color},
* which includes alpha component in bits 24-31. * which includes alpha component in bits 24-31.
*
* @throws IllegalArgumentException
*/ */
static int parseColorRGBA( String value ) { static int parseColorRGBA( String value ) {
int len = value.length(); int len = value.length();

View File

@@ -53,8 +53,8 @@ public class FlatInternalFrameCloseIcon
g.setColor( FlatButtonUI.buttonStateColor( c, c.getForeground(), null, null, hoverForeground, pressedForeground ) ); g.setColor( FlatButtonUI.buttonStateColor( c, c.getForeground(), null, null, hoverForeground, pressedForeground ) );
float mx = width / 2; float mx = width / 2f;
float my = height / 2; float my = height / 2f;
float r = 3.25f; float r = 3.25f;
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD, 4 ); Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD, 4 );

View File

@@ -94,8 +94,8 @@ public class FlatTabbedPaneCloseIcon
Color fg = FlatButtonUI.buttonStateColor( c, closeForeground, null, null, closeHoverForeground, closePressedForeground ); Color fg = FlatButtonUI.buttonStateColor( c, closeForeground, null, null, closeHoverForeground, closePressedForeground );
g.setColor( FlatUIUtils.deriveColor( fg, c.getForeground() ) ); g.setColor( FlatUIUtils.deriveColor( fg, c.getForeground() ) );
float mx = width / 2; float mx = width / 2f;
float my = height / 2; float my = height / 2f;
float r = ((bg != null) ? closeCrossFilledSize : closeCrossPlainSize) / 2; float r = ((bg != null) ? closeCrossFilledSize : closeCrossPlainSize) / 2;
// paint cross // paint cross

View File

@@ -502,9 +502,9 @@ class JsonParser {
} }
private boolean isHexDigit() { private boolean isHexDigit() {
return current >= '0' && current <= '9' return (current >= '0' && current <= '9')
|| current >= 'a' && current <= 'f' || (current >= 'a' && current <= 'f')
|| current >= 'A' && current <= 'F'; || (current >= 'A' && current <= 'F');
} }
private boolean isEndOfText() { private boolean isEndOfText() {

View File

@@ -69,7 +69,7 @@ public class Location {
if (obj == null) { if (obj == null) {
return false; return false;
} }
if (getClass() != obj.getClass()) { if (!(obj instanceof Location)) {
return false; return false;
} }
Location other = (Location)obj; Location other = (Location)obj;

View File

@@ -24,6 +24,7 @@ import java.awt.Rectangle;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.swing.Icon; import javax.swing.Icon;
@@ -179,7 +180,7 @@ public class FlatLabelUI
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule() // BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>"; String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
String lowerText = text.toLowerCase(); String lowerText = text.toLowerCase( Locale.ENGLISH );
int headIndex; int headIndex;
int styleIndex; int styleIndex;
@@ -228,7 +229,7 @@ public class FlatLabelUI
int tagBegin = i + 1; int tagBegin = i + 1;
for( i += 2; i < textLength; i++ ) { for( i += 2; i < textLength; i++ ) {
if( !Character.isLetterOrDigit( text.charAt( i ) ) ) { if( !Character.isLetterOrDigit( text.charAt( i ) ) ) {
String tag = text.substring( tagBegin, i ).toLowerCase(); String tag = text.substring( tagBegin, i ).toLowerCase( Locale.ENGLISH );
if( tagsUseFontSizeSet.contains( tag ) ) if( tagsUseFontSizeSet.contains( tag ) )
return true; return true;

View File

@@ -391,7 +391,7 @@ public class FlatPopupFactory
//---- class NonFlashingPopup --------------------------------------------- //---- class NonFlashingPopup ---------------------------------------------
private class NonFlashingPopup private static class NonFlashingPopup
extends Popup extends Popup
{ {
private Popup delegate; private Popup delegate;

View File

@@ -360,8 +360,8 @@ public class FlatScrollPaneUI
protected void updateViewport( PropertyChangeEvent e ) { protected void updateViewport( PropertyChangeEvent e ) {
super.updateViewport( e ); super.updateViewport( e );
JViewport oldViewport = (JViewport) (e.getOldValue()); JViewport oldViewport = (JViewport) e.getOldValue();
JViewport newViewport = (JViewport) (e.getNewValue()); JViewport newViewport = (JViewport) e.getNewValue();
removeViewportListeners( oldViewport ); removeViewportListeners( oldViewport );
addViewportListeners( newViewport ); addViewportListeners( newViewport );

View File

@@ -87,7 +87,6 @@ public class FlatSplitPaneUI
@Styleable protected Color oneTouchHoverArrowColor; @Styleable protected Color oneTouchHoverArrowColor;
@Styleable protected Color oneTouchPressedArrowColor; @Styleable protected Color oneTouchPressedArrowColor;
private PropertyChangeListener propertyChangeListener;
private Map<String, Object> oldStyleValues; private Map<String, Object> oldStyleValues;
public static ComponentUI createUI( JComponent c ) { public static ComponentUI createUI( JComponent c ) {
@@ -126,19 +125,9 @@ public class FlatSplitPaneUI
} }
@Override @Override
protected void installListeners() { protected PropertyChangeListener createPropertyChangeListener() {
super.installListeners(); return FlatStylingSupport.createPropertyChangeListener( splitPane, this::installStyle,
super.createPropertyChangeListener() );
propertyChangeListener = FlatStylingSupport.createPropertyChangeListener( splitPane, this::installStyle, null );
splitPane.addPropertyChangeListener( propertyChangeListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
splitPane.removePropertyChangeListener( propertyChangeListener );
propertyChangeListener = null;
} }
@Override @Override

View File

@@ -278,6 +278,7 @@ public class FlatStylingSupport
* @throws IllegalArgumentException on syntax errors * @throws IllegalArgumentException on syntax errors
* @throws ClassCastException if value type does not fit to expected type * @throws ClassCastException if value type does not fit to expected type
*/ */
@SuppressWarnings( "ReturnValueIgnored" ) // Error Prone
public static Map<String, Object> parseAndApply( Map<String, Object> oldStyleValues, public static Map<String, Object> parseAndApply( Map<String, Object> oldStyleValues,
Object style, BiFunction<String, Object, Object> applyProperty ) Object style, BiFunction<String, Object, Object> applyProperty )
throws UnknownStyleException, IllegalArgumentException throws UnknownStyleException, IllegalArgumentException

View File

@@ -1967,7 +1967,7 @@ public class FlatTabbedPaneUI
//---- class TabCloseButton ----------------------------------------------- //---- class TabCloseButton -----------------------------------------------
private class TabCloseButton private static class TabCloseButton
extends JButton extends JButton
implements UIResource implements UIResource
{ {
@@ -1977,7 +1977,7 @@ public class FlatTabbedPaneUI
//---- class ContainerUIResource ------------------------------------------ //---- class ContainerUIResource ------------------------------------------
private class ContainerUIResource private static class ContainerUIResource
extends JPanel extends JPanel
implements UIResource implements UIResource
{ {
@@ -2382,7 +2382,7 @@ public class FlatTabbedPaneUI
if( isPreciseWheel && if( isPreciseWheel &&
getScrollButtonsPlacement() == BOTH && getScrollButtonsPlacement() == BOTH &&
getScrollButtonsPolicy() == AS_NEEDED_SINGLE && getScrollButtonsPolicy() == AS_NEEDED_SINGLE &&
(isLeftToRight() || !horizontal) || // scroll buttons are hidden in right-to-left (isLeftToRight() || !horizontal) && // scroll buttons are hidden in right-to-left
scrollBackwardButtonPrefSize != null ) scrollBackwardButtonPrefSize != null )
{ {
// special cases for scrolling with touchpad or high-resolution wheel: // special cases for scrolling with touchpad or high-resolution wheel:
@@ -3051,7 +3051,7 @@ public class FlatTabbedPaneUI
break; break;
case CENTER: case CENTER:
shiftTabs( 0, (diff) / 2 ); shiftTabs( 0, diff / 2 );
topHeight += diff / 2; topHeight += diff / 2;
bottomHeight += diff - (diff / 2); bottomHeight += diff - (diff / 2);
break; break;

View File

@@ -682,7 +682,7 @@ public class FlatTitlePane
// Seems to be a bug in sun.awt.X11.XNETProtocol.requestState(), // Seems to be a bug in sun.awt.X11.XNETProtocol.requestState(),
// which does some strange state XOR-ing... // which does some strange state XOR-ing...
if( (oldState & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_VERT ) if( (oldState & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_VERT )
newState = oldState & ~Frame.MAXIMIZED_BOTH | Frame.MAXIMIZED_HORIZ; newState = (oldState & ~Frame.MAXIMIZED_BOTH) | Frame.MAXIMIZED_HORIZ;
} }
frame.setExtendedState( newState ); frame.setExtendedState( newState );

View File

@@ -575,7 +575,7 @@ public class FlatTreeUI
if( isSelected && isWideSelection() ) { if( isSelected && isWideSelection() ) {
Color oldColor = g.getColor(); Color oldColor = g.getColor();
g.setColor( selectionInactiveBackground ); g.setColor( selectionInactiveBackground );
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf ); paintWideSelection( g, bounds, row );
g.setColor( oldColor ); g.setColor( oldColor );
} }
return; return;
@@ -633,7 +633,7 @@ public class FlatTreeUI
if( isWideSelection() ) { if( isWideSelection() ) {
// wide selection // wide selection
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf ); paintWideSelection( g, bounds, row );
} else { } else {
// non-wide selection // non-wide selection
paintCellBackground( g, rendererComponent, bounds, row, true ); paintCellBackground( g, rendererComponent, bounds, row, true );
@@ -702,9 +702,7 @@ public class FlatTreeUI
return oldColor; return oldColor;
} }
private void paintWideSelection( Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, private void paintWideSelection( Graphics g, Rectangle bounds, int row ) {
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
{
float arcTop, arcBottom; float arcTop, arcBottom;
arcTop = arcBottom = UIScale.scale( selectionArc / 2f ); arcTop = arcBottom = UIScale.scale( selectionArc / 2f );

View File

@@ -725,7 +725,7 @@ public class FlatUIUtils
{ {
dotSize = UIScale.scale( dotSize ); dotSize = UIScale.scale( dotSize );
gap = UIScale.scale( gap ); gap = UIScale.scale( gap );
int gripSize = (dotSize * dotCount) + ((gap * (dotCount - 1))); int gripSize = (dotSize * dotCount) + (gap * (dotCount - 1));
// calculate grip position // calculate grip position
float gx; float gx;

View File

@@ -28,7 +28,6 @@ import java.awt.Paint;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.Shape; import java.awt.Shape;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
@@ -368,12 +367,12 @@ public class Graphics2DProxy
} }
@Override @Override
public void setRenderingHint( Key hintKey, Object hintValue ) { public void setRenderingHint( RenderingHints.Key hintKey, Object hintValue ) {
delegate.setRenderingHint( hintKey, hintValue ); delegate.setRenderingHint( hintKey, hintValue );
} }
@Override @Override
public Object getRenderingHint( Key hintKey ) { public Object getRenderingHint( RenderingHints.Key hintKey ) {
return delegate.getRenderingHint( hintKey ); return delegate.getRenderingHint( hintKey );
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf { module com.formdev.flatlaf {

View File

@@ -1214,6 +1214,7 @@ public class TestFlatStyleableValue
//---- class TestIcon ----------------------------------------------------- //---- class TestIcon -----------------------------------------------------
@SuppressWarnings( "EqualsHashCode" ) // Error Prone
public static class TestIcon public static class TestIcon
implements Icon implements Icon
{ {

View File

@@ -30,6 +30,7 @@ import com.formdev.flatlaf.FlatSystemProperties;
*/ */
public class TestUtils public class TestUtils
{ {
@SuppressWarnings( "MutablePublicArray" ) // Error Prone
public static final float[] FACTORS = { 1f, 1.25f, 1.5f, 1.75f, 2f, 2.25f, 2.5f, 2.75f, 3f, 3.25f, 3.5f, 3.75f, 4f, 5f, 6f }; public static final float[] FACTORS = { 1f, 1.25f, 1.5f, 1.75f, 2f, 2.25f, 2.5f, 2.75f, 3f, 3.25f, 3.5f, 3.75f, 4f, 5f, 6f };
public static void setup( boolean withFocus ) { public static void setup( boolean withFocus ) {

View File

@@ -440,9 +440,9 @@ class DemoFrame
Class<? extends LookAndFeel> lafClass = UIManager.getLookAndFeel().getClass(); Class<? extends LookAndFeel> lafClass = UIManager.getLookAndFeel().getClass();
try { try {
FlatLaf.setup( lafClass.newInstance() ); FlatLaf.setup( lafClass.getDeclaredConstructor().newInstance() );
FlatLaf.updateUI(); FlatLaf.updateUI();
} catch( InstantiationException | IllegalAccessException ex ) { } catch( Exception ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex ); LoggingFacade.INSTANCE.logSevere( null, ex );
} }
} }

View File

@@ -279,7 +279,7 @@ public class FlatSVGIcon
private static synchronized URI loadFromStream( InputStream in ) throws IOException { private static synchronized URI loadFromStream( InputStream in ) throws IOException {
try( InputStream in2 = in ) { try( InputStream in2 = in ) {
return svgUniverse.loadSVG( in2, "/flatlaf-stream-" + (streamNumber++) ); return svgUniverse.loadSVG( in2, "/flatlaf-stream-" + streamNumber++ );
} }
} }
@@ -474,7 +474,7 @@ public class FlatSVGIcon
URI uri = this.uri; URI uri = this.uri;
if( uri == null ) { if( uri == null ) {
URL url = getIconURL( name, dark ); URL url = getIconURL( name, dark );
if( url == null & dark ) if( url == null && dark )
url = getIconURL( name, false ); url = getIconURL( name, false );
if( url == null ) { if( url == null ) {

View File

@@ -770,6 +770,7 @@ public class FlatUIDefaultsInspector
return String.valueOf( value ); return String.valueOf( value );
} }
@SuppressWarnings( "FormatString" ) // Error Prone
private static String color2hex( Color color ) { private static String color2hex( Color color ) {
int rgb = color.getRGB(); int rgb = color.getRGB();
boolean hasAlpha = color.getAlpha() != 255; boolean hasAlpha = color.getAlpha() != 255;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.extras { module com.formdev.flatlaf.extras {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.fonts.inter { module com.formdev.flatlaf.fonts.inter {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.fonts.jetbrains_mono { module com.formdev.flatlaf.fonts.jetbrains_mono {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.fonts.roboto_mono { module com.formdev.flatlaf.fonts.roboto_mono {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.fonts.roboto { module com.formdev.flatlaf.fonts.roboto {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.intellijthemes { module com.formdev.flatlaf.intellijthemes {

View File

@@ -869,7 +869,6 @@ public class FlatWindowsNativeWindowBorder
int GetSystemMetricsForDpi( int nIndex, int dpi ); int GetSystemMetricsForDpi( int nIndex, int dpi );
boolean IsZoomed( HWND hWnd ); boolean IsZoomed( HWND hWnd );
HANDLE GetProp( HWND hWnd, String lpString );
HMENU GetSystemMenu( HWND hWnd, boolean bRevert ); HMENU GetSystemMenu( HWND hWnd, boolean bRevert );
boolean SetMenuItemInfo( HMENU hmenu, int item, boolean fByPositon, MENUITEMINFO lpmii ); boolean SetMenuItemInfo( HMENU hmenu, int item, boolean fByPositon, MENUITEMINFO lpmii );

View File

@@ -229,7 +229,7 @@ public class FlatTaskPaneUI
// compute chevron position // compute chevron position
int cx = (int) (x + width / 2 - cw / 2); int cx = (int) (x + width / 2 - cw / 2);
int cy = (int) (y + (height / 2 - ch)); int cy = (int) (y + height / 2 - ch);
float offset = ch + UIScale.scale( 1f ); float offset = ch + UIScale.scale( 1f );
// set stroke with scaled width // set stroke with scaled width

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.swingx { module com.formdev.flatlaf.swingx {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /*
* @author Karl Tauber * @author Karl Tauber
*/ */
module com.formdev.flatlaf.testing.modular.app { module com.formdev.flatlaf.testing.modular.app {

View File

@@ -1456,7 +1456,7 @@ public class FlatComponents2Test
//---- TestTableRowHeaderModel -------------------------------------------- //---- TestTableRowHeaderModel --------------------------------------------
private class TestTableRowHeaderModel private static class TestTableRowHeaderModel
extends AbstractTableModel extends AbstractTableModel
implements TableModelListener implements TableModelListener
{ {

View File

@@ -932,7 +932,7 @@ public class FlatDisabledIconsTest
@Override @Override
public int filterRGB(int x, int y, int rgb) { public int filterRGB(int x, int y, int rgb) {
// Reduce the color bandwidth in quarter (>> 2) and Shift 0x88. // Reduce the color bandwidth in quarter (>> 2) and Shift 0x88.
return (rgb & 0xff000000) + 0x888888 + ((((rgb >> 16) & 0xff) >> 2) << 16) + ((((rgb >> 8) & 0xff) >> 2) << 8) + (((rgb) & 0xff) >> 2); return (rgb & 0xff000000) + 0x888888 + ((((rgb >> 16) & 0xff) >> 2) << 16) + ((((rgb >> 8) & 0xff) >> 2) << 8) + ((rgb & 0xff) >> 2);
} }
} }
} }

View File

@@ -937,7 +937,7 @@ public class FlatMenusTest
//---- class PopupMenu ---------------------------------------------------- //---- class PopupMenu ----------------------------------------------------
private class PopupMenu extends JPopupMenu { private static class PopupMenu extends JPopupMenu {
private PopupMenu() { private PopupMenu() {
initComponents(); initComponents();
} }

View File

@@ -398,7 +398,7 @@ public class FlatSubMenusTest
//---- class PopupMenu ---------------------------------------------------- //---- class PopupMenu ----------------------------------------------------
private class PopupMenu extends JPopupMenu { private static class PopupMenu extends JPopupMenu {
private PopupMenu() { private PopupMenu() {
initComponents(); initComponents();
} }

View File

@@ -22,16 +22,20 @@ import java.awt.Font;
import java.awt.Insets; import java.awt.Insets;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -229,7 +233,8 @@ public class UIDefaultsDump
} }
if( origFile != null ) { if( origFile != null ) {
try { try {
Map<String, String> defaults1 = parse( new FileReader( origFile ) ); Map<String, String> defaults1 = parse( new InputStreamReader(
new FileInputStream( origFile ), StandardCharsets.UTF_8 ) );
Map<String, String> defaults2 = parse( new StringReader( stringWriter.toString() ) ); Map<String, String> defaults2 = parse( new StringReader( stringWriter.toString() ) );
content = diff( defaults1, defaults2 ); content = diff( defaults1, defaults2 );
@@ -242,7 +247,9 @@ public class UIDefaultsDump
// write to file // write to file
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
try( FileWriter fileWriter = new FileWriter( file ) ) { try( Writer fileWriter = new OutputStreamWriter(
new FileOutputStream( file ), StandardCharsets.UTF_8 ) )
{
fileWriter.write( content ); fileWriter.write( content );
} catch( IOException ex ) { } catch( IOException ex ) {
ex.printStackTrace(); ex.printStackTrace();
@@ -419,7 +426,7 @@ public class UIDefaultsDump
} else if( value instanceof Character ) { } else if( value instanceof Character ) {
char ch = ((Character)value).charValue(); char ch = ((Character)value).charValue();
if( ch >= ' ' && ch <= '~' ) if( ch >= ' ' && ch <= '~' )
out.printf( "'%c'", value ); out.printf( "'%c'", ch );
else else
out.printf( "'\\u%h'", (int) ch ); out.printf( "'\\u%h'", (int) ch );
} else if( value.getClass().isArray() ) } else if( value.getClass().isArray() )

View File

@@ -19,10 +19,13 @@ package com.formdev.flatlaf.testing.uidefaults;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
@@ -47,7 +50,9 @@ public class UIDefaultsKeysDump
// load existing keys file // load existing keys file
HashSet<String> keys = new HashSet<>(); HashSet<String> keys = new HashSet<>();
try( BufferedReader reader = new BufferedReader( new FileReader( keysFile ) ) ) { try( BufferedReader reader = new BufferedReader( new InputStreamReader(
new FileInputStream( keysFile ), StandardCharsets.UTF_8 ) ) )
{
String key; String key;
while( (key = reader.readLine()) != null ) { while( (key = reader.readLine()) != null ) {
keys.add( key ); keys.add( key );
@@ -64,7 +69,9 @@ public class UIDefaultsKeysDump
collectKeys( FlatTestLaf.class.getName(), keys ); collectKeys( FlatTestLaf.class.getName(), keys );
// write key file // write key file
try( Writer fileWriter = new BufferedWriter( new FileWriter( keysFile ) ) ) { try( Writer fileWriter = new BufferedWriter( new OutputStreamWriter(
new FileOutputStream( keysFile ), StandardCharsets.UTF_8 ) ) )
{
String[] sortedKeys = keys.toArray( new String[keys.size()] ); String[] sortedKeys = keys.toArray( new String[keys.size()] );
Arrays.sort( sortedKeys ); Arrays.sort( sortedKeys );
for( String key : sortedKeys ) { for( String key : sortedKeys ) {

View File

@@ -46,6 +46,6 @@ public class FlatLafThemeEditor
System.setProperty( "apple.awt.application.appearance", "system" ); System.setProperty( "apple.awt.application.appearance", "system" );
} }
FlatThemeFileEditor.main( args ); FlatThemeFileEditor.launch( args );
} }
} }

View File

@@ -52,6 +52,7 @@ class FlatThemeEditorOverlay
private Font font; private Font font;
private Font baseFont; private Font baseFont;
@SuppressWarnings( "FormatString" ) // Error Prone
@Override @Override
public void paint( Graphics g, JComponent c ) { public void paint( Graphics g, JComponent c ) {
// paint the syntax text area // paint the syntax text area

View File

@@ -102,7 +102,7 @@ class FlatThemeFileEditor
private final FlatThemePropertiesBaseManager propertiesBaseManager = new FlatThemePropertiesBaseManager(); private final FlatThemePropertiesBaseManager propertiesBaseManager = new FlatThemePropertiesBaseManager();
private final JButton newButton; private final JButton newButton;
static void main( String[] args ) { static void launch( String[] args ) {
File dir = (args.length > 0) File dir = (args.length > 0)
? new File( args[0] ) ? new File( args[0] )
: null; : null;
@@ -1306,7 +1306,7 @@ class FlatThemeFileEditor
super.addElement( obj ); super.addElement( obj );
} else { } else {
int index = binarySearch( this, obj, comparator ); int index = binarySearch( this, obj, comparator );
insertElementAt( obj, (index < 0) ? ((-index)-1) : index ); insertElementAt( obj, (index < 0) ? (-index - 1) : index );
} }
} }

View File

@@ -54,6 +54,12 @@ junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jun
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" } junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
# errorprone
errorprone = "com.google.errorprone:error_prone_core:2.19.1"
[bundles] [bundles]
junit = [ "junit-api", "junit-params" ] junit = [ "junit-api", "junit-params" ]
[plugins]
errorprone = { id = "net.ltgt.errorprone", version = "3.1.0" }