Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/InsetsEncapsulation/InsetsEncapsulation.java
47311 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Component;24import java.awt.Insets;25import java.util.ArrayList;26import java.util.Collection;2728import javax.swing.Box;29import javax.swing.JButton;30import javax.swing.JCheckBox;31import javax.swing.JCheckBoxMenuItem;32import javax.swing.JColorChooser;33import javax.swing.JComponent;34import javax.swing.JDesktopPane;35import javax.swing.JEditorPane;36import javax.swing.JFileChooser;37import javax.swing.JFormattedTextField;38import javax.swing.JInternalFrame;39import javax.swing.JLabel;40import javax.swing.JLayeredPane;41import javax.swing.JMenu;42import javax.swing.JMenuBar;43import javax.swing.JMenuItem;44import javax.swing.JOptionPane;45import javax.swing.JPasswordField;46import javax.swing.JPopupMenu;47import javax.swing.JProgressBar;48import javax.swing.JRadioButton;49import javax.swing.JRadioButtonMenuItem;50import javax.swing.JRootPane;51import javax.swing.JScrollBar;52import javax.swing.JScrollPane;53import javax.swing.JSeparator;54import javax.swing.JSlider;55import javax.swing.JSpinner;56import javax.swing.JSplitPane;57import javax.swing.JTabbedPane;58import javax.swing.JTable;59import javax.swing.JTextArea;60import javax.swing.JTextField;61import javax.swing.JTextPane;62import javax.swing.JToggleButton;63import javax.swing.JToolBar;64import javax.swing.JTree;65import javax.swing.JViewport;66import javax.swing.SwingUtilities;67import javax.swing.UIManager;68import javax.swing.UnsupportedLookAndFeelException;69import javax.swing.table.JTableHeader;7071import static javax.swing.UIManager.LookAndFeelInfo;72import static javax.swing.UIManager.getInstalledLookAndFeels;7374/**75* @test76* @bug 645980077* @author Sergey Bylokhov78*/79public final class InsetsEncapsulation implements Runnable {8081private final Collection<Component> failures = new ArrayList<>();8283public static void main(final String[] args) throws Exception {84for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {85SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));86SwingUtilities.invokeAndWait(new InsetsEncapsulation());87}88}8990@Override91public void run() {92runTest(new JLabel("hi"));93runTest(new JMenu());94runTest(new JTree());95runTest(new JTable());96runTest(new JMenuItem());97runTest(new JCheckBoxMenuItem());98runTest(new JToggleButton());99runTest(new JSpinner());100runTest(new JSlider());101runTest(Box.createVerticalBox());102runTest(Box.createHorizontalBox());103runTest(new JTextField());104runTest(new JTextArea());105runTest(new JTextPane());106runTest(new JPasswordField());107runTest(new JFormattedTextField());108runTest(new JEditorPane());109runTest(new JButton());110runTest(new JColorChooser());111runTest(new JFileChooser());112runTest(new JCheckBox());113runTest(new JInternalFrame());114runTest(new JDesktopPane());115runTest(new JTableHeader());116runTest(new JLayeredPane());117runTest(new JRootPane());118runTest(new JMenuBar());119runTest(new JOptionPane());120runTest(new JRadioButton());121runTest(new JRadioButtonMenuItem());122runTest(new JPopupMenu());123runTest(new JScrollBar());124runTest(new JScrollPane());125runTest(new JViewport());126runTest(new JSplitPane());127runTest(new JTabbedPane());128runTest(new JToolBar());129runTest(new JSeparator());130runTest(new JProgressBar());131if (!failures.isEmpty()) {132System.out.println("These classes failed");133for (final Component failure : failures) {134System.out.println(failure.getClass());135}136throw new RuntimeException("Test failed");137}138}139140void runTest(final JComponent component) {141try {142test(component);143} catch (final Throwable ignored) {144failures.add(component);145}146}147148void test(final JComponent component) {149final Insets p = component.getInsets();150p.top += 3;151if (p.equals(component.getInsets())) {152throw new RuntimeException("Insets altered by altering Insets!");153}154}155156private static void setLookAndFeel(final LookAndFeelInfo laf) {157try {158UIManager.setLookAndFeel(laf.getClassName());159System.out.println("LookAndFeel: " + laf.getClassName());160} catch (ClassNotFoundException | InstantiationException |161UnsupportedLookAndFeelException | IllegalAccessException e) {162throw new RuntimeException(e);163}164}165}166167