From a1d3b672b0d1fe3e4794ba0f504be5bcb336d4b7 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 27 Jul 2017 23:18:20 +0200 Subject: [PATCH] Moved screen util methods out of swingutil --- src/dorkbox/util/ScreenUtil.java | 23 +++++++++++++++++++++++ src/dorkbox/util/SwingUtil.java | 27 --------------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/dorkbox/util/ScreenUtil.java b/src/dorkbox/util/ScreenUtil.java index 11be2a6..23ae8e7 100644 --- a/src/dorkbox/util/ScreenUtil.java +++ b/src/dorkbox/util/ScreenUtil.java @@ -15,9 +15,11 @@ */ package dorkbox.util; +import java.awt.Container; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; +import java.awt.MouseInfo; import java.awt.Point; import java.awt.Rectangle; @@ -63,6 +65,27 @@ class ScreenUtil { return device; } + public static + void showOnSameScreenAsMouse_Center(final Container frame) { + Point mouseLocation = MouseInfo.getPointerInfo() + .getLocation(); + + GraphicsDevice deviceAtMouse = ScreenUtil.getGraphicsDeviceAt(mouseLocation); + Rectangle bounds = deviceAtMouse.getDefaultConfiguration() + .getBounds(); + frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2, bounds.y + bounds.height / 2 - frame.getHeight() / 2); + } + + public static + void showOnSameScreenAsMouse(final Container frame) { + Point mouseLocation = MouseInfo.getPointerInfo() + .getLocation(); + + GraphicsDevice deviceAtMouse = ScreenUtil.getGraphicsDeviceAt(mouseLocation); + frame.setLocation(deviceAtMouse.getDefaultConfiguration() + .getBounds().x, frame.getY()); + } + private ScreenUtil() { } diff --git a/src/dorkbox/util/SwingUtil.java b/src/dorkbox/util/SwingUtil.java index 649d63a..5a503c2 100644 --- a/src/dorkbox/util/SwingUtil.java +++ b/src/dorkbox/util/SwingUtil.java @@ -16,14 +16,10 @@ package dorkbox.util; import java.awt.Component; -import java.awt.Container; import java.awt.Dimension; import java.awt.EventQueue; -import java.awt.GraphicsDevice; import java.awt.Image; -import java.awt.MouseInfo; import java.awt.Point; -import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.HierarchyEvent; @@ -229,29 +225,6 @@ class SwingUtil { /** used when setting various icon components in the GUI to "nothing", since null doesn't work */ public static final Image BLANK_ICON = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE); - - public static - void showOnSameScreenAsMouse_Center(final Container frame) { - Point mouseLocation = MouseInfo.getPointerInfo() - .getLocation(); - - GraphicsDevice deviceAtMouse = ScreenUtil.getGraphicsDeviceAt(mouseLocation); - Rectangle bounds = deviceAtMouse.getDefaultConfiguration() - .getBounds(); - frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2, bounds.y + bounds.height / 2 - frame.getHeight() / 2); - } - - public static - void showOnSameScreenAsMouse(final Container frame) { - Point mouseLocation = MouseInfo.getPointerInfo() - .getLocation(); - - GraphicsDevice deviceAtMouse = ScreenUtil.getGraphicsDeviceAt(mouseLocation); - frame.setLocation(deviceAtMouse.getDefaultConfiguration() - .getBounds().x, frame.getY()); - } - - /** * Adds a listener to the window parent of the given component. Can be before the component is really added to its hierarchy. *