modules/graphics/src/main/java/javafx/stage/Screen.java
Print this page
*** 30,40 ****
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Rectangle2D;
- import com.sun.javafx.stage.ScreenHelper;
import com.sun.javafx.tk.ScreenConfigurationAccessor;
import com.sun.javafx.tk.Toolkit;
/**
* Describes the characteristics of a graphics destination such as monitor.
--- 30,39 ----
*** 70,83 ****
FXCollections.<Screen>observableArrayList();
private static final ObservableList<Screen> unmodifiableScreens =
FXCollections.unmodifiableObservableList(screens);
static {
- ScreenHelper.setScreenAccessor(new ScreenHelper.ScreenAccessor() {
- @Override public float getRenderScale(Screen screen) { return screen.getRenderScale(); }
- });
-
accessor = Toolkit.getToolkit().setScreenConfigurationListener(() -> updateConfiguration());
}
private Screen() {
}
--- 69,78 ----
*** 136,163 ****
int visualMinX = accessor.getVisualMinX(obj);
int visualMinY = accessor.getVisualMinY(obj);
int visualWidth = accessor.getVisualWidth(obj);
int visualHeight = accessor.getVisualHeight(obj);
double dpi = accessor.getDPI(obj);
! float renderScale = accessor.getRenderScale(obj);
if ((screen == null) ||
(screen.bounds.getMinX() != minX) ||
(screen.bounds.getMinY() != minY) ||
(screen.bounds.getWidth() != width) ||
(screen.bounds.getHeight() != height) ||
(screen.visualBounds.getMinX() != visualMinX) ||
(screen.visualBounds.getMinY() != visualMinY) ||
(screen.visualBounds.getWidth() != visualWidth) ||
(screen.visualBounds.getHeight() != visualHeight) ||
(screen.dpi != dpi) ||
! (screen.renderScale != renderScale))
{
Screen s = new Screen();
s.bounds = new Rectangle2D(minX, minY, width, height);
s.visualBounds = new Rectangle2D(visualMinX, visualMinY, visualWidth, visualHeight);
s.dpi = dpi;
! s.renderScale = renderScale;
return s;
} else {
return null;
}
}
--- 131,161 ----
int visualMinX = accessor.getVisualMinX(obj);
int visualMinY = accessor.getVisualMinY(obj);
int visualWidth = accessor.getVisualWidth(obj);
int visualHeight = accessor.getVisualHeight(obj);
double dpi = accessor.getDPI(obj);
! float outScaleX = accessor.getRecommendedOutputScaleX(obj);
! float outScaleY = accessor.getRecommendedOutputScaleY(obj);
if ((screen == null) ||
(screen.bounds.getMinX() != minX) ||
(screen.bounds.getMinY() != minY) ||
(screen.bounds.getWidth() != width) ||
(screen.bounds.getHeight() != height) ||
(screen.visualBounds.getMinX() != visualMinX) ||
(screen.visualBounds.getMinY() != visualMinY) ||
(screen.visualBounds.getWidth() != visualWidth) ||
(screen.visualBounds.getHeight() != visualHeight) ||
(screen.dpi != dpi) ||
! (screen.outputScaleX != outScaleX) ||
! (screen.outputScaleY != outScaleY))
{
Screen s = new Screen();
s.bounds = new Rectangle2D(minX, minY, width, height);
s.visualBounds = new Rectangle2D(visualMinX, visualMinY, visualWidth, visualHeight);
s.dpi = dpi;
! s.outputScaleX = outScaleX;
! s.outputScaleY = outScaleY;
return s;
} else {
return null;
}
}
*** 237,246 ****
--- 235,248 ----
* The bounds of this {@code Screen}.
*/
private Rectangle2D bounds = Rectangle2D.EMPTY;
/**
* Gets the bounds of this {@code Screen}.
+ * The bounds will be reported adjusted for the {@code outputScale} so
+ * that resizing a {@code Window} with these bounds and the same
+ * {@code outputScale} as this {@code Screen} will cover the entire
+ * screen.
* @return The bounds of this {@code Screen}
*/
public final Rectangle2D getBounds() {
return bounds;
}
*** 274,294 ****
public final double getDpi() {
return dpi;
}
/**
! * The scale factor of this {@code Screen}.
*/
! private float renderScale;
/**
! * Gets the scale factor of this {@code Screen}.
! * E.g. on Retina displays on Mac the scale factor may be equal to 2.0.
! * On regular displays this method returns 1.0.
*/
! private float getRenderScale() {
! return renderScale;
}
/**
* Returns a hash code for this {@code Screen} object.
* @return a hash code for this {@code Screen} object.
--- 276,318 ----
public final double getDpi() {
return dpi;
}
/**
! * The recommended output scale factor of this {@code Screen} in the
! * X direction.
! */
! private float outputScaleX;
!
! /**
! * Gets the recommended output scale factor of this {@code Screen} in
! * the horizontal ({@code X}) direction.
! * This scale factor should be applied to a scene in order to compensate
! * for the resolution and viewing distance of the output device.
! * The visual bounds will be reported relative to this scale factor.
! * @return the recommended output scale factor for the screen.
! */
! public final double getOutputScaleX() {
! return outputScaleX;
! }
!
! /**
! * The recommended output scale factor of this {@code Screen} in the
! * Y direction.
*/
! private float outputScaleY;
/**
! * Gets the recommended output scale factor of this {@code Screen} in
! * the vertical ({@code Y}) direction.
! * This scale factor will be applied to the scene in order to compensate
! * for the resolution and viewing distance of the output device.
! * The visual bounds will be reported relative to this scale factor.
! * @return the recommended output scale factor for the screen.
*/
! public final double getOutputScaleY() {
! return outputScaleY;
}
/**
* Returns a hash code for this {@code Screen} object.
* @return a hash code for this {@code Screen} object.
*** 296,306 ****
@Override public int hashCode() {
long bits = 7L;
bits = 37L * bits + bounds.hashCode();
bits = 37L * bits + visualBounds.hashCode();
bits = 37L * bits + Double.doubleToLongBits(dpi);
! bits = 37L * bits + Float.floatToIntBits(renderScale);
return (int) (bits ^ (bits >> 32));
}
/**
* Indicates whether some other object is "equal to" this one.
--- 320,331 ----
@Override public int hashCode() {
long bits = 7L;
bits = 37L * bits + bounds.hashCode();
bits = 37L * bits + visualBounds.hashCode();
bits = 37L * bits + Double.doubleToLongBits(dpi);
! bits = 37L * bits + Float.floatToIntBits(outputScaleX);
! bits = 37L * bits + Float.floatToIntBits(outputScaleY);
return (int) (bits ^ (bits >> 32));
}
/**
* Indicates whether some other object is "equal to" this one.
*** 312,328 ****
if (obj instanceof Screen) {
Screen other = (Screen) obj;
return (bounds == null ? other.bounds == null : bounds.equals(other.bounds))
&& (visualBounds == null ? other.visualBounds == null : visualBounds.equals(other.visualBounds))
&& other.dpi == dpi
! && other.renderScale == renderScale;
} else return false;
}
/**
* Returns a string representation of this {@code Screen} object.
* @return a string representation of this {@code Screen} object.
*/
@Override public String toString() {
! return super.toString() + " bounds:" + bounds + " visualBounds:" + visualBounds + " dpi:" + dpi + " renderScale:" + renderScale;
}
}
--- 337,354 ----
if (obj instanceof Screen) {
Screen other = (Screen) obj;
return (bounds == null ? other.bounds == null : bounds.equals(other.bounds))
&& (visualBounds == null ? other.visualBounds == null : visualBounds.equals(other.visualBounds))
&& other.dpi == dpi
! && other.outputScaleX == outputScaleX && other.outputScaleY == outputScaleY;
} else return false;
}
/**
* Returns a string representation of this {@code Screen} object.
* @return a string representation of this {@code Screen} object.
*/
@Override public String toString() {
! return super.toString() + " bounds:" + bounds + " visualBounds:" + visualBounds + " dpi:"
! + dpi + " outputScale:(" + outputScaleX + "," + outputScaleY + ")";
}
}