From 293b76f04b172ffb839ac7570cbcdb1b2c8333e5 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 25 Jun 2020 17:55:42 +0200 Subject: [PATCH] Window decorations: FlatWindowDecorationsTest: added "undecorated" checkbox --- .../testing/FlatWindowDecorationsTest.java | 38 ++++++++++++++++--- .../testing/FlatWindowDecorationsTest.jfd | 22 ++++++++--- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java index aab62652..13b77661 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java @@ -81,6 +81,11 @@ public class FlatWindowDecorationsTest iconTestAllRadioButton.setEnabled( windowHasIcons ); iconTestRandomRadioButton.setEnabled( windowHasIcons ); + if( window instanceof Frame ) + undecoratedCheckBox.setSelected( ((Frame)window).isUndecorated() ); + else if( window instanceof Dialog ) + undecoratedCheckBox.setSelected( ((Dialog)window).isUndecorated() ); + JRootPane rootPane = getWindowRootPane(); if( rootPane != null ) { int style = rootPane.getWindowDecorationStyle(); @@ -120,6 +125,21 @@ public class FlatWindowDecorationsTest ((Dialog)window).setResizable( resizableCheckBox.isSelected() ); } + private void undecoratedChanged() { + Window window = SwingUtilities.windowForComponent( this ); + if( window == null ) + return; + + window.dispose(); + + if( window instanceof Frame ) + ((Frame)window).setUndecorated( undecoratedCheckBox.isSelected() ); + else if( window instanceof Dialog ) + ((Dialog)window).setUndecorated( undecoratedCheckBox.isSelected() ); + + window.setVisible( true ); + } + private void maximizedBoundsChanged() { Window window = SwingUtilities.windowForComponent( this ); if( window instanceof Frame ) { @@ -201,6 +221,7 @@ public class FlatWindowDecorationsTest menuBarEmbeddedCheckBox = new JCheckBox(); resizableCheckBox = new JCheckBox(); maximizedBoundsCheckBox = new JCheckBox(); + undecoratedCheckBox = new JCheckBox(); JLabel label1 = new JLabel(); JLabel label2 = new JLabel(); JPanel panel1 = new JPanel(); @@ -254,6 +275,7 @@ public class FlatWindowDecorationsTest // rows "para[]0" + "[]0" + + "[]0" + "[]" + "[]" + "[top]" + @@ -282,13 +304,18 @@ public class FlatWindowDecorationsTest maximizedBoundsCheckBox.addActionListener(e -> maximizedBoundsChanged()); add(maximizedBoundsCheckBox, "cell 1 2"); + //---- undecoratedCheckBox ---- + undecoratedCheckBox.setText("undecorated"); + undecoratedCheckBox.addActionListener(e -> undecoratedChanged()); + add(undecoratedCheckBox, "cell 0 3"); + //---- label1 ---- label1.setText("Style:"); - add(label1, "cell 0 3"); + add(label1, "cell 0 4"); //---- label2 ---- label2.setText("Icon:"); - add(label2, "cell 1 3"); + add(label2, "cell 1 4"); //======== panel1 ======== { @@ -353,7 +380,7 @@ public class FlatWindowDecorationsTest styleFileChooserRadioButton.addActionListener(e -> decorationStyleChanged()); panel1.add(styleFileChooserRadioButton, "cell 0 8"); } - add(panel1, "cell 0 4"); + add(panel1, "cell 0 5"); //======== panel2 ======== { @@ -382,12 +409,12 @@ public class FlatWindowDecorationsTest iconTestRandomRadioButton.addActionListener(e -> iconChanged()); panel2.add(iconTestRandomRadioButton, "cell 0 2"); } - add(panel2, "cell 1 4"); + add(panel2, "cell 1 5"); //---- openDialogButton ---- openDialogButton.setText("Open Dialog"); openDialogButton.addActionListener(e -> openDialog()); - add(openDialogButton, "cell 0 5"); + add(openDialogButton, "cell 0 6"); //======== menuBar ======== { @@ -582,6 +609,7 @@ public class FlatWindowDecorationsTest private JCheckBox menuBarEmbeddedCheckBox; private JCheckBox resizableCheckBox; private JCheckBox maximizedBoundsCheckBox; + private JCheckBox undecoratedCheckBox; private JRadioButton styleNoneRadioButton; private JRadioButton styleFrameRadioButton; private JRadioButton stylePlainRadioButton; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd index 436718fe..e5021fd8 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" "$columnConstraints": "[left]para[fill]" - "$rowConstraints": "para[]0[]0[][][top][]" + "$rowConstraints": "para[]0[]0[]0[][][top][]" } ) { name: "this" add( new FormComponent( "javax.swing.JCheckBox" ) { @@ -55,17 +55,27 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 2" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "undecoratedCheckBox" + "text": "undecorated" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "undecoratedChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 3" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label1" "text": "Style:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 3" + "value": "cell 0 4" } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label2" "text": "Icon:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 3" + "value": "cell 1 4" } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[fill]" @@ -174,7 +184,7 @@ new FormModel { "value": "cell 0 8" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 4" + "value": "cell 0 5" } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[fill]" @@ -217,14 +227,14 @@ new FormModel { "value": "cell 0 2" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 4" + "value": "cell 1 5" } ) add( new FormComponent( "javax.swing.JButton" ) { name: "openDialogButton" "text": "Open Dialog" addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "openDialog", false ) ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 5" + "value": "cell 0 6" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 )