diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 3770ec5b..3cf5fcdb 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -17,6 +17,7 @@ package com.formdev.flatlaf; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.awt.Toolkit; @@ -30,6 +31,7 @@ import java.util.Properties; import javax.swing.UIDefaults; import javax.swing.UIDefaults.LazyValue; import javax.swing.plaf.ColorUIResource; +import javax.swing.plaf.DimensionUIResource; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.basic.BasicLookAndFeel; @@ -232,9 +234,17 @@ public abstract class FlatLaf return parseInstance( value ); // insets - if( key.endsWith( ".margin" ) ) + if( key.endsWith( ".margin" ) || key.endsWith( ".padding" ) ) return parseInsets( value ); + // insets + if( key.endsWith( "Size" ) ) + return parseSize( value ); + + // insets + if( key.endsWith( "Width" ) || key.endsWith( "Height" ) ) + return parseInteger( value, true ); + // colors ColorUIResource color = parseColor( value ); if( color != null ) @@ -278,6 +288,18 @@ public abstract class FlatLaf } } + private Dimension parseSize( String value ) { + List numbers = split( value, ',' ); + try { + return new DimensionUIResource( + Integer.parseInt( numbers.get( 0 ) ), + Integer.parseInt( numbers.get( 1 ) ) ); + } catch( NumberFormatException ex ) { + System.err.println( "invalid size '" + value + "'" ); + throw ex; + } + } + private ColorUIResource parseColor( String value ) { try { if( value.length() == 6 ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEmptyBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEmptyBorder.java new file mode 100644 index 00000000..bed676e2 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEmptyBorder.java @@ -0,0 +1,32 @@ +/* + * 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.plaf.BorderUIResource; + +/** + * Empty border for various components. + * + * @author Karl Tauber + */ +public class FlatEmptyBorder + extends BorderUIResource.EmptyBorderUIResource +{ + public FlatEmptyBorder() { + super( 0, 0, 0, 0 ); + } +} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java new file mode 100644 index 00000000..e220eb84 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java @@ -0,0 +1,103 @@ +/* + * 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.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.geom.RoundRectangle2D; +import javax.swing.JComponent; +import javax.swing.JProgressBar; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicProgressBarUI; +import com.formdev.flatlaf.util.UIScale; + +/** + * Provides the Flat LaF UI delegate for {@link javax.swing.JProgressBar}. + * + * @author Karl Tauber + */ +public class FlatProgressBarUI + extends BasicProgressBarUI +{ + public static ComponentUI createUI( JComponent c ) { + return new FlatProgressBarUI(); + } + + @Override + protected Dimension getPreferredInnerHorizontal() { + return UIScale.scale( super.getPreferredInnerHorizontal() ); + } + + @Override + protected Dimension getPreferredInnerVertical() { + return UIScale.scale( super.getPreferredInnerVertical() ); + } + + @Override + public void update( Graphics g, JComponent c ) { + if( c.isOpaque() ) + FlatUIUtils.paintParentBackground( g, c ); + + paint( g, c ); + } + + @Override + public void paint( Graphics g, JComponent c ) { + Insets insets = progressBar.getInsets(); + int x = insets.left; + int y = insets.top; + int width = progressBar.getWidth() - (insets.right + insets.left); + int height = progressBar.getHeight() - (insets.top + insets.bottom); + + if( width <= 0 || height <= 0 ) + return; + + boolean horizontal = (progressBar.getOrientation() == JProgressBar.HORIZONTAL); + int arc = horizontal ? height : width; + + FlatUIUtils.setRenderingHints( (Graphics2D) g ); + + // paint track + g.setColor( progressBar.getBackground() ); + ((Graphics2D)g).fill( new RoundRectangle2D.Float( x, y, width, height, arc, arc ) ); + + // paint progress + if( progressBar.isIndeterminate() ) { + boxRect = getBox( boxRect ); + if( boxRect != null ) { + g.setColor( progressBar.getForeground() ); + ((Graphics2D)g).fill( new RoundRectangle2D.Float( boxRect.x, boxRect.y, + boxRect.width, boxRect.height, arc, arc ) ); + } + + if( progressBar.isStringPainted() ) + paintString( g, x, y, width, height, 0, insets ); + } else { + int amountFull = getAmountFull( insets, width, height ); + + g.setColor( progressBar.getForeground() ); + ((Graphics2D)g).fill( horizontal + ? new RoundRectangle2D.Float( x, y, amountFull, height, arc, arc ) + : new RoundRectangle2D.Float( x, y + (height - amountFull), width, amountFull, arc, arc ) ); + + if( progressBar.isStringPainted() ) + paintString( g, x, y, width, height, amountFull, insets ); + } + } +} 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 64555641..920c046b 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -91,6 +91,14 @@ Component.focusColor=3d6185 Label.disabledForeground=@disabledText +#---- ProgressBar ---- + +ProgressBar.background=555555 +ProgressBar.foreground=a0a0a0 +ProgressBar.selectionForeground=@background +ProgressBar.selectionBackground=@foreground + + #---- ScrollBar ---- ScrollBar.track=3F4244 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 820508f1..24d9793e 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -22,6 +22,7 @@ EditorPaneUI=com.formdev.flatlaf.ui.FlatEditorPaneUI FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI LabelUI=com.formdev.flatlaf.ui.FlatLabelUI PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI +ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI @@ -74,6 +75,13 @@ PasswordField.background=@textComponentBackground PasswordField.margin=@textComponentMargin +#---- ProgressBar ---- + +ProgressBar.border=com.formdev.flatlaf.ui.FlatEmptyBorder +ProgressBar.horizontalSize=146,6 +ProgressBar.verticalSize=6,146 + + #---- RadioButton ---- RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder 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 b71f565d..bfe984c4 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -91,6 +91,14 @@ Component.focusColor=97c3f3 Label.disabledForeground=@disabledText +#---- ProgressBar ---- + +ProgressBar.background=c4c4c4 +ProgressBar.foreground=808080 +ProgressBar.selectionForeground=@textComponentBackground +ProgressBar.selectionBackground=@foreground + + #---- ScrollBar ---- ScrollBar.track=F5F5F5 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 f798090d..3bd8edb0 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java @@ -46,6 +46,14 @@ public class FlatComponentsTest initComponents(); } + private void indeterminateCheckBoxActionPerformed() { + boolean indeterminate = indeterminateCheckBox.isSelected(); + progressBar1.setIndeterminate( indeterminate ); + progressBar2.setIndeterminate( indeterminate ); + progressBar3.setIndeterminate( indeterminate ); + progressBar4.setIndeterminate( indeterminate ); + } + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents JLabel labelLabel = new JLabel(); @@ -118,9 +126,15 @@ public class FlatComponentsTest JScrollBar scrollBar2 = new JScrollBar(); JScrollBar scrollBar3 = new JScrollBar(); JScrollPane scrollPane14 = new JScrollPane(); + progressBar3 = new JProgressBar(); + progressBar4 = new JProgressBar(); JLabel scrollBarLabel = new JLabel(); JScrollBar scrollBar1 = new JScrollBar(); JScrollBar scrollBar4 = new JScrollBar(); + JLabel progressBarLabel = new JLabel(); + progressBar1 = new JProgressBar(); + progressBar2 = new JProgressBar(); + indeterminateCheckBox = new JCheckBox(); //======== this ======== setLayout(new MigLayout( @@ -145,6 +159,7 @@ public class FlatComponentsTest "[]" + "[]" + "[]" + + "[]" + "[]")); //---- labelLabel ---- @@ -514,6 +529,17 @@ public class FlatComponentsTest add(scrollBar3, "cell 2 10,growy"); add(scrollPane14, "cell 3 10,grow"); + //---- progressBar3 ---- + progressBar3.setOrientation(SwingConstants.VERTICAL); + progressBar3.setValue(50); + add(progressBar3, "cell 4 10"); + + //---- progressBar4 ---- + progressBar4.setOrientation(SwingConstants.VERTICAL); + progressBar4.setValue(55); + progressBar4.setStringPainted(true); + add(progressBar4, "cell 4 10"); + //---- scrollBarLabel ---- scrollBarLabel.setText("JScrollBar:"); add(scrollBarLabel, "cell 0 11"); @@ -526,10 +552,33 @@ public class FlatComponentsTest scrollBar4.setOrientation(Adjustable.HORIZONTAL); scrollBar4.setEnabled(false); add(scrollBar4, "cell 1 12,growx"); + + //---- progressBarLabel ---- + progressBarLabel.setText("JProgressBar:"); + add(progressBarLabel, "cell 0 13"); + + //---- progressBar1 ---- + progressBar1.setValue(50); + add(progressBar1, "cell 1 13"); + + //---- progressBar2 ---- + progressBar2.setStringPainted(true); + progressBar2.setValue(55); + add(progressBar2, "cell 3 13"); + + //---- indeterminateCheckBox ---- + indeterminateCheckBox.setText("indeterminate"); + indeterminateCheckBox.addActionListener(e -> indeterminateCheckBoxActionPerformed()); + add(indeterminateCheckBox, "cell 4 13"); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables + private JProgressBar progressBar3; + private JProgressBar progressBar4; + private JProgressBar progressBar1; + private JProgressBar progressBar2; + private JCheckBox indeterminateCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables //---- class TestDefaultButton -------------------------------------------- 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 b2a3da8e..453c57c1 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" ) { @@ -468,6 +468,27 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 3 10,grow" } ) + add( new FormComponent( "javax.swing.JProgressBar" ) { + name: "progressBar3" + "orientation": 1 + "value": 50 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 10" + } ) + add( new FormComponent( "javax.swing.JProgressBar" ) { + name: "progressBar4" + "orientation": 1 + "value": 55 + "stringPainted": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 10" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "scrollBarLabel" "text": "JScrollBar:" @@ -487,6 +508,41 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 12,growx" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "progressBarLabel" + "text": "JProgressBar:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 13" + } ) + add( new FormComponent( "javax.swing.JProgressBar" ) { + name: "progressBar1" + "value": 50 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 13" + } ) + add( new FormComponent( "javax.swing.JProgressBar" ) { + name: "progressBar2" + "stringPainted": true + "value": 55 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 13" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "indeterminateCheckBox" + "text": "indeterminate" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "indeterminateCheckBoxActionPerformed", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 13" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 720, 535 ) 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 19a231a0..b3017877 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -77,6 +77,15 @@ Label.foreground=008800 Label.disabledForeground=000088 +#---- ProgressBar ---- + +ProgressBar.background=88ff88 +ProgressBar.foreground=33737373 +ProgressBar.selectionForeground=ff0000 +ProgressBar.selectionBackground=000088 +ProgressBar.cycleTime=10000 + + #---- ScrollBar ---- ScrollBar.track=88ff88