使JFace窗口在任务栏中闪烁或让用户注意?

问题描述:

我想知道有人有任何想法如何解决这个问题:


在我的Java Eclipse插件中有一些过程需要一些时间。因此,用户可能最小化窗口,并让进程在后台运行

现在,当进程完成,我可以强制窗口再次来到顶端,但这是一个不可用的可用性。我宁愿要让任务栏中的闪烁。有没有办法实现这一点?


我看了一下 org.eclipse.jface.window ,但不能找到任何类似的东西,同样的对于SWT文档...


另一件事情出现在我的脑海里 - 正如人们在 mac os x linux 上使用此应用程序一样是否有一个平台独立解决方案,它将通知用户进程已经完成,但没有将窗口置于顶端?


任何想法都非常受欢迎!


编辑:

我发现在Windows上,用户可以调整他是否要启用力来前台。如果该选项被禁用,任务将在任务栏中闪烁...

这是一个很好的阅读 ...


如果有人可能知道一些平台独立的方式实现这种行为,请与我分享你的知识!

I wonder someone has any idea how to solve this:

In my Java Eclipse plugin there are some processes which take some time. Therefore the user might minimize the window and let the process run in the background.
Now, when the process is finished, I can force the window to come to the top again, but that is a no-no in usability. I'd rather want the process to blink in the taskbar instead. Is there any way to achieve this?

I had a look at the org.eclipse.jface.window but could'nt find anything like that, same goes for the SWT documentation...

Another thing which came to my mind - as people are using this app on mac os x and linux as well, is there a platform independant solution, which will inform the user that the process has finished but without bringing the window to the top?

Any ideas are highly welcome!


I found out that on windows the user can adjust whether he would like to enable a force to foreground or not. If that option is disabled, the task will just blink in the taskbar...
Here's a good read on that...

If anyone maybe knows about some platform independant way of achieving this kind of behaviour, please share your knowledge with me!

我不认为有平台独立的方式做这个。您将需要查看特定于平台的API调用,并通过JNI或JNA实现它们。

I don't think there's a platform independent way of doing this. You will have to take a look at the platform-specific API calls and implement them via JNI or JNA.

对于Windows,以下是我自己的一个应用程序的代码段:

For Windows, here's a snippet from one of my own applications:

public static void flashWindow(final Shell shell, boolean flashTray,
        boolean flashWindow) {
    try {
        if (isActiveWindow(shell)) {
            flashWindow = false;
            flashTray = false;
        }
        User32 lib = (User32) getLibrary("user32", User32.class);
        User32.FLASHWINFO flash = new User32.FLASHWINFO();
        flash.hWnd = new W32API.HANDLE(new W32API.UINT_PTR(shell.handle)
                .toPointer());
        flash.uCount = 2;
        flash.dwTimeout = 1000;
        if (flashTray || flashWindow) {
            flash.dwFlags = (flashTray ? User32.FLASHW_TRAY : 0)
                    | (flashWindow ? User32.FLASHW_CAPTION : 0);
        } else {
            flash.dwFlags = User32.FLASHW_STOP;
        }
        flash.cbSize = flash.size();
        if (lib.FlashWindowEx(flash) && !flashWindow) {
            final FocusListener focusListener = new FocusListener() {
                public void focusGained(FocusEvent arg0) {
                    flashWindow(shell, false, false);
                    shell.removeFocusListener(this);
                }

                public void focusLost(FocusEvent arg0) {
                }
            };
            shell.addFocusListener(focusListener);
        }
    } catch (UnsatisfiedLinkError e) {
    }
}

这是一个简化版本的 getLibrary()

protected static StdCallLibrary getLibrary(String libraryName,
        Class<?> interfaceClass) throws UnsatisfiedLinkError {
    try {
        StdCallLibrary lib = (StdCallLibrary) Native.loadLibrary(libraryName,
                interfaceClass);
        return lib;
    } catch (UnsatisfiedLinkError e) {
        Logger.out.error("Could not load " + libraryName + " library.");
        throw e;
    }
}

注意 dispose )图书馆完成后。