Path: blob/master/test/jdk/javax/swing/JInternalFrame/8069348/bug8069348.java
41153 views
/*1* Copyright (c) 2015, 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*/2223import java.awt.BorderLayout;24import java.awt.Color;25import java.awt.Graphics;26import java.awt.Rectangle;27import java.awt.Robot;28import java.awt.event.InputEvent;29import javax.swing.JDesktopPane;30import javax.swing.JFrame;31import javax.swing.JInternalFrame;32import javax.swing.JPanel;33import javax.swing.SwingUtilities;34import static sun.awt.OSInfo.*;3536/**37* @test38* @key headful39* @bug 8069348 8159902 819861340* @summary SunGraphics2D.copyArea() does not properly work for scaled graphics41* @author Alexandr Scherbatiy42* @modules java.desktop/sun.awt43* @run main/othervm -Dsun.java2d.uiScale=2 bug806934844* @run main/othervm -Dsun.java2d.d3d=true -Dsun.java2d.uiScale=2 bug806934845*/46public class bug8069348 {4748private static final int WIN_WIDTH = 500;49private static final int WIN_HEIGHT = 500;5051private static final Color DESKTOPPANE_COLOR = Color.YELLOW;52private static final Color FRAME_COLOR = Color.ORANGE;5354private static JFrame frame;55private static JInternalFrame internalFrame;5657public static void main(String[] args) throws Exception {5859if (!isSupported()) {60return;61}6263try {6465SwingUtilities.invokeAndWait(bug8069348::createAndShowGUI);6667Robot robot = new Robot();68robot.setAutoDelay(50);69robot.waitForIdle();7071Rectangle screenBounds = getInternalFrameScreenBounds();7273int x = screenBounds.x + screenBounds.width / 2;74int y = screenBounds.y + 10;75int dx = screenBounds.width / 2;76int dy = screenBounds.height / 2;7778robot.mouseMove(x, y);79robot.waitForIdle();8081robot.mousePress(InputEvent.BUTTON1_MASK);82robot.mouseMove(x + dx, y + dy);83robot.mouseRelease(InputEvent.BUTTON1_MASK);84robot.waitForIdle();8586int cx = screenBounds.x + screenBounds.width + dx / 2;87int cy = screenBounds.y + screenBounds.height + dy / 2;8889robot.mouseMove(cx, cy);90if (!FRAME_COLOR.equals(robot.getPixelColor(cx, cy))) {91throw new RuntimeException("Internal frame is not correctly dragged!");92}93} finally {94if (frame != null) {95frame.dispose();96}97}98}99100private static boolean isSupported() {101String d3d = System.getProperty("sun.java2d.d3d");102return !Boolean.getBoolean(d3d) || getOSType() == OSType.WINDOWS;103}104105private static Rectangle getInternalFrameScreenBounds() throws Exception {106Rectangle[] points = new Rectangle[1];107SwingUtilities.invokeAndWait(() -> {108points[0] = new Rectangle(internalFrame.getLocationOnScreen(),109internalFrame.getSize());110});111return points[0];112}113114private static void createAndShowGUI() {115116frame = new JFrame();117frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);118119JDesktopPane desktopPane = new JDesktopPane();120desktopPane.setBackground(DESKTOPPANE_COLOR);121122internalFrame = new JInternalFrame("Test") {123124@Override125public void paint(Graphics g) {126super.paint(g);127g.setColor(FRAME_COLOR);128g.fillRect(0, 0, getWidth(), getHeight());129}130};131internalFrame.setSize(WIN_WIDTH / 3, WIN_HEIGHT / 3);132internalFrame.setVisible(true);133desktopPane.add(internalFrame);134135JPanel panel = new JPanel();136panel.setLayout(new BorderLayout());137panel.add(desktopPane, BorderLayout.CENTER);138frame.add(panel);139frame.setSize(WIN_WIDTH, WIN_HEIGHT);140frame.setVisible(true);141frame.requestFocus();142}143}144145146