Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 457:effba48b76f3
Fix position
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Jun 2016 19:52:32 +0900 |
parents | 34277b436cac |
children | 4ea47640942a |
files | src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java |
diffstat | 2 files changed, 29 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java Wed Jun 22 19:11:37 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java Wed Jun 22 19:52:32 2016 +0900 @@ -3,37 +3,55 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.lang.reflect.Field; +import java.util.ArrayList; /** * Created by one on 15/08/18. */ public class IsRetina { - public static final int isRetina = getRetinaScale(); - private static int getRetinaScale() { -//other OS and JVM specific checks... + public static int getRetinaScale(int shareScreenNumber) { int scale = 1; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); - final GraphicsDevice device = env.getDefaultScreenDevice(); + final GraphicsDevice[] devices = env.getScreenDevices(); try { - Field field = device.getClass().getDeclaredField("scale"); + Field field = devices[shareScreenNumber].getClass().getDeclaredField("scale"); if (field != null) { field.setAccessible(true); - Object retinaScale = field.get(device); + Object retinaScale = field.get(devices[shareScreenNumber]); if (retinaScale instanceof Integer) { - scale = ((Integer)retinaScale).intValue(); + scale = (Integer) retinaScale; return scale; } } } catch (Exception ignore) {} - //... return scale; } + public static ArrayList<Rectangle> getScreenRectangles() { + // New screen server has one or more screens. + // Screens are numbered in the order from left. + // put screens in an ArrayList. + ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + int screenNumber = 0; + for (GraphicsDevice gd : gs) { + for (GraphicsConfiguration r : gd.getConfigurations()) { + System.out.println("Retina scale :" + getRetinaScale(screenNumber)); + Rectangle rect = r.getBounds(); + System.out.println("screen "+ screenNumber +":"+rect); + rectangles.add(rect); + } + screenNumber++; + } + return rectangles; + } + public static void main(String args[]) { - System.out.println(isRetina); + getScreenRectangles(); } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jun 22 19:11:37 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jun 22 19:52:32 2016 +0900 @@ -507,8 +507,8 @@ int screenNumber = 0; for (Rectangle rect : rectangles) { int scale = retinaScale(screenNumber); - int x = rect.x < 0 ? rect.x * scale : rect.x; - int y = rect.y < 0 ? rect.y * scale : rect.y; + int x = rect.x == -rect.width ? rect.x * scale : rect.x; + int y = rect.y == -rect.height ? rect.y * scale : rect.y; if (x < offsetx) offsetx = x; if (y < offsety) offsety = y; screenNumber++;