mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
added class FlatSystemProperties to define/document own system properties used in FlatLaf
This commit is contained in:
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines/documents own system properties used in FlatLaf.
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public interface FlatSystemProperties
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Specifies a custom scale factor used to scale the UI.
|
||||||
|
* <p>
|
||||||
|
* If Java runtime scales (Java 9 or later), this scale factor is applied on top
|
||||||
|
* of the Java system scale factor. Java 8 does not scale and this scale factor
|
||||||
|
* replaces the user scale factor that FlatLaf computes based on the font.
|
||||||
|
* To replace the Java 9+ system scale factor, use system property "sun.java2d.uiScale",
|
||||||
|
* which has the same syntax as this one.
|
||||||
|
* <p>
|
||||||
|
* <strong>Allowed Values</strong> e.g. {@code 1.5}, {@code 1.5x}, {@code 150%} or {@code 144dpi} (96dpi is 100%)<br>
|
||||||
|
*/
|
||||||
|
String UI_SCALE = "flatlaf.uiScale";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether Ubuntu font should be used on Ubuntu Linux.
|
||||||
|
* By default, if not running in a JetBrains Runtime, the Liberation Sans font
|
||||||
|
* is used because there are rendering issues (in Java) with Ubuntu fonts.
|
||||||
|
* <p>
|
||||||
|
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||||
|
* <strong>Default</strong> {@code false}
|
||||||
|
*/
|
||||||
|
String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether vertical text position is corrected when UI is scaled on HiDPI screens.
|
||||||
|
* <p>
|
||||||
|
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||||
|
* <strong>Default</strong> {@code true}
|
||||||
|
*/
|
||||||
|
String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a system property is set and returns {@code true} if its value
|
||||||
|
* is {@code "true"} (case-insensitive), otherwise it returns {@code false}.
|
||||||
|
* If the system property is not set, {@code defaultValue} is returned.
|
||||||
|
*/
|
||||||
|
static boolean getBoolean( String key, boolean defaultValue ) {
|
||||||
|
String value = System.getProperty( key );
|
||||||
|
return (value != null) ? Boolean.parseBoolean( value ) : defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,7 +78,7 @@ class LinuxFontPolicy
|
|||||||
// --> use Liberation Sans font
|
// --> use Liberation Sans font
|
||||||
if( family.startsWith( "Ubuntu" ) &&
|
if( family.startsWith( "Ubuntu" ) &&
|
||||||
!SystemInfo.IS_JETBRAINS_JVM &&
|
!SystemInfo.IS_JETBRAINS_JVM &&
|
||||||
!Boolean.parseBoolean( System.getProperty( "flatlaf.useUbuntuFont" ) ) )
|
!FlatSystemProperties.getBoolean( FlatSystemProperties.USE_UBUNTU_FONT, false ) )
|
||||||
family = "Liberation Sans";
|
family = "Liberation Sans";
|
||||||
|
|
||||||
// scale font size
|
// scale font size
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.awt.geom.AffineTransform;
|
|||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.text.AttributedCharacterIterator;
|
import java.text.AttributedCharacterIterator;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -104,7 +105,7 @@ public class HiDPIUtils
|
|||||||
|
|
||||||
private static boolean useTextYCorrection() {
|
private static boolean useTextYCorrection() {
|
||||||
if( useTextYCorrection == null )
|
if( useTextYCorrection == null )
|
||||||
useTextYCorrection = Boolean.valueOf( System.getProperty( "flatlaf.useTextYCorrection", "true" ) );
|
useTextYCorrection = FlatSystemProperties.getBoolean( FlatSystemProperties.USE_TEXT_Y_CORRECTION, true );
|
||||||
return useTextYCorrection;
|
return useTextYCorrection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import javax.swing.plaf.DimensionUIResource;
|
|||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
import javax.swing.plaf.InsetsUIResource;
|
import javax.swing.plaf.InsetsUIResource;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two scaling modes are supported for HiDPI displays:
|
* Two scaling modes are supported for HiDPI displays:
|
||||||
@@ -195,8 +196,7 @@ public class UIScale
|
|||||||
|
|
||||||
private static boolean isUserScalingEnabled() {
|
private static boolean isUserScalingEnabled() {
|
||||||
// same as in IntelliJ IDEA
|
// same as in IntelliJ IDEA
|
||||||
String hidpi = System.getProperty( "hidpi" );
|
return FlatSystemProperties.getBoolean( "hidpi", true );
|
||||||
return (hidpi != null) ? Boolean.parseBoolean( hidpi ) : true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -204,7 +204,7 @@ public class UIScale
|
|||||||
* to the given font.
|
* to the given font.
|
||||||
*/
|
*/
|
||||||
public static FontUIResource applyCustomScaleFactor( FontUIResource font ) {
|
public static FontUIResource applyCustomScaleFactor( FontUIResource font ) {
|
||||||
String uiScale = System.getProperty( "flatlaf.uiScale" );
|
String uiScale = System.getProperty( FlatSystemProperties.UI_SCALE );
|
||||||
float scaleFactor = parseScaleFactor( uiScale );
|
float scaleFactor = parseScaleFactor( uiScale );
|
||||||
if( scaleFactor <= 0 )
|
if( scaleFactor <= 0 )
|
||||||
return font;
|
return font;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.awt.Insets;
|
|||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.util.Graphics2DProxy;
|
import com.formdev.flatlaf.util.Graphics2DProxy;
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
@@ -40,7 +41,7 @@ public class FlatPaintingStringTest
|
|||||||
extends JPanel
|
extends JPanel
|
||||||
{
|
{
|
||||||
public static void main( String[] args ) {
|
public static void main( String[] args ) {
|
||||||
System.setProperty( "flatlaf.uiScale", "1x" );
|
System.setProperty( FlatSystemProperties.UI_SCALE, "1x" );
|
||||||
System.setProperty( "sun.java2d.uiScale", "1x" );
|
System.setProperty( "sun.java2d.uiScale", "1x" );
|
||||||
|
|
||||||
SwingUtilities.invokeLater( () -> {
|
SwingUtilities.invokeLater( () -> {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import com.formdev.flatlaf.FlatDarkLaf;
|
|||||||
import com.formdev.flatlaf.FlatIntelliJLaf;
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
import com.formdev.flatlaf.IntelliJTheme;
|
import com.formdev.flatlaf.IntelliJTheme;
|
||||||
import com.formdev.flatlaf.demo.LookAndFeelsComboBox;
|
import com.formdev.flatlaf.demo.LookAndFeelsComboBox;
|
||||||
import com.formdev.flatlaf.demo.DemoPrefs;
|
import com.formdev.flatlaf.demo.DemoPrefs;
|
||||||
@@ -66,10 +67,10 @@ public class FlatTestFrame
|
|||||||
DemoPrefs.init( PREFS_ROOT_PATH );
|
DemoPrefs.init( PREFS_ROOT_PATH );
|
||||||
|
|
||||||
// set scale factor
|
// set scale factor
|
||||||
if( System.getProperty( "flatlaf.uiScale", System.getProperty( "sun.java2d.uiScale" ) ) == null ) {
|
if( System.getProperty( FlatSystemProperties.UI_SCALE, System.getProperty( "sun.java2d.uiScale" ) ) == null ) {
|
||||||
String scaleFactor = DemoPrefs.getState().get( KEY_SCALE_FACTOR, null );
|
String scaleFactor = DemoPrefs.getState().get( KEY_SCALE_FACTOR, null );
|
||||||
if( scaleFactor != null )
|
if( scaleFactor != null )
|
||||||
System.setProperty( "flatlaf.uiScale", scaleFactor );
|
System.setProperty( FlatSystemProperties.UI_SCALE, scaleFactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set look and feel
|
// set look and feel
|
||||||
@@ -145,7 +146,7 @@ public class FlatTestFrame
|
|||||||
lookAndFeelComboBox.setModel( lafModel );
|
lookAndFeelComboBox.setModel( lafModel );
|
||||||
|
|
||||||
updateScaleFactorComboBox();
|
updateScaleFactorComboBox();
|
||||||
String scaleFactor = System.getProperty( "flatlaf.uiScale", System.getProperty( "sun.java2d.uiScale" ) );
|
String scaleFactor = System.getProperty( FlatSystemProperties.UI_SCALE, System.getProperty( "sun.java2d.uiScale" ) );
|
||||||
if( scaleFactor != null )
|
if( scaleFactor != null )
|
||||||
scaleFactorComboBox.setSelectedItem( scaleFactor );
|
scaleFactorComboBox.setSelectedItem( scaleFactor );
|
||||||
|
|
||||||
@@ -472,10 +473,10 @@ public class FlatTestFrame
|
|||||||
scaleFactorComboBox.setPopupVisible( false );
|
scaleFactorComboBox.setPopupVisible( false );
|
||||||
|
|
||||||
if( scaleFactor != null ) {
|
if( scaleFactor != null ) {
|
||||||
System.setProperty( "flatlaf.uiScale", scaleFactor );
|
System.setProperty( FlatSystemProperties.UI_SCALE, scaleFactor );
|
||||||
DemoPrefs.getState().put( KEY_SCALE_FACTOR, scaleFactor );
|
DemoPrefs.getState().put( KEY_SCALE_FACTOR, scaleFactor );
|
||||||
} else {
|
} else {
|
||||||
System.clearProperty( "flatlaf.uiScale" );
|
System.clearProperty( FlatSystemProperties.UI_SCALE );
|
||||||
DemoPrefs.getState().remove( KEY_SCALE_FACTOR );
|
DemoPrefs.getState().remove( KEY_SCALE_FACTOR );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class UIDefaultsDump
|
|||||||
public static void main( String[] args ) {
|
public static void main( String[] args ) {
|
||||||
Locale.setDefault( Locale.ENGLISH );
|
Locale.setDefault( Locale.ENGLISH );
|
||||||
System.setProperty( "sun.java2d.uiScale", "1x" );
|
System.setProperty( "sun.java2d.uiScale", "1x" );
|
||||||
System.setProperty( "flatlaf.uiScale", "1x" );
|
System.setProperty( FlatSystemProperties.UI_SCALE, "1x" );
|
||||||
|
|
||||||
File dir = new File( "src/main/resources/com/formdev/flatlaf/testing/uidefaults" );
|
File dir = new File( "src/main/resources/com/formdev/flatlaf/testing/uidefaults" );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user