如何处理 GWT Cloud 中的 Click 事件或任何其他事件?

发布于 2024-10-06 03:30:25 字数 108 浏览 7 评论 0原文

我正在使用 tagcloud_0.4.jar 在 GWT 中使用标签云。现在,当我单击标签云中的任何标签时,如何处理该事件,或者当用户从云中选择任何标签时如何进行 RPC 调用?

谢谢。

I am using tagcloud_0.4.jar for using Tag Cloud in GWT. Now, when I click on any tag inside the tag cloud, then how can I handle that event or how can I do RPC call when user select any tag from cloud?

Thanks.

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

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

发布评论

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

评论(1

咋地 2024-10-13 03:30:25

下面是在云端捕获 ClickEvent 的示例。但这是一种解决方法,因为库可能会发生变化。由于开发人员不提供管理云上和标签上的事件,这可能是有充分理由的......

因此,使用此代码需要您自担风险。祈祷小部件的 DOM 结构不会发生变化。我建议您向开发人员询问其小部件的一些增强功能,例如管理此类事件。

    final TagCloud cloud = new TagCloud();

    cloud.addWord(new WordTag("AAA"));
    cloud.addWord(new WordTag("AAA"));
    cloud.addWord(new WordTag("BBB"));
    cloud.addWord(new WordTag("CCC"));
    cloud.addWord(new WordTag("CCC"));
    cloud.addWord(new WordTag("CCC"));

    cloud.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // Prevent the click from the tag to be executed
            event.preventDefault();

            Element e;
            // For each tag present in the cloud, look for the one that is triggered
            for (int i = 0; i < cloud.getTags().size(); ++i) {
                // Gets the element in the cloud, this really is the unsafe part of the code
                // if the developer change the dom of its widget
                e = DOM.getChild(DOM.getChild(cloud.getElement(), 0), i);
                // Is the current element targeted by the event?
                if (event.getClientX() >= e.getOffsetLeft() && event.getClientY() >= e.getOffsetTop()
                        && event.getClientX() <= e.getOffsetLeft() + e.getOffsetWidth()
                        && event.getClientY() <= e.getOffsetTop() + e.getOffsetHeight()) {
                    // Gets the abstract tag
                    Tag t = cloud.getTags().get(i);
                    // Gets tag descendant
                    if (t instanceof WordTag) {
                        // Do what you want with your WordTag, maybe an RPC call
                    } else if (t instanceof ImageTag) {
                        // Do what you want with your ImageTag, maybe an RPC call
                    }

                    break;
                }
            }
        }
    }, ClickEvent.getType());

Here is an example to catch a ClickEvent on the cloud. But this is a workaround as the library may change. As the developper do not offer to manage events on the cloud neither on tags, this is perhaps for a good reason...

So use this code at your own risk. Pray for no change of the widget's structure DOM. I suggest you to ask the developper some enhancements on its widgets, like managing such events.

    final TagCloud cloud = new TagCloud();

    cloud.addWord(new WordTag("AAA"));
    cloud.addWord(new WordTag("AAA"));
    cloud.addWord(new WordTag("BBB"));
    cloud.addWord(new WordTag("CCC"));
    cloud.addWord(new WordTag("CCC"));
    cloud.addWord(new WordTag("CCC"));

    cloud.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // Prevent the click from the tag to be executed
            event.preventDefault();

            Element e;
            // For each tag present in the cloud, look for the one that is triggered
            for (int i = 0; i < cloud.getTags().size(); ++i) {
                // Gets the element in the cloud, this really is the unsafe part of the code
                // if the developer change the dom of its widget
                e = DOM.getChild(DOM.getChild(cloud.getElement(), 0), i);
                // Is the current element targeted by the event?
                if (event.getClientX() >= e.getOffsetLeft() && event.getClientY() >= e.getOffsetTop()
                        && event.getClientX() <= e.getOffsetLeft() + e.getOffsetWidth()
                        && event.getClientY() <= e.getOffsetTop() + e.getOffsetHeight()) {
                    // Gets the abstract tag
                    Tag t = cloud.getTags().get(i);
                    // Gets tag descendant
                    if (t instanceof WordTag) {
                        // Do what you want with your WordTag, maybe an RPC call
                    } else if (t instanceof ImageTag) {
                        // Do what you want with your ImageTag, maybe an RPC call
                    }

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