I've got an SWT shell that's resizable. Every time it is resized, I have to do something computationally intensive.
I can register a ControlListener
on my shell, but this generates events continuously throughout the resize operation, and I have no idea when a resize drag type mouse operation ends.
I'd like to be able to detect when the user is finished resizing the shell and then initiate my computationally intensive operation. Any ideas how to go about that?
How about using a timer and start your operation after a delay of say one sec since last received resize event? A rough draft:
long lastEvent;
ActionListener taskPerformer = new ActionListener() {
public void doCalc(ActionEvent evt) {
if ( (lastEvent + 1000) < System.currentTimeMillis() ) {
hardcoreCalculationTask();
} else {
// this can be timed better
new Timer(1000, taskPerformer).start();
}
}
};
}
In your resize event:
lastEvent = System.currentTimeMillis();
new Timer(1000, taskPerformer).start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With