All Downloads are FREE. Search and download functionalities are using the official Maven repository.

freeseawind.lf.basic.text.LuckPasswordFieldUI Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package freeseawind.lf.basic.text;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RectangularShape;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.JTextComponent;

import freeseawind.lf.border.LuckBorderField;
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 contentShape; private RectangularShape borderShape; private boolean isFocusGained; public static ComponentUI createUI(JComponent c) { return new LuckPasswordFieldUI(); } public void installUI(JComponent c) { super.installUI(c); LookAndFeel.installProperty(c, "opaque", Boolean.FALSE); contentShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8); borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8); handle = createFocusHandle(); c.addMouseListener(handle); c.addFocusListener(handle); } @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); c.removeMouseListener(handle); c.removeFocusListener(handle); handle = null; } /** *

创建边框焦点监听器。

* *

Create the border focus listener.

* * @return LuckBorderFocusHandle */ protected LuckBorderFocusHandle createFocusHandle() { return new LuckFocusHandler(); } @Override protected void paintBackground(Graphics g) { // 绘制和边框形状一致的背景。 // Draw border and conform to the shape of the background. JTextComponent editor = this.getComponent(); Graphics2D g2d = (Graphics2D) g; g.setColor(editor.getBackground()); contentShape.setFrame(10, 10, editor.getWidth() - 1, editor.getHeight() - 1); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2d.fill(contentShape); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); } 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 RectangularShape getContentShape() { return contentShape; } public void setContentShape(RectangularShape contentShape) { this.contentShape = contentShape; } 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