Runnable accumulates
Runnable
to perform some actions on an appendable set of data.
The set of data might be appended after the Runnable is
sent for the execution. Usually such Runnables are sent to
the EDT.
Usage example:
Say we want to implement JLabel.setText(String text) which sends
text string to the JLabel.setTextImpl(String text) on the EDT.
In the event JLabel.setText is called rapidly many times off the EDT
we will get many updates on the EDT but only the last one is important.
(Every next updates overrides the previous one.)
We might want to implement this setText in a way that only
the last update is delivered.
Here is how one can do this using AccumulativeRunnable:
AccumulativeRunnable<String> doSetTextImpl = new AccumulativeRunnable<String>(){ @Overrideprotected void run(List<String> args){ //set to the last string being passed setTextImpl(args.get(args.size() - 1)); } } void setText(String text) { //add text and send for the execution if needed. doSetTextImpl.add(text); }
Say we want to implement addDirtyRegion(Rectangle rect)
which sends this region to the
handleDirtyRegions(List<Rect> regions) on the EDT.
addDirtyRegions better be accumulated before handling on the EDT.
Here is how it can be implemented using AccumulativeRunnable:
AccumulativeRunnable<Rectangle> doHandleDirtyRegions =new AccumulativeRunnable<Rectangle>(){ @Overrideprotected void run(List<Rectangle> args){ handleDirtyRegions(args); } }; void addDirtyRegion(Rectangle rect) { doHandleDirtyRegions.add(rect); }
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final synchronized void | add(T...
the arguments to accumulate args)appends arguments and sends this |
| private synchronized List | Returns: accumulated argumentsReturns accumulated arguments and flashes the arguments storage. |
| protected abstract void | |
| public final void | |
| protected void |
| arguments | back to summary |
|---|---|
| private List<T> arguments | |
| AccumulativeRunnable | back to summary |
|---|---|
| public AccumulativeRunnable() | |
| add | back to summary |
|---|---|
| public final synchronized void add(T... args) appends arguments and sends this
This implementation uses
| |
| flush | back to summary |
|---|---|
| private synchronized List Returns accumulated arguments and flashes the arguments storage.
| |
| run | back to summary |
|---|---|
| protected abstract void run(List<T> args) Equivalent to
| |
| run | back to summary |
|---|---|
| public final void run() Implements java. Doc from java. Runs this operation.
This implementation calls | |
| submit | back to summary |
|---|---|
| protected void submit() Sends this
This method is to be executed only from
This implementation uses | |