/** *Callthismethodifthetrayiconneedtobefollowedinanautomatedmanner *Thismethodwillbecalledbyautomatedtestcases
*/ static Point getTrayIconLocation(TrayIcon icon) throws Exception { if (icon == null) { returnnull;
}
//This is added just in case the tray's native menu is visible. //It has to be hidden if visible. For that, we are showing a Frame //and clicking on it - the assumption is, the menu will //be closed if another window is clicked
ExtendedRobot robot = new ExtendedRobot(); try {
EventQueue.invokeAndWait(() -> {
frame = new Frame();
frame.setSize(100, 100);
frame.setVisible(true);
});
robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth() / 2,
frame.getLocationOnScreen().y + frame.getHeight() / 2);
robot.waitForIdle();
robot.click();
EventQueue.invokeAndWait(frame::dispose);
} catch (Exception e) { returnnull;
}
int width = (int) iconSize.getWidth(); int height = (int) iconSize.getHeight();
// Some previously created icons may not be removed // from tray until mouse move on it. So we glide // through the whole tray bar.
robot.glide((int) screenSize.getWidth(), (int) (screenSize.getHeight()-15), 0, (int) (screenSize.getHeight() - 15), 1, 2);
// Method for skipping some OS specific cases staticboolean skip(int button) { if (System.getProperty("os.name").toLowerCase().startsWith("win")){ if (button == InputEvent.BUTTON1_MASK){ // See JDK-6827035 returntrue;
}
} elseif (System.getProperty("os.name").toLowerCase().contains("os x")){ // See JDK-7153700 returntrue;
} returnfalse;
}
publicstaticboolean 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 in OEL 7 if(isOel7orLater()) {
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"); returntrue;
}
} returnfalse;
}
publicstaticboolean isOel7orLater() { if (System.getProperty("os.name").toLowerCase().contains("linux") &&
System.getProperty("os.version").toLowerCase().contains("el")) {
Pattern p = Pattern.compile("el(\\d+)");
Matcher m = p.matcher(System.getProperty("os.version")); if (m.find()) { try { return Integer.parseInt(m.group(1)) >= 7;
} catch (NumberFormatException nfe) {}
}
} returnfalse;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.