modules/swing/src/main/java/javafx/embed/swing/SwingNode.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* 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. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* 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. Oracle designates this
*** 277,286 ****
--- 277,302 ----
}
}
private List<Runnable> peerRequests = new ArrayList<>();
+ private static float getPlatformScaleX(Window win) {
+ return WindowHelper.getWindowAccessor().getPlatformScaleX(win);
+ }
+
+ private static float getPlatformScaleY(Window win) {
+ return WindowHelper.getWindowAccessor().getPlatformScaleY(win);
+ }
+
+ private float getPlatformScaleX() {
+ return getPlatformScaleX(getScene().getWindow());
+ }
+
+ private float getPlatformScaleY() {
+ return getPlatformScaleY(getScene().getWindow());
+ }
+
/*
* Called on EDT
*/
void setImageBuffer(final int[] data,
final int x, final int y,
*** 288,300 ****
final int linestride,
final int scale)
{
Runnable r = () -> {
Window win = getScene().getWindow();
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(win);
peer.setImageBuffer(IntBuffer.wrap(data), x, y, w, h,
! w / uiScale, h / uiScale, linestride, scale);
};
SwingFXUtils.runOnFxThread(() -> {
if (peer != null) {
r.run();
} else {
--- 304,317 ----
final int linestride,
final int scale)
{
Runnable r = () -> {
Window win = getScene().getWindow();
! float uiScaleX = getPlatformScaleX(win);
! float uiScaleY = getPlatformScaleY(win);
peer.setImageBuffer(IntBuffer.wrap(data), x, y, w, h,
! w / uiScaleX, h / uiScaleY, linestride, scale);
};
SwingFXUtils.runOnFxThread(() -> {
if (peer != null) {
r.run();
} else {
*** 308,319 ****
* Called on EDT
*/
void setImageBounds(final int x, final int y, final int w, final int h) {
Runnable r = () -> {
Window win = getScene().getWindow();
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(win);
! peer.setImageBounds(x, y, w, h, w / uiScale, h / uiScale);
};
SwingFXUtils.runOnFxThread(() -> {
if (peer != null) {
r.run();
} else {
--- 325,337 ----
* Called on EDT
*/
void setImageBounds(final int x, final int y, final int w, final int h) {
Runnable r = () -> {
Window win = getScene().getWindow();
! float uiScaleX = getPlatformScaleX(win);
! float uiScaleY = getPlatformScaleY(win);
! peer.setImageBounds(x, y, w, h, w / uiScaleX, h / uiScaleY);
};
SwingFXUtils.runOnFxThread(() -> {
if (peer != null) {
r.run();
} else {
*** 375,442 ****
*
* @return the preferred width that the node should be resized to during layout
*/
@Override
public double prefWidth(double height) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingPrefWidth / uiScale;
}
/**
* Returns the {@code SwingNode}'s preferred height for use in layout calculations.
* This value corresponds to the preferred height of the Swing component.
*
* @return the preferred height that the node should be resized to during layout
*/
@Override
public double prefHeight(double width) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingPrefHeight / uiScale;
}
/**
* Returns the {@code SwingNode}'s maximum width for use in layout calculations.
* This value corresponds to the maximum width of the Swing component.
*
* @return the maximum width that the node should be resized to during layout
*/
@Override public double maxWidth(double height) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingMaxWidth / uiScale;
}
/**
* Returns the {@code SwingNode}'s maximum height for use in layout calculations.
* This value corresponds to the maximum height of the Swing component.
*
* @return the maximum height that the node should be resized to during layout
*/
@Override public double maxHeight(double width) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingMaxHeight / uiScale;
}
/**
* Returns the {@code SwingNode}'s minimum width for use in layout calculations.
* This value corresponds to the minimum width of the Swing component.
*
* @return the minimum width that the node should be resized to during layout
*/
@Override public double minWidth(double height) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingMinWidth / uiScale;
}
/**
* Returns the {@code SwingNode}'s minimum height for use in layout calculations.
* This value corresponds to the minimum height of the Swing component.
*
* @return the minimum height that the node should be resized to during layout
*/
@Override public double minHeight(double width) {
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(getScene().getWindow());
! return swingMinHeight / uiScale;
}
/**
* @treatAsPrivate implementation detail
* @deprecated This is an internal API that is not intended for use and will be removed in the next version
--- 393,454 ----
*
* @return the preferred width that the node should be resized to during layout
*/
@Override
public double prefWidth(double height) {
! return swingPrefWidth / getPlatformScaleX();
}
/**
* Returns the {@code SwingNode}'s preferred height for use in layout calculations.
* This value corresponds to the preferred height of the Swing component.
*
* @return the preferred height that the node should be resized to during layout
*/
@Override
public double prefHeight(double width) {
! return swingPrefHeight / getPlatformScaleY();
}
/**
* Returns the {@code SwingNode}'s maximum width for use in layout calculations.
* This value corresponds to the maximum width of the Swing component.
*
* @return the maximum width that the node should be resized to during layout
*/
@Override public double maxWidth(double height) {
! return swingMaxWidth / getPlatformScaleX();
}
/**
* Returns the {@code SwingNode}'s maximum height for use in layout calculations.
* This value corresponds to the maximum height of the Swing component.
*
* @return the maximum height that the node should be resized to during layout
*/
@Override public double maxHeight(double width) {
! return swingMaxHeight / getPlatformScaleY();
}
/**
* Returns the {@code SwingNode}'s minimum width for use in layout calculations.
* This value corresponds to the minimum width of the Swing component.
*
* @return the minimum width that the node should be resized to during layout
*/
@Override public double minWidth(double height) {
! return swingMinWidth / getPlatformScaleX();
}
/**
* Returns the {@code SwingNode}'s minimum height for use in layout calculations.
* This value corresponds to the minimum height of the Swing component.
*
* @return the minimum height that the node should be resized to during layout
*/
@Override public double minHeight(double width) {
! return swingMinHeight / getPlatformScaleY();
}
/**
* @treatAsPrivate implementation detail
* @deprecated This is an internal API that is not intended for use and will be removed in the next version
*** 493,512 ****
}
private void addWindowListeners(final Window window) {
window.xProperty().addListener(locationListener);
window.yProperty().addListener(locationListener);
window.addEventHandler(FocusUngrabEvent.FOCUS_UNGRAB, ungrabHandler);
window.showingProperty().addListener(windowVisibleListener);
! this.scale = Math.round(WindowHelper.getWindowAccessor().getRenderScale(window));
setLwFrameScale(this.scale);
}
private void removeWindowListeners(final Window window) {
window.xProperty().removeListener(locationListener);
window.yProperty().removeListener(locationListener);
window.removeEventHandler(FocusUngrabEvent.FOCUS_UNGRAB, ungrabHandler);
window.showingProperty().removeListener(windowVisibleListener);
}
/**
--- 505,531 ----
}
private void addWindowListeners(final Window window) {
window.xProperty().addListener(locationListener);
window.yProperty().addListener(locationListener);
+ window.widthProperty().addListener(locationListener);
+ window.heightProperty().addListener(locationListener);
+ window.renderScaleXProperty().addListener(locationListener);
window.addEventHandler(FocusUngrabEvent.FOCUS_UNGRAB, ungrabHandler);
window.showingProperty().addListener(windowVisibleListener);
! // LW framework should be upgraded to separate X,Y scales...
! this.scale = (int) Math.round(window.getRenderScaleX());
setLwFrameScale(this.scale);
}
private void removeWindowListeners(final Window window) {
window.xProperty().removeListener(locationListener);
window.yProperty().removeListener(locationListener);
+ window.widthProperty().removeListener(locationListener);
+ window.heightProperty().removeListener(locationListener);
+ window.renderScaleXProperty().removeListener(locationListener);
window.removeEventHandler(FocusUngrabEvent.FOCUS_UNGRAB, ungrabHandler);
window.showingProperty().removeListener(windowVisibleListener);
}
/**
*** 582,605 ****
|| !getScene().getWindow().isShowing()) {
// Not initialized yet. Skip the update to set the real values later
return;
}
Window w = getScene().getWindow();
! float renderScale = WindowHelper.getWindowAccessor().getRenderScale(w);
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(w);
! int lwScale = Math.round(renderScale);
boolean sendScale = (this.scale != lwScale);
this.scale = lwScale;
final Point2D loc = localToScene(0, 0);
! final int windowX = (int) (w.getX() * uiScale);
! final int windowY = (int) (w.getY() * uiScale);
! final int windowW = (int) (w.getWidth() * uiScale);
! final int windowH = (int) (w.getHeight() * uiScale);
! final int frameX = (int) Math.round((w.getX() + getScene().getX() + loc.getX()) * uiScale);
! final int frameY = (int) Math.round((w.getY() + getScene().getY() + loc.getY()) * uiScale);
! final int frameW = (int) (fxWidth * uiScale);
! final int frameH = (int) (fxHeight * uiScale);
SwingFXUtils.runOnEDT(() -> {
if (lwFrame != null) {
if (sendScale) {
jlfNotifyDisplayChanged.invoke(lwFrame, scale);
--- 601,625 ----
|| !getScene().getWindow().isShowing()) {
// Not initialized yet. Skip the update to set the real values later
return;
}
Window w = getScene().getWindow();
! float renderScaleX = (float) w.getRenderScaleX();
! float uiScaleX = getPlatformScaleX(w);
! float uiScaleY = getPlatformScaleY(w);
! int lwScale = Math.round(renderScaleX);
boolean sendScale = (this.scale != lwScale);
this.scale = lwScale;
final Point2D loc = localToScene(0, 0);
! final int windowX = (int) (w.getX() * uiScaleX);
! final int windowY = (int) (w.getY() * uiScaleY);
! final int windowW = (int) (w.getWidth() * uiScaleX);
! final int windowH = (int) (w.getHeight() * uiScaleY);
! final int frameX = (int) Math.round((w.getX() + getScene().getX() + loc.getX()) * uiScaleX);
! final int frameY = (int) Math.round((w.getY() + getScene().getY() + loc.getY()) * uiScaleY);
! final int frameW = (int) (fxWidth * uiScaleX);
! final int frameH = (int) (fxHeight * uiScaleY);
SwingFXUtils.runOnEDT(() -> {
if (lwFrame != null) {
if (sendScale) {
jlfNotifyDisplayChanged.invoke(lwFrame, scale);
*** 879,893 ****
int swingModifiers = SwingEvents.fxMouseModsToMouseMods(event);
boolean swingPopupTrigger = event.isPopupTrigger();
int swingButton = SwingEvents.fxMouseButtonToMouseButton(event);
long swingWhen = System.currentTimeMillis();
Window win = getScene().getWindow();
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(win);
! int relX = (int) Math.round(event.getX() * uiScale);
! int relY = (int) Math.round(event.getY() * uiScale);
! int absX = (int) Math.round(event.getScreenX() * uiScale);
! int absY = (int) Math.round(event.getScreenY() * uiScale);
java.awt.event.MouseEvent mouseEvent =
new java.awt.event.MouseEvent(
frame, swingID, swingWhen, swingModifiers,
relX, relY, absX, absY,
event.getClickCount(), swingPopupTrigger, swingButton);
--- 899,914 ----
int swingModifiers = SwingEvents.fxMouseModsToMouseMods(event);
boolean swingPopupTrigger = event.isPopupTrigger();
int swingButton = SwingEvents.fxMouseButtonToMouseButton(event);
long swingWhen = System.currentTimeMillis();
Window win = getScene().getWindow();
! float uiScaleX = getPlatformScaleX(win);
! float uiScaleY = getPlatformScaleY(win);
! int relX = (int) Math.round(event.getX() * uiScaleX);
! int relY = (int) Math.round(event.getY() * uiScaleY);
! int absX = (int) Math.round(event.getScreenX() * uiScaleX);
! int absY = (int) Math.round(event.getScreenY() * uiScaleY);
java.awt.event.MouseEvent mouseEvent =
new java.awt.event.MouseEvent(
frame, swingID, swingWhen, swingModifiers,
relX, relY, absX, absY,
event.getClickCount(), swingPopupTrigger, swingButton);
*** 927,939 ****
int signum = (int) Math.signum(delta);
if (signum * delta < 1) {
wheelRotation = signum;
}
Window w = getScene().getWindow();
! float uiScale = WindowHelper.getWindowAccessor().getUIScale(w);
! int x = (int) Math.round(fxX * uiScale);
! int y = (int) Math.round(fxY * uiScale);
MouseWheelEvent mouseWheelEvent =
new MouseWheelEvent(source, java.awt.event.MouseEvent.MOUSE_WHEEL,
System.currentTimeMillis(), swingModifiers, x, y, 0, 0,
0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1 , -wheelRotation);
AccessController.doPrivileged(new PostEventAction(mouseWheelEvent));
--- 948,961 ----
int signum = (int) Math.signum(delta);
if (signum * delta < 1) {
wheelRotation = signum;
}
Window w = getScene().getWindow();
! float uiScaleX = getPlatformScaleX(w);
! float uiScaleY = getPlatformScaleY(w);
! int x = (int) Math.round(fxX * uiScaleX);
! int y = (int) Math.round(fxY * uiScaleY);
MouseWheelEvent mouseWheelEvent =
new MouseWheelEvent(source, java.awt.event.MouseEvent.MOUSE_WHEEL,
System.currentTimeMillis(), swingModifiers, x, y, 0, 0,
0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1 , -wheelRotation);
AccessController.doPrivileged(new PostEventAction(mouseWheelEvent));