本文整理汇总了Java中java.awt.event.InvocationEvent类的典型用法代码示例。如果您正苦于以下问题:Java InvocationEvent类的具体用法?Java InvocationEvent怎么用?Java InvocationEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvocationEvent类属于java.awt.event包,在下文中一共展示了InvocationEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeAndWait
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Causes runnable to have its run method called in the dispatch thread of the
* EventQueue. This will happen after all pending events are processed. The
* call blocks until this has happened. This method will throw an Error if
* called from the event dispatcher thread.
*
* @exception InterruptedException If another thread has interrupted
* this thread.
* @exception InvocationTargetException If an exception is thrown when running
* runnable.
*
* @since 1.2
*/
public static void invokeAndWait(Runnable runnable)
throws InterruptedException, InvocationTargetException
{
if (isDispatchThread ())
throw new Error("Can't call invokeAndWait from event dispatch thread");
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
Object notifyObject = new Object();
InvocationEvent ie =
new InvocationEvent(eq, runnable, notifyObject, true);
synchronized (notifyObject)
{
eq.postEvent(ie);
notifyObject.wait();
}
Exception exception;
if ((exception = ie.getException()) != null)
throw new InvocationTargetException(exception);
}
示例2: invokeAndWaitLowPriority
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Similar to {@link EventQueue#invokeAndWait} but posts the event at the same
* priority as paint requests, to avoid bad visual artifacts.
*/
static void invokeAndWaitLowPriority(RWLock m, Runnable r)
throws InterruptedException, InvocationTargetException {
Toolkit t = Toolkit.getDefaultToolkit();
EventQueue q = t.getSystemEventQueue();
Object lock = new PaintPriorityEventLock();
InvocationEvent ev = new PaintPriorityEvent(m, t, r, lock, true);
synchronized (lock) {
q.postEvent(ev);
lock.wait();
}
Exception e = ev.getException();
if (e != null) {
throw new InvocationTargetException(e);
}
}
示例3: invokeLater
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public static void invokeLater(Runnable event, Component component)
throws InvocationTargetException {
final InvocationEvent invocationEvent =
new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);
if (component != null) {
final AppContext appContext = SunToolkit.targetToAppContext(component);
SunToolkit.postEvent(appContext, invocationEvent);
// 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
SunToolkit.flushPendingEvents(appContext);
} else {
// This should be the equivalent to EventQueue.invokeAndWait
((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
}
final Throwable eventException = invocationEvent.getException();
if (eventException == null) return;
if (eventException instanceof UndeclaredThrowableException) {
throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
}
throw new InvocationTargetException(eventException);
}
示例4: synthesizeWindowActivation
import java.awt.event.InvocationEvent; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
if (!activate || EventQueue.isDispatchThread()) {
((WFramePeer)getPeer()).emulateActivation(activate);
} else {
// To avoid focus concurrence b/w IE and EmbeddedFrame
// activation is postponed by means of posting it to EDT.
Runnable r = new Runnable() {
public void run() {
((WFramePeer)getPeer()).emulateActivation(true);
}
};
WToolkit.postEvent(WToolkit.targetToAppContext(this),
new InvocationEvent(this, r));
}
}
示例5: replaceSurfaceDataLater
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public void replaceSurfaceDataLater() {
Runnable r = new Runnable() {
@Override
public void run() {
// Shouldn't do anything if object is disposed in meanwhile
// No need for sync as disposeAction in Window is performed
// on EDT
if (!isDisposed()) {
try {
replaceSurfaceData();
} catch (InvalidPipeException e) {
// REMIND : what do we do if our surface creation failed?
}
}
}
};
Component c = (Component)target;
// Fix 6255371.
if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing(c, r)) {
postEvent(new InvocationEvent(c, r));
}
}
示例6: invokeAndWait
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Kicks an event over to the appropriate event queue and waits for it to
* finish To avoid deadlocking, we manually run the NSRunLoop while waiting
* Any selector invoked using ThreadUtilities performOnMainThread will be
* processed in doAWTRunLoop The InvocationEvent will call
* LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
* run loop. Does not dispatch native events while in the loop
*/
public static void invokeAndWait(Runnable runnable, Component component)
throws InvocationTargetException {
Objects.requireNonNull(component, "Null component provided to invokeAndWait");
long mediator = createAWTRunLoopMediator();
InvocationEvent invocationEvent =
new InvocationEvent(component,
runnable,
() -> {
if (mediator != 0) {
stopAWTRunLoop(mediator);
}
},
true);
AppContext appContext = SunToolkit.targetToAppContext(component);
SunToolkit.postEvent(appContext, invocationEvent);
// 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
SunToolkit.flushPendingEvents(appContext);
doAWTRunLoop(mediator, false);
checkException(invocationEvent);
}
示例7: synthesizeWindowActivation
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public void synthesizeWindowActivation(final boolean activate) {
final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
if (!activate || EventQueue.isDispatchThread()) {
peer.emulateActivation(activate);
} else {
// To avoid focus concurrence b/w IE and EmbeddedFrame
// activation is postponed by means of posting it to EDT.
Runnable r = new Runnable() {
public void run() {
peer.emulateActivation(true);
}
};
WToolkit.postEvent(WToolkit.targetToAppContext(this),
new InvocationEvent(this, r));
}
}
示例8: offer
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Checks if there's an active SelectorPerformer corresponding to the invocation's AppContext,
* adds the invocation to the SelectorPerformer's queue and returns true.
* Otherwise does nothing and returns false.
*/
public static boolean offer(InvocationEvent invocation) {
Object source = invocation.getSource();
SelectorPerformer performer = (source instanceof Component) ?
getInstance((Component)source) :
getInstance(Toolkit.getDefaultToolkit().getSystemEventQueue());
if (performer == null) return false;
synchronized (performer.invocations) {
if (!performer.invocations.isEmpty()) {
performer.invocations.peek().add(invocation);
return true;
}
}
return false;
}
示例9: invokeAndWait
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Causes runnable to have its run method called in the dispatch thread of the
* EventQueue. This will happen after all pending events are processed. The
* call blocks until this has happened. This method will throw an Error if
* called from the event dispatcher thread.
*
* @exception InterruptedException If another thread has interrupted
* this thread.
* @exception InvocationTargetException If an exception is thrown when running
* runnable.
*
* @since 1.2
*/
public static void invokeAndWait(Runnable runnable)
throws InterruptedException, InvocationTargetException
{
if (isDispatchThread ())
throw new Error("Can't call invokeAndWait from event dispatch thread");
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
Object notifyObject = new Object();
InvocationEvent ie =
new InvocationEvent(eq, runnable, notifyObject, true);
synchronized (notifyObject)
{
eq.postEvent(ie);
notifyObject.wait();
}
Exception exception;
if ((exception = ie.getException()) != null)
throw new InvocationTargetException(exception);
}
示例10: invokeAndWait
import java.awt.event.InvocationEvent; //导入依赖的package包/类
/**
* Causes <code>runnable</code> to have its <code>run</code>
* method called in the dispatch thread of
* {@link Toolkit#getSystemEventQueue the system EventQueue}.
* This will happen after all pending events are processed.
* The call blocks until this has happened. This method
* will throw an Error if called from the event dispatcher thread.
*
* @param runnable the <code>Runnable</code> whose <code>run</code>
* method should be executed
* synchronously on the <code>EventQueue</code>
* @exception InterruptedException if any thread has
* interrupted this thread
* @exception InvocationTargetException if an throwable is thrown
* when running <code>runnable</code>
* @see #invokeLater
* @since 1.2
*/
public static void invokeAndWait(Runnable runnable)
throws InterruptedException, InvocationTargetException {
if (EventQueue.isDispatchThread()) {
throw new Error("Cannot call invokeAndWait from the event dispatcher thread");
}
class AWTInvocationLock {}
Object lock = new AWTInvocationLock();
InvocationEvent event =
new InvocationEvent(Toolkit.getDefaultToolkit(), runnable, lock,
true);
synchronized (lock) {
Toolkit.getEventQueue().postEvent(event);
lock.wait();
}
Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null) {
throw new InvocationTargetException(eventThrowable);
}
}
示例11: replaceSurfaceDataLater
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public void replaceSurfaceDataLater() {
Runnable r = new Runnable() {
public void run() {
// Shouldn't do anything if object is disposed in meanwhile
// No need for sync as disposeAction in Window is performed
// on EDT
if (!isDisposed()) {
try {
replaceSurfaceData();
} catch (InvalidPipeException e) {
// REMIND : what do we do if our surface creation failed?
}
}
}
};
// Fix 6255371.
if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing((Component)target, r)) {
postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), r));
}
}
示例12: handleButtonPressRelease
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public void handleButtonPressRelease(XEvent xev) {
/*
* Fix for 6385277.
* We request focus on simple Window by click in order
* to make it behave like Frame/Dialog in this case and also to unify
* the behaviour with what we have on MS Windows.
* handleJavaMouseEvent() would be more suitable place to do this
* but we want Swing to have this functionality also.
*/
if (xev.get_type() == XConstants.ButtonPress) {
final XWindowPeer parentXWindow = getParentTopLevel();
Window parentWindow = (Window)parentXWindow.getTarget();
if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
{
postEvent(new InvocationEvent(parentWindow, new Runnable() {
public void run() {
// Request focus on the EDT of 'parentWindow' because
// XDecoratedPeer.requestWindowFocus() calls client code.
parentXWindow.requestXFocus();
}
}));
}
}
super.handleButtonPressRelease(xev);
}
示例13: invokeLater
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
final InvocationEvent invocationEvent =
new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);
if (component != null) {
final AppContext appContext = SunToolkit.targetToAppContext(component);
SunToolkit.postEvent(appContext, invocationEvent);
// 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
SunToolkit.flushPendingEvents(appContext);
} else {
// This should be the equivalent to EventQueue.invokeAndWait
((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
}
final Throwable eventException = invocationEvent.getException();
if (eventException == null) return;
if (eventException instanceof UndeclaredThrowableException) {
throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
}
throw new InvocationTargetException(eventException);
}
示例14: replaceSurfaceDataLater
import java.awt.event.InvocationEvent; //导入依赖的package包/类
public void replaceSurfaceDataLater() {
Runnable r = new Runnable() {
public void run() {
// Shouldn't do anything if object is disposed in meanwhile
// No need for sync as disposeAction in Window is performed
// on EDT
if (!isDisposed()) {
try {
replaceSurfaceData();
} catch (InvalidPipeException e) {
// REMIND : what do we do if our surface creation failed?
}
}
}
};
Component c = (Component)target;
// Fix 6255371.
if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing(c, r)) {
postEvent(new InvocationEvent(c, r));
}
}
示例15: updateCurrentEventAndTime
import java.awt.event.InvocationEvent; //导入依赖的package包/类
private void updateCurrentEventAndTime(AWTEvent event) {
currentEvent = event;
long when = 0;
if (event instanceof ActionEvent) {
when = ((ActionEvent) event).getWhen();
} else if (event instanceof InputEvent) {
when = ((InputEvent) event).getWhen();
} else if (event instanceof InputMethodEvent) {
when = ((InputMethodEvent) event).getWhen();
} else if (event instanceof InvocationEvent) {
when = ((InvocationEvent) event).getWhen();
}
if (when != 0) {
mostRecentEventTime = when;
}
}