From ff55cc1a2af2a1c884048a98df1944adae82561c Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 7 Jun 2020 11:57:05 +0200 Subject: [PATCH] Window decorations: do not overwrite maximized bounds if controlled from the application --- .../com/formdev/flatlaf/ui/FlatTitlePane.java | 11 ++++++++++- .../testing/FlatWindowDecorationsTest.java | 18 ++++++++++++++++++ .../testing/FlatWindowDecorationsTest.jfd | 12 +++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 1addf9d6..399d1949 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -43,6 +43,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.accessibility.AccessibleContext; import javax.swing.BorderFactory; import javax.swing.BoxLayout; @@ -367,7 +368,11 @@ class FlatTitlePane Frame frame = (Frame) window; // set maximized bounds to avoid that maximized window overlaps Windows task bar - if( !hasJBRCustomDecoration() ) { + // (if not running in JBR and if not modified from the application) + if( !hasJBRCustomDecoration() && + (frame.getMaximizedBounds() == null || + Objects.equals( frame.getMaximizedBounds(), rootPane.getClientProperty( "flatlaf.maximizedBounds" ) )) ) + { GraphicsConfiguration gc = window.getGraphicsConfiguration(); // Screen bounds, which may be smaller than physical size on Java 9+. @@ -415,6 +420,10 @@ class FlatTitlePane // change maximized bounds frame.setMaximizedBounds( maximizedBounds ); + + // remember maximized bounds in client property to be able to detect + // whether maximized bounds are modified from the application + rootPane.putClientProperty( "flatlaf.maximizedBounds", maximizedBounds ); } // maximize window 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 9b7830f0..aab62652 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 @@ -73,6 +73,8 @@ public class FlatWindowDecorationsTest Window window = SwingUtilities.windowForComponent( this ); menuBarCheckBox.setEnabled( window instanceof JFrame ); + menuBarEmbeddedCheckBox.setEnabled( window instanceof JFrame ); + maximizedBoundsCheckBox.setEnabled( window instanceof Frame ); boolean windowHasIcons = (window != null && !window.getIconImages().isEmpty()); iconNoneRadioButton.setEnabled( windowHasIcons ); @@ -118,6 +120,15 @@ public class FlatWindowDecorationsTest ((Dialog)window).setResizable( resizableCheckBox.isSelected() ); } + private void maximizedBoundsChanged() { + Window window = SwingUtilities.windowForComponent( this ); + if( window instanceof Frame ) { + ((Frame)window).setMaximizedBounds( maximizedBoundsCheckBox.isSelected() + ? new Rectangle( 50, 100, 1000, 700 ) + : null ); + } + } + private void menuItemActionPerformed(ActionEvent e) { SwingUtilities.invokeLater( () -> { JOptionPane.showMessageDialog( this, e.getActionCommand(), "Menu Item", JOptionPane.PLAIN_MESSAGE ); @@ -189,6 +200,7 @@ public class FlatWindowDecorationsTest menuBarCheckBox = new JCheckBox(); menuBarEmbeddedCheckBox = new JCheckBox(); resizableCheckBox = new JCheckBox(); + maximizedBoundsCheckBox = new JCheckBox(); JLabel label1 = new JLabel(); JLabel label2 = new JLabel(); JPanel panel1 = new JPanel(); @@ -265,6 +277,11 @@ public class FlatWindowDecorationsTest resizableCheckBox.addActionListener(e -> resizableChanged()); add(resizableCheckBox, "cell 0 2"); + //---- maximizedBoundsCheckBox ---- + maximizedBoundsCheckBox.setText("maximized bounds (50,100, 1000,700)"); + maximizedBoundsCheckBox.addActionListener(e -> maximizedBoundsChanged()); + add(maximizedBoundsCheckBox, "cell 1 2"); + //---- label1 ---- label1.setText("Style:"); add(label1, "cell 0 3"); @@ -564,6 +581,7 @@ public class FlatWindowDecorationsTest private JCheckBox menuBarCheckBox; private JCheckBox menuBarEmbeddedCheckBox; private JCheckBox resizableCheckBox; + private JCheckBox maximizedBoundsCheckBox; 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 5675caf2..436718fe 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 @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.2.0.298" Java: "13.0.2" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -45,6 +45,16 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 2" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "maximizedBoundsCheckBox" + "text": "maximized bounds (50,100, 1000,700)" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "maximizedBoundsChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 2" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label1" "text": "Style:"