diff src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java @ 456:34277b436cac

Using retina scale to share screnn if minus postion
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 22 Jun 2016 19:11:37 +0900
parents 432e2967eaab
children 4ea47640942a
line wrap: on
line diff
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java	Wed Jun 22 12:29:57 2016 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java	Wed Jun 22 19:11:37 2016 +0900
@@ -923,7 +923,7 @@
         int singleHeight = (int) (rectangle1.getHeight());
         int x = (int) (rectangle1.getX()) + offset.x; // convert double to int
         int y = (int) (rectangle1.getY()) + offset.y;
-        int scale = retinaScale(shareScreenNumber);
+        int scale = viewer.retinaScale(shareScreenNumber);
         showScreenInfo("request screen change", 0, x, y, singleWidth, singleHeight, scale);
         if (viewer.getRfb().isTreeManager()) {
             changeVncServer(viewer, x, y, singleWidth * scale, singleHeight * scale, scale, viewer.getRfb().getId());
@@ -938,27 +938,6 @@
         }
     }
 
-    private int retinaScale(int shareScreenNumber) {
-        int scale = 1;
-        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
-        final GraphicsDevice[] devices = env.getScreenDevices();
-
-        try {
-            Field field = devices[shareScreenNumber].getClass().getDeclaredField("scale");
-
-            if (field != null) {
-                field.setAccessible(true);
-                Object retinaScale = field.get(devices[shareScreenNumber]);
-
-                if (retinaScale instanceof Integer) {
-                    scale = (Integer) retinaScale;
-                    return scale;
-                }
-            }
-        } catch (Exception ignore) {}
-        return scale;
-    }
-
     private boolean scanPort(String adr, int port) {
         try {
             Socket socket = new Socket(adr, port);
@@ -984,7 +963,7 @@
 
         int thisScreenWidth = (int) rectangles.get(thisScreenNumber).getWidth();
         int thisScreenHeight = (int) rectangles.get(thisScreenNumber).getHeight();
-        int thisRetinaScale = retinaScale(thisScreenNumber);
+        int thisRetinaScale = viewer.retinaScale(thisScreenNumber);
 
         final int thatScreenX = presenter.getX();
         final int thatScreenY = presenter.getY();