Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting when a user is finished resizing SWT shell

Tags:

java

swt

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?

like image 286
jsn Avatar asked Dec 13 '22 00:12

jsn


1 Answers

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();
like image 185
stacker Avatar answered Dec 31 '22 13:12

stacker