Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/DimensionEncapsulation/DimensionEncapsulation.java
47525 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.Button;24import java.awt.Canvas;25import java.awt.Checkbox;26import java.awt.Choice;27import java.awt.Component;28import java.awt.Dialog;29import java.awt.Dimension;30import java.awt.FileDialog;31import java.awt.Frame;32import java.awt.Label;33import java.awt.List;34import java.awt.Panel;35import java.awt.ScrollPane;36import java.awt.Scrollbar;37import java.awt.TextArea;38import java.awt.TextField;39import java.awt.Window;40import java.util.ArrayList;41import java.util.Objects;4243import javax.swing.Box;44import javax.swing.JButton;45import javax.swing.JCheckBox;46import javax.swing.JCheckBoxMenuItem;47import javax.swing.JColorChooser;48import javax.swing.JDesktopPane;49import javax.swing.JDialog;50import javax.swing.JEditorPane;51import javax.swing.JFileChooser;52import javax.swing.JFormattedTextField;53import javax.swing.JFrame;54import javax.swing.JInternalFrame;55import javax.swing.JLabel;56import javax.swing.JLayeredPane;57import javax.swing.JMenu;58import javax.swing.JMenuBar;59import javax.swing.JMenuItem;60import javax.swing.JOptionPane;61import javax.swing.JPasswordField;62import javax.swing.JPopupMenu;63import javax.swing.JProgressBar;64import javax.swing.JRadioButton;65import javax.swing.JRadioButtonMenuItem;66import javax.swing.JRootPane;67import javax.swing.JScrollPane;68import javax.swing.JSeparator;69import javax.swing.JSlider;70import javax.swing.JSpinner;71import javax.swing.JSplitPane;72import javax.swing.JTabbedPane;73import javax.swing.JTable;74import javax.swing.JTextArea;75import javax.swing.JTextField;76import javax.swing.JTextPane;77import javax.swing.JToggleButton;78import javax.swing.JToolBar;79import javax.swing.JTree;80import javax.swing.JViewport;81import javax.swing.JWindow;82import javax.swing.SwingUtilities;83import javax.swing.UIManager;84import javax.swing.UIManager.LookAndFeelInfo;85import javax.swing.UnsupportedLookAndFeelException;86import javax.swing.table.JTableHeader;8788import static javax.swing.UIManager.getInstalledLookAndFeels;8990/**91* @test92* @bug 645979893* @author Sergey Bylokhov94*/95public final class DimensionEncapsulation implements Runnable {9697java.util.List<Component> failures = new ArrayList<>();9899public static void main(final String[] args) throws Exception {100for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {101SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));102SwingUtilities.invokeAndWait(new DimensionEncapsulation());103}104}105106@Override107public void run() {108runTest(new Panel());109runTest(new Button());110runTest(new Checkbox());111runTest(new Canvas());112runTest(new Choice());113runTest(new Label());114runTest(new Scrollbar());115runTest(new TextArea());116runTest(new TextField());117runTest(new Dialog(new JFrame()));118runTest(new Frame());119runTest(new Window(new JFrame()));120runTest(new FileDialog(new JFrame()));121runTest(new List());122runTest(new ScrollPane());123runTest(new JFrame());124runTest(new JDialog(new JFrame()));125runTest(new JWindow(new JFrame()));126runTest(new JLabel("hi"));127runTest(new JMenu());128runTest(new JTree());129runTest(new JTable());130runTest(new JMenuItem());131runTest(new JCheckBoxMenuItem());132runTest(new JToggleButton());133runTest(new JSpinner());134runTest(new JSlider());135runTest(Box.createVerticalBox());136runTest(Box.createHorizontalBox());137runTest(new JTextField());138runTest(new JTextArea());139runTest(new JTextPane());140runTest(new JPasswordField());141runTest(new JFormattedTextField());142runTest(new JEditorPane());143runTest(new JButton());144runTest(new JColorChooser());145runTest(new JFileChooser());146runTest(new JCheckBox());147runTest(new JInternalFrame());148runTest(new JDesktopPane());149runTest(new JTableHeader());150runTest(new JLayeredPane());151runTest(new JRootPane());152runTest(new JMenuBar());153runTest(new JOptionPane());154runTest(new JRadioButton());155runTest(new JRadioButtonMenuItem());156runTest(new JPopupMenu());157//runTest(new JScrollBar()); --> don't test defines max and min in158// terms of preferred159runTest(new JScrollPane());160runTest(new JViewport());161runTest(new JSplitPane());162runTest(new JTabbedPane());163runTest(new JToolBar());164runTest(new JSeparator());165runTest(new JProgressBar());166if (!failures.isEmpty()) {167System.out.println("These classes failed");168for (final Component failure : failures) {169System.out.println(failure.getClass());170}171throw new RuntimeException("Test failed");172}173}174175public void runTest(final Component c) {176try {177test(c);178c.setMinimumSize(new Dimension(100, 10));179c.setMaximumSize(new Dimension(200, 20));180c.setPreferredSize(new Dimension(300, 30));181test(c);182} catch (final Throwable ignored) {183failures.add(c);184}185}186187public void test(final Component component) {188final Dimension psize = component.getPreferredSize();189psize.width += 200;190if (Objects.equals(psize, component.getPreferredSize())) {191throw new RuntimeException("PreferredSize is wrong");192}193final Dimension msize = component.getMaximumSize();194msize.width += 200;195if (Objects.equals(msize, component.getMaximumSize())) {196throw new RuntimeException("MaximumSize is wrong");197}198final Dimension misize = component.getMinimumSize();199misize.width += 200;200if (Objects.equals(misize, component.getMinimumSize())) {201throw new RuntimeException("MinimumSize is wrong");202}203}204205private static void setLookAndFeel(final LookAndFeelInfo laf) {206try {207UIManager.setLookAndFeel(laf.getClassName());208System.out.println("LookAndFeel: " + laf.getClassName());209} catch (ClassNotFoundException | InstantiationException |210UnsupportedLookAndFeelException | IllegalAccessException e) {211throw new RuntimeException(e);212}213}214}215216