mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Extras: added extension class for JProgressBar (issue #117)
This commit is contained in:
@@ -43,6 +43,16 @@ public interface FlatComponentExtension
|
||||
return (value instanceof Boolean) ? (boolean) value : UIManager.getBoolean( defaultValueKey );
|
||||
}
|
||||
|
||||
default boolean getClientPropertyBoolean( Object key, boolean defaultValue ) {
|
||||
Object value = getClientProperty( key );
|
||||
return (value instanceof Boolean) ? (boolean) value : defaultValue;
|
||||
}
|
||||
|
||||
default void putClientPropertyBoolean( Object key, boolean value, boolean defaultValue ) {
|
||||
putClientProperty( key, (value != defaultValue) ? value : null );
|
||||
}
|
||||
|
||||
|
||||
default <T extends Enum<T>> T getClientPropertyEnumString( Object key, Class<T> enumType,
|
||||
String defaultValueKey, T defaultValue )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2020 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
|
||||
*
|
||||
* https://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.extras.components;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JProgressBar} that provides easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatProgressBar
|
||||
extends JProgressBar
|
||||
implements FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Returns whether the progress bar has always the larger height even if no string is painted.
|
||||
*/
|
||||
public boolean isLargeHeight() {
|
||||
return getClientPropertyBoolean( PROGRESS_BAR_LARGE_HEIGHT, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the progress bar has always the larger height even if no string is painted.
|
||||
*/
|
||||
public void setLargeHeight( boolean largeHeight ) {
|
||||
putClientPropertyBoolean( PROGRESS_BAR_LARGE_HEIGHT, largeHeight, false );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the progress bar is paint with square edges.
|
||||
*/
|
||||
public boolean isSquare() {
|
||||
return getClientPropertyBoolean( PROGRESS_BAR_SQUARE, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the progress bar is paint with square edges.
|
||||
*/
|
||||
public void setSquare( boolean square ) {
|
||||
putClientPropertyBoolean( PROGRESS_BAR_SQUARE, square, false );
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,22 @@ public class FlatComponentsTest
|
||||
progressBar4.setIndeterminate( indeterminate );
|
||||
}
|
||||
|
||||
private void squareChanged() {
|
||||
boolean square = squareCheckBox.isSelected();
|
||||
progressBar1.setSquare( square );
|
||||
progressBar2.setSquare( square );
|
||||
progressBar3.setSquare( square );
|
||||
progressBar4.setSquare( square );
|
||||
}
|
||||
|
||||
private void largeHeightChanged() {
|
||||
boolean largeHeight = largeHeightCheckBox.isSelected();
|
||||
progressBar1.setLargeHeight( largeHeight );
|
||||
progressBar2.setLargeHeight( largeHeight );
|
||||
progressBar3.setLargeHeight( largeHeight );
|
||||
progressBar4.setLargeHeight( largeHeight );
|
||||
}
|
||||
|
||||
private void borderPaintedChanged() {
|
||||
boolean borderPainted = borderPaintedCheckBox.isSelected();
|
||||
|
||||
@@ -254,8 +270,8 @@ public class FlatComponentsTest
|
||||
JSlider slider2 = new JSlider();
|
||||
JSlider slider4 = new JSlider();
|
||||
JScrollPane scrollPane14 = new JScrollPane();
|
||||
progressBar3 = new JProgressBar();
|
||||
progressBar4 = new JProgressBar();
|
||||
progressBar3 = new FlatProgressBar();
|
||||
progressBar4 = new FlatProgressBar();
|
||||
JToolBar toolBar2 = new JToolBar();
|
||||
JButton button9 = new JButton();
|
||||
JButton button10 = new JButton();
|
||||
@@ -291,12 +307,14 @@ public class FlatComponentsTest
|
||||
slider3 = new JSlider();
|
||||
JSlider slider5 = new JSlider();
|
||||
JLabel progressBarLabel = new JLabel();
|
||||
progressBar1 = new JProgressBar();
|
||||
progressBar2 = new JProgressBar();
|
||||
progressBar1 = new FlatProgressBar();
|
||||
progressBar2 = new FlatProgressBar();
|
||||
indeterminateCheckBox = new JCheckBox();
|
||||
squareCheckBox = new JCheckBox();
|
||||
JLabel toolTipLabel = new JLabel();
|
||||
JToolTip toolTip1 = new JToolTip();
|
||||
JToolTip toolTip2 = new JToolTip();
|
||||
largeHeightCheckBox = new JCheckBox();
|
||||
JLabel toolBarLabel = new JLabel();
|
||||
JToolBar toolBar1 = new JToolBar();
|
||||
JButton button4 = new JButton();
|
||||
@@ -1249,6 +1267,11 @@ public class FlatComponentsTest
|
||||
indeterminateCheckBox.addActionListener(e -> indeterminateProgress());
|
||||
add(indeterminateCheckBox, "cell 4 21");
|
||||
|
||||
//---- squareCheckBox ----
|
||||
squareCheckBox.setText("square");
|
||||
squareCheckBox.addActionListener(e -> squareChanged());
|
||||
add(squareCheckBox, "cell 4 21");
|
||||
|
||||
//---- toolTipLabel ----
|
||||
toolTipLabel.setText("JToolTip:");
|
||||
add(toolTipLabel, "cell 0 22");
|
||||
@@ -1261,6 +1284,11 @@ public class FlatComponentsTest
|
||||
toolTip2.setTipText("Tool tip with\nmultiple\nlines.");
|
||||
add(toolTip2, "cell 1 22 3 1");
|
||||
|
||||
//---- largeHeightCheckBox ----
|
||||
largeHeightCheckBox.setText("large height");
|
||||
largeHeightCheckBox.addActionListener(e -> largeHeightChanged());
|
||||
add(largeHeightCheckBox, "cell 4 22,aligny top,growy 0");
|
||||
|
||||
//---- toolBarLabel ----
|
||||
toolBarLabel.setText("JToolBar:");
|
||||
add(toolBarLabel, "cell 0 23");
|
||||
@@ -1389,8 +1417,8 @@ public class FlatComponentsTest
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private JTextField textField1;
|
||||
private JProgressBar progressBar3;
|
||||
private JProgressBar progressBar4;
|
||||
private FlatProgressBar progressBar3;
|
||||
private FlatProgressBar progressBar4;
|
||||
private JComboBox<String> buttonTypeComboBox;
|
||||
private JCheckBox borderPaintedCheckBox;
|
||||
private JCheckBox roundRectCheckBox;
|
||||
@@ -1402,9 +1430,11 @@ public class FlatComponentsTest
|
||||
private JRadioButton magentaCyanOutlineRadioButton;
|
||||
private JCheckBox focusPaintedCheckBox;
|
||||
private JSlider slider3;
|
||||
private JProgressBar progressBar1;
|
||||
private JProgressBar progressBar2;
|
||||
private FlatProgressBar progressBar1;
|
||||
private FlatProgressBar progressBar2;
|
||||
private JCheckBox indeterminateCheckBox;
|
||||
private JCheckBox squareCheckBox;
|
||||
private JCheckBox largeHeightCheckBox;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
|
||||
//---- class TestDefaultButton --------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "15" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.3.0.337" Java: "15" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -892,7 +892,7 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 3 13,grow"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JProgressBar" ) {
|
||||
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatProgressBar" ) {
|
||||
name: "progressBar3"
|
||||
"orientation": 1
|
||||
"value": 60
|
||||
@@ -902,7 +902,7 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 13 1 6,growy"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JProgressBar" ) {
|
||||
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatProgressBar" ) {
|
||||
name: "progressBar4"
|
||||
"orientation": 1
|
||||
"value": 60
|
||||
@@ -1187,7 +1187,7 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 21"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JProgressBar" ) {
|
||||
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatProgressBar" ) {
|
||||
name: "progressBar1"
|
||||
"value": 60
|
||||
auxiliary() {
|
||||
@@ -1196,7 +1196,7 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 21 3 1,growx"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JProgressBar" ) {
|
||||
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatProgressBar" ) {
|
||||
name: "progressBar2"
|
||||
"stringPainted": true
|
||||
"value": 60
|
||||
@@ -1216,6 +1216,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 21"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "squareCheckBox"
|
||||
"text": "square"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "squareChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 21"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "toolTipLabel"
|
||||
"text": "JToolTip:"
|
||||
@@ -1234,6 +1244,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 22 3 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "largeHeightCheckBox"
|
||||
"text": "large height"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "largeHeightChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 22,aligny top,growy 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "toolBarLabel"
|
||||
"text": "JToolBar:"
|
||||
|
||||
Reference in New Issue
Block a user