diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java new file mode 100644 index 00000000..f7109b44 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java @@ -0,0 +1,64 @@ +/* + * 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 static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import javax.swing.JComponent; +import javax.swing.JSeparator; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicSeparatorUI; + +/** + * Provides the Flat LaF UI delegate for {@link javax.swing.JSeparator}. + * + * @author Karl Tauber + */ +public class FlatSeparatorUI + extends BasicSeparatorUI +{ + private static final int WIDTH = 2; + + private static ComponentUI instance; + + public static ComponentUI createUI( JComponent c ) { + if( instance == null ) + instance = new FlatSeparatorUI(); + return instance; + } + + @Override + public void paint( Graphics g, JComponent c ) { + g.setColor( c.getForeground() ); + + if( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL ) + ((Graphics2D)g).fill( new Rectangle2D.Float( 0, 0, scale( (float) WIDTH ), c.getHeight() ) ); + else + ((Graphics2D)g).fill( new Rectangle2D.Float( 0, 0, c.getWidth(), scale( (float) WIDTH ) ) ); + } + + @Override + public Dimension getPreferredSize( JComponent c ) { + if( ((JSeparator) c).getOrientation() == JSeparator.VERTICAL ) + return new Dimension( scale( WIDTH ), 0 ); + else + return new Dimension( 0, WIDTH ); + } +} 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 cebceed4..31c551a1 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -112,3 +112,8 @@ ProgressBar.selectionBackground=@foreground ScrollBar.track=3F4244 ScrollBar.thumb=47A6A6A6 + + +#---- Separator ---- + +Separator.foreground=515151 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 d2d4f08c..4d4f95b8 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -27,6 +27,7 @@ ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI +SeparatorUI=com.formdev.flatlaf.ui.FlatSeparatorUI TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI TextPaneUI=com.formdev.flatlaf.ui.FlatTextPaneUI 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 4b4eb335..9ac14cd7 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -112,3 +112,8 @@ ProgressBar.selectionBackground=@foreground ScrollBar.track=F5F5F5 ScrollBar.thumb=33737373 + + +#---- Separator ---- + +Separator.foreground=cdcdcd 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 771d4c6b..3cbaad1b 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java @@ -130,12 +130,15 @@ public class FlatComponentsTest JPanel panel1 = new JPanel(); JScrollBar scrollBar2 = new JScrollBar(); JScrollBar scrollBar3 = new JScrollBar(); + JSeparator separator2 = new JSeparator(); JScrollPane scrollPane14 = new JScrollPane(); progressBar3 = new JProgressBar(); progressBar4 = new JProgressBar(); JLabel scrollBarLabel = new JLabel(); JScrollBar scrollBar1 = new JScrollBar(); JScrollBar scrollBar4 = new JScrollBar(); + JLabel separatorLabel = new JLabel(); + JSeparator separator1 = new JSeparator(); JLabel progressBarLabel = new JLabel(); progressBar1 = new JProgressBar(); progressBar2 = new JProgressBar(); @@ -166,6 +169,7 @@ public class FlatComponentsTest "[]" + "[]" + "[]" + + "[]" + "[]")); //---- labelLabel ---- @@ -577,6 +581,10 @@ public class FlatComponentsTest //---- scrollBar3 ---- scrollBar3.setEnabled(false); add(scrollBar3, "cell 2 11,growy"); + + //---- separator2 ---- + separator2.setOrientation(SwingConstants.VERTICAL); + add(separator2, "cell 2 11,growy"); add(scrollPane14, "cell 3 11,grow"); //---- progressBar3 ---- @@ -603,23 +611,28 @@ public class FlatComponentsTest scrollBar4.setEnabled(false); add(scrollBar4, "cell 1 13,growx"); + //---- separatorLabel ---- + separatorLabel.setText("JSeparator:"); + add(separatorLabel, "cell 0 14"); + add(separator1, "cell 1 14,growx"); + //---- progressBarLabel ---- progressBarLabel.setText("JProgressBar:"); - add(progressBarLabel, "cell 0 14"); + add(progressBarLabel, "cell 0 15"); //---- progressBar1 ---- progressBar1.setValue(50); - add(progressBar1, "cell 1 14"); + add(progressBar1, "cell 1 15"); //---- progressBar2 ---- progressBar2.setStringPainted(true); progressBar2.setValue(55); - add(progressBar2, "cell 3 14"); + add(progressBar2, "cell 3 15"); //---- indeterminateCheckBox ---- indeterminateCheckBox.setText("indeterminate"); indeterminateCheckBox.addActionListener(e -> indeterminateCheckBoxActionPerformed()); - add(indeterminateCheckBox, "cell 4 14"); + add(indeterminateCheckBox, "cell 4 15"); // 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 24dd8db4..8deb7612 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" ) { @@ -521,6 +521,12 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 2 11,growy" } ) + add( new FormComponent( "javax.swing.JSeparator" ) { + name: "separator2" + "orientation": 1 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 11,growy" + } ) add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { name: "scrollPane14" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { @@ -566,11 +572,22 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 13,growx" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "separatorLabel" + "text": "JSeparator:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 14" + } ) + add( new FormComponent( "javax.swing.JSeparator" ) { + name: "separator1" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 14,growx" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "progressBarLabel" "text": "JProgressBar:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 14" + "value": "cell 0 15" } ) add( new FormComponent( "javax.swing.JProgressBar" ) { name: "progressBar1" @@ -579,7 +596,7 @@ new FormModel { "JavaCodeGenerator.variableLocal": false } }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 14" + "value": "cell 1 15" } ) add( new FormComponent( "javax.swing.JProgressBar" ) { name: "progressBar2" @@ -589,7 +606,7 @@ new FormModel { "JavaCodeGenerator.variableLocal": false } }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 3 14" + "value": "cell 3 15" } ) add( new FormComponent( "javax.swing.JCheckBox" ) { name: "indeterminateCheckBox" @@ -599,11 +616,11 @@ new FormModel { } addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "indeterminateCheckBoxActionPerformed", false ) ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 4 14" + "value": "cell 4 15" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) - "size": new java.awt.Dimension( 720, 535 ) + "size": new java.awt.Dimension( 720, 650 ) } ) } } 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 824185ab..c6e1df08 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -105,3 +105,8 @@ ProgressBar.cycleTime=10000 ScrollBar.track=88ff88 ScrollBar.thumb=33737373 + + +#---- Separator ---- + +Separator.foreground=00bb00