4919N/A/*
4919N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4919N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4919N/A *
4919N/A * This code is free software; you can redistribute it and/or modify it
4919N/A * under the terms of the GNU General Public License version 2 only, as
4919N/A * published by the Free Software Foundation.
4919N/A *
4919N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4919N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4919N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4919N/A * version 2 for more details (a copy is included in the LICENSE file that
4919N/A * accompanied this code).
4919N/A *
4919N/A * You should have received a copy of the GNU General Public License version
4919N/A * 2 along with this work; if not, write to the Free Software Foundation,
4919N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4919N/A *
4919N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4919N/A * or visit www.oracle.com if you need additional information or have any
4919N/A * questions.
4919N/A */
4919N/A
4919N/A/* @test
4919N/A @bug 7158712
4919N/A @summary Synth Property "ComboBox.popupInsets" is ignored
4919N/A @library ../../../regtesthelpers
4919N/A @author Pavel Porvatov
4919N/A*/
4919N/A
4919N/Aimport sun.awt.SunToolkit;
4919N/A
4919N/Aimport javax.swing.*;
4919N/Aimport javax.swing.plaf.basic.BasicComboPopup;
4919N/Aimport javax.swing.plaf.synth.SynthLookAndFeel;
4919N/Aimport java.awt.*;
4919N/Aimport java.awt.event.InputEvent;
4919N/Aimport java.io.ByteArrayInputStream;
4919N/Aimport java.util.concurrent.Callable;
4919N/A
4919N/Apublic class bug7158712 {
4919N/A private static final String SYNTH_XML = "<synth>" +
4919N/A " <style id=\"all\">" +
4919N/A " <font name=\"Dialog\" size=\"12\"/>" +
4919N/A " </style>" +
4919N/A " <bind style=\"all\" type=\"REGION\" key=\".*\"/>" +
4919N/A " <style id=\"arrowButton\">" +
4919N/A " <property key=\"ArrowButton.size\" type=\"integer\" value=\"18\"/>" +
4919N/A " </style>" +
4919N/A " <bind style=\"arrowButton\" type=\"region\" key=\"ArrowButton\"/>" +
4919N/A " <style id=\"comboBox\">" +
4919N/A " <property key=\"ComboBox.popupInsets\" type=\"insets\" value=\"-5 -5 5 -5\"/>" +
4919N/A " </style>" +
4919N/A " <bind style=\"comboBox\" type=\"region\" key=\"ComboBox\"/>" +
4919N/A "</synth>";
4919N/A
4919N/A private static JComboBox<String> comboBox;
4919N/A
4919N/A public static void main(String[] args) throws Exception {
4919N/A Robot robot = new Robot();
4919N/A
4919N/A robot.setAutoDelay(500);
4919N/A
4919N/A SynthLookAndFeel laf = new SynthLookAndFeel();
4919N/A
4919N/A laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);
4919N/A
4919N/A UIManager.setLookAndFeel(laf);
4919N/A
4919N/A EventQueue.invokeAndWait(new Runnable() {
4919N/A public void run() {
4919N/A comboBox = new JComboBox<>(
4919N/A new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});
4919N/A
4919N/A JFrame frame = new JFrame();
4919N/A
4919N/A frame.add(comboBox, BorderLayout.NORTH);
4919N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4919N/A frame.setSize(new Dimension(400, 300));
4919N/A frame.setLocationRelativeTo(null);
4919N/A frame.setVisible(true);
4919N/A }
4919N/A });
4919N/A
4919N/A ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
4919N/A
4919N/A Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
4919N/A @Override
4919N/A public Point call() throws Exception {
4919N/A return comboBox.getLocationOnScreen();
4919N/A }
4919N/A });
4919N/A
4919N/A robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
4919N/A robot.mousePress(InputEvent.BUTTON1_MASK);
4919N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
4919N/A
4919N/A SwingUtilities.invokeAndWait(new Runnable() {
4919N/A @Override
4919N/A public void run() {
4919N/A BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);
4919N/A
4919N/A Point popupPoint = popup.getLocationOnScreen();
4919N/A Point comboBoxPoint = comboBox.getLocationOnScreen();
4919N/A
4919N/A if (comboBoxPoint.x - 5 != popupPoint.x ||
4919N/A comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
4919N/A throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
4919N/A ", comboBox location: " + comboBoxPoint);
4919N/A }
4919N/A
4919N/A System.out.println("Test bug7158712 passed");
4919N/A }
4919N/A });
4919N/A }
4919N/A}