mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-27 03:46:17 -06:00
Button: get focusWidth and arc from UI defaults
This commit is contained in:
@@ -212,6 +212,11 @@ public abstract class FlatLaf
|
||||
if( color != null )
|
||||
return color;
|
||||
|
||||
// integer
|
||||
Integer integer = parseInteger( value, false );
|
||||
if( integer != null )
|
||||
return integer;
|
||||
|
||||
// string
|
||||
return value;
|
||||
}
|
||||
@@ -242,4 +247,16 @@ public abstract class FlatLaf
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer parseInteger( String value, boolean reportError ) {
|
||||
try {
|
||||
return Integer.parseInt( value );
|
||||
} catch( NumberFormatException ex ) {
|
||||
if( reportError ) {
|
||||
System.err.println( "invalid integer '" + value + "'" );
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.GradientPaint;
|
||||
@@ -25,7 +26,6 @@ import java.awt.Insets;
|
||||
import java.awt.Paint;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.basic.BasicBorders;
|
||||
import static com.formdev.flatlaf.util.UIScale.*;
|
||||
|
||||
/**
|
||||
* Border for {@link javax.swing.JButton}.
|
||||
@@ -46,7 +46,7 @@ public class FlatButtonBorder
|
||||
|
||||
float focusWidth = getFocusWidth();
|
||||
float lineWidth = getLineWidth();
|
||||
float arc = scale( 6f ); //TODO
|
||||
float arc = FlatUIUtils.getButtonArc();
|
||||
|
||||
if( c.hasFocus() ) {
|
||||
g2.setColor( UIManager.getColor( FlatButtonUI.isDefaultButton( c )
|
||||
@@ -90,12 +90,10 @@ public class FlatButtonBorder
|
||||
}
|
||||
|
||||
protected float getFocusWidth() {
|
||||
//TODO
|
||||
return scale( 2f );
|
||||
return FlatUIUtils.getFocusWidth();
|
||||
}
|
||||
|
||||
protected float getLineWidth() {
|
||||
//TODO
|
||||
return scale( 1f );
|
||||
return FlatUIUtils.getLineWidth();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicButtonUI;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
/**
|
||||
@@ -65,9 +64,8 @@ public class FlatButtonUI
|
||||
try {
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
|
||||
//TODO
|
||||
float focusWidth = UIScale.scale( 2f );
|
||||
float arc = UIScale.scale( 6f );
|
||||
float focusWidth = FlatUIUtils.getFocusWidth();
|
||||
float arc = FlatUIUtils.getButtonArc();
|
||||
|
||||
g2.setColor( getBackground( c ) );
|
||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Container;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -23,6 +24,7 @@ import java.awt.RenderingHints;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
@@ -34,6 +36,27 @@ public class FlatUIUtils
|
||||
{
|
||||
public static final boolean MAC_USE_QUARTZ = Boolean.getBoolean( "apple.awt.graphics.UseQuartz" );
|
||||
|
||||
public static int getUIInt( String key, int defaultValue ) {
|
||||
Object value = UIManager.get( key );
|
||||
return (value instanceof Integer) ? (Integer) value : defaultValue;
|
||||
}
|
||||
|
||||
public static float getFocusWidth() {
|
||||
return scale( (float) getUIInt( "Component.focusWidth", 2 ) );
|
||||
}
|
||||
|
||||
public static float getLineWidth() {
|
||||
return scale( 1f );
|
||||
}
|
||||
|
||||
public static float getComponentArc() {
|
||||
return scale( (float) getUIInt( "Component.arc", 5 ) );
|
||||
}
|
||||
|
||||
public static float getButtonArc() {
|
||||
return scale( (float) getUIInt( "Button.arc", 6 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets rendering hints used for painting.
|
||||
*/
|
||||
|
||||
@@ -23,3 +23,10 @@ LabelUI=com.formdev.flatlaf.ui.FlatLabelUI
|
||||
#---- Button ----
|
||||
|
||||
Button.border=com.formdev.flatlaf.ui.FlatButtonBorder
|
||||
Button.arc=6
|
||||
|
||||
|
||||
#---- Component ----
|
||||
|
||||
Component.focusWidth=2
|
||||
Component.arc=5
|
||||
|
||||
@@ -29,6 +29,7 @@ Button.startBorderColor=ff0000
|
||||
Button.endBorderColor=0000ff
|
||||
Button.disabledBorderColor=000088
|
||||
Button.focusedBorderColor=466d94
|
||||
#Button.arc=10
|
||||
|
||||
Button.default.background=dddddd
|
||||
Button.default.foreground=880000
|
||||
@@ -41,6 +42,8 @@ Button.default.focusColor=ff0000
|
||||
#---- Component ----
|
||||
|
||||
Component.focusColor=97c3f3
|
||||
#Component.focusWidth=5
|
||||
#Component.arc=8
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
Reference in New Issue
Block a user