开发者

What type of event is control-click in gwt

开发者 https://www.devze.com 2023-01-16 07:19 出处:网络
What is the event type for the control click in a table cell in a GWT application?I want to basically change the color of the background when the user does this action.

What is the event type for the control click in a table cell in a GWT application? I want to basically change the color of the background when the user does this action.

This part of my code basically just looks like:

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.ONMOU开发者_运维技巧SEDOWN: {
            //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;
        }*/
        }

    }

What do I need to do to capture this event?


The http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/Event.html object passed into onBrowserEvent has methods. Methods such as boolean getCtrlKey().

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

This will work for Windows, not sure about Mac and Linux. On OS X you might check getMetaKey() instead, since Command is normally used where Control is used on Windows.


How about wrapping the contents of the cell in a FocusPanel and adding the appropriate handler (most likely MouseDownHandler)? (tip: create the handler once and add it to all the related cells)
You can also add key handlers, etc. to FocusPanel so you won't need to dabble in native browser events (which could lead to some trouble, browser-specific code, etc.), let GWT do that for you :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号