ProgressBar implemented

This commit is contained in:
Karl Tauber
2019-08-22 17:47:02 +02:00
parent 436fdf0bd5
commit ff325324d2
9 changed files with 297 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
package com.formdev.flatlaf; package com.formdev.flatlaf;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Toolkit; import java.awt.Toolkit;
@@ -30,6 +31,7 @@ import java.util.Properties;
import javax.swing.UIDefaults; import javax.swing.UIDefaults;
import javax.swing.UIDefaults.LazyValue; import javax.swing.UIDefaults.LazyValue;
import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.DimensionUIResource;
import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.basic.BasicLookAndFeel; import javax.swing.plaf.basic.BasicLookAndFeel;
@@ -232,9 +234,17 @@ public abstract class FlatLaf
return parseInstance( value ); return parseInstance( value );
// insets // insets
if( key.endsWith( ".margin" ) ) if( key.endsWith( ".margin" ) || key.endsWith( ".padding" ) )
return parseInsets( value ); return parseInsets( value );
// insets
if( key.endsWith( "Size" ) )
return parseSize( value );
// insets
if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
return parseInteger( value, true );
// colors // colors
ColorUIResource color = parseColor( value ); ColorUIResource color = parseColor( value );
if( color != null ) if( color != null )
@@ -278,6 +288,18 @@ public abstract class FlatLaf
} }
} }
private Dimension parseSize( String value ) {
List<String> 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 ) { private ColorUIResource parseColor( String value ) {
try { try {
if( value.length() == 6 ) { if( value.length() == 6 ) {

View File

@@ -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 );
}
}

View File

@@ -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 );
}
}
}

View File

@@ -91,6 +91,14 @@ Component.focusColor=3d6185
Label.disabledForeground=@disabledText Label.disabledForeground=@disabledText
#---- ProgressBar ----
ProgressBar.background=555555
ProgressBar.foreground=a0a0a0
ProgressBar.selectionForeground=@background
ProgressBar.selectionBackground=@foreground
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.track=3F4244 ScrollBar.track=3F4244

View File

@@ -22,6 +22,7 @@ EditorPaneUI=com.formdev.flatlaf.ui.FlatEditorPaneUI
FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI
LabelUI=com.formdev.flatlaf.ui.FlatLabelUI LabelUI=com.formdev.flatlaf.ui.FlatLabelUI
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI
ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI
@@ -74,6 +75,13 @@ PasswordField.background=@textComponentBackground
PasswordField.margin=@textComponentMargin PasswordField.margin=@textComponentMargin
#---- ProgressBar ----
ProgressBar.border=com.formdev.flatlaf.ui.FlatEmptyBorder
ProgressBar.horizontalSize=146,6
ProgressBar.verticalSize=6,146
#---- RadioButton ---- #---- RadioButton ----
RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder

View File

@@ -91,6 +91,14 @@ Component.focusColor=97c3f3
Label.disabledForeground=@disabledText Label.disabledForeground=@disabledText
#---- ProgressBar ----
ProgressBar.background=c4c4c4
ProgressBar.foreground=808080
ProgressBar.selectionForeground=@textComponentBackground
ProgressBar.selectionBackground=@foreground
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.track=F5F5F5 ScrollBar.track=F5F5F5

View File

@@ -46,6 +46,14 @@ public class FlatComponentsTest
initComponents(); initComponents();
} }
private void indeterminateCheckBoxActionPerformed() {
boolean indeterminate = indeterminateCheckBox.isSelected();
progressBar1.setIndeterminate( indeterminate );
progressBar2.setIndeterminate( indeterminate );
progressBar3.setIndeterminate( indeterminate );
progressBar4.setIndeterminate( indeterminate );
}
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JLabel labelLabel = new JLabel(); JLabel labelLabel = new JLabel();
@@ -118,9 +126,15 @@ public class FlatComponentsTest
JScrollBar scrollBar2 = new JScrollBar(); JScrollBar scrollBar2 = new JScrollBar();
JScrollBar scrollBar3 = new JScrollBar(); JScrollBar scrollBar3 = new JScrollBar();
JScrollPane scrollPane14 = new JScrollPane(); JScrollPane scrollPane14 = new JScrollPane();
progressBar3 = new JProgressBar();
progressBar4 = new JProgressBar();
JLabel scrollBarLabel = new JLabel(); JLabel scrollBarLabel = new JLabel();
JScrollBar scrollBar1 = new JScrollBar(); JScrollBar scrollBar1 = new JScrollBar();
JScrollBar scrollBar4 = new JScrollBar(); JScrollBar scrollBar4 = new JScrollBar();
JLabel progressBarLabel = new JLabel();
progressBar1 = new JProgressBar();
progressBar2 = new JProgressBar();
indeterminateCheckBox = new JCheckBox();
//======== this ======== //======== this ========
setLayout(new MigLayout( setLayout(new MigLayout(
@@ -145,6 +159,7 @@ public class FlatComponentsTest
"[]" + "[]" +
"[]" + "[]" +
"[]" + "[]" +
"[]" +
"[]")); "[]"));
//---- labelLabel ---- //---- labelLabel ----
@@ -514,6 +529,17 @@ public class FlatComponentsTest
add(scrollBar3, "cell 2 10,growy"); add(scrollBar3, "cell 2 10,growy");
add(scrollPane14, "cell 3 10,grow"); 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 ----
scrollBarLabel.setText("JScrollBar:"); scrollBarLabel.setText("JScrollBar:");
add(scrollBarLabel, "cell 0 11"); add(scrollBarLabel, "cell 0 11");
@@ -526,10 +552,33 @@ public class FlatComponentsTest
scrollBar4.setOrientation(Adjustable.HORIZONTAL); scrollBar4.setOrientation(Adjustable.HORIZONTAL);
scrollBar4.setEnabled(false); scrollBar4.setEnabled(false);
add(scrollBar4, "cell 1 12,growx"); 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 - End of component initialization //GEN-END:initComponents
} }
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // 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 // JFormDesigner - End of variables declaration //GEN-END:variables
//---- class TestDefaultButton -------------------------------------------- //---- class TestDefaultButton --------------------------------------------

View File

@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3,gap 5 5" "$layoutConstraints": "insets 0,hidemode 3,gap 5 5"
"$columnConstraints": "[][][][][][]" "$columnConstraints": "[][][][][][]"
"$rowConstraints": "[][][][][][][][][][][][][]" "$rowConstraints": "[][][][][][][][][][][][][][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -468,6 +468,27 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 10,grow" "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" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "scrollBarLabel" name: "scrollBarLabel"
"text": "JScrollBar:" "text": "JScrollBar:"
@@ -487,6 +508,41 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 12,growx" "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 ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 720, 535 ) "size": new java.awt.Dimension( 720, 535 )

View File

@@ -77,6 +77,15 @@ Label.foreground=008800
Label.disabledForeground=000088 Label.disabledForeground=000088
#---- ProgressBar ----
ProgressBar.background=88ff88
ProgressBar.foreground=33737373
ProgressBar.selectionForeground=ff0000
ProgressBar.selectionBackground=000088
ProgressBar.cycleTime=10000
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.track=88ff88 ScrollBar.track=88ff88