< prev index next >
test/jdk/java/awt/Choice/PopupPosTest/PopupPosTest.java
Print this page
*** 20,65 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
! test
! @bug 5044150
@summary Tests that pupup doesn't popdown if no space to display under
@author andrei.dmitriev area=awt.choice
! @library /test/lib
! @build jdk.test.lib.Platform
! @run applet PopupPosTest.html
*/
! import java.applet.Applet;
! import java.awt.*;
! import java.awt.event.*;
!
! import jdk.test.lib.Platform;
!
! public class PopupPosTest extends Applet
! {
! public void start ()
! {
! if (Platform.isOSX()) {
! // On OS X, popup isn't under the mouse
! return;
! }
! Frame frame = new TestFrame();
! }
! }
!
! class TestFrame extends Frame implements ItemListener {
! Robot robot;
! Toolkit tk = Toolkit.getDefaultToolkit();
! Choice choice = new Choice();
! boolean indexChanged = false;
! final static int INITIAL_ITEM = 99;
! volatile boolean stateChanged;
! public TestFrame() {
for (int i = 0; i < 100; i++) {
choice.addItem("Item Item Item " + i);
}
choice.addItemListener(this);
--- 20,59 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
! @test
! @key headful
! @bug 5044150 8197811
@summary Tests that pupup doesn't popdown if no space to display under
@author andrei.dmitriev area=awt.choice
! @run main PopupPosTest
*/
! import java.awt.Frame;
! import java.awt.Toolkit;
! import java.awt.Choice;
! import java.awt.Dimension;
! import java.awt.Robot;
! import java.awt.Point;
! import java.awt.Font;
! import java.awt.BorderLayout;
! import java.awt.event.ItemListener;
! import java.awt.event.ItemEvent;
! import java.awt.event.KeyEvent;
! import java.awt.event.InputEvent;
!
! public class PopupPosTest extends Frame implements ItemListener {
! private Robot robot;
! private Toolkit tk = Toolkit.getDefaultToolkit();
! private Choice choice = new Choice();
! private boolean indexChanged = false;
! private final static int INITIAL_ITEM = 99;
! private volatile boolean stateChanged;
! private PopupPosTest() {
for (int i = 0; i < 100; i++) {
choice.addItem("Item Item Item " + i);
}
choice.addItemListener(this);
*** 78,87 ****
--- 72,82 ----
// fix for 6175418. When we take "choice.getHeight()/2"
// divider 2 is not sufficiently big to hit into the
// small box Choice. We should use bigger divider to get
// smaller value choice.getHeight()/i. 4 is sufficient.
Point pt = choice.getLocationOnScreen();
+ System.out.println("Choice size: " + choice.getSize());
// click on 1/4 of Choice's height
mouseMoveAndPressOnChoice(pt.x + choice.getWidth()/2,
pt.y + choice.getHeight()/4);
// click on center of Choice's height
*** 105,115 ****
}
if(stateChanged){
throw new RuntimeException("Test failed. ItemEvent was generated on a simple mouse click when the dropdown appears under mouse");
}
! }// start()
public void itemStateChanged(ItemEvent ie) {
System.out.println("choice.stateChanged = "+ ie);
stateChanged = true;
}
--- 100,110 ----
}
if(stateChanged){
throw new RuntimeException("Test failed. ItemEvent was generated on a simple mouse click when the dropdown appears under mouse");
}
! }
public void itemStateChanged(ItemEvent ie) {
System.out.println("choice.stateChanged = "+ ie);
stateChanged = true;
}
*** 126,136 ****
checkSelectedIndex();
}
public void openChoice(){
Point pt = choice.getLocationOnScreen();
! robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/4,
pt.y + choice.getHeight()/2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(30);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
--- 121,131 ----
checkSelectedIndex();
}
public void openChoice(){
Point pt = choice.getLocationOnScreen();
! robot.mouseMove(pt.x + choice.getWidth() - 10,
pt.y + choice.getHeight()/2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(30);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
*** 140,150 ****
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
}
public void checkSelectedIndex(){
if (choice.getSelectedIndex() != INITIAL_ITEM) {
System.out.println("choice.getSelectedIndex = "+ choice.getSelectedIndex());
indexChanged = true;
}
}
! }// class TestFrame
--- 135,150 ----
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
}
public void checkSelectedIndex(){
+ System.out.println("choice.getSelectedIndex = " + choice.getSelectedIndex());
if (choice.getSelectedIndex() != INITIAL_ITEM) {
System.out.println("choice.getSelectedIndex = "+ choice.getSelectedIndex());
indexChanged = true;
}
}
!
! public static void main(String[] args) {
! new PopupPosTest();
! }
! }
< prev index next >