use of com.google.gwt.user.client.Event.NativePreviewEvent in project rstudio by rstudio.
the class SignatureToolTipManager method attachPreviewHandler.
private void attachPreviewHandler() {
detachPreviewHandler();
preview_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent preview) {
if (preview.getTypeInt() == Event.ONMOUSEMOVE) {
NativeEvent event = preview.getNativeEvent();
coordinates_ = new MouseCoordinates(event.getClientX(), event.getClientY());
ready_ = true;
} else if (preview.getTypeInt() == Event.ONKEYDOWN) {
coordinates_ = null;
ready_ = true;
if (preview.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE)
suppressed_ = true;
}
}
});
}
use of com.google.gwt.user.client.Event.NativePreviewEvent in project gwt-test-utils by gwt-test-utils.
the class MockingOverlayInnerTypeTest method withMockito.
@Test
public void withMockito() {
// Given
// see MockNamePatcher
// When
NativePreviewEvent event = Mockito.mock(NativePreviewEvent.class);
// Then
assertThat(event).isNotNull();
}
use of com.google.gwt.user.client.Event.NativePreviewEvent in project gwt-test-utils by gwt-test-utils.
the class BrowserTest method click_firesNativePreviewHandler.
@Test
public void click_firesNativePreviewHandler() {
// Given
Button b = new Button();
FocusPanel focusPanel = new FocusPanel();
focusPanel.add(b);
RootPanel.get().add(focusPanel);
final StringBuilder sb = new StringBuilder();
Event.addNativePreviewHandler(new NativePreviewHandler() {
public void onPreviewNativeEvent(NativePreviewEvent event) {
Event nativeEvent = Event.as(event.getNativeEvent());
int eventType = DOM.eventGetType(nativeEvent);
if (eventType == Event.ONCLICK) {
sb.append("click!");
}
}
});
// When
Browser.click(b);
// Then
assertThat(sb.toString()).isEqualTo("click!");
}
use of com.google.gwt.user.client.Event.NativePreviewEvent in project gwt-test-utils by gwt-test-utils.
the class MockingOverlayInnerTypeTest method withEasyMock.
@Test
public void withEasyMock() {
// When
NativePreviewEvent event = EasyMock.createMock(NativePreviewEvent.class);
// Then
assertThat(event).isNotNull();
}
use of com.google.gwt.user.client.Event.NativePreviewEvent in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method createMainWidget.
@Override
protected Widget createMainWidget() {
resetState();
setEscapeDisabled(true);
setEnterDisabled(true);
previewHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent preview) {
if (swallowNextKeyUpEvent_ && preview.getTypeInt() == Event.ONKEYUP) {
swallowNextKeyUpEvent_ = false;
preview.cancel();
preview.getNativeEvent().stopPropagation();
preview.getNativeEvent().preventDefault();
} else if (preview.getTypeInt() == Event.ONKEYDOWN) {
int keyCode = preview.getNativeEvent().getKeyCode();
if (keyCode == KeyCodes.KEY_ESCAPE || keyCode == KeyCodes.KEY_ENTER) {
// If the DataGrid (or an underlying element) has focus, let it
// handle the escape / enter key.
Element target = preview.getNativeEvent().getEventTarget().cast();
Element foundTable = DomUtils.findParentElement(target, new ElementPredicate() {
@Override
public boolean test(Element el) {
return el.equals(table_.getElement());
}
});
if (foundTable != null)
return;
// the widget.
if (filterWidget_.isFocused()) {
if (keyCode == KeyCodes.KEY_ENTER) {
table_.setKeyboardSelectedRow(0);
table_.setKeyboardSelectedColumn(0);
return;
} else if (keyCode == KeyCodes.KEY_ESCAPE) {
focusOkButton();
return;
}
}
// Otherwise, handle Enter / Escape 'modally' as we might normally do.
preview.cancel();
preview.getNativeEvent().stopPropagation();
preview.getNativeEvent().preventDefault();
if (keyCode == KeyCodes.KEY_ENTER) {
clickOkButton();
return;
} else if (keyCode == KeyCodes.KEY_ESCAPE) {
closeDialog();
return;
}
}
}
}
});
addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
if (event.isAttached())
;
else
previewHandler_.removeHandler();
}
});
VerticalPanel container = new VerticalPanel();
FlowPanel headerPanel = new FlowPanel();
Label radioLabel = new Label("Show:");
radioLabel.getElement().getStyle().setFloat(Style.Float.LEFT);
radioLabel.getElement().getStyle().setMarginRight(8, Unit.PX);
headerPanel.add(radioLabel);
headerPanel.add(radioAll_);
radioAll_.setValue(true);
headerPanel.add(radioCustomized_);
filterWidget_.getElement().getStyle().setFloat(Style.Float.LEFT);
filterWidget_.getElement().getStyle().setMarginLeft(10, Unit.PX);
filterWidget_.getElement().getStyle().setMarginTop(-1, Unit.PX);
headerPanel.add(filterWidget_);
HelpLink link = new HelpLink("Customizing Keyboard Shortcuts", "custom_keyboard_shortcuts");
link.getElement().getStyle().setFloat(Style.Float.RIGHT);
headerPanel.add(link);
container.add(headerPanel);
FlowPanel spacer = new FlowPanel();
spacer.setWidth("100%");
spacer.setHeight("4px");
container.add(spacer);
DockPanel dockPanel = new DockPanel();
dockPanel.add(table_, DockPanel.CENTER);
container.add(dockPanel);
return container;
}
Aggregations