core: minor code cleanup:

- add final where possible
- removed "public" from interface methods
- simplified conditional expressions
- removed unnecessary unboxing
- removed unused assignements
- removed redundant casts

(used IntelliJ IDEA 2021.3 inspections)
This commit is contained in:
Karl Tauber
2022-02-25 21:49:15 +01:00
parent 0aecfb565f
commit a365b750d9
17 changed files with 32 additions and 45 deletions

View File

@@ -605,7 +605,7 @@ public abstract class FlatLaf
uiFont = ((ActiveFont)defaultFont).derive( baseFont, fontSize -> { uiFont = ((ActiveFont)defaultFont).derive( baseFont, fontSize -> {
return Math.round( fontSize * UIScale.computeFontScaleFactor( baseFont ) ); return Math.round( fontSize * UIScale.computeFontScaleFactor( baseFont ) );
} ); } );
}; }
// increase font size if system property "flatlaf.uiScale" is set // increase font size if system property "flatlaf.uiScale" is set
uiFont = UIScale.applyCustomScaleFactor( uiFont ); uiFont = UIScale.applyCustomScaleFactor( uiFont );

View File

@@ -534,12 +534,12 @@ public class IntelliJTheme
} }
/** Rename UI default keys (key --> value). */ /** Rename UI default keys (key --> value). */
private static Map<String, String> uiKeyMapping = new HashMap<>(); private static final Map<String, String> uiKeyMapping = new HashMap<>();
/** Copy UI default keys (value --> key). */ /** Copy UI default keys (value --> key). */
private static Map<String, String> uiKeyCopying = new HashMap<>(); private static final Map<String, String> uiKeyCopying = new HashMap<>();
private static Map<String, String> uiKeyInverseMapping = new HashMap<>(); private static final Map<String, String> uiKeyInverseMapping = new HashMap<>();
private static Map<String, String> checkboxKeyMapping = new HashMap<>(); private static final Map<String, String> checkboxKeyMapping = new HashMap<>();
private static Map<String, String> checkboxDuplicateColors = new HashMap<>(); private static final Map<String, String> checkboxDuplicateColors = new HashMap<>();
static { static {
// ComboBox // ComboBox

View File

@@ -170,7 +170,7 @@ class LinuxFontPolicy
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" ); Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" );
if( value instanceof Integer ) { if( value instanceof Integer ) {
int dpi = ((Integer)value).intValue() / 1024; int dpi = (Integer) value / 1024;
if( dpi == -1 ) if( dpi == -1 )
dpi = 96; dpi = 96;
if( dpi < 50 ) if( dpi < 50 )
@@ -278,7 +278,7 @@ 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 FileReader( file ) ) ) {
String line = null; String line;
while( (line = reader.readLine()) != null ) while( (line = reader.readLine()) != null )
lines.add( line ); lines.add( line );
} catch( IOException ex ) { } catch( IOException ex ) {

View File

@@ -350,7 +350,7 @@ class UIDefaultsLoader
enum ValueType { UNKNOWN, STRING, BOOLEAN, CHARACTER, INTEGER, INTEGERORFLOAT, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR, FONT, enum ValueType { UNKNOWN, STRING, BOOLEAN, CHARACTER, INTEGER, INTEGERORFLOAT, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR, FONT,
SCALEDINTEGER, SCALEDFLOAT, SCALEDINSETS, SCALEDDIMENSION, INSTANCE, CLASS, GRAYFILTER, NULL, LAZY } SCALEDINTEGER, SCALEDFLOAT, SCALEDINSETS, SCALEDDIMENSION, INSTANCE, CLASS, GRAYFILTER, NULL, LAZY }
private static ValueType[] tempResultValueType = new ValueType[1]; private static final ValueType[] tempResultValueType = new ValueType[1];
private static Map<Class<?>, ValueType> javaValueTypes; private static Map<Class<?>, ValueType> javaValueTypes;
private static Map<String, ValueType> knownValueTypes; private static Map<String, ValueType> knownValueTypes;
@@ -1209,7 +1209,7 @@ class UIDefaultsLoader
} }
Integer integer = parseInteger( value, true ); Integer integer = parseInteger( value, true );
if( integer.intValue() < min || integer.intValue() > max ) if( integer < min || integer > max )
throw new NumberFormatException( "integer '" + value + "' out of range (" + min + '-' + max + ')' ); throw new NumberFormatException( "integer '" + value + "' out of range (" + min + '-' + max + ')' );
return integer; return integer;
} }
@@ -1250,28 +1250,28 @@ class UIDefaultsLoader
private static ActiveValue parseScaledInteger( String value ) { private static ActiveValue parseScaledInteger( String value ) {
int val = parseInteger( value, true ); int val = parseInteger( value, true );
return (ActiveValue) t -> { return t -> {
return UIScale.scale( val ); return UIScale.scale( val );
}; };
} }
private static ActiveValue parseScaledFloat( String value ) { private static ActiveValue parseScaledFloat( String value ) {
float val = parseFloat( value, true ); float val = parseFloat( value, true );
return (ActiveValue) t -> { return t -> {
return UIScale.scale( val ); return UIScale.scale( val );
}; };
} }
private static ActiveValue parseScaledInsets( String value ) { private static ActiveValue parseScaledInsets( String value ) {
Insets insets = parseInsets( value ); Insets insets = parseInsets( value );
return (ActiveValue) t -> { return t -> {
return UIScale.scale( insets ); return UIScale.scale( insets );
}; };
} }
private static ActiveValue parseScaledDimension( String value ) { private static ActiveValue parseScaledDimension( String value ) {
Dimension dimension = parseDimension( value ); Dimension dimension = parseDimension( value );
return (ActiveValue) t -> { return t -> {
return UIScale.scale( dimension ); return UIScale.scale( dimension );
}; };
} }

View File

@@ -700,7 +700,7 @@ public class FlatComboBoxUI
return true; return true;
Component editorComponent = comboBox.getEditor().getEditorComponent(); Component editorComponent = comboBox.getEditor().getEditorComponent();
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false; return editorComponent != null && FlatUIUtils.isPermanentFocusOwner( editorComponent );
} else } else
return FlatUIUtils.isPermanentFocusOwner( comboBox ); return FlatUIUtils.isPermanentFocusOwner( comboBox );
} }

View File

@@ -199,7 +199,7 @@ public class FlatRadioButtonUI
return infos; return infos;
} }
private static Insets tempInsets = new Insets( 0, 0, 0, 0 ); private static final Insets tempInsets = new Insets( 0, 0, 0, 0 );
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {

View File

@@ -510,7 +510,7 @@ public class FlatRootPaneUI
return; return;
Container parent = c.getParent(); Container parent = c.getParent();
boolean active = parent instanceof Window ? ((Window)parent).isActive() : false; boolean active = parent instanceof Window && ((Window)parent).isActive();
g.setColor( FlatUIUtils.deriveColor( active ? activeBorderColor : inactiveBorderColor, baseBorderColor ) ); g.setColor( FlatUIUtils.deriveColor( active ? activeBorderColor : inactiveBorderColor, baseBorderColor ) );
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl ); HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl );
@@ -522,9 +522,7 @@ public class FlatRootPaneUI
protected boolean isWindowMaximized( Component c ) { protected boolean isWindowMaximized( Component c ) {
Container parent = c.getParent(); Container parent = c.getParent();
return parent instanceof Frame return parent instanceof Frame && (((Frame)parent).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
? (((Frame)parent).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0
: false;
} }
} }

View File

@@ -293,9 +293,7 @@ public class FlatSpinnerUI
return true; return true;
JTextField textField = getEditorTextField( spinner.getEditor() ); JTextField textField = getEditorTextField( spinner.getEditor() );
return (textField != null) return textField != null && FlatUIUtils.isPermanentFocusOwner( textField );
? FlatUIUtils.isPermanentFocusOwner( textField )
: false;
} }
protected Color getBackground( boolean enabled ) { protected Color getBackground( boolean enabled ) {

View File

@@ -650,7 +650,7 @@ public class FlatTabbedPaneUI
case "tabIconPlacement": value = parseTabIconPlacement( (String) value ); break; case "tabIconPlacement": value = parseTabIconPlacement( (String) value ); break;
} }
} else { } else {
Object oldValue = null; Object oldValue;
switch( key ) { switch( key ) {
// BasicTabbedPaneUI // BasicTabbedPaneUI
case "tabInsets": oldValue = tabInsets; tabInsets = (Insets) value; return oldValue; case "tabInsets": oldValue = tabInsets; tabInsets = (Insets) value; return oldValue;
@@ -2412,7 +2412,7 @@ public class FlatTabbedPaneUI
if( tabPane == null || tabViewport == null ) if( tabPane == null || tabViewport == null )
return; return;
if( !scrolled || tabViewport == null ) if( !scrolled )
return; return;
scrolled = false; scrolled = false;
@@ -2525,9 +2525,7 @@ public class FlatTabbedPaneUI
setRolloverTab( tabIndex ); setRolloverTab( tabIndex );
// check whether mouse hit tab close area // check whether mouse hit tab close area
boolean hitClose = isTabClosable( tabIndex ) boolean hitClose = isTabClosable( tabIndex ) && getTabCloseHitArea( tabIndex ).contains( x, y );
? getTabCloseHitArea( tabIndex ).contains( x, y )
: false;
if( e.getID() == MouseEvent.MOUSE_PRESSED ) if( e.getID() == MouseEvent.MOUSE_PRESSED )
pressedTabIndex = hitClose ? tabIndex : -1; pressedTabIndex = hitClose ? tabIndex : -1;
setRolloverTabClose( hitClose ); setRolloverTabClose( hitClose );
@@ -2550,8 +2548,7 @@ public class FlatTabbedPaneUI
if( tabIndex == lastTipTabIndex ) if( tabIndex == lastTipTabIndex )
return; // closeTip already set return; // closeTip already set
if( tabIndex != lastTipTabIndex ) restoreTabToolTip();
restoreTabToolTip();
lastTipTabIndex = tabIndex; lastTipTabIndex = tabIndex;
lastTip = tabPane.getToolTipTextAt( lastTipTabIndex ); lastTip = tabPane.getToolTipTextAt( lastTipTabIndex );

View File

@@ -883,9 +883,7 @@ debug*/
} }
protected boolean isWindowMaximized( Component c ) { protected boolean isWindowMaximized( Component c ) {
return window instanceof Frame return window instanceof Frame && (((Frame) window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
? (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0
: false;
} }
} }

View File

@@ -164,11 +164,7 @@ public class FlatToggleButtonUI
@Override @Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) { public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = super.getStyleableInfos( c ); Map<String, Class<?>> infos = super.getStyleableInfos( c );
Iterator<String> it = infos.keySet().iterator(); infos.keySet().removeIf( s -> s.startsWith( "help." ) );
while( it.hasNext() ) {
if( it.next().startsWith( "help." ) )
it.remove();
}
return infos; return infos;
} }

View File

@@ -71,7 +71,7 @@ public class FlatUIUtils
public static final boolean MAC_USE_QUARTZ = Boolean.getBoolean( "apple.awt.graphics.UseQuartz" ); public static final boolean MAC_USE_QUARTZ = Boolean.getBoolean( "apple.awt.graphics.UseQuartz" );
private static boolean useSharedUIs = true; private static boolean useSharedUIs = true;
private static WeakHashMap<LookAndFeel, IdentityHashMap<Object, ComponentUI>> sharedUIinstances = new WeakHashMap<>(); private static final WeakHashMap<LookAndFeel, IdentityHashMap<Object, ComponentUI>> sharedUIinstances = new WeakHashMap<>();
public static Rectangle addInsets( Rectangle r, Insets insets ) { public static Rectangle addInsets( Rectangle r, Insets insets ) {
return new Rectangle( return new Rectangle(

View File

@@ -284,7 +284,7 @@ public class JBRCustomDecorations
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
Window window = SwingUtilities.windowForComponent( c ); Window window = SwingUtilities.windowForComponent( c );
boolean active = (window != null) ? window.isActive() : false; boolean active = window != null && window.isActive();
// paint top border // paint top border
// - in light themes // - in light themes

View File

@@ -68,7 +68,7 @@ public interface AnimatedIcon
extends Icon extends Icon
{ {
@Override @Override
public default void paintIcon( Component c, Graphics g, int x, int y ) { default void paintIcon( Component c, Graphics g, int x, int y ) {
AnimationSupport.paintIcon( this, c, g, x, y ); AnimationSupport.paintIcon( this, c, g, x, y );
} }

View File

@@ -291,7 +291,7 @@ public class HSLColor
// Calculate the Saturation // Calculate the Saturation
float s = 0; float s;
if (max == min) if (max == min)
s = 0; s = 0;
@@ -386,7 +386,7 @@ public class HSLColor
s /= 100f; s /= 100f;
l /= 100f; l /= 100f;
float q = 0; float q;
if (l < 0.5) if (l < 0.5)
q = l * (1 + s); q = l * (1 + s);

View File

@@ -31,7 +31,7 @@ import com.formdev.flatlaf.FlatSystemProperties;
public class HiDPIUtils public class HiDPIUtils
{ {
public interface Painter { public interface Painter {
public void paint( Graphics2D g, int x, int y, int width, int height, double scaleFactor ); void paint( Graphics2D g, int x, int y, int width, int height, double scaleFactor );
} }
public static void paintAtScale1x( Graphics2D g, JComponent c, Painter painter ) { public static void paintAtScale1x( Graphics2D g, JComponent c, Painter painter ) {

View File

@@ -89,7 +89,7 @@ public class JavaCompatibility
getClippedStringMethod = cls.getMethod( SystemInfo.isJava_9_orLater getClippedStringMethod = cls.getMethod( SystemInfo.isJava_9_orLater
? "getClippedString" ? "getClippedString"
: "clipStringIfNecessary", : "clipStringIfNecessary",
new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); JComponent.class, FontMetrics.class, String.class, int.class );
} catch( Exception ex ) { } catch( Exception ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex ); LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex ); throw new RuntimeException( ex );