/* * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @summary This is a helper class to find the location of a system tray icon, * and skip some OS specific cases in tests. * @library /lib/client * @build ExtendedRobot SystemTrayIconHelper
*/ publicclass SystemTrayIconHelper {
static Frame frame;
/** * Call this method if the tray icon need to be followed in an automated manner * This method will be called by automated testcases
*/ 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.