870N/A/*
870N/A test %I% %E%
870N/A @bug 6315717
870N/A @summary verifies that MouseEvent could be constructed correctly for mouse extra buttons in regard to sun.awt.enableExtraMouseButtons property
870N/A @author Andrei Dmitriev : area=awt.event
870N/A @run main/othervm -Dsun.awt.enableExtraMouseButtons=false CTORRestrictions_Disable
870N/A */
870N/A
870N/A/*
870N/A * verify that user can't create the MouseEvent? with button4|5|... when property "sun.awt.enableExtraMouseButtons"=false
870N/A * verify that user can create the MouseEvent? with button1|2|3 when property "sun.awt.enableExtraMouseButtons"=false
870N/A */
870N/A
870N/Aimport java.awt.*;
870N/Aimport java.awt.event.*;
870N/A
870N/Apublic class CTORRestrictions_Disable {
870N/A static Frame frame = new Frame("MouseEvent Test Frame");
870N/A static Point mousePosition;
870N/A static Point mousePositionOnScreen;
870N/A
870N/A public static void main(String []s){
870N/A Robot robot = null;
870N/A try {
870N/A robot = new Robot();
870N/A } catch (AWTException ex) {
870N/A throw new RuntimeException("Test Failed", ex);
870N/A }
870N/A frame.setSize (200,200);
870N/A frame.setLocation (300, 400);
870N/A frame.setVisible(true);
870N/A robot.delay(1000);
870N/A System.out.println(Toolkit.getDefaultToolkit().getDesktopProperty("sun.awt.enableExtraMouseButtons"));
870N/A mousePosition = new Point(100, 100);
870N/A mousePositionOnScreen = new Point(frame.getLocationOnScreen().x + mousePosition.x,
870N/A frame.getLocationOnScreen().y + mousePosition.y);
870N/A
870N/A System.out.println("Stage 1");
870N/A for (int buttonId = 1; buttonId <= MouseInfo.getNumberOfButtons(); buttonId++){
870N/A try {
870N/A postMouseEventNewCtor(buttonId);
870N/A if (buttonId > 3) {
870N/A throw new RuntimeException("Stage 1 FAILED: MouseEvent CTOR accepted the extra button " + (buttonId+1) + " instead of throwing an exception.");
870N/A }
870N/A } catch (IllegalArgumentException e){
870N/A if (buttonId > 3) {
870N/A System.out.println("Passed: an exception caught for extra button.");
870N/A } else {
870N/A throw new RuntimeException("Stage 1 FAILED : exception happen on standard button.", e);
870N/A }
870N/A }
870N/A }
870N/A
870N/A System.out.println("Stage 2");
870N/A for (int buttonId = 1; buttonId <= MouseInfo.getNumberOfButtons(); buttonId++){
870N/A try {
870N/A postMouseEventOldCtor(buttonId);
870N/A if (buttonId > 3) {
870N/A throw new RuntimeException("Stage 2 FAILED: MouseEvent CTOR accepted the extra button " + (buttonId+1) + " instead of throwing an exception.");
870N/A }
870N/A } catch (IllegalArgumentException e){
870N/A if (buttonId > 3) {
870N/A System.out.println("Passed: an exception caught for extra button.");
870N/A } else {
870N/A throw new RuntimeException("Stage 2 FAILED : exception happen on standard button.", e);
870N/A }
870N/A }
870N/A }
870N/A System.out.println("Test passed.");
870N/A }
870N/A
870N/A public static void postMouseEventNewCtor(int buttonId) {
870N/A MouseEvent me = new MouseEvent(frame,
870N/A MouseEvent.MOUSE_PRESSED,
870N/A System.currentTimeMillis(),
870N/A MouseEvent.BUTTON1_DOWN_MASK,
870N/A mousePosition.x, mousePosition.y,
870N/A mousePositionOnScreen.x,
870N/A mousePositionOnScreen.y,
870N/A 1,
870N/A false, //popupTrigger
870N/A buttonId //button
870N/A );
870N/A frame.dispatchEvent( ( AWTEvent )me );
870N/A }
870N/A
870N/A public static void postMouseEventOldCtor(int buttonId) {
870N/A MouseEvent meOld = new MouseEvent(frame,
870N/A MouseEvent.MOUSE_PRESSED,
870N/A System.currentTimeMillis(),
870N/A MouseEvent.BUTTON1_DOWN_MASK,
870N/A mousePosition.x, mousePosition.y,
870N/A 1,
870N/A false, //popupTrigger
870N/A buttonId //button
870N/A );
870N/A frame.dispatchEvent( ( AWTEvent )meOld );
870N/A }
870N/A}
870N/A
870N/A