From faed3fabc6ffbce4a74390d22c4563adccab6356 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 21 Aug 2019 14:37:58 +0200 Subject: [PATCH] FormattedTextField implemented --- .../flatlaf/ui/FlatFormattedTextFieldUI.java | 38 +++++++++++++++++++ .../formdev/flatlaf/FlatDarkLaf.properties | 6 +-- .../com/formdev/flatlaf/FlatLaf.properties | 9 +++++ .../formdev/flatlaf/FlatLightLaf.properties | 6 +-- .../formdev/flatlaf/FlatComponentsTest.java | 31 +++++++++++++++ .../formdev/flatlaf/FlatComponentsTest.jfd | 36 +++++++++++++++++- .../formdev/flatlaf/FlatTestLaf.properties | 10 ++--- 7 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFormattedTextFieldUI.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFormattedTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFormattedTextFieldUI.java new file mode 100644 index 00000000..34dda915 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFormattedTextFieldUI.java @@ -0,0 +1,38 @@ +/* + * 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 javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; + +/** + * Provides the Flat LaF UI delegate for {@link javax.swing.JFormattedTextField}. + * + * @author Karl Tauber + */ +public class FlatFormattedTextFieldUI + extends FlatTextFieldUI +{ + public static ComponentUI createUI( JComponent c ) { + return new FlatFormattedTextFieldUI(); + } + + @Override + protected String getPropertyPrefix() { + return "FormattedTextField"; + } +} diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 3db70950..0c9839fd 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -19,6 +19,7 @@ @background=3c3f41 @foreground=bbbbbb @disabledText=777777 +@textComponentBackground=45494A #---- globals ---- @@ -88,8 +89,3 @@ Component.focusColor=3d6185 #---- Label ---- Label.disabledForeground=@disabledText - - -#---- TextField ---- - -TextField.background=45494A diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 2c604a43..525e6404 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -18,6 +18,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 RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI @@ -41,6 +42,13 @@ Component.focusWidth=2 Component.arc=5 +#---- FormattedTextField ---- + +FormattedTextField.border=com.formdev.flatlaf.ui.FlatBorder +FormattedTextField.background=@textComponentBackground +FormattedTextField.margin=2,6,2,6 + + #---- RadioButton ---- RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder @@ -50,4 +58,5 @@ RadioButton.icon=com.formdev.flatlaf.ui.FlatRadioButtonIcon #---- TextField ---- TextField.border=com.formdev.flatlaf.ui.FlatBorder +TextField.background=@textComponentBackground TextField.margin=2,6,2,6 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 2d41c172..b083225e 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -19,6 +19,7 @@ @background=f2f2f2 @foreground=000000 @disabledText=999999 +@textComponentBackground=ffffff #---- globals ---- @@ -88,8 +89,3 @@ Component.focusColor=97c3f3 #---- Label ---- Label.disabledForeground=@disabledText - - -#---- TextField ---- - -TextField.background=ffffff diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java index af0c15b5..04584b29 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java @@ -71,6 +71,11 @@ public class FlatComponentsTest JTextField textField2 = new JTextField(); JTextField textField3 = new JTextField(); JTextField textField4 = new JTextField(); + JLabel formattedTextFieldLabel = new JLabel(); + JFormattedTextField formattedTextField1 = new JFormattedTextField(); + JFormattedTextField formattedTextField2 = new JFormattedTextField(); + JFormattedTextField formattedTextField3 = new JFormattedTextField(); + JFormattedTextField formattedTextField4 = new JFormattedTextField(); //======== this ======== setLayout(new MigLayout( @@ -87,6 +92,8 @@ public class FlatComponentsTest "[]" + "[]" + "[]" + + "[]" + + "[]" + "[]")); //---- labelLabel ---- @@ -206,6 +213,30 @@ public class FlatComponentsTest textField4.setEnabled(false); textField4.setEditable(false); add(textField4, "cell 4 4,growx"); + + //---- formattedTextFieldLabel ---- + formattedTextFieldLabel.setText("JFormattedTextField:"); + add(formattedTextFieldLabel, "cell 0 5"); + + //---- formattedTextField1 ---- + formattedTextField1.setText("editable"); + add(formattedTextField1, "cell 1 5,growx"); + + //---- formattedTextField2 ---- + formattedTextField2.setText("disabled"); + formattedTextField2.setEnabled(false); + add(formattedTextField2, "cell 2 5,growx"); + + //---- formattedTextField3 ---- + formattedTextField3.setText("not editable"); + formattedTextField3.setEditable(false); + add(formattedTextField3, "cell 3 5,growx"); + + //---- formattedTextField4 ---- + formattedTextField4.setText("not editable disabled"); + formattedTextField4.setEnabled(false); + formattedTextField4.setEditable(false); + add(formattedTextField4, "cell 4 5,growx"); // JFormDesigner - End of component initialization //GEN-END:initComponents } diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd index 3d0423ae..edc3e584 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "insets 0,hidemode 3,gap 5 5" "$columnConstraints": "[][][][][][]" - "$rowConstraints": "[][][][][]" + "$rowConstraints": "[][][][][][][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -178,6 +178,40 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 4 4,growx" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "formattedTextFieldLabel" + "text": "JFormattedTextField:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 5" + } ) + add( new FormComponent( "javax.swing.JFormattedTextField" ) { + name: "formattedTextField1" + "text": "editable" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 5,growx" + } ) + add( new FormComponent( "javax.swing.JFormattedTextField" ) { + name: "formattedTextField2" + "text": "disabled" + "enabled": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 5,growx" + } ) + add( new FormComponent( "javax.swing.JFormattedTextField" ) { + name: "formattedTextField3" + "text": "not editable" + "editable": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 5,growx" + } ) + add( new FormComponent( "javax.swing.JFormattedTextField" ) { + name: "formattedTextField4" + "text": "not editable disabled" + "enabled": false + "editable": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 5,growx" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 580, 300 ) diff --git a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties index 0e1749c8..83db1628 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -14,6 +14,11 @@ # limitations under the License. # +#---- variables ---- + +@textComponentBackground=ffffff + + #---- globals ---- *.background=ccffcc @@ -70,8 +75,3 @@ Component.focusColor=97c3f3 Label.foreground=008800 Label.disabledForeground=000088 - - -#---- TextField ---- - -TextField.background=ffffff