mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 14:30:56 +03:00
PasswordField: Caps lock icon no longer painted over long text (issue #172)
This commit is contained in:
@@ -35,6 +35,7 @@ FlatLaf Change Log
|
|||||||
non-opaque. (issue #349)
|
non-opaque. (issue #349)
|
||||||
- OptionPane: Align wrapped lines to the right if component orientation is
|
- OptionPane: Align wrapped lines to the right if component orientation is
|
||||||
right-to-left. (issue #350)
|
right-to-left. (issue #350)
|
||||||
|
- PasswordField: Caps lock icon no longer painted over long text. (issue #172)
|
||||||
- Window decorations: Window title bar width is no longer considered when
|
- Window decorations: Window title bar width is no longer considered when
|
||||||
calculating preferred/minimum width of window. (issue #351)
|
calculating preferred/minimum width of window. (issue #351)
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.awt.event.FocusEvent;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.JFormattedTextField;
|
import javax.swing.JFormattedTextField;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.DefaultCaret;
|
import javax.swing.text.DefaultCaret;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
@@ -142,4 +143,23 @@ public class FlatCaret
|
|||||||
moveDot( doc.getLength() );
|
moveDot( doc.getLength() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public void scrollCaretToVisible() {
|
||||||
|
JTextComponent c = getComponent();
|
||||||
|
if( c == null || c.getUI() == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Rectangle loc = c.getUI().modelToView( c, getDot(), getDotBias() );
|
||||||
|
if( loc != null ) {
|
||||||
|
adjustVisibility( loc );
|
||||||
|
damage( loc );
|
||||||
|
}
|
||||||
|
} catch( BadLocationException ex ) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
@@ -123,8 +124,10 @@ public class FlatPasswordFieldUI
|
|||||||
repaint( e );
|
repaint( e );
|
||||||
}
|
}
|
||||||
private void repaint( KeyEvent e ) {
|
private void repaint( KeyEvent e ) {
|
||||||
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK )
|
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK ) {
|
||||||
e.getComponent().repaint();
|
e.getComponent().repaint();
|
||||||
|
scrollCaretToVisible();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,16 +172,36 @@ public class FlatPasswordFieldUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void paintCapsLock( Graphics g ) {
|
protected void paintCapsLock( Graphics g ) {
|
||||||
if( !showCapsLock )
|
if( !isCapsLockVisible() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
if( !FlatUIUtils.isPermanentFocusOwner( c ) ||
|
|
||||||
!Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
int y = (c.getHeight() - capsLockIcon.getIconHeight()) / 2;
|
int y = (c.getHeight() - capsLockIcon.getIconHeight()) / 2;
|
||||||
int x = c.getWidth() - capsLockIcon.getIconWidth() - y;
|
int x = c.getWidth() - capsLockIcon.getIconWidth() - y;
|
||||||
capsLockIcon.paintIcon( c, g, x, y );
|
capsLockIcon.paintIcon( c, g, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
protected boolean isCapsLockVisible() {
|
||||||
|
if( !showCapsLock )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
JTextComponent c = getComponent();
|
||||||
|
return FlatUIUtils.isPermanentFocusOwner( c ) &&
|
||||||
|
Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Insets getPadding() {
|
||||||
|
Insets padding = super.getPadding();
|
||||||
|
if( !isCapsLockVisible() )
|
||||||
|
return padding;
|
||||||
|
|
||||||
|
return FlatUIUtils.addInsets( padding, new Insets( 0, 0, 0, capsLockIcon.getIconWidth() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,4 +290,13 @@ public class FlatTextFieldUI
|
|||||||
Object padding = getComponent().getClientProperty( FlatClientProperties.TEXT_FIELD_PADDING );
|
Object padding = getComponent().getClientProperty( FlatClientProperties.TEXT_FIELD_PADDING );
|
||||||
return (padding instanceof Insets) ? UIScale.scale( (Insets) padding ) : null;
|
return (padding instanceof Insets) ? UIScale.scale( (Insets) padding ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
protected void scrollCaretToVisible() {
|
||||||
|
Caret caret = getComponent().getCaret();
|
||||||
|
if( caret instanceof FlatCaret )
|
||||||
|
((FlatCaret)caret).scrollCaretToVisible();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Insets addInsets( Insets insets1, Insets insets2 ) {
|
public static Insets addInsets( Insets insets1, Insets insets2 ) {
|
||||||
|
if( insets1 == null )
|
||||||
|
return insets2;
|
||||||
|
if( insets2 == null )
|
||||||
|
return insets1;
|
||||||
|
|
||||||
return new Insets(
|
return new Insets(
|
||||||
insets1.top + insets2.top,
|
insets1.top + insets2.top,
|
||||||
insets1.left + insets2.left,
|
insets1.left + insets2.left,
|
||||||
|
|||||||
Reference in New Issue
Block a user