|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import java.awt.Component; |
| 25 | +import java.awt.Dimension; |
| 26 | +import java.awt.EventQueue; |
| 27 | + |
| 28 | +import javax.swing.JFrame; |
| 29 | +import javax.swing.JLayeredPane; |
| 30 | +import javax.swing.JRootPane; |
| 31 | +import javax.swing.UIManager; |
| 32 | +import javax.swing.UnsupportedLookAndFeelException; |
| 33 | + |
| 34 | +import static javax.swing.UIManager.getInstalledLookAndFeels; |
| 35 | + |
| 36 | +/** |
| 37 | + * @test |
| 38 | + * @bug 4916923 |
| 39 | + * @key headful |
| 40 | + * @summary MetalRootLayout does not correctly calculate minimumsize |
| 41 | + */ |
| 42 | +public final class RootPaneDecorationSize { |
| 43 | + |
| 44 | + public static void main(String[] args) throws Exception { |
| 45 | + for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) { |
| 46 | + EventQueue.invokeAndWait(() -> setLookAndFeel(laf)); |
| 47 | + EventQueue.invokeAndWait(RootPaneDecorationSize::test); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private static void test() { |
| 52 | + JFrame frame = new JFrame(); |
| 53 | + Dimension size; |
| 54 | + Dimension min; |
| 55 | + Dimension pref; |
| 56 | + try { |
| 57 | + // undecorated frame and decorated root pane usually used together |
| 58 | + frame.setUndecorated(true); |
| 59 | + frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); |
| 60 | + // customize the current L&F (mimic custom L&F) |
| 61 | + JLayeredPane layeredPane = frame.getRootPane().getLayeredPane(); |
| 62 | + for (Component comp : layeredPane.getComponents()) { |
| 63 | + comp.setMinimumSize(new Dimension(1000, 10)); |
| 64 | + comp.setMaximumSize(new Dimension(1000, 10)); |
| 65 | + comp.setPreferredSize(new Dimension(1000, 10)); |
| 66 | + } |
| 67 | + frame.pack(); |
| 68 | + size = frame.getSize(); |
| 69 | + min = frame.getMinimumSize(); |
| 70 | + pref = frame.getPreferredSize(); |
| 71 | + } finally { |
| 72 | + frame.dispose(); |
| 73 | + } |
| 74 | + System.err.println("\tsize = " + size); |
| 75 | + System.err.println("\tminimumSize = " + min); |
| 76 | + System.err.println("\tpreferredSize = " + pref); |
| 77 | + |
| 78 | + // We cannot predict which size will be used by the current L&F |
| 79 | + // but based on customization above the height < 1000 and width > 1000 |
| 80 | + if (size.height > 1000 || min.height > 1000 || pref.height > 1000) { |
| 81 | + throw new RuntimeException("The height too big"); |
| 82 | + } |
| 83 | + if (size.width < 1000 || min.width < 1000 || pref.width < 1000) { |
| 84 | + throw new RuntimeException("The width too small"); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) { |
| 89 | + try { |
| 90 | + System.err.println("LookAndFeel: " + laf.getClassName()); |
| 91 | + UIManager.setLookAndFeel(laf.getClassName()); |
| 92 | + } catch (UnsupportedLookAndFeelException ignored){ |
| 93 | + System.err.println("Unsupported LookAndFeel: " + laf.getClassName()); |
| 94 | + } catch (ClassNotFoundException | InstantiationException | |
| 95 | + IllegalAccessException e) { |
| 96 | + throw new RuntimeException(e); |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments