下面列出了java.awt.EventQueue#getMostRecentEventTime() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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");
}
/**
* 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();
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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();
}
}
/**
* 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);
}
}
}
/**
* 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();
}
}
/**
* 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);
}
}
}
/**
* 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();
}
}
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);
}
/**
* 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);
}
}
}
/**
* 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();
}
}
/**
* 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();
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}