mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 08:15:09 +03:00
TextField, FormattedTextField and PasswordField: support round border (issue #65)
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
- TextField, FormattedTextField and PasswordField: Support round borders (see UI
|
||||||
|
default value `TextComponent.arc`). (issue #65)
|
||||||
|
|
||||||
|
|
||||||
## 0.27
|
## 0.27
|
||||||
|
|
||||||
- Support `JInternalFrame` and `JDesktopPane`. (issues #39 and #11)
|
- Support `JInternalFrame` and `JDesktopPane`. (issues #39 and #11)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import javax.swing.plaf.ComponentUI;
|
|||||||
*
|
*
|
||||||
* <!-- FlatTextFieldUI -->
|
* <!-- FlatTextFieldUI -->
|
||||||
*
|
*
|
||||||
|
* @uiDefault TextComponent.arc int
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import com.formdev.flatlaf.FlatClientProperties;
|
|||||||
*
|
*
|
||||||
* <!-- FlatPasswordFieldUI -->
|
* <!-- FlatPasswordFieldUI -->
|
||||||
*
|
*
|
||||||
|
* @uiDefault TextComponent.arc int
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
@@ -62,6 +63,7 @@ import com.formdev.flatlaf.FlatClientProperties;
|
|||||||
public class FlatPasswordFieldUI
|
public class FlatPasswordFieldUI
|
||||||
extends BasicPasswordFieldUI
|
extends BasicPasswordFieldUI
|
||||||
{
|
{
|
||||||
|
protected int arc;
|
||||||
protected int focusWidth;
|
protected int focusWidth;
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
@@ -78,6 +80,7 @@ public class FlatPasswordFieldUI
|
|||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
String prefix = getPropertyPrefix();
|
String prefix = getPropertyPrefix();
|
||||||
|
arc = UIManager.getInt( "TextComponent.arc" );
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
@@ -128,7 +131,7 @@ public class FlatPasswordFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintSafely( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth, isIntelliJTheme );
|
FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme );
|
||||||
FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground );
|
FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground );
|
||||||
super.paintSafely( g );
|
super.paintSafely( g );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
|
import java.awt.Component;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border for various text components (e.g. {@link javax.swing.JTextField}).
|
||||||
|
*
|
||||||
|
* @uiDefault Component.arc int
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class FlatTextBorder
|
||||||
|
extends FlatBorder
|
||||||
|
{
|
||||||
|
protected final int arc = UIManager.getInt( "TextComponent.arc" );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getArc( Component c ) {
|
||||||
|
return scale( (float) arc );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import javax.swing.JSpinner;
|
|||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicTextFieldUI;
|
import javax.swing.plaf.basic.BasicTextFieldUI;
|
||||||
@@ -59,6 +60,7 @@ import com.formdev.flatlaf.FlatClientProperties;
|
|||||||
*
|
*
|
||||||
* <!-- FlatTextFieldUI -->
|
* <!-- FlatTextFieldUI -->
|
||||||
*
|
*
|
||||||
|
* @uiDefault TextComponent.arc int
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
@@ -70,6 +72,7 @@ import com.formdev.flatlaf.FlatClientProperties;
|
|||||||
public class FlatTextFieldUI
|
public class FlatTextFieldUI
|
||||||
extends BasicTextFieldUI
|
extends BasicTextFieldUI
|
||||||
{
|
{
|
||||||
|
protected int arc;
|
||||||
protected int focusWidth;
|
protected int focusWidth;
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
@@ -86,6 +89,7 @@ public class FlatTextFieldUI
|
|||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
String prefix = getPropertyPrefix();
|
String prefix = getPropertyPrefix();
|
||||||
|
arc = UIManager.getInt( "TextComponent.arc" );
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
@@ -136,7 +140,7 @@ public class FlatTextFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintSafely( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
paintBackground( g, getComponent(), focusWidth, isIntelliJTheme );
|
paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme );
|
||||||
paintPlaceholder( g, getComponent(), placeholderForeground );
|
paintPlaceholder( g, getComponent(), placeholderForeground );
|
||||||
super.paintSafely( g );
|
super.paintSafely( g );
|
||||||
}
|
}
|
||||||
@@ -146,13 +150,15 @@ public class FlatTextFieldUI
|
|||||||
// background is painted elsewhere
|
// background is painted elsewhere
|
||||||
}
|
}
|
||||||
|
|
||||||
static void paintBackground( Graphics g, JTextComponent c, int focusWidth, boolean isIntelliJTheme ) {
|
static void paintBackground( Graphics g, JTextComponent c, int focusWidth, int arc, boolean isIntelliJTheme ) {
|
||||||
|
Border border = c.getBorder();
|
||||||
|
|
||||||
// do not paint background if:
|
// do not paint background if:
|
||||||
// - not opaque and
|
// - not opaque and
|
||||||
// - border is not a flat border and
|
// - border is not a flat border and
|
||||||
// - opaque was explicitly set (to false)
|
// - opaque was explicitly set (to false)
|
||||||
// (same behaviour as in AquaTextFieldUI)
|
// (same behaviour as in AquaTextFieldUI)
|
||||||
if( !c.isOpaque() && !(c.getBorder() instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
|
if( !c.isOpaque() && !(border instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// fill background if opaque to avoid garbage if user sets opaque to true
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
@@ -164,7 +170,8 @@ public class FlatTextFieldUI
|
|||||||
try {
|
try {
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
float fFocusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) focusWidth ) : 0;
|
float fFocusWidth = (border instanceof FlatBorder) ? scale( (float) focusWidth ) : 0;
|
||||||
|
float fArc = (border instanceof FlatTextBorder) ? scale( (float) arc ) : 0;
|
||||||
|
|
||||||
Color background = c.getBackground();
|
Color background = c.getBackground();
|
||||||
g2.setColor( !(background instanceof UIResource)
|
g2.setColor( !(background instanceof UIResource)
|
||||||
@@ -172,7 +179,7 @@ public class FlatTextFieldUI
|
|||||||
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
||||||
? FlatUIUtils.getParentBackground( c )
|
? FlatUIUtils.getParentBackground( c )
|
||||||
: background) );
|
: background) );
|
||||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, 0 );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, fArc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ FileView.floppyDriveIcon=com.formdev.flatlaf.icons.FlatFileViewFloppyDriveIcon
|
|||||||
|
|
||||||
#---- FormattedTextField ----
|
#---- FormattedTextField ----
|
||||||
|
|
||||||
FormattedTextField.border=com.formdev.flatlaf.ui.FlatBorder
|
FormattedTextField.border=com.formdev.flatlaf.ui.FlatTextBorder
|
||||||
FormattedTextField.margin=@textComponentMargin
|
FormattedTextField.margin=@textComponentMargin
|
||||||
FormattedTextField.background=@textComponentBackground
|
FormattedTextField.background=@textComponentBackground
|
||||||
FormattedTextField.placeholderForeground=@disabledText
|
FormattedTextField.placeholderForeground=@disabledText
|
||||||
@@ -296,7 +296,7 @@ OptionPane.warningIcon=com.formdev.flatlaf.icons.FlatOptionPaneWarningIcon
|
|||||||
|
|
||||||
#---- PasswordField ----
|
#---- PasswordField ----
|
||||||
|
|
||||||
PasswordField.border=com.formdev.flatlaf.ui.FlatBorder
|
PasswordField.border=com.formdev.flatlaf.ui.FlatTextBorder
|
||||||
PasswordField.margin=@textComponentMargin
|
PasswordField.margin=@textComponentMargin
|
||||||
PasswordField.background=@textComponentBackground
|
PasswordField.background=@textComponentBackground
|
||||||
PasswordField.placeholderForeground=@disabledText
|
PasswordField.placeholderForeground=@disabledText
|
||||||
@@ -457,11 +457,12 @@ TextArea.background=@textComponentBackground
|
|||||||
|
|
||||||
# allowed values: "never", "once" (default) or "always"
|
# allowed values: "never", "once" (default) or "always"
|
||||||
TextComponent.selectAllOnFocusPolicy=once
|
TextComponent.selectAllOnFocusPolicy=once
|
||||||
|
TextComponent.arc=0
|
||||||
|
|
||||||
|
|
||||||
#---- TextField ----
|
#---- TextField ----
|
||||||
|
|
||||||
TextField.border=com.formdev.flatlaf.ui.FlatBorder
|
TextField.border=com.formdev.flatlaf.ui.FlatTextBorder
|
||||||
TextField.margin=@textComponentMargin
|
TextField.margin=@textComponentMargin
|
||||||
TextField.background=@textComponentBackground
|
TextField.background=@textComponentBackground
|
||||||
TextField.placeholderForeground=@disabledText
|
TextField.placeholderForeground=@disabledText
|
||||||
|
|||||||
Reference in New Issue
Block a user