< prev index next >

src/java.desktop/share/classes/sun/java2d/SunGraphicsEnvironment.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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

@@ -31,44 +31,30 @@
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
 import java.awt.Insets;
+import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
-import java.awt.font.TextAttribute;
+import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.awt.peer.ComponentPeer;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FilenameFilter;
 import java.io.InputStreamReader;
-import java.io.IOException;
-import java.text.AttributedCharacterIterator;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.security.AccessController;
 import java.util.Locale;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.TreeMap;
-import java.util.Vector;
-import java.util.concurrent.ConcurrentHashMap;
-import sun.awt.AppContext;
+
 import sun.awt.DisplayChangedListener;
-import sun.awt.FontConfiguration;
 import sun.awt.SunDisplayChanger;
-import sun.font.CompositeFontDescriptor;
-import sun.font.Font2D;
 import sun.font.FontManager;
 import sun.font.FontManagerFactory;
 import sun.font.FontManagerForSGE;
-import sun.font.NativeFont;
-import java.security.AccessController;
+import sun.java2d.pipe.Region;
 import sun.security.action.GetPropertyAction;
 
 /**
  * This is an implementation of a GraphicsEnvironment object for the
  * default local GraphicsEnvironment.

@@ -387,6 +373,50 @@
             return scale <= 0 ? -1 : scale / units;
         } catch (NumberFormatException ignored) {
             return -1;
         }
     }
+
+    /**
+     * Returns the graphics configuration which bounds contain the given point.
+     *
+     * @param  current the default configuration which is checked in the first
+     *         place
+     * @param  x the x coordinate of the given point
+     * @param  y the y coordinate of the given point
+     * @return the graphics configuration
+     */
+    public static GraphicsConfiguration getGraphicsConfigurationAtPoint(
+            GraphicsConfiguration current, double x, double y) {
+        if (current.getBounds().contains(x, y)) {
+            return current;
+        }
+        GraphicsEnvironment env = getLocalGraphicsEnvironment();
+        for (GraphicsDevice device : env.getScreenDevices()) {
+            GraphicsConfiguration config = device.getDefaultConfiguration();
+            if (config.getBounds().contains(x, y)) {
+                return config;
+            }
+        }
+        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 = 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);
+    }
 }
< prev index next >