< prev index next >

test/java/awt/TrayIcon/SystemTrayIconHelper.java

Print this page

        

@@ -64,11 +64,13 @@
                 BufferedImage screen = robot.createScreenCapture(new Rectangle(screenSize));
 
                 for (int x = (int) (screenSize.getWidth()-width); x > 0; x--) {
                     for (int y = (int) (screenSize.getHeight()-height); y > (screenSize.getHeight()-50); y--) {
                         if (imagesEquals(((BufferedImage)icon.getImage()).getSubimage(0, 0, width, height), screen.getSubimage(x, y, width, height))) {
-                            return new Point(x+5, y+5);
+                            Point point = new Point(x + 5, y + 5);
+                            System.out.println("Icon location " + point);
+                            return point;
                         }
                     }
                 }
             } catch (Exception e) {
                 e.printStackTrace();

@@ -89,26 +91,30 @@
                         "nativeGetIconLocation", new Class[]{Long.TYPE});
                 m_getLocation.setAccessible(true);
                 point2d = (Point2D)m_getLocation.invoke(peer, new Object[]{model});
                 Point po = new Point((int)(point2d.getX()), (int)(point2d.getY()));
                 po.translate(10, -5);
+                System.out.println("Icon location " + po);
                 return po;
             }catch(Exception e) {
                 e.printStackTrace();
                 return null;
             }
         } else {
             try {
                 // sun.awt.X11.XTrayIconPeer
                 Field f_peer = getField(java.awt.TrayIcon.class, "peer");
 
+                SystemTrayIconHelper.openTrayIfNeeded(robot);
+
                 Object peer = f_peer.get(icon);
                 Method m_getLOS = peer.getClass().getDeclaredMethod(
                         "getLocationOnScreen", new Class[]{});
                 m_getLOS.setAccessible(true);
                 Point point = (Point)m_getLOS.invoke(peer, new Object[]{});
                 point.translate(5, 5);
+                System.out.println("Icon location " + point);
                 return point;
             } catch (Exception e) {
                 e.printStackTrace();
                 return null;
             }

@@ -167,6 +173,34 @@
             // See JDK-7153700
             return true;
         }
         return false;
     }
+
+    public static boolean openTrayIfNeeded(Robot robot) {
+        String sysv = System.getProperty("os.version");
+        System.out.println("System version is " + sysv);
+        //Additional step to raise the system try in Gnome 3
+        if(sysv != null && sysv.contains("el7")) {
+            System.out.println("OEL 7 detected");
+            GraphicsConfiguration gc = GraphicsEnvironment.
+                    getLocalGraphicsEnvironment().getDefaultScreenDevice().
+                    getDefaultConfiguration();
+            Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
+            if(insets.bottom > 0) {
+                Dimension screenSize = Toolkit.getDefaultToolkit()
+                        .getScreenSize();
+                robot.mouseMove(screenSize.width - insets.bottom / 2,
+                        screenSize.height - insets.bottom / 2);
+                robot.delay(50);
+                robot.mousePress(InputEvent.BUTTON1_MASK);
+                robot.delay(50);
+                robot.mouseRelease(InputEvent.BUTTON1_MASK);
+                robot.waitForIdle();
+                robot.delay(1000);
+                System.out.println("Tray is opened");
+                return true;
+            }
+        }
+        return false;
+    }
 }
< prev index next >