jdk/test/javax/swing/JRootPane/SilenceOfDeprecatedMenuBar/SilenceOfDeprecatedMenuBar.java
author serb
Tue, 29 Mar 2016 17:03:18 +0300
changeset 36787 402e5e40f6e5
parent 30933 03b018d18b52
child 40128 e635645d2a8a
permissions -rw-r--r--
7179078: Remove @beaninfo processing from the makefiles Reviewed-by: erikj, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30933
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     1
/*
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     4
 *
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     8
 *
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    13
 * accompanied this code).
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    14
 *
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    18
 *
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    21
 * questions.
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    22
 */
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    23
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    24
import javax.swing.JFrame;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    25
import javax.swing.JMenuBar;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    26
import javax.swing.JRootPane;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    27
import javax.swing.SwingUtilities;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    28
import javax.swing.UIManager;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    29
import javax.swing.UnsupportedLookAndFeelException;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    30
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    31
import static javax.swing.UIManager.getInstalledLookAndFeels;
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    32
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    33
/**
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    34
 * @test
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    35
 * @bug 6368321
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    36
 * @author Sergey Bylokhov
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    37
 */
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    38
public final class SilenceOfDeprecatedMenuBar implements Runnable {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    39
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    40
    public static void main(final String[] args) throws Exception {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    41
        for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    42
            SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    43
            SwingUtilities.invokeAndWait(new SilenceOfDeprecatedMenuBar());
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    44
        }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    45
    }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    46
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    47
    @Override
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    48
    public void run() {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    49
        final JFrame frame = new DeprecatedFrame();
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    50
        try {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    51
            final JMenuBar bar = new JMenuBar();
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    52
            frame.setJMenuBar(bar);
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    53
            frame.setBounds(100, 100, 100, 100);
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    54
            frame.setLocationRelativeTo(null);
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    55
            frame.setVisible(true);
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    56
            if (bar != frame.getJMenuBar()) {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    57
                throw new RuntimeException("Wrong JMenuBar");
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    58
            }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    59
        } finally {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    60
            frame.dispose();
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    61
        }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    62
    }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    63
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    64
    private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    65
        try {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    66
            UIManager.setLookAndFeel(laf.getClassName());
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    67
            System.out.println("LookAndFeel: " + laf.getClassName());
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    68
        } catch (ClassNotFoundException | InstantiationException |
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    69
                UnsupportedLookAndFeelException | IllegalAccessException e) {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    70
            throw new RuntimeException(e);
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    71
        }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    72
    }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    73
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    74
    private static class DeprecatedFrame extends JFrame {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    75
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    76
        @Override
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    77
        protected JRootPane createRootPane() {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    78
            return new JRootPane() {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    79
                @Override
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    80
                public JMenuBar getMenuBar() {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    81
                    throw new RuntimeException("Should not be here");
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    82
                }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    83
                @Override
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    84
                public void setMenuBar(final JMenuBar menu) {
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    85
                    throw new RuntimeException("Should not be here");
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    86
                }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    87
            };
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    88
        }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    89
    }
03b018d18b52 6368321: MetalRootPaneUI calls to deprecated code
serb
parents:
diff changeset
    90
}