Search in sources :

Example 21 with WindowEvent

use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.

the class NoResizeEventOnDMChangeTest method testFSWindow.

private static void testFSWindow(final GraphicsDevice gd, final DisplayMode[] dms, final Window fsWin) {
    System.out.println("Testing FS window: " + fsWin);
    Component c = new Canvas() {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.magenta);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.setColor(Color.red);
            g.drawString("FS Window   : " + fsWin, 50, 50);
            DisplayMode dm = getGraphicsConfiguration().getDevice().getDisplayMode();
            g.drawString("Display Mode: " + dm.getWidth() + "x" + dm.getHeight(), 50, 75);
        }
    };
    fsWin.add("Center", c);
    fsWin.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            fsWin.dispose();
            if (fsWin.getOwner() != null) {
                fsWin.getOwner().dispose();
            }
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(fsWin);
            }
        });
    } catch (Exception ex) {
    }
    sleep(1000);
    final ResizeEventChecker r1 = new ResizeEventChecker();
    final ResizeEventChecker r2 = new ResizeEventChecker();
    if (gd.isDisplayChangeSupported()) {
        fsWin.addComponentListener(r1);
        c.addComponentListener(r2);
        for (final DisplayMode dm1 : dms) {
            try {
                EventQueue.invokeAndWait(new Runnable() {

                    public void run() {
                        System.err.printf("----------- Setting DM %dx%d:\n", dm1.getWidth(), dm1.getHeight());
                        try {
                            gd.setDisplayMode(dm1);
                            r1.incDmChanges();
                            r2.incDmChanges();
                        } catch (IllegalArgumentException iae) {
                        }
                    }
                });
            } catch (Exception ex) {
            }
            for (int i = 0; i < 3; i++) {
                fsWin.repaint();
                sleep(1000);
            }
        }
        fsWin.removeComponentListener(r1);
        c.removeComponentListener(r2);
    }
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(null);
                fsWin.dispose();
                if (fsWin.getOwner() != null) {
                    fsWin.getOwner().dispose();
                }
            }
        });
    } catch (Exception ex) {
    }
    System.out.printf("FS Window: resizes=%d, dm changes=%d\n", r1.getResizes(), r1.getDmChanges());
    System.out.printf("Component: resizes=%d, dm changes=%d\n", r2.getResizes(), r2.getDmChanges());
    if (r1.getResizes() < r1.getDmChanges()) {
        throw new RuntimeException("FS Window didn't receive all resizes!");
    }
    if (r2.getResizes() < r2.getDmChanges()) {
        throw new RuntimeException("Component didn't receive all resizes!");
    }
}
Also used : Canvas(java.awt.Canvas) WindowAdapter(java.awt.event.WindowAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) WindowEvent(java.awt.event.WindowEvent) Component(java.awt.Component)

Example 22 with WindowEvent

use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.

the class TooMuchWheelRotationEventsTest method createUI.

private static void createUI() {
    final JFrame mainFrame = new JFrame("Trackpad scrolling test");
    GridBagLayout layout = new GridBagLayout();
    JPanel mainControlPanel = new JPanel(layout);
    JPanel resultButtonPanel = new JPanel(layout);
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel testPanel = createTestPanel();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(testPanel, gbc);
    JTextArea instructionTextArea = new JTextArea();
    instructionTextArea.setText(INSTRUCTIONS);
    instructionTextArea.setEditable(false);
    instructionTextArea.setBackground(Color.white);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);
    JButton passButton = new JButton("Pass");
    passButton.setActionCommand("Pass");
    passButton.addActionListener((ActionEvent e) -> {
        testResult = true;
        mainFrame.dispose();
        countDownLatch.countDown();
    });
    JButton failButton = new JButton("Fail");
    failButton.setActionCommand("Fail");
    failButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mainFrame.dispose();
            countDownLatch.countDown();
        }
    });
    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    mainControlPanel.add(resultButtonPanel, gbc);
    mainFrame.add(mainControlPanel);
    mainFrame.pack();
    mainFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            mainFrame.dispose();
            countDownLatch.countDown();
        }
    });
    mainFrame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter)

Example 23 with WindowEvent

use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.

the class TexturePaintPrintingTest method doTest.

private static void doTest(Runnable action) {
    String description = " A TexturePaint graphics will be shown on console.\n" + " The same graphics is sent to printer.\n" + " Please verify if TexturePaint shading is printed.\n" + " If none is printed, press FAIL else press PASS";
    final JDialog dialog = new JDialog();
    dialog.setTitle("printSelectionTest");
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        f.dispose();
        dialog.dispose();
        pass();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        f.dispose();
        dialog.dispose();
        fail();
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("main dialog closing");
            testGeneratedInterrupt = false;
            mainThread.interrupt();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JDialog(javax.swing.JDialog)

Example 24 with WindowEvent

use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.

the class OnScreenRenderingResizeTest method main.

public static void main(String[] args) {
    for (String arg : args) {
        if ("-inf".equals(arg)) {
            System.err.println("Test will run indefinitely");
            RUN_TIME = Long.MAX_VALUE;
        } else if ("-nocheck".equals(arg)) {
            System.err.println("Test will not check rendering results");
            nocheck = true;
        } else {
            System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
        }
    }
    BufferedImage output = new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
    output.setAccelerationPriority(0.0f);
    Graphics g = output.getGraphics();
    g.setColor(renderColor);
    g.fillRect(0, 0, output.getWidth(), output.getHeight());
    final Frame frame = new Frame("OnScreenRenderingResizeTest") {

        public void paint(Graphics g) {
        }

        public void update(Graphics g) {
        }
    };
    frame.setBackground(bgColor);
    frame.setUndecorated(true);
    frame.pack();
    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    Rectangle gcBounds = gc.getBounds();
    frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            done = true;
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                frame.setVisible(true);
            }
        });
        // wait for Vista's effects to complete
        Thread.sleep(2000);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    int maxW = gcBounds.width / 2;
    int maxH = gcBounds.height / 2;
    int minW = frame.getWidth();
    int minH = frame.getHeight();
    int incW = 10, incH = 10, cnt = 0;
    Robot robot = null;
    if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
        try {
            robot = new Robot();
        } catch (AWTException ex) {
            System.err.println("Robot creation failed, continuing.");
        }
    } else {
        System.err.println("No screen rendering checks.");
    }
    VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
    vi.validate(gc);
    long timeStarted = System.currentTimeMillis();
    while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
        if (++cnt > 100) {
            int w = frame.getWidth() + incW;
            int h = frame.getHeight() + incH;
            if (w < minW || w > maxW) {
                incW = -incW;
            }
            if (h < minH || h > maxH) {
                incH = -incH;
            }
            frame.setSize(w, h);
            cnt = 0;
        }
        // try to put the device into non-default state, for example,
        // this operation below will set the transform
        vi.validate(gc);
        Graphics2D vig = (Graphics2D) vi.getGraphics();
        vig.rotate(30.0f, vi.getWidth() / 2, vi.getHeight() / 2);
        vig.drawImage(output, 0, 0, vi.getWidth(), vi.getHeight(), null);
        Insets in = frame.getInsets();
        frame.getGraphics().drawImage(output, in.left, in.top, null);
        if (cnt == 90 && robot != null) {
            robot.waitForIdle();
            // area where we blitted to should be either white or green
            Point p = frame.getLocationOnScreen();
            p.translate(in.left + 10, in.top + 10);
            BufferedImage bi = robot.createScreenCapture(new Rectangle(p.x, p.y, IMAGE_W / 2, IMAGE_H / 2));
            int[] accepted1 = { Color.white.getRGB(), Color.green.getRGB() };
            checkBI(bi, accepted1);
            // the are where we didn't render should stay white
            p = frame.getLocationOnScreen();
            p.translate(in.left, in.top + IMAGE_H + 5);
            bi = robot.createScreenCapture(new Rectangle(p.x, p.y, frame.getWidth() - in.left - in.right, frame.getHeight() - in.top - in.bottom - 5 - IMAGE_H));
            int[] accepted2 = { Color.white.getRGB() };
            checkBI(bi, accepted2);
        }
        Thread.yield();
    }
    frame.dispose();
    System.out.println("Test Passed");
}
Also used : Frame(java.awt.Frame) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) AWTException(java.awt.AWTException) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) WindowEvent(java.awt.event.WindowEvent) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 25 with WindowEvent

use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Aggregations

WindowEvent (java.awt.event.WindowEvent)184 WindowAdapter (java.awt.event.WindowAdapter)128 JPanel (javax.swing.JPanel)41 JButton (javax.swing.JButton)38 BorderLayout (java.awt.BorderLayout)35 JFrame (javax.swing.JFrame)35 Dimension (java.awt.Dimension)31 ActionEvent (java.awt.event.ActionEvent)31 JLabel (javax.swing.JLabel)30 JScrollPane (javax.swing.JScrollPane)25 ActionListener (java.awt.event.ActionListener)23 GridBagConstraints (java.awt.GridBagConstraints)19 GridBagLayout (java.awt.GridBagLayout)19 FlowLayout (java.awt.FlowLayout)17 Insets (java.awt.Insets)14 Frame (java.awt.Frame)12 JTextArea (javax.swing.JTextArea)12 Container (java.awt.Container)11 JDialog (javax.swing.JDialog)11 IOException (java.io.IOException)9