Path: blob/master/test/jdk/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java
41153 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/**23* @test24* @bug 6614214 819861325* @summary Verifies that we enter the fs mode on the correct screen.26* Here is how to test: start the test on on a multi-screen system.27* Verify that the display is correctly tracked by dragging the frame back28* and forth between screens. Then verify that the correct device enters29* the full-screen mode - when "Enter FS mode" is pressed it should enter on30* the device where the frame is.31*32* Then change the order of the monitors in the DisplayProperties dialog,33* (while the app is running) and see that it still works.34* Restart the app, verify again.35*36* Now change the primary monitor on the system and verify with the37* app running, as well as after restarting it that we still enter the38* fs mode on the right device.39*40* @run main/manual/othervm DeviceIdentificationTest41* @run main/manual/othervm -Dsun.java2d.noddraw=true DeviceIdentificationTest42*/4344import java.awt.Button;45import java.awt.Color;46import java.awt.Frame;47import java.awt.Graphics;48import java.awt.GraphicsConfiguration;49import java.awt.GraphicsDevice;50import java.awt.GraphicsEnvironment;51import java.awt.Panel;52import java.awt.event.ActionEvent;53import java.awt.event.ActionListener;54import java.awt.event.ComponentAdapter;55import java.awt.event.ComponentEvent;56import java.awt.event.MouseAdapter;57import java.awt.event.MouseEvent;58import java.awt.event.WindowAdapter;59import java.awt.event.WindowEvent;6061public class DeviceIdentificationTest {6263public static void main(String args[]) {64final Frame f = new Frame("DeviceIdentificationTest");65f.addWindowListener(new WindowAdapter() {66public void windowClosing(WindowEvent e) {67f.dispose();68}69});70f.addComponentListener(new ComponentAdapter() {71public void componentMoved(ComponentEvent e) {72f.setTitle("Currently on: "+73f.getGraphicsConfiguration().getDevice());74}75});7677Panel p = new Panel();78Button b = new Button("Print Current Devices");79b.addActionListener(new ActionListener() {80public void actionPerformed(ActionEvent e) {81GraphicsDevice gds[] =82GraphicsEnvironment.getLocalGraphicsEnvironment().83getScreenDevices();84int i = 0;85System.err.println("--- Devices: ---");86for (GraphicsDevice gd : gds) {87System.err.println("Device["+i+"]= "+ gd);88System.err.println(" bounds = "+89gd.getDefaultConfiguration().getBounds());90i++;91}92System.err.println("-------------------");93}94});95p.add(b);9697b = new Button("Print My Device");98b.addActionListener(new ActionListener() {99public void actionPerformed(ActionEvent e) {100GraphicsConfiguration gc = f.getGraphicsConfiguration();101GraphicsDevice gd = gc.getDevice();102System.err.println("--- My Device ---");103System.err.println("Device = "+ gd);104System.err.println(" bounds = "+105gd.getDefaultConfiguration().getBounds());106}107});108p.add(b);109110b = new Button("Create FS Frame on my Device");111b.addActionListener(new ActionListener() {112public void actionPerformed(ActionEvent e) {113GraphicsConfiguration gc = f.getGraphicsConfiguration();114final GraphicsDevice gd = gc.getDevice();115System.err.println("--- Creating FS Frame on Device ---");116System.err.println("Device = "+ gd);117System.err.println(" bounds = "+118gd.getDefaultConfiguration().getBounds());119final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {120public void paint(Graphics g) {121g.setColor(Color.green);122g.fillRect(0, 0, getWidth(), getHeight());123g.setColor(Color.red);124g.drawString("FS on device: "+gd, 200, 200);125g.drawString("Click to exit Full-screen.", 200, 250);126}127};128fsf.setUndecorated(true);129fsf.addMouseListener(new MouseAdapter() {130public void mouseClicked(MouseEvent e) {131gd.setFullScreenWindow(null);132fsf.dispose();133}134});135gd.setFullScreenWindow(fsf);136}137});138p.add(b);139f.add("North", p);140141p = new Panel();142b = new Button("Test Passed");143b.setBackground(Color.green);144b.addActionListener(new ActionListener() {145public void actionPerformed(ActionEvent e) {146System.out.println("Test Passed");147f.dispose();148}149});150p.add(b);151b = new Button("Test Failed");152b.setBackground(Color.red);153b.addActionListener(new ActionListener() {154public void actionPerformed(ActionEvent e) {155System.out.println("Test FAILED");156f.dispose();157throw new RuntimeException("Test FAILED");158}159});160p.add(b);161f.add("South", p);162163f.pack();164f.setVisible(true);165}166}167168169