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;
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<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 ) {
try {
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
#---- ProgressBar ----
ProgressBar.background=555555
ProgressBar.foreground=a0a0a0
ProgressBar.selectionForeground=@background
ProgressBar.selectionBackground=@foreground
#---- ScrollBar ----
ScrollBar.track=3F4244

View File

@@ -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

View File

@@ -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