4612N/A/*
4612N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4612N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4612N/A *
4612N/A * This code is free software; you can redistribute it and/or modify it
4612N/A * under the terms of the GNU General Public License version 2 only, as
4612N/A * published by the Free Software Foundation.
4612N/A *
4612N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4612N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4612N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4612N/A * version 2 for more details (a copy is included in the LICENSE file that
4612N/A * accompanied this code).
4612N/A *
4612N/A * You should have received a copy of the GNU General Public License version
4612N/A * 2 along with this work; if not, write to the Free Software Foundation,
4612N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4612N/A *
4612N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4612N/A * or visit www.oracle.com if you need additional information or have any
4612N/A * questions.
4612N/A */
4612N/A
4612N/Aimport javax.swing.*;
4612N/Aimport javax.swing.plaf.basic.BasicTabbedPaneUI;
4612N/Aimport javax.swing.plaf.synth.SynthLookAndFeel;
4612N/Aimport java.lang.reflect.Method;
4612N/A
4612N/A/* @test
4612N/A @bug 7010561
4612N/A @summary Tab text position with Synth based LaF is different to Java 5/6
4612N/A @author Pavel Porvatov
4612N/A*/
4612N/Apublic class bug7010561 {
4612N/A private static int[] TAB_PLACEMENT = {
4612N/A SwingConstants.BOTTOM,
4612N/A SwingConstants.BOTTOM,
4612N/A SwingConstants.TOP,
4612N/A SwingConstants.TOP,
4612N/A
4612N/A };
4612N/A
4612N/A private static boolean[] IS_SELECTED = {
4612N/A false,
4612N/A true,
4612N/A false,
4612N/A true
4612N/A };
4612N/A
4612N/A private static int[] RETURN_VALUE = {
4612N/A -1,
4612N/A 1,
4612N/A 1,
4612N/A -1
4612N/A };
4612N/A
4612N/A public static void main(String[] args) throws Exception {
4612N/A UIManager.setLookAndFeel(new SynthLookAndFeel());
4612N/A
4612N/A SwingUtilities.invokeAndWait(new Runnable() {
4612N/A @Override
4612N/A public void run() {
4612N/A JTabbedPane tabbedPane = new JTabbedPane();
4612N/A
4612N/A tabbedPane.addTab("Tab 1", new JLabel("Tab 1"));
4612N/A
4612N/A // Ensure internal TabbedPane fields are initialized
4612N/A tabbedPane.doLayout();
4612N/A
4612N/A BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI();
4612N/A
4612N/A try {
4612N/A Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class,
4612N/A int.class, boolean.class);
4612N/A
4612N/A method.setAccessible(true);
4612N/A
4612N/A for (int i = 0; i < 4; i++) {
4612N/A int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0,
4612N/A IS_SELECTED[i])).intValue();
4612N/A
4612N/A if (res != RETURN_VALUE[i]) {
4612N/A throw new RuntimeException("Test bug7010561 failed on index " + i);
4612N/A }
4612N/A }
4612N/A } catch (Exception e) {
4612N/A throw new RuntimeException(e);
4612N/A }
4612N/A
4612N/A System.out.println("Test bug7010561 passed");
4612N/A }
4612N/A });
4612N/A }
4612N/A}