Interface EDTUtil
-
public interface EDTUtilEDT stands for Event Dispatch Thread.EDTUtil comprises the functionality of:
- Periodically issuing an event dispatch command on the EDT.
- Ability to enqueue tasks, executed on the EDT.
- Controlling the EDT, ie start and stop in a sane manner.
- Create a Window on one thread
- Modify the Window within the same thread
- Handle incoming events from within the same thread
-
-
Field Summary
Fields Modifier and Type Field Description static longdefaultEDTPollPeriod
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description longgetPollPeriod()booleaninvoke(boolean wait, Runnable task)Appends task to the EDT task queue if current thread is not EDT, otherwise execute task immediately.booleaninvokeStop(boolean wait, Runnable finalTask)Append the final task to the EDT task queue, signals EDT to stop.booleanisCurrentThreadEDT()Returns true if the current thread is the event dispatch thread (EDT).booleanisCurrentThreadEDTorNEDT()booleanisCurrentThreadNEDT()Returns true if the current thread is the internal NEWT event dequeue thread (NEDT).booleanisRunning()voidsetPollPeriod(long ms)voidstart()Starts the EDT after it's creation or afterstopping.booleanwaitUntilIdle()Wait until the EDT task queue is empty.
The last task may still be in execution when this method returns.booleanwaitUntilStopped()Wait until EDT task is stopped.
Nostopaction is performed,invokeStop(boolean, java.lang.Runnable)should be used before.
-
-
-
Field Detail
-
defaultEDTPollPeriod
static final long defaultEDTPollPeriod
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPollPeriod
long getPollPeriod()
- Returns:
- poll period in milliseconds
-
setPollPeriod
void setPollPeriod(long ms)
- Parameters:
ms- poll period in milliseconds
-
start
void start() throws IllegalStateExceptionStarts the EDT after it's creation or afterstopping.If the EDT is running, it must be
stoppedfirst and the caller should waituntil it's stopped.- Throws:
IllegalStateException- if EDT is running and not subject to be stopped, i.e.isRunning()returns trueRuntimeException- if EDT could not be started- See Also:
invokeStop(boolean, java.lang.Runnable),waitUntilStopped()
-
isCurrentThreadEDT
boolean isCurrentThreadEDT()
Returns true if the current thread is the event dispatch thread (EDT).The EDT is the platform specific thread dispatching toolkit-events and executing toolkit-tasks enqueued via
invoke(boolean, Runnable).Usually it is the same thread as used to dequeue informal
NEWTEvents (NEDT), seeisCurrentThreadNEDT(), however, this may differ, e.g. SWT and AWT implementation.
-
isCurrentThreadNEDT
boolean isCurrentThreadNEDT()
Returns true if the current thread is the internal NEWT event dequeue thread (NEDT).The NEDT is the NEWT thread used to dequeue informal
NEWTEvents enqueued internally viaDisplayImpl.enqueueEvent(boolean, NEWTEvent).Usually it is the same thread as the EDT, see
isCurrentThreadEDT(), however, this may differ, e.g. SWT and AWT implementation.
-
isCurrentThreadEDTorNEDT
boolean isCurrentThreadEDTorNEDT()
-
isRunning
boolean isRunning()
- Returns:
- True if EDT is running and not subject to be stopped.
-
invokeStop
boolean invokeStop(boolean wait, Runnable finalTask)Append the final task to the EDT task queue, signals EDT to stop.If
waitistruemethods blocks until EDT is stopped.taskmaybenull
Due to the nature of this method:- All previous queued tasks will be finished.
- No new tasks are allowed, an Exception is thrown.
- Can be issued from within EDT, ie from within an enqueued task.
start()may follow immediately, ie creating a new EDT
- Returns:
- true if
taskhas been executed or queued for later execution, otherwise false
-
invoke
boolean invoke(boolean wait, Runnable task)Appends task to the EDT task queue if current thread is not EDT, otherwise execute task immediately.Wait until execution is finished if
Can be issued from within EDT, ie from within an enqueued task.wait == true.- Returns:
- true if
taskhas been executed or queued for later execution, otherwise false
-
waitUntilIdle
boolean waitUntilIdle()
Wait until the EDT task queue is empty.
The last task may still be in execution when this method returns.- Returns:
- true if waited for idle, otherwise false, i.e. in case of current thread is EDT or NEDT
-
waitUntilStopped
boolean waitUntilStopped()
Wait until EDT task is stopped.
Nostopaction is performed,invokeStop(boolean, java.lang.Runnable)should be used before.If caller thread is EDT or NEDT, this call will not block.
- Returns:
- true if stopped, otherwise false, i.e. in case of current thread is EDT or NEDT
-
-