JBR-5194 add regressions tests for custom decorations support

with fix for JBR-5300 Change source code and test files to use GPL license

(cherry picked from commit 5fc82006c4)
This commit is contained in:
Sergey Shelomentsev
2023-02-14 13:53:23 +02:00
committed by jbrbot
parent 4e95202b6c
commit a90e73a7cd
24 changed files with 2968 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Robot;
import java.awt.event.InputEvent;
/*
* @test
* @summary Verify mouse events in custom title bar's area added by ActionListener
* @requires (os.family == "windows" | os.family == "mac")
* @run main ActionListenerTest
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main ActionListenerTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class ActionListenerTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), actionListener);
if (!status) {
throw new RuntimeException("ActionListenerTest FAILED");
}
}
private static final Task actionListener = new Task("Using of action listener") {
private Button button;
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void customizeWindow() {
button = new Button();
button.setBounds(200, 20, 50, 50);
button.addActionListener(a -> {
System.out.println("Action listener got event");
});
window.add(button);
}
@Override
public void test() throws AWTException {
final int initialHeight = window.getHeight();
final int initialWidth = window.getWidth();
System.out.println("Initial bounds: " + window.getBounds());
Robot robot = new Robot();
robot.delay(500);
int x = button.getLocationOnScreen().x + button.getWidth() / 2;
int y = button.getLocationOnScreen().y + button.getHeight() / 2;
System.out.println("Click at (" + x + ", " + y + ")");
robot.mouseMove(x, y);
robot.delay(300);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(2000);
if (window.getHeight() != initialHeight || window.getWidth() != initialWidth) {
passed = false;
System.out.println("Adding of action listener should block native title bar behavior");
}
}
};
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
/*
* @test
* @summary Verify modifying of title bar height
* @requires (os.family == "windows" | os.family == "mac")
* @run main ChangeTitleBarHeightTest
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main ChangeTitleBarHeightTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class ChangeTitleBarHeightTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), changeTitleBarHeight);
if (!status) {
throw new RuntimeException("ChangeTitleBarHeightTest FAILED");
}
}
private static final Task changeTitleBarHeight = new Task("Changing of title bar height") {
private final float initialHeight = 50;
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(initialHeight);
}
@Override
public void test() {
passed = passed && TestUtils.checkTitleBarHeight(titleBar, initialHeight);
float newHeight = 100;
titleBar.setHeight(newHeight);
passed = passed && TestUtils.checkTitleBarHeight(titleBar, newHeight);
}
};
}

View File

@@ -0,0 +1,56 @@
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import util.ScreenShotHelpers;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.IOException;
/*
* @test
* @summary Verify modifying of title bar height
* @requires (os.family == "windows" | os.family == "mac")
* @run main CheckFullScreen
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main CheckFullScreen -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class CheckFullScreen {
public static void main(String... args) throws AWTException, IOException {
Frame f = new Frame(){
@Override
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(Color.BLUE);
g.fillRect(r.x, r.y, r.width, 100);
super.paint(g);
}
};
WindowDecorations.CustomTitleBar titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(100);
JBR.getWindowDecorations().setCustomTitleBar(f, titleBar);
f.setVisible(true);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
Robot robot = new Robot();
robot.delay(5000);
BufferedImage image = ScreenShotHelpers.takeScreenshot(f);
ScreenShotHelpers.storeScreenshot("fullscreen", image);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
/*
* @test
* @summary Verify creating to a custom title bar
* @requires (os.family == "windows" | os.family == "mac")
* @run main CreateTitleBarTest
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main CreateTitleBarTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class CreateTitleBarTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), createTitleBar);
if (!status) {
throw new RuntimeException("CreateTitleBarTest FAILED");
}
}
private static final Task createTitleBar = new Task("Create title bar with default settings") {
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void test() {
passed = passed && TestUtils.checkTitleBarHeight(titleBar, TestUtils.TITLE_BAR_HEIGHT);
passed = passed && TestUtils.checkFrameInsets(window);
if (titleBar.getLeftInset() == 0 && titleBar.getRightInset() == 0) {
passed = false;
System.out.println("Left or right space must be occupied by system controls");
}
}
};
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Detect and check behavior of clicking to native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main DialogNativeControlsTest
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main DialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class DialogNativeControlsTest {
public static void main(String... args) {
boolean status = nativeControlClicks.run(TestUtils::createDialogWithCustomTitleBar);
if (!status) {
throw new RuntimeException("DialogNativeControlsTest FAILED");
}
}
private static final Task nativeControlClicks = new Task("Native controls clicks") {
private boolean closingActionCalled;
private boolean maximizingActionDetected;
private final WindowListener windowListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closingActionCalled = true;
}
};
private final WindowStateListener windowStateListener = new WindowAdapter() {
@Override
public void windowStateChanged(WindowEvent e) {
if (e.getNewState() == 6) {
maximizingActionDetected = true;
}
}
};
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void init() {
closingActionCalled = false;
maximizingActionDetected = false;
}
@Override
protected void cleanup() {
window.removeWindowListener(windowListener);
window.removeWindowStateListener(windowStateListener);
}
@Override
protected void customizeWindow() {
window.addWindowListener(windowListener);
window.addWindowStateListener(windowStateListener);
}
@Override
public void test() throws Exception {
robot.delay(500);
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
window.getLocationOnScreen().y + window.getHeight() / 2);
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
if (foundControls.size() == 0) {
passed = false;
System.out.println("Error: no controls found");
}
foundControls.forEach(control -> {
System.out.println("Using control: " + control);
int x = window.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
int y = window.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
System.out.println("Click to (" + x + ", " + y + ")");
int screenX = window.getBounds().x;
int screenY = window.getBounds().y;
int h = window.getBounds().height;
int w = window.getBounds().width;
robot.delay(500);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(1500);
window.setBounds(screenX, screenY, w, h);
window.setVisible(true);
robot.delay(1500);
});
if (System.getProperty("os.name").toLowerCase().startsWith("mac") && !maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
}
}
};
}

View File

@@ -0,0 +1,176 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Detect and check behavior of clicking to native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main FrameNativeControlsTest
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main FrameNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class FrameNativeControlsTest {
public static void main(String... args) {
boolean status = frameNativeControlsClicks.run(TestUtils::createFrameWithCustomTitleBar);
if (!status) {
throw new RuntimeException("FrameNativeControlsTest FAILED");
}
}
private static final Task frameNativeControlsClicks = new Task("Frame native controls clicks") {
private boolean closingActionCalled;
private boolean iconifyingActionCalled;
private boolean maximizingActionDetected;
private boolean deiconifyindActionDetected;
private final WindowListener windowListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closingActionCalled = true;
}
@Override
public void windowIconified(WindowEvent e) {
iconifyingActionCalled = true;
window.setVisible(true);
}
};
private final WindowStateListener windowStateListener = new WindowAdapter() {
@Override
public void windowStateChanged(WindowEvent e) {
System.out.println("change " + e.getOldState() + " -> " + e.getNewState());
if (e.getNewState() == 6) {
maximizingActionDetected = true;
}
if (e.getOldState() == 1 && e.getNewState() == 0) {
deiconifyindActionDetected = true;
}
}
};
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void init() {
closingActionCalled = false;
iconifyingActionCalled = false;
maximizingActionDetected = false;
deiconifyindActionDetected = false;
}
@Override
protected void cleanup() {
window.removeWindowListener(windowListener);
window.removeWindowStateListener(windowStateListener);
}
@Override
protected void customizeWindow() {
window.addWindowListener(windowListener);
window.addWindowStateListener(windowStateListener);
}
@Override
public void test() throws Exception {
robot.delay(500);
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
window.getLocationOnScreen().y + window.getHeight() / 2);
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
if (foundControls.size() == 0) {
passed = false;
System.out.println("Error: no controls found");
}
foundControls.forEach(control -> {
System.out.println("Using control: " + control);
int x = window.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
int y = window.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
System.out.println("Click to (" + x + ", " + y + ")");
int screenX = window.getBounds().x;
int screenY = window.getBounds().y;
int h = window.getBounds().height;
int w = window.getBounds().width;
robot.delay(500);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(1500);
window.setBounds(screenX, screenY, w, h);
window.setVisible(true);
robot.delay(1500);
});
if (!maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
}
if (!iconifyingActionCalled) {
passed = false;
System.out.println("Error: iconifying action was not detected");
}
if (!deiconifyindActionDetected) {
passed = false;
System.out.println("Error: deiconifying action was not detected");
}
}
};
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Verify a property to change visibility of native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main HiddenNativeControlsTest
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main HiddenNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class HiddenNativeControlsTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hiddenControls);
if (!status) {
throw new RuntimeException("HiddenNativeControlsTest FAILED");
}
}
private static final Task hiddenControls = new Task("Hidden native controls") {
private static final String PROPERTY_NAME = "controls.visible";
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
titleBar.putProperty(PROPERTY_NAME, false);
}
@Override
public void test() throws Exception {
Robot robot = new Robot();
robot.delay(1000);
robot.mouseMove(0, 0);
robot.delay(1000);
passed = passed && TestUtils.checkTitleBarHeight(titleBar, TestUtils.TITLE_BAR_HEIGHT);
passed = passed && TestUtils.checkFrameInsets(window);
if (!"false".equals(titleBar.getProperties().get(PROPERTY_NAME).toString())) {
passed = false;
System.out.println("controls.visible isn't false");
}
if (titleBar.getLeftInset() != 0 || titleBar.getRightInset() != 0) {
passed = false;
System.out.println("System controls are hidden so insets must be zero");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
System.out.println("image w = " + image.getWidth() + " h = " + image.getHeight());
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
System.out.println("Found controls at the title bar:");
foundControls.forEach(System.out::println);
if (foundControls.size() != 0) {
passed = false;
System.out.println("Error: there are must be 0 controls");
}
if (!passed) {
String path = ScreenShotHelpers.storeScreenshot("hidden-controls-test-" + window.getName(), image);
System.out.println("Screenshot stored in " + path);
}
}
};
}

View File

@@ -0,0 +1,189 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
/*
* @test
* @summary Verify control under native actions in custom title bar
* @requires (os.family == "windows" | os.family == "mac")
* @run main HitTestClientArea
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main HitTestClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class HitTestClientArea {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hitTestClientArea);
if (!status) {
throw new RuntimeException("HitTestClientArea FAILED");
}
}
private static final Task hitTestClientArea = new Task("Hit test client area") {
private static final List<Integer> BUTTON_MASKS = List.of(
InputEvent.BUTTON1_DOWN_MASK,
InputEvent.BUTTON2_DOWN_MASK,
InputEvent.BUTTON3_DOWN_MASK
);
private static final int PANEL_WIDTH = 400;
private static final int PANEL_HEIGHT = (int) TestUtils.TITLE_BAR_HEIGHT;
private final boolean[] gotClicks = new boolean[BUTTON_MASKS.size()];
private Panel panel;
@Override
protected void cleanup() {
super.cleanup();
}
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void customizeWindow() {
panel = new Panel(){
@Override
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(Color.CYAN);
g.fillRect(r.x, r.y, PANEL_WIDTH, PANEL_HEIGHT);
super.paint(g);
}
};
panel.setBounds(0, 0, PANEL_WIDTH, PANEL_HEIGHT);
panel.setSize(PANEL_WIDTH, PANEL_HEIGHT);
panel.addMouseListener(new MouseAdapter() {
private void hit() {
titleBar.forceHitTest(true);
}
@Override
public void mouseClicked(MouseEvent e) {
hit();
if (e.getButton() >= 1 && e.getButton() <= 3) {
gotClicks[e.getButton() - 1] = true;
}
}
@Override
public void mousePressed(MouseEvent e) {
hit();
}
@Override
public void mouseReleased(MouseEvent e) {
hit();
}
@Override
public void mouseEntered(MouseEvent e) {
hit();
}
@Override
public void mouseDragged(MouseEvent e) {
hit();
}
@Override
public void mouseMoved(MouseEvent e) {
hit();
}
});
window.add(panel);
}
@Override
public void test() throws AWTException {
Robot robot = new Robot();
BUTTON_MASKS.forEach(mask -> {
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() / 2,
panel.getLocationOnScreen().y + panel.getHeight() / 2);
robot.mousePress(mask);
robot.mouseRelease(mask);
robot.delay(500);
});
Point initialLocation = window.getLocationOnScreen();
robot.delay(500);
int initialX = panel.getLocationOnScreen().x + panel.getWidth() / 2;
int initialY = panel.getLocationOnScreen().y + panel.getHeight() / 2;
robot.mouseMove(initialX, initialY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
for (int i = 0; i < 10; i++) {
initialX += 3;
initialY += 3;
robot.delay(500);
robot.mouseMove(initialX, initialY);
}
robot.delay(500);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Point newLocation = window.getLocationOnScreen();
boolean moved = initialLocation.x < newLocation.x && initialLocation.y < newLocation.y;
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
if (!gotClicks[i]) {
System.out.println("Mouse click to button no " + (i+1) + " was not registered");
passed = false;
}
}
passed = passed && !moved;
}
};
}

View File

@@ -0,0 +1,186 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Color;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.List;
/*
* @test
* @summary Verify control under native actions in custom title bar
* @requires (os.family == "windows" | os.family == "mac")
* @run main HitTestNonClientArea
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main HitTestNonClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class HitTestNonClientArea {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hitTestNonClientArea);
if (!status) {
throw new RuntimeException("HitTestNonClientArea FAILED");
}
}
private static final Task hitTestNonClientArea = new Task("Hit test non-client area") {
private static final List<Integer> BUTTON_MASKS = List.of(
InputEvent.BUTTON1_DOWN_MASK,
InputEvent.BUTTON2_DOWN_MASK,
InputEvent.BUTTON3_DOWN_MASK
);
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 40;
private final boolean[] gotClicks = new boolean[BUTTON_MASKS.size()];
private Button button;
@Override
protected void cleanup() {
Arrays.fill(gotClicks, false);
}
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void customizeWindow() {
button = new Button();
button.setBackground(Color.CYAN);
button.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
MouseAdapter adapter = new MouseAdapter() {
private void hit() {
titleBar.forceHitTest(false);
}
@Override
public void mouseClicked(MouseEvent e) {
hit();
if (e.getButton() >= 1 && e.getButton() <= 3) {
gotClicks[e.getButton() - 1] = true;
}
}
@Override
public void mousePressed(MouseEvent e) {
hit();
}
@Override
public void mouseReleased(MouseEvent e) {
hit();
}
@Override
public void mouseEntered(MouseEvent e) {
hit();
}
@Override
public void mouseDragged(MouseEvent e) {
hit();
}
@Override
public void mouseMoved(MouseEvent e) {
hit();
}
};
button.addMouseListener(adapter);
button.addMouseMotionListener(adapter);
Panel panel = new Panel();
panel.setBounds(300, 20, 100, 50);
panel.add(button);
window.add(panel);
}
@Override
public void test() throws AWTException {
Robot robot = new Robot();
BUTTON_MASKS.forEach(mask -> {
robot.delay(500);
robot.mouseMove(button.getLocationOnScreen().x + button.getWidth() / 2,
button.getLocationOnScreen().y + button.getHeight() / 2);
robot.mousePress(mask);
robot.mouseRelease(mask);
robot.delay(500);
});
Point initialLocation = window.getLocationOnScreen();
robot.delay(500);
int initialX = button.getLocationOnScreen().x + button.getWidth() / 2;
int initialY = button.getLocationOnScreen().y + button.getHeight() / 2;
robot.mouseMove(initialX, initialY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
for (int i = 0; i < 10; i++) {
initialX += 3;
initialY += 3;
robot.delay(500);
robot.mouseMove(initialX, initialY);
}
robot.delay(500);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Point newLocation = window.getLocationOnScreen();
passed = initialLocation.x < newLocation.x && initialLocation.y < newLocation.y;
if (!passed) {
System.out.println("Window location was changed");
}
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
if (!gotClicks[i]) {
System.out.println("Mouse click to button no " + (i+1) + " was not registered");
passed = false;
}
}
}
};
}

View File

@@ -0,0 +1,156 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Detect and check behavior of clicking to native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main JDialogNativeControlsTest
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main JDialogNativeControlsTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class JDialogNativeControlsTest {
public static void main(String... args) {
boolean status = nativeControlClicks.run(TestUtils::createJDialogWithCustomTitleBar);
if (!status) {
throw new RuntimeException("JDialogNativeControlsTest FAILED");
}
}
private static final Task nativeControlClicks = new Task("Native controls clicks") {
private boolean closingActionCalled;
private boolean maximizingActionDetected;
private final WindowListener windowListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closingActionCalled = true;
}
};
private final WindowStateListener windowStateListener = new WindowAdapter() {
@Override
public void windowStateChanged(WindowEvent e) {
System.out.println("change " + e.getOldState() + " -> " + e.getNewState());
if (e.getNewState() == 6) {
maximizingActionDetected = true;
}
}
};
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void init() {
closingActionCalled = false;
maximizingActionDetected = false;
}
@Override
protected void cleanup() {
window.removeWindowListener(windowListener);
window.removeWindowStateListener(windowStateListener);
}
@Override
protected void customizeWindow() {
window.addWindowListener(windowListener);
window.addWindowStateListener(windowStateListener);
}
@Override
public void test() throws Exception {
robot.delay(500);
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
window.getLocationOnScreen().y + window.getHeight() / 2);
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
if (foundControls.size() == 0) {
passed = false;
System.out.println("Error: no controls found");
}
foundControls.forEach(control -> {
System.out.println("Using control: " + control);
int x = window.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
int y = window.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
System.out.println("Click to (" + x + ", " + y + ")");
int screenX = window.getBounds().x;
int screenY = window.getBounds().y;
int h = window.getBounds().height;
int w = window.getBounds().width;
robot.delay(500);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(1500);
window.setBounds(screenX, screenY, w, h);
window.setVisible(true);
robot.delay(1500);
});
if (!maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
}
}
};
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.InputEvent;
/*
* @test
* @summary Verify ability to maximize window by clicking to custom title bar area
* @requires (os.family == "windows" | os.family == "mac")
* @run main MaximizeWindowTest
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main MaximizeWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class MaximizeWindowTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), maximizeWindow);
if (!status) {
throw new RuntimeException("MaximizeWindowTest FAILED");
}
}
private static final Task maximizeWindow = new Task("Maximize frame") {
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void test() throws AWTException {
setResizable(true);
setWindowSize(window, titleBar);
int initialWidth = window.getWidth();
int initialHeight = window.getHeight();
doubleClickToTitleBar(window, titleBar);
System.out.printf(String.format("Initial size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
System.out.printf(String.format("New size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
if (initialHeight == window.getHeight() && initialWidth == window.getWidth()) {
passed = false;
System.out.println("Frame size wasn't changed");
}
setResizable(false);
setWindowSize(window, titleBar);
initialWidth = window.getWidth();
initialHeight = window.getHeight();
doubleClickToTitleBar(window, titleBar);
System.out.printf(String.format("Initial size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
System.out.printf(String.format("New size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
if (initialHeight != window.getHeight() || initialWidth != window.getWidth()) {
passed = false;
System.out.println("Frame size was changed");
}
}
private void setResizable(boolean value) {
if (window instanceof Frame frame) {
frame.setResizable(value);
} else if (window instanceof Dialog dialog) {
dialog.setResizable(value);
}
}
};
private static void setWindowSize(Window window, WindowDecorations.CustomTitleBar titleBar) {
System.out.println("Window was created with bounds: " + window.getBounds());
int w = window.getBounds().width / 2;
int h = window.getBounds().height / 2;
window.setBounds(window.getBounds().x, window.getBounds().y, w, h);
System.out.println("New window bounds: " + window.getBounds());
window.setSize(w, h);
}
private static void doubleClickToTitleBar(Window window, WindowDecorations.CustomTitleBar titleBar) throws AWTException {
int leftX = window.getInsets().left + (int) titleBar.getLeftInset();
int rightX = window.getBounds().width - window.getInsets().right - (int) titleBar.getRightInset();
int x = window.getLocationOnScreen().x + (rightX - leftX) / 2;
int topY = window.getInsets().top;
int bottomY = (int) TestUtils.TITLE_BAR_HEIGHT;
int y = window.getLocationOnScreen().y + (bottomY - topY) / 2;
System.out.println("Window bounds: " + window.getBounds());
System.out.println("Window insets: " + window.getInsets());
System.out.println("Window location on screen: " + window.getLocationOnScreen());
System.out.println("leftX = " + leftX + ", rightX = " + rightX);
System.out.println("topY = " + topY + ", bottomY = " + bottomY);
System.out.println("Double click to (" + x + ", " + y + ")");
Robot robot = new Robot();
robot.delay(1000);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(1000);
}
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/*
* @test
* @summary Regression test for JBR-3157 Maximized window with custom decorations isn't focused on showing
* @requires (os.family == "windows" | os.family == "mac")
* @run main/othervm MaximizedWindowFocusTest
* @run main/othervm MaximizedWindowFocusTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main/othervm MaximizedWindowFocusTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
*/
public class MaximizedWindowFocusTest {
private static Robot robot;
private static JFrame frame1;
private static JFrame frame2;
private static JButton button;
private static final CompletableFuture<Boolean> frame2Focused = new CompletableFuture<>();
public static void main(String... args) throws Exception {
robot = new Robot();
try {
SwingUtilities.invokeAndWait(MaximizedWindowFocusTest::initUI);
robot.delay(1000);
clickOn(button);
frame2Focused.get(5, TimeUnit.SECONDS);
} finally {
SwingUtilities.invokeAndWait(MaximizedWindowFocusTest::disposeUI);
}
}
private static void initUI() {
frame1 = new JFrame("MaximizedCustomDecorationsTest");
button = new JButton("Open maximized frame");
button.addActionListener(e -> {
frame1.dispose();
frame2 = new JFrame("Frame with custom decorations");
WindowDecorations.CustomTitleBar titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(100);
JBR.getWindowDecorations().setCustomTitleBar(frame2, titleBar);
frame2.addWindowFocusListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
frame2Focused.complete(true);
}
});
frame2.setExtendedState(Frame.MAXIMIZED_BOTH);
frame2.setVisible(true);
});
frame1.add(button);
frame1.pack();
frame1.setVisible(true);
}
private static void disposeUI() {
if (frame1 != null) frame1.dispose();
if (frame2 != null) frame2.dispose();
}
private static void clickAt(int x, int y) {
robot.delay(500);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(500);
}
private static void clickOn(Component component) {
Point location = component.getLocationOnScreen();
clickAt(location.x + component.getWidth() / 2, location.y + component.getHeight() / 2);
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Detect and check behavior of clicking to native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main MinimizingWindowTest
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main MinimizingWindowTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class MinimizingWindowTest {
public static void main(String... args) {
boolean status = minimizingWindowTest.run(TestUtils::createFrameWithCustomTitleBar);
if (!status) {
throw new RuntimeException("MinimizingWindowTest FAILED");
}
}
private static final Task minimizingWindowTest = new Task("Frame native controls clicks") {
private boolean iconifyingActionCalled;
private boolean iconifyingActionDetected;
private final WindowListener windowListener = new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
iconifyingActionCalled = true;
window.setVisible(true);
}
};
private final WindowStateListener windowStateListener = new WindowAdapter() {
@Override
public void windowStateChanged(WindowEvent e) {
System.out.println("change " + e.getOldState() + " -> " + e.getNewState());
if (e.getOldState() == 0 && e.getNewState() == 1) {
iconifyingActionDetected = true;
}
}
};
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void init() {
iconifyingActionCalled = false;
iconifyingActionDetected = false;
}
@Override
protected void cleanup() {
window.removeWindowListener(windowListener);
window.removeWindowStateListener(windowStateListener);
}
@Override
protected void customizeWindow() {
window.addWindowListener(windowListener);
window.addWindowStateListener(windowStateListener);
}
@Override
public void test() throws Exception {
robot.delay(500);
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
window.getLocationOnScreen().y + window.getHeight() / 2);
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
if (foundControls.size() == 0) {
passed = false;
System.out.println("Error: no controls found");
}
foundControls.forEach(control -> {
System.out.println("Using control: " + control);
int x = window.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
int y = window.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
System.out.println("Click to (" + x + ", " + y + ")");
int screenX = window.getBounds().x;
int screenY = window.getBounds().y;
int h = window.getBounds().height;
int w = window.getBounds().width;
robot.delay(500);
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(1500);
window.setBounds(screenX, screenY, w, h);
window.setVisible(true);
robot.delay(1500);
});
if (!iconifyingActionCalled || !iconifyingActionDetected) {
passed = false;
System.out.println("Error: iconifying action was not detected");
}
if (!passed) {
String path = ScreenShotHelpers.storeScreenshot("minimizing-window-test-" + window.getName(), image);
System.out.println("Screenshot stored in " + path);
}
}
};
}

View File

@@ -0,0 +1,188 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.List;
/*
* @test
* @summary Verify mouse events on custom title bar area
* @requires (os.family == "windows" | os.family == "mac")
* @run main MouseEventsOnClientArea
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main MouseEventsOnClientArea -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class MouseEventsOnClientArea {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), mouseClicks);
if (!status) {
throw new RuntimeException("MouseEventsOnClientArea FAILED");
}
}
private static final Task mouseClicks = new Task("mouseClicks") {
private static final List<Integer> BUTTON_MASKS = List.of(
InputEvent.BUTTON1_DOWN_MASK,
InputEvent.BUTTON2_DOWN_MASK,
InputEvent.BUTTON3_DOWN_MASK
);
private static final int PANEL_WIDTH = 400;
private static final int PANEL_HEIGHT = (int) TestUtils.TITLE_BAR_HEIGHT;
private final boolean[] buttonsPressed = new boolean[BUTTON_MASKS.size()];
private final boolean[] buttonsReleased = new boolean[BUTTON_MASKS.size()];
private final boolean[] buttonsClicked = new boolean[BUTTON_MASKS.size()];
private boolean mouseEntered;
private boolean mouseExited;
private Panel panel;
@Override
protected void init() {
Arrays.fill(buttonsPressed, false);
Arrays.fill(buttonsReleased, false);
Arrays.fill(buttonsClicked, false);
mouseEntered = false;
mouseExited = false;
}
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
protected void customizeWindow() {
panel = new Panel() {
@Override
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(Color.CYAN);
g.fillRect(r.x, r.y, PANEL_WIDTH, PANEL_HEIGHT);
super.paint(g);
}
};
panel.setBounds(0, 0, PANEL_WIDTH, PANEL_HEIGHT);
panel.setSize(PANEL_WIDTH, PANEL_HEIGHT);
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() >= 1 && e.getButton() <= 3) {
buttonsClicked[e.getButton() - 1] = true;
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() >= 1 && e.getButton() <= 3) {
buttonsPressed[e.getButton() - 1] = true;
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() >= 1 && e.getButton() <= 3) {
buttonsReleased[e.getButton() - 1] = true;
}
}
@Override
public void mouseEntered(MouseEvent e) {
mouseEntered = true;
}
@Override
public void mouseExited(MouseEvent e) {
mouseExited = true;
}
});
window.add(panel);
}
@Override
public void test() throws AWTException {
Robot robot = new Robot();
BUTTON_MASKS.forEach(mask -> {
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() / 2,
panel.getLocationOnScreen().y + panel.getHeight() / 2);
robot.mousePress(mask);
robot.mouseRelease(mask);
robot.delay(500);
});
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() / 2,
panel.getLocationOnScreen().y + panel.getHeight() / 2);
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() + 10,
panel.getLocationOnScreen().y + panel.getWidth() + 10);
robot.delay(500);
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
System.out.println("Button mask: " + BUTTON_MASKS.get(i));
System.out.println("pressed = " + buttonsPressed[i]);
System.out.println("released = " + buttonsReleased[i]);
System.out.println("clicked = " + buttonsClicked[i]);
passed = buttonsPressed[i] && buttonsReleased[i] && buttonsClicked[i];
}
if (!mouseEntered) {
System.out.println("Error: mouse enter wasn't detected");
passed = false;
}
if (!mouseExited) {
System.out.println("Error: mouse exit wasn't detected");
passed = false;
}
}
};
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.Task;
import util.ScreenShotHelpers;
import util.TestUtils;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Verify a property to change visibility of native controls
* @requires (os.family == "windows" | os.family == "mac")
* @run main NativeControlsVisibilityTest
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main NativeControlsVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class NativeControlsVisibilityTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibleControls);
if (!status) {
throw new RuntimeException("NativeControlsVisibilityTest FAILED");
}
}
private static final Task visibleControls = new Task("Visible native controls") {
private static final String PROPERTY_NAME = "controls.visible";
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void test() throws Exception {
Robot robot = new Robot();
robot.delay(500);
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
window.getLocationOnScreen().y + window.getHeight() / 2);
robot.delay(500);
passed = passed && TestUtils.checkTitleBarHeight(titleBar, TestUtils.TITLE_BAR_HEIGHT);
passed = passed && TestUtils.checkFrameInsets(window);
if (titleBar.getLeftInset() == 0 && titleBar.getRightInset() == 0) {
passed = false;
System.out.println("Left or right inset must be non-zero");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
// List<Rect> foundControls = ScreenShotHelpers.detectControls(image, (int) titleBar.getHeight(),
// (int) titleBar.getLeftInset(), (int) titleBar.getRightInset());
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
System.out.println("Found controls at the title bar:");
foundControls.forEach(System.out::println);
if (foundControls.size() != 3) {
passed = false;
System.out.println("Error: there are must be 3 controls");
}
if (!passed) {
String path = ScreenShotHelpers.storeScreenshot("visible-controls-test-" + window.getName(), image);
System.out.println("Screenshot stored in " + path);
}
}
};
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.RectCoordinates;
import util.Task;
import util.ScreenShotHelpers;
import util.TestUtils;
import java.awt.Dimension;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
/*
* @test
* @summary Verify custom title bar in case of window resizing
* @requires (os.family == "windows" | os.family == "mac")
* @run main WindowResizeTest
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main WindowResizeTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class WindowResizeTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), windowResizeTest);
if (!status) {
throw new RuntimeException("WindowResizeTest FAILED");
}
}
private static final Task windowResizeTest = new Task("Window resize test") {
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void test() throws Exception {
Robot robot = new Robot();
robot.delay(1000);
final float initialTitleBarHeight = titleBar.getHeight();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final int newHeight = screenSize.height / 2;
final int newWidth = screenSize.width / 2;
window.setSize(newWidth, newHeight);
robot.delay(1000);
if (titleBar.getHeight() != initialTitleBarHeight) {
passed = false;
System.out.println("Error: title bar height has been changed");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
RectCoordinates coords = ScreenShotHelpers.findRectangleTitleBar(image, (int) titleBar.getHeight());
System.out.println("Planned title bar rectangle coordinates: (" + coords.x1() + ", " + coords.y1() +
"), (" + coords.x2() + ", " + coords.y2() + ")");
System.out.println("w = " + image.getWidth() + " h = " + image.getHeight());
}
};
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TestUtils;
import java.awt.Robot;
/*
* @test
* @summary Verify custom title bar in case of changing visibility of a window
* @requires (os.family == "windows" | os.family == "mac")
* @run main WindowVisibilityTest
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main WindowVisibilityTest -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class WindowVisibilityTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibilityTest);
if (!status) {
throw new RuntimeException("WindowVisibilityTest FAILED");
}
}
private static final Task visibilityTest = new Task("visibilityTest") {
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
}
@Override
public void test() throws Exception {
Robot robot = new Robot();
final float titleBarHeight = titleBar.getHeight();
window.setVisible(false);
robot.delay(1000);
window.setVisible(true);
robot.delay(1000);
if (titleBarHeight != titleBar.getHeight()) {
passed = false;
System.out.println("Error: title bar height has been changed");
}
if (!titleBar.getContainingWindow().equals(window)) {
passed = false;
System.out.println("Error: wrong containing window");
}
}
};
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import java.awt.Color;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.util.List;
/*
* @test
* @summary Verify a property to change visibility of native controls
* @requires os.family == "windows"
* @run main WindowsControlWidthTest
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
* @run main WindowsControlWidthTest -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0
*/
public class WindowsControlWidthTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), nativeControlsWidth);
if (!status) {
throw new RuntimeException("WindowsControlWidthTest FAILED");
}
}
private static final Task nativeControlsWidth = new Task("Native controls width") {
private static final String WIDTH_PROPERTY = "controls.width";
private static final int CONTROLS_WIDTH = 80;
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
titleBar.putProperty(WIDTH_PROPERTY, CONTROLS_WIDTH);
}
@Override
public void test() throws Exception {
passed = passed && TestUtils.checkTitleBarHeight(titleBar, TestUtils.TITLE_BAR_HEIGHT);
passed = passed && TestUtils.checkFrameInsets(window);
if (titleBar.getLeftInset() == 0 && titleBar.getRightInset() == 0) {
passed = false;
System.out.println("Left or right inset must be non-zero");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
foundControls.forEach(control -> {
System.out.println("Detected control: " + control);
int calculatedWidth = control.getY2() - control.getY1();
System.out.println("Calculated width: " + calculatedWidth);
float diff = (float) calculatedWidth / (float) (control.getX2() - control.getX1());
if (diff < 0.9 || diff > 1.1) {
System.out.println("Error: control's width is much differ than the expected value");
passed = false;
}
});
}
};
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import com.jetbrains.WindowDecorations;
import java.awt.Window;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
public class CommonAPISuite {
public static boolean runTestSuite(List<Function<WindowDecorations.CustomTitleBar, Window>> functions, Task task) {
AtomicBoolean testPassed = new AtomicBoolean(true);
functions.forEach(function -> testPassed.set(testPassed.get() && task.run(function)));
return testPassed.get();
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.awt.Color;
import java.util.Objects;
public class Rect {
private int x1 = -1;
private int y1 = -1;
private int x2 = -1;
private int y2 = -1;
private int pixelCount = 0;
private final Color commonColor;
public Rect(Color commonColor) {
this.commonColor = commonColor;
}
public Rect(int x1, int y1, int x2, int y2, int pixelCount, Color commonColor) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.pixelCount = pixelCount;
this.commonColor = commonColor;
}
public int getX1() {
return x1;
}
public int getY1() {
return y1;
}
public int getX2() {
return x2;
}
public int getY2() {
return y2;
}
public void addPoint(int x, int y) {
pixelCount++;
if (x1 == -1 || x2 == -1) {
x1 = x;
x2 = x;
}
if (y1 == -1 || y2 == -1) {
y1 = y;
y2 = y;
}
if (x < x1) x1 = x;
if (x > x2) x2 = x;
if (y < y1) y1 = y;
if (y > y1) y2 = y;
}
public int getPixelCount() {
return pixelCount;
}
public Color getCommonColor() {
return commonColor;
}
@Override
public String toString() {
return "Rect{" +
"x1=" + x1 +
", y1=" + y1 +
", x2=" + x2 +
", y2=" + y2 +
", pixelCount=" + pixelCount +
", commonColor=" + commonColor +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Rect rect = (Rect) o;
return x1 == rect.x1 && y1 == rect.y1 && x2 == rect.x2 && y2 == rect.y2;
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
public record RectCoordinates(int x1, int y1, int x2, int y2) {
}

View File

@@ -0,0 +1,243 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import javax.imageio.ImageIO;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
public class ScreenShotHelpers {
public static BufferedImage takeScreenshot(Window window) throws AWTException {
Robot robot = new Robot();
robot.delay(1000);
final BufferedImage screenShot = robot.createScreenCapture(
new Rectangle(window.getLocationOnScreen().x, window.getLocationOnScreen().y,
window.getWidth(), window.getHeight()));
return screenShot;
}
public static String storeScreenshot(String namePrefix, BufferedImage image) throws IOException {
final String fileName = String.format("%s-%s.png", namePrefix, UUID.randomUUID());
File file = new File(fileName);
ImageIO.write(image, "png", file);
return file.getAbsolutePath();
}
public static RectCoordinates findRectangleTitleBar(BufferedImage image, int titleBarHeight) {
int centerX = image.getWidth() / 2;
int centerY = titleBarHeight / 2;
final Color centerColor = adjustColor(new Color(image.getRGB(centerX, centerY)));
int startY = centerY;
for (int y = centerY; y >= 0; y--) {
Color adjustedColor = adjustColor(new Color(image.getRGB(centerX, y)));
if (!adjustedColor.equals(centerColor)) {
startY = y + 1;
break;
}
}
int endY = centerY;
for (int y = centerY; y <= (int) TestUtils.TITLE_BAR_HEIGHT; y++) {
Color adjustedColor = adjustColor(new Color(image.getRGB(centerX, y)));
if (!adjustedColor.equals(centerColor)) {
endY = y - 1;
break;
}
}
int startX = centerX;
for (int x = centerX; x >= 0; x--) {
Color adjustedColor = adjustColor(new Color(image.getRGB(x, startY)));
if (!adjustedColor.equals(centerColor)) {
startX = x + 1;
break;
}
}
int endX = centerX;
for (int x = centerX; x < image.getWidth(); x++) {
Color adjustedColor = adjustColor(new Color(image.getRGB(x, startY)));
if (!adjustedColor.equals(centerColor)) {
endX = x - 1;
break;
}
}
return new RectCoordinates(startX, startY, endX, endY);
}
public static List<Rect> detectControlsByBackground(BufferedImage image, int titleBarHeight, Color backgroundColor) {
RectCoordinates coords = findRectangleTitleBar(image, titleBarHeight);
List<Rect> result = new ArrayList<>();
System.out.println(coords);
List<Integer> lefts = new ArrayList<>();
List<Integer> rights = new ArrayList<>();
int leftX = -1;
int rightX = -1;
for (int x = coords.x1(); x <= coords.x2(); x++) {
boolean isBackground = true;
for (int y = coords.y1(); y <= coords.y2(); y++) {
Color color = adjustColor(new Color(image.getRGB(x, y)));
if (!color.equals(backgroundColor)) {
isBackground = false;
break;
}
}
if (!isBackground) {
if (leftX == -1) {
leftX = x;
}
rightX = x;
} else if (leftX != -1) {
lefts.add(leftX);
rights.add(rightX);
leftX = -1;
rightX = -1;
}
}
for (int i = 0; i < lefts.size(); i++) {
int lx = lefts.get(i);
int rx = rights.get(i);
System.out.println("lx = " + lx + " rx = " + rx);
result.add(new Rect(lx, coords.y1(), rx, coords.y2(), 0, Color.BLACK));
}
return result;
}
public static List<Rect> detectControls(BufferedImage image, int titleBarHeight, int leftInset, int rightInset) {
RectCoordinates coords = ScreenShotHelpers.findRectangleTitleBar(image, titleBarHeight);
Map<Color, Rect> map = new HashMap<>();
for (int x = coords.x1(); x <= coords.x2(); x++) {
for (int y = coords.y1(); y <= coords.y2(); y++) {
Color color = new Color(image.getRGB(x, y));
Color adjustedColor = adjustColor(color);
Rect rect = map.getOrDefault(adjustedColor, new Rect(adjustedColor));
rect.addPoint(x, y);
map.put(adjustedColor, rect);
}
}
int checkedHeight = coords.y2() - coords.y1() + 1;
int checkedWidth = coords.x2() - coords.x1() + 1;
int pixels = checkedWidth * checkedHeight;
int nonCoveredAreaApprox = pixels - (leftInset * checkedHeight + rightInset * checkedHeight);
List<Rect> rects = map.values().stream().filter(v -> v.getPixelCount() < nonCoveredAreaApprox).toList();
return groupRects(rects);
}
private static List<Rect> groupRects(List<Rect> rects) {
List<Rect> found = new ArrayList<>();
List<Rect> items = new ArrayList<>(rects);
while (!items.isEmpty()) {
AtomicReference<Rect> rect = new AtomicReference<>(items.remove(0));
List<Rect> restItems = new ArrayList<>();
items.forEach(item -> {
Rect intersected = intersect(rect.get(), item);
if (intersected != null) {
rect.set(intersected);
} else {
restItems.add(item);
}
});
found.add(rect.get());
items = restItems;
}
return found;
}
private static Color adjustColor(Color color) {
int r = adjustValue(color.getRed());
int g = adjustValue(color.getGreen());
int b = adjustValue(color.getBlue());
return new Color(r, g, b);
}
private static int adjustValue(int value) {
final int round = 64;
int div = (value + 1) / round;
int mod = (value + 1) % round;
int result = div > 0 ? round * div - 1 : 0;
if (mod > 32) result += round;
return result;
}
private static Rect intersect(Rect r1, Rect r2) {
int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
if (r1.getX1() <= r2.getX1() && r2.getX1() <= r1.getX2()) {
x1 = r1.getX1();
x2 = Math.max(r2.getX2(), r1.getX2());
}
if (r2.getX1() <= r1.getX1() && r1.getX1() <= r2.getX2()) {
x1 = r2.getX1();
x2 = Math.max(r2.getX2(), r1.getX2());
}
if (r1.getY1() < r2.getY1() && r2.getY1() <= r2.getY1()) {
y1 = r1.getY1();
y2 = Math.max(r1.getY2(), r2.getY2());
}
if (r2.getY1() <= r1.getY1() && r1.getY1() <= r2.getY2()) {
y1 = r2.getY1();
y2 = Math.max(r1.getY2(), r2.getY2());
}
if (x1 == -1 || x2 == -1 || y1 == -1 || y2 == -1) {
return null;
}
Color commonColor = r1.getPixelCount() > r2.getPixelCount() ? r1.getCommonColor() : r2.getCommonColor();
return new Rect(x1, y1, x2, y2, r1.getPixelCount() + r2.getPixelCount(), commonColor);
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import com.jetbrains.WindowDecorations;
import java.awt.*;
import java.util.function.Function;
abstract public class Task {
private final String name;
protected WindowDecorations.CustomTitleBar titleBar;
protected Window window;
protected boolean passed = true;
protected Robot robot;
public Task(String name) {
this.name = name;
}
public final boolean run(Function<WindowDecorations.CustomTitleBar, Window> windowCreator) {
try {
robot = new Robot();
} catch (AWTException e) {
System.out.println("ERROR: unable to initialize robot");
e.printStackTrace();
return false;
}
init();
System.out.printf("RUN TEST CASE: %s%n", name);
passed = true;
prepareTitleBar();
window = windowCreator.apply(titleBar);
System.out.println("Created a window with the custom title bar. Window name: " + window.getName());
customizeWindow();
window.setVisible(true);
try {
test();
} catch (Exception e) {
System.out.println("ERROR: An error occurred during tests execution");
e.printStackTrace();
passed = false;
}
cleanup();
titleBar = null;
window.dispose();
if (passed) {
System.out.println("State: PASSED");
} else {
System.out.println("State: FAILED");
}
return passed;
}
protected void init() {
}
protected void cleanup() {
}
abstract public void prepareTitleBar();
protected void customizeWindow() {
}
abstract public void test() throws Exception;
}

View File

@@ -0,0 +1,173 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.util.List;
import java.util.function.Function;
public class TestUtils {
public static final float TITLE_BAR_HEIGHT = 100;
public static final Color TITLE_BAR_COLOR = Color.BLUE;
public static final int DEFAULT_LOCATION_X = 100;
public static final int DEFAULT_LOCATION_Y = 100;
private static final int DEFAULT_WIDTH = 1200;
private static final int DEFAULT_HEIGHT = 600;
private static final List<Function<WindowDecorations.CustomTitleBar, Window>> windowCreationFunctions = List.of(
TestUtils::createJFrameWithCustomTitleBar,
TestUtils::createFrameWithCustomTitleBar,
TestUtils::createJDialogWithCustomTitleBar,
TestUtils::createDialogWithCustomTitleBar
);
public static boolean checkTitleBarHeight(WindowDecorations.CustomTitleBar titleBar, float expected) {
if (titleBar.getHeight() != expected) {
System.out.printf(String.format("Wrong title bar height. Actual = %f, expected = %d\n", titleBar.getHeight(), expected));
return false;
}
return true;
}
public static boolean checkFrameInsets(Window window) {
Insets insets = window.getInsets();
if (insets.top != 0) {
System.out.println("Frame top inset must be zero, but got " + insets.top);
return false;
}
return true;
}
public static List<Function<WindowDecorations.CustomTitleBar, Window>> getWindowCreationFunctions() {
return windowCreationFunctions;
}
public static Frame createFrameWithCustomTitleBar(WindowDecorations.CustomTitleBar titleBar) {
Frame frame = new Frame(){
@Override
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(TITLE_BAR_COLOR);
g.fillRect(r.x, r.y, r.width, (int) TITLE_BAR_HEIGHT);
}
};
frame.setName("Frame");
frame.setTitle("Frame");
frame.setBounds(calculateWindowBounds(frame));
JBR.getWindowDecorations().setCustomTitleBar(frame, titleBar);
return frame;
}
public static JFrame createJFrameWithCustomTitleBar(WindowDecorations.CustomTitleBar titleBar) {
JFrame frame = new JFrame();
frame.setContentPane(new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Rectangle r = g.getClipBounds();
g.setColor(Color.BLUE);
g.fillRect(r.x, r.y, r.width, 100);
}
});
frame.setName("JFrame");
frame.setTitle("JFrame");
frame.setBounds(calculateWindowBounds(frame));
JBR.getWindowDecorations().setCustomTitleBar(frame, titleBar);
return frame;
}
public static Dialog createDialogWithCustomTitleBar(WindowDecorations.CustomTitleBar titleBar) {
Dialog dialog = new Dialog((Frame) null){
@Override
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(TITLE_BAR_COLOR);
g.fillRect(r.x, r.y, r.width, (int) TITLE_BAR_HEIGHT);
}
};
dialog.setName("Dialog");
dialog.setTitle("Dialog");
dialog.setBounds(calculateWindowBounds(dialog));
JBR.getWindowDecorations().setCustomTitleBar(dialog, titleBar);
return dialog;
}
public static JDialog createJDialogWithCustomTitleBar(WindowDecorations.CustomTitleBar titleBar) {
JDialog dialog = new JDialog();
dialog.setContentPane(new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Rectangle r = g.getClipBounds();
g.setColor(TITLE_BAR_COLOR);
g.fillRect(r.x, r.y, r.width, (int) TITLE_BAR_HEIGHT);
}
});
dialog.setName("JDialog");
dialog.setTitle("JDialog");
dialog.setBounds(calculateWindowBounds(dialog));
JBR.getWindowDecorations().setCustomTitleBar(dialog, titleBar);
return dialog;
}
private static Rectangle calculateWindowBounds(Window window) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets scnMax = Toolkit.getDefaultToolkit().
getScreenInsets(window.getGraphicsConfiguration());
int maxHeight = screenSize.height - scnMax.top - scnMax.bottom;
int maxWidth = screenSize.width - scnMax.left - scnMax.right;
return new Rectangle(scnMax.left + 2, scnMax.top + 2, (int) (maxWidth * 0.8), (int) (maxHeight * 0.8));
}
}