mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
TextComponent: scale caret width on HiDPI screens when running on Java 8
This commit is contained in:
@@ -3,6 +3,7 @@ FlatLaf Change Log
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- TextComponent: Scale caret width on HiDPI screens when running on Java 8.
|
||||||
- ProgressBar: If progress text is visible:
|
- ProgressBar: If progress text is visible:
|
||||||
- use smaller font
|
- use smaller font
|
||||||
- reduced height
|
- reduced height
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.util.Properties;
|
|||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.swing.UIDefaults;
|
import javax.swing.UIDefaults;
|
||||||
|
import javax.swing.UIDefaults.ActiveValue;
|
||||||
import javax.swing.UIDefaults.LazyValue;
|
import javax.swing.UIDefaults.LazyValue;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import javax.swing.plaf.DimensionUIResource;
|
import javax.swing.plaf.DimensionUIResource;
|
||||||
@@ -39,9 +40,9 @@ import com.formdev.flatlaf.ui.FlatEmptyBorder;
|
|||||||
import com.formdev.flatlaf.ui.FlatLineBorder;
|
import com.formdev.flatlaf.ui.FlatLineBorder;
|
||||||
import com.formdev.flatlaf.util.ColorFunctions;
|
import com.formdev.flatlaf.util.ColorFunctions;
|
||||||
import com.formdev.flatlaf.util.DerivedColor;
|
import com.formdev.flatlaf.util.DerivedColor;
|
||||||
import com.formdev.flatlaf.util.ScaledNumber;
|
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load UI defaults from properties files associated to Flat LaF classes and add to UI defaults.
|
* Load UI defaults from properties files associated to Flat LaF classes and add to UI defaults.
|
||||||
@@ -202,7 +203,7 @@ class UIDefaultsLoader
|
|||||||
return resolveValue( properties, newValue );
|
return resolveValue( properties, newValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum ValueType { UNKNOWN, STRING, INTEGER, BORDER, ICON, INSETS, SIZE, COLOR, SCALEDNUMBER, INSTANCE, CLASS }
|
private enum ValueType { UNKNOWN, STRING, INTEGER, BORDER, ICON, INSETS, SIZE, COLOR, SCALEDINTEGER, INSTANCE, CLASS }
|
||||||
|
|
||||||
static Object parseValue( String key, String value ) {
|
static Object parseValue( String key, String value ) {
|
||||||
return parseValue( key, value, v -> v, Collections.emptyList() );
|
return parseValue( key, value, v -> v, Collections.emptyList() );
|
||||||
@@ -266,7 +267,7 @@ class UIDefaultsLoader
|
|||||||
case INSETS: return parseInsets( value );
|
case INSETS: return parseInsets( value );
|
||||||
case SIZE: return parseSize( value );
|
case SIZE: return parseSize( value );
|
||||||
case COLOR: return parseColorOrFunction( value, true );
|
case COLOR: return parseColorOrFunction( value, true );
|
||||||
case SCALEDNUMBER: return parseScaledNumber( value );
|
case SCALEDINTEGER: return parseScaledInteger( value );
|
||||||
case INSTANCE: return parseInstance( value, addonClassLoaders );
|
case INSTANCE: return parseInstance( value, addonClassLoaders );
|
||||||
case CLASS: return parseClass( value, addonClassLoaders );
|
case CLASS: return parseClass( value, addonClassLoaders );
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
@@ -506,11 +507,10 @@ class UIDefaultsLoader
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ScaledNumber parseScaledNumber( String value ) {
|
private static ActiveValue parseScaledInteger( String value ) {
|
||||||
try {
|
int val = parseInteger( value, true );
|
||||||
return new ScaledNumber( Integer.parseInt( value ) );
|
return (ActiveValue) t -> {
|
||||||
} catch( NumberFormatException ex ) {
|
return UIScale.scale( val );
|
||||||
throw new NumberFormatException( "invalid integer '" + value + "'" );
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 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
|
|
||||||
*
|
|
||||||
* http://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 static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A number that scales its value.
|
|
||||||
*
|
|
||||||
* NOTE:
|
|
||||||
* Using ScaledNumber in UI defaults works only if the value is get with
|
|
||||||
* sun.swing.DefaultLookup.getInt(), which is used by some basic UI delegates,
|
|
||||||
* because this method uses "instanceof Number".
|
|
||||||
* UIManager.getInt() on the other hand uses "instanceof Integer" and does not work.
|
|
||||||
*
|
|
||||||
* @author Karl Tauber
|
|
||||||
*/
|
|
||||||
public class ScaledNumber
|
|
||||||
extends Number
|
|
||||||
{
|
|
||||||
private final int value;
|
|
||||||
|
|
||||||
public ScaledNumber( int value ) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int intValue() {
|
|
||||||
return scale( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long longValue() {
|
|
||||||
return scale( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float floatValue() {
|
|
||||||
return scale( (float) value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doubleValue() {
|
|
||||||
return scale( (float) value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Integer.hashCode( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals( Object obj ) {
|
|
||||||
return (obj instanceof ScaledNumber)
|
|
||||||
? (value == ((ScaledNumber)obj).value)
|
|
||||||
: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return Integer.toString( value );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -99,6 +99,11 @@ Button.defaultButtonFollowsFocus=false
|
|||||||
Button.default.borderWidth=1
|
Button.default.borderWidth=1
|
||||||
|
|
||||||
|
|
||||||
|
#---- Caret ----
|
||||||
|
|
||||||
|
Caret.width={scaledInteger}1
|
||||||
|
|
||||||
|
|
||||||
#---- CheckBox ----
|
#---- CheckBox ----
|
||||||
|
|
||||||
CheckBox.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
CheckBox.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
||||||
@@ -227,7 +232,7 @@ OptionPane.maxCharactersPerLine=80
|
|||||||
OptionPane.iconMessageGap=16
|
OptionPane.iconMessageGap=16
|
||||||
OptionPane.messagePadding=3
|
OptionPane.messagePadding=3
|
||||||
OptionPane.buttonPadding=8
|
OptionPane.buttonPadding=8
|
||||||
OptionPane.buttonMinimumWidth={scaledNumber}72
|
OptionPane.buttonMinimumWidth={scaledInteger}72
|
||||||
OptionPane.sameSizeButtons=true
|
OptionPane.sameSizeButtons=true
|
||||||
OptionPane.setButtonMargin=false
|
OptionPane.setButtonMargin=false
|
||||||
OptionPane.buttonOrientation=4
|
OptionPane.buttonOrientation=4
|
||||||
@@ -333,8 +338,8 @@ SplitPane.dividerSize={integer}5
|
|||||||
SplitPane.continuousLayout=true
|
SplitPane.continuousLayout=true
|
||||||
SplitPane.border=null
|
SplitPane.border=null
|
||||||
SplitPane.centerOneTouchButtons=true
|
SplitPane.centerOneTouchButtons=true
|
||||||
SplitPane.oneTouchButtonSize={scaledNumber}6
|
SplitPane.oneTouchButtonSize={scaledInteger}6
|
||||||
SplitPane.oneTouchButtonOffset={scaledNumber}2
|
SplitPane.oneTouchButtonOffset={scaledInteger}2
|
||||||
|
|
||||||
SplitPaneDivider.border=null
|
SplitPaneDivider.border=null
|
||||||
SplitPaneDivider.oneTouchArrowColor=@@ComboBox.buttonArrowColor
|
SplitPaneDivider.oneTouchArrowColor=@@ComboBox.buttonArrowColor
|
||||||
|
|||||||
Reference in New Issue
Block a user