Java 类java.awt.AWTException 实例源码
项目:openjdk-jdk10
文件:MouseWheelAbsXY.java
private static void test(GraphicsConfiguration gc) throws AWTException {
final Window frame = new Frame(gc);
try {
frame.addMouseWheelListener(e -> {
wheelX = e.getXOnScreen();
wheelY = e.getYOnScreen();
done = true;
});
frame.setSize(300, 300);
frame.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
mouseX = frame.getX() + frame.getWidth() / 2;
mouseY = frame.getY() + frame.getHeight() / 2;
robot.mouseMove(mouseX, mouseY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseWheel(10);
validate();
} finally {
frame.dispose();
}
}
项目:WhatsappCrush
文件:WhatsappCrushGUI.java
private void startCrushing() {
message = messageET.getText();
String mspStr= mpsET.getText();
try{
mps= Integer.parseInt(mspStr);
delay= 1000/mps;
}catch(Exception e){
label.setText("Please Enter Message / sec Correctly.");
return;
}
try {
robot = new Robot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Shivam shiv = new Shivam();
shiv.start();
} catch (AWTException ex) {
}
}
项目:SlideBar
文件:AdobePremiere.java
@Override
public void setup() {
// setup keyhook
try {
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
GlobalScreen.registerNativeHook();
} catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
HKM = new KeyHook();
HKM.addValidHotkey("Space");
GlobalScreen.addNativeKeyListener(HKM);
System.out.println("[KeyHook setup]");
try {
robot = new Robot();
} catch (AWTException e) {
System.out.println("Robot could not be created...");
}
}
项目:openjdk-jdk10
文件:X11GraphicsConfig.java
/**
* Attempts to create an XDBE-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* handle to the native backbuffer is returned.
*/
public long createBackBuffer(X11ComponentPeer peer,
int numBuffers, BufferCapabilities caps)
throws AWTException
{
if (!X11GraphicsDevice.isDBESupported()) {
throw new AWTException("Page flipping is not supported");
}
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
long window = peer.getContentWindow();
int swapAction = getSwapAction(caps.getFlipContents());
return createBackBuffer(window, swapAction);
}
项目:litiengine
文件:Program.java
private static void initSystemTray() {
// add system tray icon with popup menu
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
PopupMenu menu = new PopupMenu();
MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
exitItem.addActionListener(a -> Game.terminate());
menu.add(exitItem);
trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
trayIcon.setImageAutoSize(true);
try {
tray.add(trayIcon);
} catch (AWTException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
项目:incubator-netbeans
文件:HintsUI.java
public void keyReleased(KeyEvent e) {
// Fix (workaround) for issue #186557
if (org.openide.util.Utilities.isWindows()) {
if (Boolean.getBoolean("HintsUI.disable.AltEnter.hack")) { // NOI18N
return;
}
if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ALT) {
e.consume();
altReleased = true;
} else if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ENTER) {
altEnterPressed = false;
if (altReleased) {
try {
java.awt.Robot r = new java.awt.Robot();
r.keyRelease(KeyEvent.VK_ALT);
} catch (AWTException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
项目:openjdk-jdk10
文件:CreateImage.java
private static void checkCreateImage(final Component comp,
final boolean isNull) {
if ((comp.createImage(10, 10) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
if ((comp.createVolatileImage(10, 10) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
try {
if ((comp.createVolatileImage(10, 10, null) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
} catch (final AWTException ignored) {
// this check is not applicable
}
}
项目:AgentWorkbench
文件:AgentGUITrayIcon.java
/**
* Starts the TrayIcon, if this is supported. If not, it should start a
* simple JDialog, doing the same as independent Window.
*/
private void initialize() {
switch (this.getTrayIconUsage()) {
case TrayIcon:
try {
// --- System-Tray is supported ---------------------
this.getSystemTray().add(this.getTrayIcon(true));
} catch (AWTException e) {
System.err.println("TrayIcon supported, but could not be added. => Use TrayDialog instead !");
this.getAgentGUITrayDialog(true).setVisible(true);
}
break;
case TrayDialog:
this.getAgentGUITrayDialog(true).setVisible(true);
break;
default:
break;
}
// --- Refresh tray icon ------------------------------------
this.getAgentGUITrayPopUp().refreshView();
}
项目:jdk8u-jdk
文件:bug7097771.java
public static void main(final String[] args) throws AWTException {
final bug7097771 frame = new bug7097771();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
final Button button = new Button();
button.addActionListener(frame);
frame.add(button);
frame.setVisible(true);
sleep();
frame.setEnabled(false);
button.setEnabled(false);
button.setEnabled(true);
sleep();
Util.clickOnComp(button, new Robot());
sleep();
frame.dispose();
if (action) {
throw new RuntimeException("Button is not disabled.");
}
}
项目:voicemenu
文件:Event_TransformationMenu.java
@Override
public void execute(@NotNull String pattern) {
try {
Robot r = new Robot();
r.keyPress(157);
r.keyPress(90);
r.keyRelease(90);
r.keyRelease(157);
} catch (AWTException e) {
e.printStackTrace();
}
SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);
}
项目:marathonv5
文件:NativeEventsTest.java
private void checkDoubleClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
events = eventToCheck;
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
actionsArea.setText("");
}
});
driver = new JavaDriver();
WebElement b = driver.findElement(By.name("click-me"));
WebElement t = driver.findElement(By.name("actions"));
Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
Dimension size = EventQueueWait.call_noexc(button, "getSize");
Robot r = new Robot();
r.setAutoDelay(10);
r.setAutoWaitForIdle(true);
r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(50);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
new EventQueueWait() {
@Override public boolean till() {
return actionsArea.getText().contains("(2");
}
}.wait("Waiting for actionsArea failed?");
String expected = t.getText();
tclear();
Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
new Actions(driver).moveToElement(b).doubleClick().perform();
AssertJUnit.assertEquals(expected, t.getText());
}
项目:openjdk-jdk10
文件:Test6541987.java
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
项目:jdk8u-jdk
文件:GLXGraphicsConfig.java
/**
* Attempts to create a GLX-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* value of 1 is returned.
*/
@Override
public long createBackBuffer(X11ComponentPeer peer,
int numBuffers, BufferCapabilities caps)
throws AWTException
{
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
throw new AWTException("FlipContents.PRIOR is not supported");
}
// non-zero return value means backbuffer creation was successful
// (checked in X11ComponentPeer.flip(), etc.)
return 1;
}
项目:sAINT
文件:Screenshot.java
public static void TakeScreenshot(String filePath, String fileName) {
try {
Robot robot = new Robot();
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, "jpg", new File(filePath + fileName + ".jpg"));
} catch (AWTException | IOException ex) {
System.out.println(ex.getMessage());
}
}
项目:blitzcrank_screenshoot
文件:Blitzcrank.java
/**
* @param args the command line arguments
* @throws java.awt.AWTException
* @throws java.lang.InterruptedException
* @throws java.io.IOException
*/
public static void main(String[] args) throws AWTException, InterruptedException, IOException {
String stringfyCurrent = String.valueOf(System.currentTimeMillis());
String path = "{path}";
String name = "capture" + stringfyCurrent;
String type = ".jpg";
//--
File file = new File(path + name + type);
BufferedImage imagexd = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(imagexd, type.replace(".", ""), baos);
byte[] bytes = baos.toByteArray();
OutputStream out = new FileOutputStream(file);
out.write(bytes);
}
项目:openjdk-jdk10
文件:ExecutableInputMethodManager.java
ExecutableInputMethodManager() {
// set up host adapter locator
Toolkit toolkit = Toolkit.getDefaultToolkit();
try {
if (toolkit instanceof InputMethodSupport) {
InputMethodDescriptor hostAdapterDescriptor =
((InputMethodSupport)toolkit)
.getInputMethodAdapterDescriptor();
if (hostAdapterDescriptor != null) {
hostAdapterLocator = new InputMethodLocator(hostAdapterDescriptor, null, null);
}
}
} catch (AWTException e) {
// if we can't get a descriptor, we'll just have to do without native input methods
}
javaInputMethodLocatorList = new Vector<InputMethodLocator>();
initializeInputMethodLocatorList();
}
项目:jdk8u-jdk
文件:CGLGraphicsConfig.java
@Override
public void assertOperationSupported(final int numBuffers,
final BufferCapabilities caps)
throws AWTException {
// Assume this method is never called with numBuffers != 2, as 0 is
// unsupported, and 1 corresponds to a SingleBufferStrategy which
// doesn't depend on the peer. Screen is considered as a separate
// "buffer".
if (numBuffers != 2) {
throw new AWTException("Only double buffering is supported");
}
final BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
throw new AWTException("FlipContents.PRIOR is not supported");
}
}
项目:openjdk-jdk10
文件:AllKeyCode.java
public void generateFunctionKeyPress() {
try {
Robot robot = new Robot();
robot.waitForIdle();
for (int i = 0; i < allKeyArr.length; i++) {
keyPressedIndex = i;
robot.keyPress(allKeyArr[i]);
robot.keyRelease(allKeyArr[i]);
robot.waitForIdle();
}
removeListener();
} catch (AWTException e) {
throw new RuntimeException("Robot creation failed");
}
}
项目:geomapapp
文件:XMLJTreeDialog.java
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
try {
Robot robot = new java.awt.Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException ex) {
System.out.println(ex);
}
}
}
项目:openjdk-jdk10
文件:LightweightEventTest.java
public static void main(String[] args) throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
constructTestUI();
}
});
try {
testRobot = new Robot();
} catch (AWTException ex) {
throw new RuntimeException("Could not initiate a drag operation");
}
testRobot.waitForIdle();
// Method performing auto test operation
boolean result = test();
disposeTestUI();
if (result == false) {
throw new RuntimeException("Test FAILED!");
}
}
项目:Clipcon-Client
文件:TrayIconManager.java
/** Add tray icon to system tray */
public void addTrayIconInSystemTray() {
if (SystemTray.isSupported()) {
setEventListener();
setMenu();
try {
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(showListener);
trayIcon.addMouseListener(mouseListener);
systemTray.add(trayIcon);
} catch (AWTException e) {
e.printStackTrace();
}
} else {
System.err.println("Tray unavailable");
}
}
项目:jdk8u-jdk
文件:Test6541987.java
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
项目:jdk8u-jdk
文件:PaintNativeOnUpdate.java
public static void main(final String[] args) throws AWTException {
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
label.repaint();// first paint
sleep();
label.repaint();// incremental paint
sleep();
Robot robot = new Robot();
robot.setAutoDelay(50);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
项目:openjdk-jdk10
文件:Test6505027.java
public void press() throws AWTException {
Point point = this.table.getCellRect(1, 1, false).getLocation();
SwingUtilities.convertPointToScreen(point, this.table);
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.mouseMove(point.x + 1, point.y + 1);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
项目:jdk8u-jdk
文件:DisposeFrameOnDragTest.java
public static void main(String[] args) throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
constructTestUI();
}
});
Util.waitForIdle(null);
try {
Point loc = textArea.getLocationOnScreen();
Util.drag(new Robot(),
new Point((int) loc.x + 3, (int) loc.y + 3),
new Point((int) loc.x + 40, (int) loc.y + 40),
InputEvent.BUTTON1_MASK);
} catch (AWTException ex) {
throw new RuntimeException("Could not initiate a drag operation");
}
Util.waitForIdle(null);
}
项目:OpenJSharp
文件:X11GraphicsConfig.java
/**
* Attempts to create an XDBE-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* handle to the native backbuffer is returned.
*/
public long createBackBuffer(X11ComponentPeer peer,
int numBuffers, BufferCapabilities caps)
throws AWTException
{
if (!X11GraphicsDevice.isDBESupported()) {
throw new AWTException("Page flipping is not supported");
}
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
long window = peer.getContentWindow();
int swapAction = getSwapAction(caps.getFlipContents());
return createBackBuffer(window, swapAction);
}
项目:jdk8u-jdk
文件:D3DGraphicsConfig.java
/**
* Checks that the requested configuration is natively supported; if not,
* an AWTException is thrown.
*/
@Override
public void assertOperationSupported(Component target,
int numBuffers,
BufferCapabilities caps)
throws AWTException
{
if (numBuffers < 2 || numBuffers > 4) {
throw new AWTException("Only 2-4 buffers supported");
}
if (caps.getFlipContents() == BufferCapabilities.FlipContents.COPIED &&
numBuffers != 2)
{
throw new AWTException("FlipContents.COPIED is only" +
"supported for 2 buffers");
}
}
项目:incubator-netbeans
文件:AntSanityTest.java
/**
* Using AWT robot presses and immediately releases certain key.
* @param code Code of the key to be pressed.
*/
private void pressKey(int code) {
try {
Robot robot = new Robot();
robot.keyPress(code);
robot.keyRelease(code);
} catch (AWTException ex) {
Exceptions.printStackTrace(ex);
}
}
项目:jdk8u-jdk
文件:InputMethodLocator.java
/**
* Returns whether support for locale is available from
* the input method.
*/
boolean isLocaleAvailable(Locale locale) {
try {
Locale[] locales = descriptor.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
if (locales[i].equals(locale)) {
return true;
}
}
} catch (AWTException e) {
// treat this as no locale available
}
return false;
}
项目:openjdk-jdk10
文件:CustomCompositeTest.java
private static void testVolatileImage(GraphicsConfiguration cfg,
boolean accelerated)
{
VolatileImage dst = null;
try {
dst = cfg.createCompatibleVolatileImage(640, 480,
new ImageCapabilities(accelerated));
} catch (AWTException e) {
System.out.println("Unable to create volatile image, skip the test.");
return;
}
renderToVolatileImage(dst);
}
项目:phoenix.webui.framework
文件:SeleniumHover.java
@Override
public void hover(Element ele)
{
WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
if(webEle == null)
{
logger.warn("can not found element.");
return;
}
if(!(ele instanceof FileUpload))
{
Dimension size = webEle.getSize();
Point loc = webEle.getLocation();
int toolbarHeight = engine.getToolbarHeight();
int x = size.getWidth() / 2 + loc.getX();
int y = size.getHeight() / 2 + loc.getY() + toolbarHeight;
try
{
new Robot().mouseMove(x, y);
}
catch (AWTException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
项目:phoenix.webui.framework
文件:AwtKeyboard.java
@Override
public void enter()
{
try
{
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
catch (AWTException e)
{
e.printStackTrace();
}
}
项目:phoenix.webui.framework
文件:AwtKeyboard.java
@Override
public void space()
{
try
{
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
}
catch (AWTException e)
{
e.printStackTrace();
}
}
项目:openjdk-jdk10
文件:PaintNativeOnUpdate.java
public static void main(final String[] args) throws AWTException {
ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(50);
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
robot.waitForIdle(1000);
label.repaint();// first paint
robot.waitForIdle(1000);
label.repaint();// incremental paint
robot.waitForIdle(1000);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
项目:marathonv5
文件:Generator.java
public static void main(String[] args) throws AWTException, Throwable {
final Generator test = new Generator();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
test.setVisible(true);
}
});
}
项目:openjdk-jdk10
文件:AppletFlipBuffer.java
private static void test(final Applet applet) {
ComponentAccessor acc = AWTAccessor.getComponentAccessor();
for (int i = 1; i < 10; ++i) {
for (final BufferCapabilities caps : bcs) {
try {
acc.createBufferStrategy(applet, i, caps);
} catch (final AWTException ignored) {
// this kind of buffer strategy is not supported
}
}
}
}
项目:marathonv5
文件:JavaAgent.java
@Override public byte[] getScreenShot() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
BufferedImage bufferedImage;
Dimension windowSize = Toolkit.getDefaultToolkit().getScreenSize();
bufferedImage = new Robot().createScreenCapture(new Rectangle(0, 0, windowSize.width, windowSize.height));
ImageIO.write(bufferedImage, "png", baos);
} catch (AWTException e) {
e.printStackTrace();
}
return baos.toByteArray();
}
项目:marathonv5
文件:RobotDevice.java
public RobotDevice() {
try {
this.robot = new Robot();
robotXsetAutoWaitForIdle(true);
robotXsetAutoDelay();
} catch (AWTException e) {
e.printStackTrace();
}
}
项目:jdk8u-jdk
文件:MultiScreenLocationTest.java
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
项目:marathonv5
文件:NativeEventsTest.java
private void checkKeyEvent(int eventToCheck, String keysToSend, int... keysToPress)
throws InterruptedException, InvocationTargetException, AWTException {
events = eventToCheck;
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
actionsArea.setText("");
}
});
driver = new JavaDriver();
WebElement b = driver.findElement(By.name("enter-text"));
WebElement t = driver.findElement(By.name("actions"));
Point location = EventQueueWait.call_noexc(textField, "getLocationOnScreen");
Dimension size = EventQueueWait.call_noexc(textField, "getSize");
Robot r = new Robot();
r.setAutoDelay(10);
r.setAutoWaitForIdle(true);
r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
for (int keysToPres : keysToPress) {
r.keyPress(keysToPres);
}
for (int i = keysToPress.length - 1; i >= 0; i--) {
r.keyRelease(keysToPress[i]);
}
new EventQueueWait() {
@Override public boolean till() {
return actionsArea.getText().length() > 0;
}
}.wait("Waiting for actionsArea failed?");
String expected = t.getText();
tclear();
Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
b.sendKeys(keysToSend);
System.out.println("Expected: " + expected);
AssertJUnit.assertEquals(expected, t.getText());
new Actions(driver).moveToElement(b).click().perform();
AssertJUnit.assertEquals(expected, t.getText());
}