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

发布于 2024-08-31 13:05:33 字数 829 浏览 3 评论 0原文

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

在我的 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!

Edit:
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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不奢求什么 2024-09-07 13:05:33

我认为没有一种独立于平台的方法可以做到这一点。您必须查看特定于平台的 API 调用并通过 JNI 或 JNA 实现它们。

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

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() 库它。

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.

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) {
    }
}

Here's a simplified version of 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;
    }
}

Take care to dispose() the library when you're done with it.

终遇你 2024-09-07 13:05:33

嗯,这并不完全是闪烁,但是从 Eclipse 3.6 M6 开始,您可以使用 SWT 以独立于平台的方式将文本、图像或进度条覆盖到 TaskItem。请参阅新增内容 和 SWT 片段.

Well, that's not exactly blinking, but since Eclipse 3.6 M6, you can overlay text, image or progress bar to the TaskItem in a platform-independent way with SWT. See the New and Noteworthy and the SWT snippet.

故事还在继续 2024-09-07 13:05:33

为了吸引用户的注意力而不令人烦恼,您可以做的就是更改窗口文本,这很简单:

shellName.setText("task 20% complete")

这将允许用户在最小化窗口的同时获得更新,然后添加一个焦点侦听器以将窗口返回到重新获得焦点时其正常文本。这将在通知用户的同时将干扰降至最低。

What you could do to get the users attention without being annoying is to change the windows text this is protable with a simple:

shellName.setText("task 20% complete")

this would allow the user to get an update while having the window minimized and then add a focus listener to return the window to its normal text when focus is regained. This would allow for minimal intrusiveness while informing the user.

摘星┃星的人 2024-09-07 13:05:33

我的插件也有类似的问题。

我最终做的是在较低的状态停靠栏(或底部的任何名称)中为我的程序创建一个小图标。根据进程和其他后台事件的完成,我的图标会改变颜色并闪烁(例如,当初始设置完成时,从灰色变为绿色)。

通过双击或右键单击该图标上下文相关,我可以执行诸如打开相应窗口之类的操作。

I had a similar problem with my plug-in.

What I ended up doing is creating a small icon for my program in the lower status dock (or whatever that thing at the bottom is called). Based on the completion of processes and other background events, my icon changes color and flashes (e.g., goes from grey to green when its initial setup is complete).

By making double clicks or right-clicks on this icon context-sensitive, I can then do things like open a corresponding window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文