430N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
430N/A * published by the Free Software Foundation.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A/**
430N/A * @test
430N/A * @bug 6614214
430N/A * @summary Verifies that we enter the fs mode on the correct screen.
430N/A * Here is how to test: start the test on on a multi-screen system.
430N/A * Verify that the display is correctly tracked by dragging the frame back
430N/A * and forth between screens. Then verify that the correct device enters
430N/A * the full-screen mode - when "Enter FS mode" is pressed it should enter on
430N/A * the device where the frame is.
430N/A *
430N/A * Then change the order of the monitors in the DisplayProperties dialog,
430N/A * (while the app is running) and see that it still works.
430N/A * Restart the app, verify again.
430N/A *
430N/A * Now change the primary monitor on the system and verify with the
430N/A * app running, as well as after restarting it that we still enter the
430N/A * fs mode on the right device.
430N/A *
430N/A * @run main/manual/othervm DeviceIdentificationTest
430N/A * @run main/manual/othervm -Dsun.java2d.noddraw=true DeviceIdentificationTest
430N/A * @run main/manual/othervm -Dsun.java2d.opengl=True DeviceIdentificationTest
430N/A */
430N/A
430N/Aimport java.awt.Button;
430N/Aimport java.awt.Color;
430N/Aimport java.awt.Frame;
430N/Aimport java.awt.Graphics;
430N/Aimport java.awt.GraphicsConfiguration;
430N/Aimport java.awt.GraphicsDevice;
430N/Aimport java.awt.GraphicsEnvironment;
430N/Aimport java.awt.Panel;
430N/Aimport java.awt.event.ActionEvent;
430N/Aimport java.awt.event.ActionListener;
430N/Aimport java.awt.event.ComponentAdapter;
430N/Aimport java.awt.event.ComponentEvent;
430N/Aimport java.awt.event.MouseAdapter;
430N/Aimport java.awt.event.MouseEvent;
430N/Aimport java.awt.event.WindowAdapter;
430N/Aimport java.awt.event.WindowEvent;
430N/A
430N/Apublic class DeviceIdentificationTest {
430N/A
430N/A public static void main(String args[]) {
430N/A final Frame f = new Frame("DeviceIdentificationTest");
430N/A f.addWindowListener(new WindowAdapter() {
430N/A public void windowClosing(WindowEvent e) {
430N/A f.dispose();
430N/A }
430N/A });
430N/A f.addComponentListener(new ComponentAdapter() {
430N/A public void componentMoved(ComponentEvent e) {
430N/A f.setTitle("Currently on: "+
430N/A f.getGraphicsConfiguration().getDevice());
430N/A }
430N/A });
430N/A
430N/A Panel p = new Panel();
430N/A Button b = new Button("Print Current Devices");
430N/A b.addActionListener(new ActionListener() {
430N/A public void actionPerformed(ActionEvent e) {
430N/A GraphicsDevice gds[] =
430N/A GraphicsEnvironment.getLocalGraphicsEnvironment().
430N/A getScreenDevices();
430N/A int i = 0;
430N/A System.err.println("--- Devices: ---");
430N/A for (GraphicsDevice gd : gds) {
430N/A System.err.println("Device["+i+"]= "+ gd);
430N/A System.err.println(" bounds = "+
430N/A gd.getDefaultConfiguration().getBounds());
430N/A i++;
430N/A }
430N/A System.err.println("-------------------");
430N/A }
430N/A });
430N/A p.add(b);
430N/A
430N/A b = new Button("Print My Device");
430N/A b.addActionListener(new ActionListener() {
430N/A public void actionPerformed(ActionEvent e) {
430N/A GraphicsConfiguration gc = f.getGraphicsConfiguration();
430N/A GraphicsDevice gd = gc.getDevice();
430N/A System.err.println("--- My Device ---");
430N/A System.err.println("Device = "+ gd);
430N/A System.err.println(" bounds = "+
430N/A gd.getDefaultConfiguration().getBounds());
430N/A }
430N/A });
430N/A p.add(b);
430N/A
430N/A b = new Button("Create FS Frame on my Device");
430N/A b.addActionListener(new ActionListener() {
430N/A public void actionPerformed(ActionEvent e) {
430N/A GraphicsConfiguration gc = f.getGraphicsConfiguration();
430N/A final GraphicsDevice gd = gc.getDevice();
430N/A System.err.println("--- Creating FS Frame on Device ---");
430N/A System.err.println("Device = "+ gd);
430N/A System.err.println(" bounds = "+
430N/A gd.getDefaultConfiguration().getBounds());
430N/A final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {
430N/A public void paint(Graphics g) {
430N/A g.setColor(Color.green);
430N/A g.fillRect(0, 0, getWidth(), getHeight());
430N/A g.setColor(Color.red);
430N/A g.drawString("FS on device: "+gd, 200, 200);
430N/A g.drawString("Click to exit Full-screen.", 200, 250);
430N/A }
430N/A };
430N/A fsf.setUndecorated(true);
430N/A fsf.addMouseListener(new MouseAdapter() {
430N/A public void mouseClicked(MouseEvent e) {
430N/A gd.setFullScreenWindow(null);
430N/A fsf.dispose();
430N/A }
430N/A });
430N/A gd.setFullScreenWindow(fsf);
430N/A }
430N/A });
430N/A p.add(b);
430N/A f.add("North", p);
430N/A
430N/A p = new Panel();
430N/A b = new Button("Test Passed");
430N/A b.setBackground(Color.green);
430N/A b.addActionListener(new ActionListener() {
430N/A public void actionPerformed(ActionEvent e) {
430N/A System.out.println("Test Passed");
430N/A f.dispose();
430N/A }
430N/A });
430N/A p.add(b);
430N/A b = new Button("Test Failed");
430N/A b.setBackground(Color.red);
430N/A b.addActionListener(new ActionListener() {
430N/A public void actionPerformed(ActionEvent e) {
430N/A System.out.println("Test FAILED");
430N/A f.dispose();
430N/A throw new RuntimeException("Test FAILED");
430N/A }
430N/A });
430N/A p.add(b);
430N/A f.add("South", p);
430N/A
430N/A f.pack();
430N/A f.setVisible(true);
430N/A }
430N/A}