mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Demo: ExtrasPanel:
- animate "rainbow" icon only if extras tab is visible - recreated added components in JFormDesigner
This commit is contained in:
@@ -22,6 +22,7 @@ import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
|
|||||||
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.HierarchyEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -29,7 +30,8 @@ import java.awt.*;
|
|||||||
public class ExtrasPanel
|
public class ExtrasPanel
|
||||||
extends JPanel
|
extends JPanel
|
||||||
{
|
{
|
||||||
public int counter = 0;
|
private Timer rainbowIconTimer;
|
||||||
|
private int rainbowCounter = 0;
|
||||||
|
|
||||||
public ExtrasPanel() {
|
public ExtrasPanel() {
|
||||||
initComponents();
|
initComponents();
|
||||||
@@ -54,6 +56,34 @@ public class ExtrasPanel
|
|||||||
addSVGIcon( "errorDialog.svg" );
|
addSVGIcon( "errorDialog.svg" );
|
||||||
addSVGIcon( "informationDialog.svg" );
|
addSVGIcon( "informationDialog.svg" );
|
||||||
addSVGIcon( "warningDialog.svg" );
|
addSVGIcon( "warningDialog.svg" );
|
||||||
|
|
||||||
|
initRainbowIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRainbowIcon() {
|
||||||
|
FlatSVGIcon icon = new FlatSVGIcon( "com/formdev/flatlaf/demo/extras/svg/informationDialog.svg" );
|
||||||
|
icon.setColorFilter( new ColorFilter( color -> {
|
||||||
|
rainbowCounter += 1;
|
||||||
|
rainbowCounter %= 255;
|
||||||
|
return Color.getHSBColor( rainbowCounter / 255f, 1, 1 );
|
||||||
|
} ) );
|
||||||
|
rainbowIcon.setIcon( icon );
|
||||||
|
|
||||||
|
rainbowIconTimer = new Timer( 30, e -> {
|
||||||
|
rainbowIcon.repaint();
|
||||||
|
} );
|
||||||
|
|
||||||
|
// start rainbow timer only if panel is shown ("Extras" tab is active)
|
||||||
|
addHierarchyListener( e -> {
|
||||||
|
if( e.getID() == HierarchyEvent.HIERARCHY_CHANGED &&
|
||||||
|
(e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 )
|
||||||
|
{
|
||||||
|
if( isShowing() )
|
||||||
|
rainbowIconTimer.start();
|
||||||
|
else
|
||||||
|
rainbowIconTimer.stop();
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSVGIcon( String name ) {
|
private void addSVGIcon( String name ) {
|
||||||
@@ -64,6 +94,16 @@ public class ExtrasPanel
|
|||||||
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void brighterChanged() {
|
||||||
|
FlatSVGIcon.ColorFilter.getInstance().setMapper( brighterToggleButton.isSelected()
|
||||||
|
? color -> color.brighter().brighter()
|
||||||
|
: null );
|
||||||
|
|
||||||
|
// repaint whole application window because global color filter also affects
|
||||||
|
// icons in menubar, toolbar, etc.
|
||||||
|
SwingUtilities.windowForComponent( this ).repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
label4 = new JLabel();
|
label4 = new JLabel();
|
||||||
@@ -76,9 +116,9 @@ public class ExtrasPanel
|
|||||||
separator1 = new JSeparator();
|
separator1 = new JSeparator();
|
||||||
label5 = new JLabel();
|
label5 = new JLabel();
|
||||||
label6 = new JLabel();
|
label6 = new JLabel();
|
||||||
label7 = new JLabel();
|
|
||||||
rainbowIcon = new JLabel();
|
rainbowIcon = new JLabel();
|
||||||
toggleButton1 = new JToggleButton();
|
label7 = new JLabel();
|
||||||
|
brighterToggleButton = new JToggleButton();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
@@ -94,6 +134,7 @@ public class ExtrasPanel
|
|||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- label4 ----
|
//---- label4 ----
|
||||||
@@ -132,55 +173,28 @@ public class ExtrasPanel
|
|||||||
//---- label3 ----
|
//---- label3 ----
|
||||||
label3.setText("The icons may change colors when switching to another theme.");
|
label3.setText("The icons may change colors when switching to another theme.");
|
||||||
add(label3, "cell 1 3 2 1");
|
add(label3, "cell 1 3 2 1");
|
||||||
|
add(separator1, "cell 1 4 2 1,growx");
|
||||||
add(separator1, "cell 1 4, grow");
|
|
||||||
|
|
||||||
//---- label5 ----
|
//---- label5 ----
|
||||||
label5.setText("Color filters can be also applied to icons. Globally or for each instance.");
|
label5.setText("Color filters can be also applied to icons. Globally or for each instance.");
|
||||||
add(label5, "cell 1 5");
|
add(label5, "cell 1 5 2 1");
|
||||||
|
|
||||||
//---- label6 ----
|
//---- label6 ----
|
||||||
label6.setText( "Rainbow color filter" );
|
label6.setText("Rainbow color filter");
|
||||||
add(label6, "cell 1 6");
|
add(label6, "cell 1 6 2 1");
|
||||||
|
add(rainbowIcon, "cell 1 6 2 1");
|
||||||
//---- rainbowIcon ----
|
|
||||||
rainbowIcon = createRainbowIcon("informationDialog.svg");
|
|
||||||
add(rainbowIcon, "cell 1 6");
|
|
||||||
|
|
||||||
//---- label7 ----
|
//---- label7 ----
|
||||||
label7.setText( "Global icon color filter" );
|
label7.setText("Global icon color filter");
|
||||||
add(label7, "cell 1 7");
|
add(label7, "cell 1 7 2 1");
|
||||||
|
|
||||||
// ---- button1 ----
|
|
||||||
toggleButton1.setText( "Toggle brighter" );
|
|
||||||
add(toggleButton1, "cell 1 7");
|
|
||||||
|
|
||||||
// ---- toggleButton1 ----
|
|
||||||
toggleButton1.addActionListener( (e) -> {
|
|
||||||
if (toggleButton1.isSelected())
|
|
||||||
FlatSVGIcon.ColorFilter.getInstance().setMapper( color -> color.brighter() );
|
|
||||||
else
|
|
||||||
FlatSVGIcon.ColorFilter.getInstance().setMapper( null );
|
|
||||||
SwingUtilities.getRootPane( toggleButton1 ).repaint();
|
|
||||||
} );
|
|
||||||
|
|
||||||
|
//---- brighterToggleButton ----
|
||||||
|
brighterToggleButton.setText("Toggle brighter");
|
||||||
|
brighterToggleButton.addActionListener(e -> brighterChanged());
|
||||||
|
add(brighterToggleButton, "cell 1 7 2 1");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
private JLabel createRainbowIcon(String name) {
|
|
||||||
FlatSVGIcon rainbowIcon = new FlatSVGIcon( "com/formdev/flatlaf/demo/extras/svg/" + name);
|
|
||||||
rainbowIcon.setColorFilter( new ColorFilter( (color) -> {
|
|
||||||
counter+=1;
|
|
||||||
counter%=255;
|
|
||||||
return Color.getHSBColor(counter/255f, 1, 1);
|
|
||||||
}) );
|
|
||||||
JLabel label = new JLabel(rainbowIcon);
|
|
||||||
new Timer(30, (e) -> {
|
|
||||||
label.repaint();
|
|
||||||
}).start();
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||||
private JLabel label4;
|
private JLabel label4;
|
||||||
private JLabel label1;
|
private JLabel label1;
|
||||||
@@ -189,11 +203,11 @@ public class ExtrasPanel
|
|||||||
private JLabel label2;
|
private JLabel label2;
|
||||||
private JPanel svgIconsPanel;
|
private JPanel svgIconsPanel;
|
||||||
private JLabel label3;
|
private JLabel label3;
|
||||||
|
private JSeparator separator1;
|
||||||
private JLabel label5;
|
private JLabel label5;
|
||||||
private JLabel label6;
|
private JLabel label6;
|
||||||
private JLabel label7;
|
|
||||||
private JSeparator separator1;
|
|
||||||
private JLabel rainbowIcon;
|
private JLabel rainbowIcon;
|
||||||
private JToggleButton toggleButton1;
|
private JLabel label7;
|
||||||
|
private JToggleButton brighterToggleButton;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -6,7 +6,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 dialog,hidemode 3"
|
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||||
"$columnConstraints": "[][][left]"
|
"$columnConstraints": "[][][left]"
|
||||||
"$rowConstraints": "[]para[][][]"
|
"$rowConstraints": "[]para[][][][][][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
@@ -56,6 +56,41 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 3 2 1"
|
"value": "cell 1 3 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JSeparator" ) {
|
||||||
|
name: "separator1"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 4 2 1,growx"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label5"
|
||||||
|
"text": "Color filters can be also applied to icons. Globally or for each instance."
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 5 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label6"
|
||||||
|
"text": "Rainbow color filter"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 6 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "rainbowIcon"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 6 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label7"
|
||||||
|
"text": "Global icon color filter"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
|
name: "brighterToggleButton"
|
||||||
|
"text": "Toggle brighter"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "brighterChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
}, 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( 500, 300 )
|
"size": new java.awt.Dimension( 500, 300 )
|
||||||
|
|||||||
Reference in New Issue
Block a user