Java Code Examples for java.awt.EventQueue#getMostRecentEventTime()

The following examples show how to use java.awt.EventQueue#getMostRecentEventTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeTemplatesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testMemoryRelease() throws Exception { // Issue #147984
    org.netbeans.junit.Log.enableInstances(Logger.getLogger("TIMER"), "CodeTemplateInsertHandler", Level.FINEST);

    JEditorPane pane = new JEditorPane();
    NbEditorKit kit = new NbEditorKit();
    pane.setEditorKit(kit);
    Document doc = pane.getDocument();
    assertTrue(doc instanceof BaseDocument);
    CodeTemplateManager mgr = CodeTemplateManager.get(doc);
    String templateText = "Test with parm ";
    CodeTemplate ct = mgr.createTemporary(templateText + " ${a}");
    ct.insert(pane);
    assertEquals(templateText + " a", doc.getText(0, doc.getLength()));

    // Send Enter to stop editing
    KeyEvent enterKeyEvent = new KeyEvent(pane, KeyEvent.KEY_PRESSED,
            EventQueue.getMostRecentEventTime(),
            0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED);

    SwingUtilities.processKeyBindings(enterKeyEvent);
    // CT editing should be finished

    org.netbeans.junit.Log.assertInstances("CodeTemplateInsertHandler instances not GCed");
}
 
Example 2
Source File: InputMethodEvent.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 3
Source File: InputMethodEvent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 4
Source File: JFileChooser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 5
Source File: JFileChooser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 6
Source File: InputMethodEvent.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        // Can't use getMostRecentEventTimeForSource because source is always null during deserialization
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 7
Source File: InputMethodEvent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 8
Source File: JFileChooser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 9
Source File: ExtendedJSliderToolTips.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void postToolTip(JComponent comp) {
	Action action = comp.getActionMap().get("postTip");
	if (action == null) {
		return;
	}
	ActionEvent ae = new ActionEvent(comp, ActionEvent.ACTION_PERFORMED, "postTip", EventQueue.getMostRecentEventTime(),
			0);
	action.actionPerformed(ae);
}
 
Example 10
Source File: InputMethodEvent.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        // Can't use getMostRecentEventTimeForSource because source is always null during deserialization
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 11
Source File: JFileChooser.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 12
Source File: InputMethodEvent.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        // Can't use getMostRecentEventTimeForSource because source is always null during deserialization
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 13
Source File: JFileChooser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 14
Source File: InputMethodEvent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the <code>when</code> field if it is not present in the
 * object input stream. In that case, the field will be initialized by
 * invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
 */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();
    if (when == 0) {
        // Can't use getMostRecentEventTimeForSource because source is always null during deserialization
        when = EventQueue.getMostRecentEventTime();
    }
}
 
Example 15
Source File: JFileChooser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 16
Source File: JFileChooser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 17
Source File: JFileChooser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
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;
    // Process the listeners last to first, notifying
    // 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);
        }
    }
}
 
Example 18
Source File: InputMethodEvent.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an <code>InputMethodEvent</code> with the specified
 * source component, type, text, caret, and visiblePosition.
 * <p>
 * The offsets of caret and visiblePosition are relative to the current
 * composed text; that is, the composed text within <code>text</code>
 * if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
 * the composed text within the <code>text</code> of the
 * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
 * The time stamp for this event is initialized by invoking
 * {@link java.awt.EventQueue#getMostRecentEventTime()}.
 * <p>Note that passing in an invalid <code>id</code> results in
 * unspecified behavior. This method throws an
 * <code>IllegalArgumentException</code> if <code>source</code>
 * is <code>null</code>.
 *
 * @param source the object where the event originated
 * @param id the event type
 * @param text the combined committed and composed text,
 *      committed text first; must be <code>null</code>
 *      when the event type is <code>CARET_POSITION_CHANGED</code>;
 *      may be <code>null</code> for
 *      <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
 *      committed or composed text
 * @param committedCharacterCount the number of committed
 *      characters in the text
 * @param caret the caret (a.k.a. insertion point);
 *      <code>null</code> if there's no caret within current
 *      composed text
 * @param visiblePosition the position that's most important
 *      to be visible; <code>null</code> if there's no
 *      recommendation for a visible position within current
 *      composed text
 * @throws IllegalArgumentException if <code>id</code> is not
 *      in the range
 *      <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
 *      or if id is <code>CARET_POSITION_CHANGED</code> and
 *      <code>text</code> is not <code>null</code>;
 *      or if <code>committedCharacterCount</code> is not in the range
 *      <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
 * @throws IllegalArgumentException if <code>source</code> is null
 */
public InputMethodEvent(Component source, int id,
        AttributedCharacterIterator text, int committedCharacterCount,
        TextHitInfo caret, TextHitInfo visiblePosition) {
    this(source, id, EventQueue.getMostRecentEventTime(), text,
         committedCharacterCount, caret, visiblePosition);
}
 
Example 19
Source File: InputMethodEvent.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>InputMethodEvent</code> with the specified
 * source component, type, text, caret, and visiblePosition.
 * <p>
 * The offsets of caret and visiblePosition are relative to the current
 * composed text; that is, the composed text within <code>text</code>
 * if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
 * the composed text within the <code>text</code> of the
 * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
 * The time stamp for this event is initialized by invoking
 * {@link java.awt.EventQueue#getMostRecentEventTime()}.
 * <p>Note that passing in an invalid <code>id</code> results in
 * unspecified behavior. This method throws an
 * <code>IllegalArgumentException</code> if <code>source</code>
 * is <code>null</code>.
 *
 * @param source the object where the event originated
 * @param id the event type
 * @param text the combined committed and composed text,
 *      committed text first; must be <code>null</code>
 *      when the event type is <code>CARET_POSITION_CHANGED</code>;
 *      may be <code>null</code> for
 *      <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
 *      committed or composed text
 * @param committedCharacterCount the number of committed
 *      characters in the text
 * @param caret the caret (a.k.a. insertion point);
 *      <code>null</code> if there's no caret within current
 *      composed text
 * @param visiblePosition the position that's most important
 *      to be visible; <code>null</code> if there's no
 *      recommendation for a visible position within current
 *      composed text
 * @throws IllegalArgumentException if <code>id</code> is not
 *      in the range
 *      <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
 *      or if id is <code>CARET_POSITION_CHANGED</code> and
 *      <code>text</code> is not <code>null</code>;
 *      or if <code>committedCharacterCount</code> is not in the range
 *      <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
 * @throws IllegalArgumentException if <code>source</code> is null
 */
public InputMethodEvent(Component source, int id,
        AttributedCharacterIterator text, int committedCharacterCount,
        TextHitInfo caret, TextHitInfo visiblePosition) {
    this(source, id, EventQueue.getMostRecentEventTime(), text,
         committedCharacterCount, caret, visiblePosition);
}
 
Example 20
Source File: InputMethodEvent.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>InputMethodEvent</code> with the specified
 * source component, type, text, caret, and visiblePosition.
 * <p>
 * The offsets of caret and visiblePosition are relative to the current
 * composed text; that is, the composed text within <code>text</code>
 * if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
 * the composed text within the <code>text</code> of the
 * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
 * The time stamp for this event is initialized by invoking
 * {@link java.awt.EventQueue#getMostRecentEventTime()}.
 * <p>Note that passing in an invalid <code>id</code> results in
 * unspecified behavior. This method throws an
 * <code>IllegalArgumentException</code> if <code>source</code>
 * is <code>null</code>.
 *
 * @param source the object where the event originated
 * @param id the event type
 * @param text the combined committed and composed text,
 *      committed text first; must be <code>null</code>
 *      when the event type is <code>CARET_POSITION_CHANGED</code>;
 *      may be <code>null</code> for
 *      <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
 *      committed or composed text
 * @param committedCharacterCount the number of committed
 *      characters in the text
 * @param caret the caret (a.k.a. insertion point);
 *      <code>null</code> if there's no caret within current
 *      composed text
 * @param visiblePosition the position that's most important
 *      to be visible; <code>null</code> if there's no
 *      recommendation for a visible position within current
 *      composed text
 * @throws IllegalArgumentException if <code>id</code> is not
 *      in the range
 *      <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
 *      or if id is <code>CARET_POSITION_CHANGED</code> and
 *      <code>text</code> is not <code>null</code>;
 *      or if <code>committedCharacterCount</code> is not in the range
 *      <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
 * @throws IllegalArgumentException if <code>source</code> is null
 */
public InputMethodEvent(Component source, int id,
        AttributedCharacterIterator text, int committedCharacterCount,
        TextHitInfo caret, TextHitInfo visiblePosition) {
    this(source, id, EventQueue.getMostRecentEventTime(), text,
         committedCharacterCount, caret, visiblePosition);
}