PasswordField implemented

This commit is contained in:
Karl Tauber
2019-08-21 14:47:46 +02:00
parent faed3fabc6
commit b534cd5082
4 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
/*
* 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 java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.JTextComponent;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
*
* @author Karl Tauber
*/
public class FlatPasswordFieldUI
extends BasicPasswordFieldUI
{
private final Handler handler = new Handler();
public static ComponentUI createUI( JComponent c ) {
return new FlatPasswordFieldUI();
}
@Override
protected void installListeners() {
super.installListeners();
getComponent().addFocusListener( handler );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
getComponent().removeFocusListener( handler );
}
@Override
protected void paintBackground( Graphics g ) {
JTextComponent c = getComponent();
FlatUIUtils.paintParentBackground( g, c );
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
float focusWidth = FlatUIUtils.getFocusWidth();
g2.setColor( c.getBackground() );
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, 0 );
} finally {
g2.dispose();
}
}
//---- class Handler ------------------------------------------------------
private class Handler
implements FocusListener
{
@Override
public void focusGained( FocusEvent e ) {
getComponent().repaint();
}
@Override
public void focusLost( FocusEvent e ) {
getComponent().repaint();
}
}
}

View File

@@ -20,6 +20,7 @@ ButtonUI=com.formdev.flatlaf.ui.FlatButtonUI
CheckBoxUI=com.formdev.flatlaf.ui.FlatCheckBoxUI
FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI
LabelUI=com.formdev.flatlaf.ui.FlatLabelUI
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI
@@ -49,6 +50,13 @@ FormattedTextField.background=@textComponentBackground
FormattedTextField.margin=2,6,2,6
#---- PasswordField ----
PasswordField.border=com.formdev.flatlaf.ui.FlatBorder
PasswordField.background=@textComponentBackground
PasswordField.margin=2,6,2,6
#---- RadioButton ----
RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder