< prev index next >

src/java.desktop/share/classes/sun/swing/SwingUtilities2.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -59,10 +59,11 @@
 import java.security.PrivilegedAction;
 import java.util.*;
 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;
 import java.util.concurrent.FutureTask;
 

@@ -2268,10 +2269,31 @@
 
         return current;
     }
 
     /**
+     * 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 {
         void repaintPerformed(JComponent c, int x, int y, int w, int h);
     }
< prev index next >