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

The following examples show how to use java.awt.Dialog#add() . 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: MultiResolutionSplashTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 2
Source File: MultiResolutionSplashTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 3
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 4
Source File: MultiResolutionSplashTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 5
Source File: MultiResolutionSplashTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 6
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 7
Source File: UnixMultiResolutionSplashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                String scaleStr = System.getenv("GDK_SCALE");
                if (scaleStr != null && !scaleStr.equals("")) {
                    try {
                        scaleFactors[0] = Float.valueOf(scaleStr);
                    } catch (NumberFormatException ex) {
                        scaleFactors[0] = 1.0f;
                    }
                }
                dialog.setVisible(false);
            }
        };
        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();
        return scaleFactors[0];
    }
 
Example 8
Source File: MultiResolutionSplashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = getScreenScaleFactor();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 9
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 10
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 11
Source File: MultiResolutionSplashTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 12
Source File: MultiResolutionSplashTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 13
Source File: ChildWindowProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testChildPropertiesWithDialogAsParent() {

        parentDialog = new Dialog((Dialog) null, "parent Dialog");
        parentDialog.setSize(WIDTH, HEIGHT);
        parentDialog.setLocation(100, 100);
        parentDialog.setBackground(Color.RED);
        parentLabel = new Label("ParentForegroundAndFont");
        parentFont = new Font("Courier New", Font.ITALIC, 15);
        parentDialog.setForeground(Color.BLUE);
        parentDialog.setFont(parentFont);

        parentDialog.add(parentLabel);
        parentDialog.setVisible(true);

        windowChild = new Window(parentDialog);
        windowChild.setSize(WIDTH, HEIGHT);
        windowChild.setLocation(WIDTH + 200, 100);
        childLabel = new Label("ChildForegroundAndFont");
        windowChild.add(childLabel);
        windowChild.setVisible(true);

        if (parentDialog.getBackground() == windowChild.getBackground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Background Color");
        }
        if (parentDialog.getForeground() == windowChild.getForeground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Foreground Color");
        }
        if (parentDialog.getFont() == windowChild.getFont()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Font Color");
        }
    }
 
Example 14
Source File: ScaledTransform.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testScaleFactor(final GraphicsConfiguration gc) {
    final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);

    try {
        dialog.setSize(100, 100);
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                if (g instanceof Graphics2D) {
                    AffineTransform gcTx = gc.getDefaultTransform();
                    AffineTransform gTx
                            = ((Graphics2D) g).getTransform();
                    passed = gcTx.getScaleX() == gTx.getScaleX()
                            && gcTx.getScaleY() == gTx.getScaleY();
                } else {
                    passed = true;
                }
                dialog.setVisible(false);
            }
        };
        dialog.add(panel);
        dialog.setVisible(true);

        if (!passed) {
            throw new RuntimeException("Transform is not scaled!");
        }
    } finally {
        dialog.dispose();
    }
}
 
Example 15
Source File: ChildDialogProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testChildPropertiesWithFrameAsParent() {

        parentFrame = new Frame("parent Frame");
        parentFrame.setSize(WIDTH, HEIGHT);
        parentFrame.setLocation(100, 400);
        parentFrame.setBackground(Color.BLUE);
        parentLabel = new Label("ParentForegroundAndFont");
        parentFont = new Font("Courier New", Font.ITALIC, 15);
        parentFrame.setForeground(Color.RED);
        parentFrame.setFont(parentFont);
        parentFrame.add(parentLabel);
        parentFrame.setVisible(true);

        frameChildDialog = new Dialog(parentFrame, "Frame's child");
        frameChildDialog.setSize(WIDTH, HEIGHT);
        frameChildDialog.setLocation(WIDTH + 200, 400);
        childLabel = new Label("ChildForegroundAndFont");
        frameChildDialog.add(childLabel);
        frameChildDialog.setVisible(true);

        if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Frame's Background Color");
        }

        if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Frame's Foreground Color");
        }

        if (parentFrame.getFont() == frameChildDialog.getFont()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Frame's Font Style/Color");
        }
    }
 
Example 16
Source File: ScaledTransform.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testScaleFactor(final GraphicsConfiguration gc) {
    final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);

    try {
        dialog.setSize(100, 100);
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                if (g instanceof Graphics2D) {
                    AffineTransform gcTx = gc.getDefaultTransform();
                    AffineTransform gTx
                            = ((Graphics2D) g).getTransform();
                    passed = gcTx.getScaleX() == gTx.getScaleX()
                            && gcTx.getScaleY() == gTx.getScaleY();
                } else {
                    passed = true;
                }
                dialog.setVisible(false);
            }
        };
        dialog.add(panel);
        dialog.setVisible(true);

        if (!passed) {
            throw new RuntimeException("Transform is not scaled!");
        }
    } finally {
        dialog.dispose();
    }
}
 
Example 17
Source File: DialogUtils.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public static void addCloseButton(Dialog dDialog, ActionListener actionListener) {
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createRigidArea(new Dimension(50, 50)));
    buttonPanel.add(Box.createVerticalStrut(50));
    buttonPanel.add(Box.createGlue());
    dDialog.add(buttonPanel, BorderLayout.SOUTH);
    JButton closeButton = new JButton("Close");
    buttonPanel.add(closeButton);
    closeButton.addActionListener(actionListener);
    dDialog.doLayout();
    dDialog.pack();
}
 
Example 18
Source File: ChangeWindowResizabiltyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    for(int i = 0; i < 10; i++) {
        Dialog dialog = new Dialog((Frame) null);
        dialog.setLocation(100, 100);
        Component panel = new Panel();
        panel.setPreferredSize(new Dimension(200, 100));
        dialog.add(panel);
        dialog.pack();
        dialog.setVisible(true);
        robot.waitForIdle();
        robot.delay(200);

        Point frameLoc = dialog.getLocationOnScreen();
        Point contentLoc = panel.getLocationOnScreen();

        System.out.println("Decor location " + frameLoc);
        System.out.println("Content location " + contentLoc);

        dialog.setResizable(false);
        robot.waitForIdle();
        robot.delay(200);

        Point l = dialog.getLocationOnScreen();
        if (!l.equals(frameLoc)) {
            dialog.dispose();
            throw new RuntimeException("Decorated frame location moved " +
                    "after setResizable(false)" + l);
        }

        l = panel.getLocationOnScreen();
        if (!l.equals(contentLoc)) {
            dialog.dispose();
            throw new RuntimeException("Content location moved after " +
                    "setResizable(false)" + l);
        }

        if (panel.getLocationOnScreen().y <
                  dialog.getLocationOnScreen().y + dialog.getInsets().top) {
            dialog.dispose();
            throw new RuntimeException(
                        "Wrong content position after setResizable(false)");
        }

        dialog.setResizable(true);
        robot.waitForIdle();
        robot.delay(200);

        l = dialog.getLocationOnScreen();
        if (!l.equals(frameLoc)) {
            dialog.dispose();
            throw new RuntimeException("Decorated frame location moved " +
                    "after setResizable(true)" + l);
        }

        l = panel.getLocationOnScreen();
        if (!l.equals(contentLoc)) {
            dialog.dispose();
            throw new RuntimeException("Content location moved after " +
                    "setResizable(true)" + l);
        }
        if (panel.getLocationOnScreen().y <
                  dialog.getLocationOnScreen().y + dialog.getInsets().top) {
            dialog.dispose();
            throw new RuntimeException(
                         "Wrong content position after setResizable(true)");
        }

        dialog.dispose();
    }
}
 
Example 19
Source File: ChildDialogProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void testChildPropertiesWithDialogAsParent() {

        parentDialog = new Dialog((Dialog) null, "parent Dialog");
        parentDialog.setSize(WIDTH, HEIGHT);
        parentDialog.setLocation(100, 100);
        parentDialog.setBackground(Color.RED);

        parentLabel = new Label("ParentForegroundAndFont");
        parentFont = new Font("Courier New", Font.ITALIC, 15);
        parentDialog.setForeground(Color.BLUE);
        parentDialog.setFont(parentFont);

        parentDialog.add(parentLabel);
        parentDialog.setVisible(true);

        dialogChild = new Dialog(parentDialog, "Dialog's child");
        dialogChild.setSize(WIDTH, HEIGHT);
        dialogChild.setLocation(WIDTH + 200, 100);
        childLabel = new Label("ChildForegroundAndFont");
        dialogChild.add(childLabel);

        dialogChild.setVisible(true);

        if (parentDialog.getBackground() == dialogChild.getBackground()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Dialog's Background Color");
        }

        if (parentDialog.getForeground() == dialogChild.getForeground()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Dialog's Foreground Color");
        }

        if (parentDialog.getFont() == dialogChild.getFont()) {
            dispose();
            throw new RuntimeException("Child Dialog Should NOT Inherit "
                    + "Parent Dialog's Font Style/Color");
        }

    }
 
Example 20
Source File: NbPresenterLeakTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@RandomlyFails // NB-Core-Build #1189
public void testLeakingNbPresenterDescriptor () throws InterruptedException, InvocationTargetException {
    try {
        Class.forName("java.lang.AutoCloseable");
    } catch (ClassNotFoundException ex) {
        // this test is known to fail due to JDK bugs 7070542 & 7072167
        // which are unlikely to be fixed on JDK6. Thus, if AutoCloseable
        // is not present, skip the test
        return;
    }
    
    WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels(), null);
    wizardDescriptor.setModal (false);
    Dialog dialog = DialogDisplayer.getDefault ().createDialog (wizardDescriptor);
    WeakReference<WizardDescriptor> w = new WeakReference<WizardDescriptor> (wizardDescriptor);
    
    SwingUtilities.invokeAndWait (new EDTJob(dialog, true));
    assertShowing("button is visible", true, dialog);
    SwingUtilities.invokeAndWait (new EDTJob(dialog, false));
    assertShowing("button is no longer visible", false, dialog);
    boolean cancelled = wizardDescriptor.getValue() !=
        WizardDescriptor.FINISH_OPTION;
    Dialog d = new JDialog();
    
    // workaround for JDK bug 6575402
    JPanel p = new JPanel();
    d.setLayout(new BorderLayout());
    d.add(p, BorderLayout.CENTER);
    JButton btn = new JButton("Button");
    p.add(btn, BorderLayout.NORTH);
    
    SwingUtilities.invokeAndWait (new EDTJob(d, true));
    assertShowing("button is visible", true, btn);
    dialog.setBounds(Utilities.findCenterBounds(dialog.getSize()));
    SwingUtilities.invokeAndWait (new EDTJob(d, false));
    assertShowing("button is no longer visible", false, btn);

    assertNull ("BufferStrategy was disposed.", dialog.getBufferStrategy ());

    RepaintManager rm = RepaintManager.currentManager(dialog);
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    
    dialog = null;
    wizardDescriptor = null;
    
    SwingUtilities.invokeAndWait (new Runnable() {

        @Override
        public void run() {
            Frame f = new Frame();
            f.setPreferredSize( new Dimension(100,100));
            f.setVisible( true );
            JDialog dlg = new JDialog(f);
            dlg.setVisible(true);
        }
    });

    assertGC ("Dialog disappears.", w);
}