Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java
38829 views
/*1* Copyright (c) 2007, 2008, 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 661421425* @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* @run main/manual/othervm -Dsun.java2d.opengl=True DeviceIdentificationTest43*/4445import java.awt.Button;46import java.awt.Color;47import java.awt.Frame;48import java.awt.Graphics;49import java.awt.GraphicsConfiguration;50import java.awt.GraphicsDevice;51import java.awt.GraphicsEnvironment;52import java.awt.Panel;53import java.awt.event.ActionEvent;54import java.awt.event.ActionListener;55import java.awt.event.ComponentAdapter;56import java.awt.event.ComponentEvent;57import java.awt.event.MouseAdapter;58import java.awt.event.MouseEvent;59import java.awt.event.WindowAdapter;60import java.awt.event.WindowEvent;6162public class DeviceIdentificationTest {6364public static void main(String args[]) {65final Frame f = new Frame("DeviceIdentificationTest");66f.addWindowListener(new WindowAdapter() {67public void windowClosing(WindowEvent e) {68f.dispose();69}70});71f.addComponentListener(new ComponentAdapter() {72public void componentMoved(ComponentEvent e) {73f.setTitle("Currently on: "+74f.getGraphicsConfiguration().getDevice());75}76});7778Panel p = new Panel();79Button b = new Button("Print Current Devices");80b.addActionListener(new ActionListener() {81public void actionPerformed(ActionEvent e) {82GraphicsDevice gds[] =83GraphicsEnvironment.getLocalGraphicsEnvironment().84getScreenDevices();85int i = 0;86System.err.println("--- Devices: ---");87for (GraphicsDevice gd : gds) {88System.err.println("Device["+i+"]= "+ gd);89System.err.println(" bounds = "+90gd.getDefaultConfiguration().getBounds());91i++;92}93System.err.println("-------------------");94}95});96p.add(b);9798b = new Button("Print My Device");99b.addActionListener(new ActionListener() {100public void actionPerformed(ActionEvent e) {101GraphicsConfiguration gc = f.getGraphicsConfiguration();102GraphicsDevice gd = gc.getDevice();103System.err.println("--- My Device ---");104System.err.println("Device = "+ gd);105System.err.println(" bounds = "+106gd.getDefaultConfiguration().getBounds());107}108});109p.add(b);110111b = new Button("Create FS Frame on my Device");112b.addActionListener(new ActionListener() {113public void actionPerformed(ActionEvent e) {114GraphicsConfiguration gc = f.getGraphicsConfiguration();115final GraphicsDevice gd = gc.getDevice();116System.err.println("--- Creating FS Frame on Device ---");117System.err.println("Device = "+ gd);118System.err.println(" bounds = "+119gd.getDefaultConfiguration().getBounds());120final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {121public void paint(Graphics g) {122g.setColor(Color.green);123g.fillRect(0, 0, getWidth(), getHeight());124g.setColor(Color.red);125g.drawString("FS on device: "+gd, 200, 200);126g.drawString("Click to exit Full-screen.", 200, 250);127}128};129fsf.setUndecorated(true);130fsf.addMouseListener(new MouseAdapter() {131public void mouseClicked(MouseEvent e) {132gd.setFullScreenWindow(null);133fsf.dispose();134}135});136gd.setFullScreenWindow(fsf);137}138});139p.add(b);140f.add("North", p);141142p = new Panel();143b = new Button("Test Passed");144b.setBackground(Color.green);145b.addActionListener(new ActionListener() {146public void actionPerformed(ActionEvent e) {147System.out.println("Test Passed");148f.dispose();149}150});151p.add(b);152b = new Button("Test Failed");153b.setBackground(Color.red);154b.addActionListener(new ActionListener() {155public void actionPerformed(ActionEvent e) {156System.out.println("Test FAILED");157f.dispose();158throw new RuntimeException("Test FAILED");159}160});161p.add(b);162f.add("South", p);163164f.pack();165f.setVisible(true);166}167}168169170