![JAR search and dependency download from the Maven repository](/logo.png)
freeseawind.lf.basic.text.LuckPasswordFieldUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of littleluck Show documentation
Show all versions of littleluck Show documentation
Java Swing cross platform LookAndFeel
The newest version!
package freeseawind.lf.basic.text;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.RectangularShape;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import freeseawind.lf.border.LuckBorderField;
import freeseawind.lf.border.LuckShapeBorder;
import freeseawind.lf.event.LuckBorderFocusHandle;
/**
*
* PasswordFieldUI实现类,设置组件为不完全透明,使用圆角焦点边框作为默认边框。
*
*
*
* PasswordFieldUI implementation class, setting the component is not completely
* transparent, rounded corners as the default focus frame border.
*
*
* @author freeseawind@github
* @version 1.0
*
*/
public class LuckPasswordFieldUI extends BasicPasswordFieldUI
implements LuckBorderField
{
protected LuckBorderFocusHandle handle;
private RectangularShape borderShape;
private boolean isFocusGained;
public static ComponentUI createUI(JComponent c)
{
return new LuckPasswordFieldUI();
}
public void installUI(JComponent c)
{
super.installUI(c);
if(c.getBorder() instanceof LuckShapeBorder)
{
installFocusListener(c);
}
}
@Override
public void uninstallUI(JComponent c)
{
super.uninstallUI(c);
uninstallFocusListener(c);
}
protected void paintBackground(Graphics g)
{
JComponent editor = getComponent();
((Graphics2D)g).setColor(editor.getBackground());
borderShape.setFrame(0, 0, editor.getWidth() - 1, editor.getHeight() - 1);
((Graphics2D)g).fill(borderShape);
}
/**
*
* 初始化边框焦点监听器
*
* Initializes the border focus listener
*
*
* @param c
*/
protected void installFocusListener(JComponent c)
{
handle = createFocusHandle();
borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);
c.addMouseListener(handle);
c.addFocusListener(handle);
}
/**
* remove focus Listener
*
* @param c
*/
protected void uninstallFocusListener(JComponent c)
{
if(handle != null)
{
c.removeMouseListener(handle);
c.removeFocusListener(handle);
handle = null;
}
borderShape = null;
}
/**
* 创建边框焦点监听器。
*
* Create the border focus listener.
*
* @return LuckBorderFocusHandle
*/
protected LuckBorderFocusHandle createFocusHandle()
{
return new LuckFocusHandler();
}
public void setFocusGained(boolean isFoucusGaind)
{
this.isFocusGained = isFoucusGaind;
}
public boolean isFocusGaind()
{
return isFocusGained;
}
public RectangularShape getBorderShape()
{
return borderShape;
}
public void setBorderShape(RectangularShape shape)
{
this.borderShape = shape;
}
public class LuckFocusHandler extends LuckBorderFocusHandle
{
@Override
public JComponent getComponent()
{
return LuckPasswordFieldUI.this.getComponent();
}
@Override
public LuckBorderField getBorderField()
{
return LuckPasswordFieldUI.this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy