检测用户何时完成调整

检测用户何时完成调整

本文介绍了检测用户何时完成调整 SWT shell 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可调整大小的 SWT shell.每次调整大小时,我都必须做一些计算密集型的事情.

I've got an SWT shell that's resizable. Every time it is resized, I have to do something computationally intensive.

我可以在我的 shell 上注册一个 ControlListener,但这会在整个调整大小操作过程中持续生成事件,我不知道调整大小拖动类型的鼠标操作何时结束.

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.

我希望能够检测到用户何时完成调整 shell 的大小,然后启动我的计算密集型操作.任何想法如何去做?

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();

这篇关于检测用户何时完成调整 SWT shell 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:55