Java Code Examples for java.awt.Dialog#getBounds()

The following examples show how to use java.awt.Dialog#getBounds() . 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: ModalDialogOrderingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 2
Source File: ModalDialogOrderingTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 3
Source File: ModalDialogOrderingTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 4
Source File: ModalDialogOrderingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 5
Source File: AddModulePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param props
 * @param initialFilterText initial filter text or null if not given
 * @return 
 */
public static ModuleDependency[] selectDependencies(final SingleModuleProperties props, final String initialFilterText) {
    final AddModulePanel addPanel;
    if (null != initialFilterText) {
        // init dialog with filter text
        addPanel = new AddModulePanel(props, initialFilterText);
    }
    else{
        // keep backwards compatibility
        addPanel = new AddModulePanel(props);
    }
    final DialogDescriptor descriptor = new DialogDescriptor(addPanel,
            getMessage("CTL_AddModuleDependencyTitle"));
    descriptor.setHelpCtx(new HelpCtx("org.netbeans.modules.apisupport.project.ui.customizer.AddModulePanel"));
    descriptor.setClosingOptions(new Object[0]);
    final Dialog d = DialogDisplayer.getDefault().createDialog(descriptor);
    descriptor.setButtonListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (DialogDescriptor.OK_OPTION.equals(e.getSource()) && addPanel.getSelectedDependencies().length == 0) {
                return;
            }
            d.setVisible(false);
            d.dispose();
        }
    });
    if (lastSize != null) {
        d.setBounds(lastSize);
    }
    d.setVisible(true);
    lastSize = d.getBounds();
    d.dispose();
    if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
        return addPanel.getSelectedDependencies();
    } else {
        return new ModuleDependency[0]; // #114932
    }
}
 
Example 6
Source File: ModalDialogOrderingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 7
Source File: ModalDialogOrderingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 8
Source File: ModalDialogOrderingTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 9
Source File: ModalDialogOrderingTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 10
Source File: ModalDialogOrderingTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 11
Source File: ModalDialogOrderingTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 12
Source File: ModalDialogOrderingTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 13
Source File: ModalDialogOrderingTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 14
Source File: JavaHelp.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** If needed, visually rearrange dialogViewer and dlg on screen.
 * If they overlap, try to make them not overlap.
 * @param dlg the visible modal dialog
 * @param dialogOrFrameViewer The viewer, a dialog of a frame.
 */
private void rearrange(Dialog dlg, Window dialogOrFrameViewer) {
    Rectangle r1 = dlg.getBounds();
    Rectangle r2 = dialogOrFrameViewer.getBounds();
    if (r1.intersects(r2)) {
        Installer.log.fine("modal dialog and dialog viewer overlap");
        Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
        int xExtra = s.width - r1.width - r2.width;
        int yExtra = s.height - r1.height - r2.height;
        if(xExtra >= yExtra){
            //compare y axes of r1 and r2 to know how to relocate them - horizontal relocation
            int r1Yaxis = r1.x + (r1.width/2);
            int r2Yaxis = r2.x + (r2.width/2);
            if(r1Yaxis <= r2Yaxis) {
                Installer.log.fine(" send help to the right");
                if((r1.x + r1.width + r2.width) <= s.width) {
                    Installer.log.fine("there is enough place fo help");
                    r2.x = r1.x + r1.width;
                } else {
                    Installer.log.fine("there is not enough place");
                    if((r1.width + r2.width) < s.width) {
                        Installer.log.fine("relocate both");
                        r2.x = s.width - r2.width;
                        r1.x = r2.x - r1.width;
                    } else {
                        Installer.log.fine("relocate both and resize help");
                        r1.x = 0;
                        r2.x = r1.width;
                        r2.width = s.width - r1.width;
                    }
                }
            } else {
                Installer.log.fine("send help to the left");
                if((r1.x - r2.width) > 0) {
                    Installer.log.fine("there is enough place for help");
                    r2.x = r1.x - r2.width;
                } else {
                    Installer.log.fine("there is not enough place");
                    if((r1.width + r2.width) < s.width){
                        Installer.log.fine("relocate both");
                        r2.x = 0;
                        r1.x = r2.width;
                    } else {
                        Installer.log.fine("relocate both and resize help");
                        r1.x = s.width - r1.width;
                        r2.x = 0;
                        r2.width = r1.x;
                    }
                }
            }
        } else {
            //compare x axes of r1 and r2 to know how to relocate them
            int r1Xaxis = r1.y + (r1.height/2);
            int r2Xaxis = r2.y + (r2.height/2);
            if(r1Xaxis <= r2Xaxis) {
                Installer.log.fine(" send help to the bottom");
                if((r1.y + r1.height + r2.height) <= s.height) {
                    Installer.log.fine("there is enough place fo help");
                    r2.y = r1.y + r1.height;
                } else {
                    Installer.log.fine("there is not enough place");
                    if((r1.height + r2.height) < s.height) {
                        Installer.log.fine("relocate both");
                        r2.y = s.height - r2.height;
                        r1.y = r2.y - r1.height;
                    } else {
                        Installer.log.fine("relocate both and resize help");
                        r1.y = 0;
                        r2.y = r1.height;
                        r2.height = s.height - r1.height;
                    }
                }
            } else {
                Installer.log.fine("send help to the top");
                if((r1.y - r2.height) > 0){
                    Installer.log.fine("there is enough place for help");
                    r2.y = r1.y - r2.height;
                } else {
                    Installer.log.fine("there is not enough place");
                    if((r1.height + r2.height) < s.height) {
                        Installer.log.fine("relocate both");
                        r2.y = 0;
                        r1.y = r2.height;
                    } else {
                        Installer.log.fine("relocate both and resize help");
                        r1.y = s.height - r1.height;
                        r2.y = 0;  //or with -1
                        r2.height = r1.y;
                    }
                }
            }
        }
        dlg.setBounds(r1);
        dialogOrFrameViewer.setBounds(r2);
    }
}
 
Example 15
Source File: ModalDialogOrderingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        ExtendedRobot robot = new ExtendedRobot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            robot.waitForIdle(1000);
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle(1000);

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);


        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }else{
            frame.dispose();
            dialog.dispose();
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}