Search in sources :

Example 21 with WindowAdapter

use of java.awt.event.WindowAdapter 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 22 with WindowAdapter

use of java.awt.event.WindowAdapter 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)

Example 23 with WindowAdapter

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

the class DragInterceptorFrame method initGUI.

private void initGUI(Point location) {
    this.setLocation(location);
    this.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            DragInterceptorFrame.this.dispose();
        }
    });
    setSize(200, 200);
    this.setVisible(true);
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 24 with WindowAdapter

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

the class VSyncedBufferStrategyTest method createAndShowBSFrame.

private static Frame createAndShowBSFrame() {
    final Frame f = new Frame("Not V-Synced");
    int myNum;
    synchronized (VSyncedBufferStrategyTest.class) {
        myNum = frameNum++;
    }
    final VSyncedBufferStrategyTest component = new VSyncedBufferStrategyTest(false);
    f.setIgnoreRepaint(true);
    f.add("Center", component);
    Panel p = new Panel();
    Button b = new Button("Request VSync");
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            f.setTitle("Possibly V-Synced");
            component.setRequestVSync(true);
        }
    });
    p.add(b);
    b = new Button("Relinquish VSync");
    b.addActionListener(new ActionListener() {

        int inc = 1;

        public void actionPerformed(ActionEvent e) {
            f.setTitle("Not V-Synced");
            component.setRequestVSync(false);
            f.setSize(f.getWidth() + inc, f.getHeight());
            inc = -inc;
        }
    });
    p.add(b);
    f.add("South", p);
    f.pack();
    f.setLocation(10, myNum * f.getHeight());
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            component.done = true;
            f.dispose();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            component.done = true;
        }
    });
    return f;
}
Also used : Panel(java.awt.Panel) JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) ActionListener(java.awt.event.ActionListener) Button(java.awt.Button) JButton(javax.swing.JButton) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 25 with WindowAdapter

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

the class VSyncedBufferStrategyTest method createAndShowDescGUI.

private static void createAndShowDescGUI(final Frame f3, final Frame f1, final Frame f2) throws HeadlessException, RuntimeException {
    final JFrame desc = new JFrame("VSyncedBufferStrategyTest - Description");
    desc.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            f1.dispose();
            f2.dispose();
            f3.dispose();
            l.countDown();
        }
    });
    JPanel p = new JPanel();
    JButton bPassed = new JButton("Passed");
    bPassed.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            desc.dispose();
            f1.dispose();
            f2.dispose();
            f3.dispose();
            l.countDown();
        }
    });
    JButton bFailed = new JButton("Failed");
    bFailed.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            failed = true;
            desc.dispose();
            f1.dispose();
            f2.dispose();
            f3.dispose();
            l.countDown();
        }
    });
    p.setLayout(new FlowLayout());
    p.add(bPassed);
    p.add(bFailed);
    JTextArea ta = new JTextArea(24, 75);
    ta.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    ta.setEditable(false);
    ta.setText(description);
    desc.add("Center", new JScrollPane(ta));
    desc.add("South", p);
    desc.pack();
    desc.setLocation(BLOCK_W * 10 + 50, 0);
    desc.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JTextArea(javax.swing.JTextArea) 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) Font(java.awt.Font)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)129 WindowEvent (java.awt.event.WindowEvent)128 JPanel (javax.swing.JPanel)37 JButton (javax.swing.JButton)34 BorderLayout (java.awt.BorderLayout)31 JFrame (javax.swing.JFrame)30 Dimension (java.awt.Dimension)29 JLabel (javax.swing.JLabel)26 JScrollPane (javax.swing.JScrollPane)24 ActionEvent (java.awt.event.ActionEvent)21 ActionListener (java.awt.event.ActionListener)19 GridBagConstraints (java.awt.GridBagConstraints)18 GridBagLayout (java.awt.GridBagLayout)18 FlowLayout (java.awt.FlowLayout)17 Insets (java.awt.Insets)13 JTextArea (javax.swing.JTextArea)12 Container (java.awt.Container)11 Frame (java.awt.Frame)10 JDialog (javax.swing.JDialog)9 IOException (java.io.IOException)8