【问题标题】:What type of event is control-click in gwtgwt中的control-click是什么类型的事件
【发布时间】:2010-09-12 05:52:14
【问题描述】:

在 GWT 应用程序的表格单元格中单击控件的事件类型是什么?当用户执行此操作时,我想基本上改变背景的颜色。

我的这部分代码基本上是这样的:

public void onBrowserEvent(Event event) {
        Element td = getEventTargetCell(event);

        if (td == null) return;
        Element tr = DOM.getParent(td);

        System.out.println("Event " + Event.getCurrentEvent());
        switch (DOM.eventGetType(event)) {
        case Event.ONMOUSEDOWN: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            onRowClick(tr);
            break;
        }
        case Event.ONMOUSEUP: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
            break;
        }
        case Event.ONMOUSEOVER: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            onRowRollover(tr);
            break;
        }
        case Event.ONMOUSEOUT: {
            //DOM.setStyleAttribute(td, "backgroundColor","#ffffff");
            break;
        }
        /*case Event.ONCLICK: {
            DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }*/
        case Event.ONDBLCLICK: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
            break;
        }
        case Event.KEYEVENTS: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }
        case Event.ONFOCUS: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }
        /*case Event. {
            DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }*/
        }

    }

我需要做什么来捕捉这个事件?

【问题讨论】:

    标签: gwt cell jquery-ui-selectable


    【解决方案1】:

    传递给 onBrowserEvent 的 http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/Event.html 对象有方法。 boolean getCtrlKey()等方法。

    case Event.ONCLICK: {
        if (event.getCtrlKey()) {
            DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
        }
        break;
    }
    

    这适用于 Windows,不确定 Mac 和 Linux。在 OS X 上,您可以改为检查 getMetaKey(),因为 Command 通常用于在 Windows 上使用 Control 的地方。

    【讨论】:

      【解决方案2】:

      如何将单元格的内容包装在FocusPanel 中并添加适当的处理程序(很可能是MouseDownHandler)? (提示:创建一次处理程序并将其添加到所有相关单元格)
      您还可以将密钥处理程序等添加到FocusPanel,这样您就不需要涉足本机浏览器事件(这可能会导致一些麻烦,浏览器特定的代码等),让 GWT 为您做这件事:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-28
        • 2019-08-04
        • 2022-12-17
        • 1970-01-01
        • 1970-01-01
        • 2018-06-13
        相关资源
        最近更新 更多