public final class RateLimitingScanListeners
extends java.lang.Object
ScanListener.recordRead(au.com.southsky.jfreesane.SaneDevice, int, int) notifications. The primary purpose of this class is to allow
users to easily build user interfaces that provide progress information without having to deal
with these potentially very high frequency notifications.
For example:
final JProgressBar progressBar = new JProgressBar();
// Construct a new ScanAdapter that updates progressBar.
ScanListener progressBarUpdater = new ScanAdapter() {
@Override public recordRead(...) {
// Swing updates must be done in the Swing event listener thread.
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
progressBar.setValue(...);
}
});
}
};
// Wrap the listener to yield notifications up to 10 times per second and acquire the image.
ScanListener rateLimitedListener = RateLimitingScanListeners
.noMoreFrequentlyThan(progressBarUpdater, 100, TimeUnit.MILLISECONDS));
saneDevice.acquireImage(rateLimitedListener);
| Modifier and Type | Method and Description |
|---|---|
static ScanListener |
noMoreFrequentlyThan(ScanListener listener,
long time,
java.util.concurrent.TimeUnit timeUnit)
Returns
ScanListener that calls the given listener ScanListener.recordRead(au.com.southsky.jfreesane.SaneDevice, int, int)
method no more frequently than the given time any one device. |
public static ScanListener noMoreFrequentlyThan(ScanListener listener, long time, java.util.concurrent.TimeUnit timeUnit)
ScanListener that calls the given listener ScanListener.recordRead(au.com.southsky.jfreesane.SaneDevice, int, int)
method no more frequently than the given time any one device. Record read events from one
device that occur more frequently are simply discarded.