use of java.awt.AWTEvent in project jgnash by ccavanaugh.
the class IndeterminateCheckBox method iterateState.
// Mostly delegates to model
private void iterateState() {
//Maybe do nothing at all?
if (!getModel().isEnabled()) {
return;
}
grabFocus();
// Iterate state
((ButtonModelEx) getModel()).iterateState();
// Fire ActionEvent
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent) {
modifiers = ((InputEvent) currentEvent).getModifiers();
} else if (currentEvent instanceof ActionEvent) {
modifiers = ((ActionEvent) currentEvent).getModifiers();
}
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getText(), System.currentTimeMillis(), modifiers));
}
use of java.awt.AWTEvent in project jdk8u_jdk by JetBrains.
the class ResetMostRecentFocusOwnerTest method start.
@Override
public void start() {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.err.println(e);
}
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
boolean gained = false;
final Robot robot = Util.createRobot();
JFrame frame1 = new JFrame("Main Frame");
final JButton b1 = new JButton("button1");
frame1.add(b1);
frame1.pack();
frame1.setLocation(0, 300);
Util.showWindowWait(frame1);
final JFrame frame2 = new JFrame("Test Frame");
final JButton b2 = new JButton("button2");
frame2.add(b2);
frame2.pack();
frame2.setLocation(300, 300);
b2.setEnabled(false);
b2.requestFocus();
Util.showWindowWait(frame2);
robot.delay(500);
//
if (!b1.hasFocus()) {
gained = Util.trackFocusGained(b1, new Runnable() {
public void run() {
Util.clickOnComp(b1, robot);
}
}, 5000, false);
if (!gained) {
throw new RuntimeException("Unexpected state: focus is not on <button1>");
}
}
robot.delay(500);
//
// Click <button2>, check that focus is set on the parent frame.
//
gained = false;
gained = Util.trackFocusGained(frame2, new Runnable() {
public void run() {
Util.clickOnComp(b2, robot);
}
}, 5000, false);
if (!gained) {
throw new RuntimeException("Test failed: focus wasn't set to <frame2>");
}
System.out.println("Test passed.");
}
use of java.awt.AWTEvent in project chatty by chatty.
the class ActivityTracker method startTracking.
/**
* Start tracking activity (globally currently only mouse activity, inside
* of the program keypresses and mouse actions).
*/
public static void startTracking() {
if (timer == null) {
checkMouseLocation();
timer = new Timer(DELAY, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkMouseLocation();
}
});
timer.start();
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
triggerActivity();
}
}, AWTEvent.KEY_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);
LOGGER.info("Started tracking user activity..");
}
}
use of java.awt.AWTEvent in project evosuite by EvoSuite.
the class MockJFileChooser method fireActionPerformed.
protected void fireActionPerformed(String command) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
long mostRecentEventTime = EventQueue.getMostRecentEventTime();
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent) {
modifiers = ((InputEvent) currentEvent).getModifiers();
} else if (currentEvent instanceof ActionEvent) {
modifiers = ((ActionEvent) currentEvent).getModifiers();
}
ActionEvent e = null;
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ActionListener.class) {
// Lazily create the event:
if (e == null) {
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command, mostRecentEventTime, modifiers);
}
((ActionListener) listeners[i + 1]).actionPerformed(e);
}
}
}
use of java.awt.AWTEvent in project freeplane by freeplane.
the class FreeplaneApplet method findComponentAt.
@Override
public Component findComponentAt(int x, int y) {
final Component c = super.findComponentAt(x, y);
if (c == null) {
return null;
}
final AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (controller != Controller.getCurrentController() && currentEvent instanceof MouseEvent && currentEvent.getID() == MouseEvent.MOUSE_MOVED) {
if (appletLock.tryLock()) {
Controller.setCurrentController(controller);
appletLock.unlock();
}
}
return c;
}
Aggregations