--- old/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java 2018-05-18 11:43:37.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java 2018-05-18 11:43:37.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2018, 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 @@ -61,6 +61,7 @@ import sun.font.FontDesignMetrics; import sun.font.FontUtilities; import sun.java2d.SunGraphicsEnvironment; +import sun.java2d.pipe.Region; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -2270,6 +2271,27 @@ } /** + * Converts coordinates from the user's space to the device space using + * appropriate device transformation. + * + * @param x coordinate in the user space + * @param y coordinate in the user space + * @return the point which uses device space(pixels) + */ + public static Point convertToDeviceSpace(double x, double y) { + GraphicsConfiguration gc = + GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration(); + gc = getGraphicsConfigurationAtPoint(gc, x, y); + + AffineTransform tx = gc.getDefaultTransform(); + x = Region.clipRound(x * tx.getScaleX()); + y = Region.clipRound(y * tx.getScaleY()); + + return new Point((int) x, (int) y); + } + + /** * Used to listen to "blit" repaints in RepaintManager. */ public interface RepaintListener {