mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
Demo: ExtrasPanel: added "Toggle RED" button
This commit is contained in:
@@ -20,9 +20,11 @@ import javax.swing.*;
|
|||||||
import com.formdev.flatlaf.extras.*;
|
import com.formdev.flatlaf.extras.*;
|
||||||
import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
|
import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
|
||||||
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
||||||
|
import com.formdev.flatlaf.util.HSLColor;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.HierarchyEvent;
|
import java.awt.event.HierarchyEvent;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -94,7 +96,27 @@ public class ExtrasPanel
|
|||||||
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void redChanged() {
|
||||||
|
brighterToggleButton.setSelected( false );
|
||||||
|
|
||||||
|
Function<Color, Color> mapper = null;
|
||||||
|
if( redToggleButton.isSelected() ) {
|
||||||
|
float[] redHSL = HSLColor.fromRGB( Color.red );
|
||||||
|
mapper = color -> {
|
||||||
|
float[] hsl = HSLColor.fromRGB( color );
|
||||||
|
return HSLColor.toRGB( redHSL[0], 70, hsl[2] );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
FlatSVGIcon.ColorFilter.getInstance().setMapper( mapper );
|
||||||
|
|
||||||
|
// repaint whole application window because global color filter also affects
|
||||||
|
// icons in menubar, toolbar, etc.
|
||||||
|
SwingUtilities.windowForComponent( this ).repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void brighterChanged() {
|
private void brighterChanged() {
|
||||||
|
redToggleButton.setSelected( false );
|
||||||
|
|
||||||
FlatSVGIcon.ColorFilter.getInstance().setMapper( brighterToggleButton.isSelected()
|
FlatSVGIcon.ColorFilter.getInstance().setMapper( brighterToggleButton.isSelected()
|
||||||
? color -> color.brighter().brighter()
|
? color -> color.brighter().brighter()
|
||||||
: null );
|
: null );
|
||||||
@@ -118,6 +140,7 @@ public class ExtrasPanel
|
|||||||
label6 = new JLabel();
|
label6 = new JLabel();
|
||||||
rainbowIcon = new JLabel();
|
rainbowIcon = new JLabel();
|
||||||
label7 = new JLabel();
|
label7 = new JLabel();
|
||||||
|
redToggleButton = new JToggleButton();
|
||||||
brighterToggleButton = new JToggleButton();
|
brighterToggleButton = new JToggleButton();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
@@ -188,6 +211,11 @@ public class ExtrasPanel
|
|||||||
label7.setText("Global icon color filter");
|
label7.setText("Global icon color filter");
|
||||||
add(label7, "cell 1 7 2 1");
|
add(label7, "cell 1 7 2 1");
|
||||||
|
|
||||||
|
//---- redToggleButton ----
|
||||||
|
redToggleButton.setText("Toggle RED");
|
||||||
|
redToggleButton.addActionListener(e -> redChanged());
|
||||||
|
add(redToggleButton, "cell 1 7 2 1");
|
||||||
|
|
||||||
//---- brighterToggleButton ----
|
//---- brighterToggleButton ----
|
||||||
brighterToggleButton.setText("Toggle brighter");
|
brighterToggleButton.setText("Toggle brighter");
|
||||||
brighterToggleButton.addActionListener(e -> brighterChanged());
|
brighterToggleButton.addActionListener(e -> brighterChanged());
|
||||||
@@ -208,6 +236,7 @@ public class ExtrasPanel
|
|||||||
private JLabel label6;
|
private JLabel label6;
|
||||||
private JLabel rainbowIcon;
|
private JLabel rainbowIcon;
|
||||||
private JLabel label7;
|
private JLabel label7;
|
||||||
|
private JToggleButton redToggleButton;
|
||||||
private JToggleButton brighterToggleButton;
|
private JToggleButton brighterToggleButton;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 7 2 1"
|
"value": "cell 1 7 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
|
name: "redToggleButton"
|
||||||
|
"text": "Toggle RED"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "redChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
name: "brighterToggleButton"
|
name: "brighterToggleButton"
|
||||||
"text": "Toggle brighter"
|
"text": "Toggle brighter"
|
||||||
|
|||||||
Reference in New Issue
Block a user