Java Code Examples for java.awt.event.InputEvent#getMaskForButton()

The following examples show how to use java.awt.event.InputEvent#getMaskForButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Robot.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 2
Source File: Robot.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 3
Source File: Robot.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 4
Source File: Robot.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 5
Source File: Robot.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 6
Source File: Robot.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 7
Source File: Robot.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 8
Source File: Robot.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 9
Source File: Robot.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 10
Source File: Robot.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 11
Source File: Robot.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 12
Source File: CheckGetMaskForButton.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 13
Source File: CheckGetMaskForButton.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 14
Source File: CheckGetMaskForButton.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 15
Source File: CheckGetMaskForButton.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 16
Source File: CheckGetMaskForButton.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 17
Source File: LWCToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest() {

        int x1 = frameBounds.x + frameBounds.width - 1;
        int y1 = frameBounds.y + frameBounds.height - 1;
        int x2 = frameBounds.x + frameBounds.width * 5 - 1;
        int y2 = frameBounds.y + frameBounds.height * 5 - 1;

        if (MouseInfo.getNumberOfButtons() < 1)
            throw new RuntimeException("The systems without a mouse");

        int button = 1;
        int buttonMask = InputEvent.getMaskForButton(button);

        for (int i = 0; i < ITERATION_NUMBER; i++) {
            robot.mouseMove(x1, y1);
            robot.waitForIdle();

            robot.mousePress(buttonMask);
            robot.waitForIdle();


            for (int j=2; j<10;j++) {

                robot.mouseMove(frameBounds.x + frameBounds.width * j - 1, frameBounds.y + frameBounds.height * j - 1);
                robot.waitForIdle();

            }
            robot.mouseRelease(buttonMask);
            robot.waitForIdle();

            robot.mousePress(buttonMask);
            robot.waitForIdle();

            for (int j=8; j>1;j--) {

                robot.mouseMove(frameBounds.x + frameBounds.width * j - 1, frameBounds.y + frameBounds.height * j - 1);
                robot.waitForIdle();

            }

            robot.mouseMove(x1, y1);
            robot.waitForIdle();

            robot.mouseRelease(buttonMask);
            robot.waitForIdle();
        }
    }
 
Example 18
Source File: CheckGetMaskForButton.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 19
Source File: CheckGetMaskForButton.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
Example 20
Source File: CheckGetMaskForButton.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}