use of java.awt.AWTException in project HearthStats.net-Uploader by HearthStats.
the class JnaUtil method main.
public static void main(String[] args) throws InterruptedException {
String[] testStrs = { "Untitled-Notepad", "Untitled - Notepad", "Untitled - Notepad", "Java-Epic", "Java - Epic", "Fubars rule!", "The First Night", "New Tab", "Citrix X", "EHR PROD - SVC" };
for (String testStr : testStrs) {
Pointer hWnd = getWinHwnd(testStr);
boolean isWindow = windowExists(hWnd);
System.out.printf("%-22s %5b %16s %b%n", testStr, windowExists(testStr), hWnd, isWindow);
}
String ehrProd = "EHR PROD - SVC";
Pointer hWnd = getWinHwnd(ehrProd);
System.out.println("is it foreground window? " + isForegroundWindow(hWnd));
boolean foo = setForegroundWindow(ehrProd);
System.out.println("foregroundwindow: " + foo);
Thread.sleep(400);
System.out.println("is it foreground window? " + isForegroundWindow(hWnd));
Thread.sleep(400);
try {
Rectangle rect = getWindowRect(ehrProd);
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(rect);
ImageIcon icon = new ImageIcon(img);
JLabel label = new JLabel(icon);
JOptionPane.showMessageDialog(null, label);
} catch (AWTException e) {
e.printStackTrace();
} catch (JnaUtilException e) {
e.printStackTrace();
}
}
use of java.awt.AWTException in project otapij by FellowTraveler.
the class MainPage method setToSystray.
private void setToSystray() {
Image image = null;
System.out.println("creating instance");
if (SystemTray.isSupported()) {
System.out.println("system tray supported");
tray = SystemTray.getSystemTray();
ImageIcon image1 = new javax.swing.ImageIcon(getClass().getResource("/com/moneychanger/ui/images/images.jpeg"));
image = image1.getImage();
ActionListener exitListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting....");
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
defaultItem = new MenuItem("Open");
defaultItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//tray.remove(trayIcon);
setVisible(true);
repaint();
setVisible(true);
System.out.println("Open");
}
});
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Moneychanger", popup);
trayIcon.setImageAutoSize(true);
} else {
System.out.println("system tray not supported");
}
final String os = System.getProperty("os.name").toLowerCase();
addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(WindowEvent e) {
System.out.println("-----:" + e.getNewState());
if (e.getNewState() == ICONIFIED) {
try {
tray.add(trayIcon);
if (os.indexOf("nix") < 0 || os.indexOf("nux") < 0) {
setVisible(false);
}
System.out.println("added to SystemTray");
} catch (AWTException ex) {
System.out.println("unable to add to tray");
}
}
if (e.getNewState() == 7) {
try {
tray.add(trayIcon);
if (!(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0)) {
setVisible(false);
}
System.out.println("added to SystemTray");
} catch (AWTException ex) {
System.out.println("unable to add to system tray");
}
}
if (e.getNewState() == MAXIMIZED_BOTH) {
tray.remove(trayIcon);
setVisible(true);
System.out.println("Max both");
System.out.println("Tray icon removed");
}
if (e.getNewState() == NORMAL) {
tray.remove(trayIcon);
setVisible(true);
System.out.println("Max NORMAL");
System.out.println("Tray icon removed");
}
}
});
// setIconImage(Toolkit.getDefaultToolkit().getImage("Duke256.png"));
if (image != null) {
setIconImage(image);
}
}
use of java.awt.AWTException in project jdk8u_jdk by JetBrains.
the class WindowDragTest method main.
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.setAutoDelay(1000);
Frame frame1 = new Frame();
frame1.setBounds(50, 50, 300, 200);
frame1.setVisible(true);
frame1.toFront();
frame1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Clicking frame1 succeeded - mouse is not captured
passed = true;
}
});
robot.delay(1000);
Frame frame2 = new Frame();
frame2.setBounds(100, 100, 300, 200);
frame2.setVisible(true);
frame2.toFront();
robot.delay(1000);
Point p = frame2.getLocationOnScreen();
Dimension d = frame2.getSize();
// Move cursor to frame2 title bar to drag
robot.mouseMove(p.x + (int) (d.getWidth() / 2), p.y + (int) frame2.getInsets().top / 2);
Util.waitForIdle(robot);
// Start window dragging
robot.mousePress(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
// Dispose window being dragged
frame2.dispose();
Util.waitForIdle(robot);
// Release mouse button to be able to get MOUSE_CLICKED event on Util.clickOnComp()
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
// Click frame1 to check whether mouse is not captured by frame2
Util.clickOnComp(frame1, robot);
Util.waitForIdle(robot);
frame1.dispose();
if (passed) {
System.out.println("Test passed.");
} else {
System.out.println("Test failed.");
throw new RuntimeException("Test failed.");
}
} catch (AWTException e) {
throw new RuntimeException("AWTException occurred - problem creating robot!");
}
}
use of java.awt.AWTException in project jdk8u_jdk by JetBrains.
the class ExtraMouseClick method start.
//End init()
public void start() {
frame.setSize(480, 300);
frame.setVisible(true);
try {
robot = new Robot();
} catch (AWTException e) {
throw new RuntimeException(e);
}
//a time to show Frame
Util.waitForIdle(robot);
fp = frame.getLocationOnScreen();
for (int i = 0; i < TRIALS; i++) {
checkClicked();
clearFlags();
}
for (int i = 0; i < TRIALS; i++) {
oneDrag(2);
clearFlags();
}
for (int i = 0; i < TRIALS; i++) {
oneDrag(5);
clearFlags();
}
for (int i = 0; i < TRIALS; i++) {
oneDrag(70);
clearFlags();
}
//Check that no Drag event occur in the SMUDGE area
String sToolkit = Toolkit.getDefaultToolkit().getClass().getName();
System.out.println("Toolkit == " + sToolkit);
if ("sun.awt.windows.WToolkit".equals(sToolkit)) {
int dragWidth = ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.width")).intValue();
int dragHeight = ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.height")).intValue();
System.out.println("dragWidth==" + dragWidth + ":: dragHeight==" + dragHeight);
// DragWidth and dragHeight may be equal to 1. In that case the SMUDGE rectangle
// narrowed into 1x1 pixel and we can't drag a mouse in it.
// In that case we may skip following testcase but I'd prefer if we move mouse on 1 pixel only.
// And that should pass as well.
dragWidth = dragWidth > 1 ? dragWidth / 2 : 1;
dragHeight = dragHeight > 1 ? dragHeight / 2 : 1;
for (int i = 0; i < TRIALS; i++) {
smallWin32Drag(dragWidth, dragHeight);
clearFlags();
}
} else if ("sun.lwawt.macosx.LWCToolkit".equals(sToolkit)) {
// On MacOS X every mouse move event is MOUSE_DRAGGED event and
// MOUSE_DRAGGED is sent back form the Native code to the java code
// for every mouse move. Therefore 'smallDrag test should be
// disabled for toolkit 'sun.lwawt.macosx.LWCToolkit'.
} else {
for (int i = 0; i < TRIALS; i++) {
//on Motif and XAWT SMUDGE area is 4-pixels wide
smallDrag(SMUDGE_WIDTH - 1, SMUDGE_HEIGHT - 1);
clearFlags();
}
}
System.out.println("Test passed.");
}
use of java.awt.AWTException in project jdk8u_jdk by JetBrains.
the class DisposeFrameOnDragTest method main.
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);
}
Aggregations