Search in sources :

Example 1 with AWTEvent

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));
}
Also used : ActionEvent(java.awt.event.ActionEvent) AWTEvent(java.awt.AWTEvent) InputEvent(java.awt.event.InputEvent)

Example 2 with AWTEvent

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.");
}
Also used : JFrame(javax.swing.JFrame) AWTEventListener(java.awt.event.AWTEventListener) JButton(javax.swing.JButton) AWTEvent(java.awt.AWTEvent) Robot(java.awt.Robot)

Example 3 with AWTEvent

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..");
    }
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AWTEventListener(java.awt.event.AWTEventListener) AWTEvent(java.awt.AWTEvent)

Example 4 with AWTEvent

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);
        }
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AWTEvent(java.awt.AWTEvent) InputEvent(java.awt.event.InputEvent)

Example 5 with AWTEvent

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;
}
Also used : MouseEvent(java.awt.event.MouseEvent) AWTEvent(java.awt.AWTEvent) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

AWTEvent (java.awt.AWTEvent)25 MouseEvent (java.awt.event.MouseEvent)8 WakeupCriterion (javax.media.j3d.WakeupCriterion)8 WakeupOnAWTEvent (javax.media.j3d.WakeupOnAWTEvent)8 AWTEventListener (java.awt.event.AWTEventListener)6 ActionEvent (java.awt.event.ActionEvent)5 Component (java.awt.Component)4 InputEvent (java.awt.event.InputEvent)4 ActionListener (java.awt.event.ActionListener)3 ActiveEvent (java.awt.ActiveEvent)2 EventQueue (java.awt.EventQueue)2 Point (java.awt.Point)2 Transform3D (javax.media.j3d.Transform3D)2 JButton (javax.swing.JButton)2 SplashWindow (apps.SplashWindow)1 DatabaseWindowPanel (cbit.vcell.client.desktop.DatabaseWindowPanel)1 BioModelMetaDataPanel (cbit.vcell.desktop.BioModelMetaDataPanel)1 BioModelNode (cbit.vcell.desktop.BioModelNode)1 GeometryMetaDataPanel (cbit.vcell.desktop.GeometryMetaDataPanel)1 MathModelMetaDataPanel (cbit.vcell.desktop.MathModelMetaDataPanel)1