elemental.events.KeyboardEvent Java Examples
The following examples show how to use
elemental.events.KeyboardEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemErrorHandler.java From flow with Apache License 2.0 | 6 votes |
/** * Shows an error notification for an error which is unrecoverable, using * the given parameters. * * @param caption * the caption of the message * @param message * the message body * @param details * message details or {@code null} if there are no details * @param url * a URL to redirect to when the user clicks the message or * {@code null} to refresh on click * @param querySelector * query selector to find the element under which the error will * be added . If element is not found or the selector is * {@code null}, body will be used */ public void handleUnrecoverableError(String caption, String message, String details, String url, String querySelector) { if (caption == null && message == null && details == null) { if (!isWebComponentMode()) { WidgetUtil.redirect(url); } return; } Element systemErrorContainer = handleError(caption, message, details, querySelector); if (!isWebComponentMode()) { systemErrorContainer.addEventListener("click", e -> WidgetUtil.redirect(url), false); Browser.getDocument().addEventListener(Event.KEYDOWN, e -> { int keyCode = ((KeyboardEvent) e).getKeyCode(); if (keyCode == KeyCode.ESC) { e.preventDefault(); WidgetUtil.redirect(url); } }, false); } }
Example #2
Source File: Client.java From vertxui with GNU General Public License v3.0 | 5 votes |
public Client() { head.script(FigWheelyClient.urlJavascript); EventBus.importJs((Void) -> { String name = window.prompt("What is your name?", ""); Fluent input = body.input(null, "text"); Fluent messages = body.div(); EventBus eventBus = EventBus.create(url, null); eventBus.onopen(event -> { eventBus.publish(freeway, name + ": Ola, I'm " + name + ".", null); eventBus.registerHandler(freeway, null, (error, in) -> { // onmessage messages.li(null, in.get("body").asString()); }); // extra example: pojo consume Pojofy.eventbusReceive(eventBus, addressPojo, null, AllExamplesClient.dto, a -> console.log("Received pojo: " + a.color)); }); input.keydown((fluent, event) -> { if (event.getKeyCode() == KeyboardEvent.KeyCode.ENTER) { eventBus.publish(freeway, name + ": " + input.domValue(), null); input.att(Att.value, null); // extra example: object publish Pojofy.eventbusPublish(eventBus, addressPojo, new Dto("blue by " + name), Json.parse("{\"action\":\"save\"}"), AllExamplesClient.dto); } }); input.focus(); }); }
Example #3
Source File: InputNumber.java From vertxui with GNU General Public License v3.0 | 5 votes |
public InputNumber() { super("input", null); att(Att.type, "text").css(Css.width, "39px").keypress((Fluent ___, KeyboardEvent event) -> { int code = event.getCharCode(); if ((code >= 48 && code <= 57) || code == 0 || code == 46) { return; } event.preventDefault(); }); }
Example #4
Source File: Client.java From vertxui with GNU General Public License v3.0 | 5 votes |
public Client() { head.script(FigWheelyClient.urlJavascript); SockJS.importJs((Void) -> { String name = window.prompt("What is your name?", ""); Fluent input = body.input(null, "text"); Fluent messages = body.div(); SockJS socket = SockJS.create(url); socket.setOnopen(e -> { socket.send(name + ": Ola, I'm " + name + "."); }); socket.setOnmessage(e -> { // extra: pojo example if (Pojofy.socketReceive(urlPojo, e, AllExamplesClient.dto, d -> console.log("Received pojo color=" + d.color))) { return; } messages.li(null, ((MessageEvent) e).getData().toString()); }); input.keydown((fluent, event) -> { if (event.getKeyCode() == KeyboardEvent.KeyCode.ENTER) { socket.send(name + ": " + input.domValue()); input.att(Att.value, null); // extra: pojo example Pojofy.socketSend(socket, urlPojo, new Dto("violet"), AllExamplesClient.dto, Json.parse("{\"action\":\"save\"}")); } }); input.focus(); }); }
Example #5
Source File: Controller.java From vertxui with GNU General Public License v3.0 | 5 votes |
public void onBillOnlyNumeric(Fluent __, KeyboardEvent event) { int code = event.getCharCode(); if ((code >= 48 && code <= 57) || code == 0) { return; // numeric or a not-a-character is OK } event.preventDefault(); }
Example #6
Source File: Controller.java From vertxui with GNU General Public License v3.0 | 5 votes |
public void onGroceryAdd(Fluent fluent, KeyboardEvent event) { if (event.getKeyCode() != KeyboardEvent.KeyCode.ENTER) { return; } // Internet explorer 11 // PREVENT SENDING THE FORM BECAUSE IT HAS ONLY ONE ELEMENT event.preventDefault(); String text = fluent.domValue(); if (!text.isEmpty()) { fluent.att(Att.value, null); // Apply change in model grocery.all.add(text); // Push model to view view.syncGrocery(); // Push change to server store.addGrocery(text, textOnError -> { view.errorGroceryAdd(text); grocery.all.remove(text); view.syncGrocery(); }); } }
Example #7
Source File: Controller.java From vertxui with GNU General Public License v3.0 | 5 votes |
public void onInput(Fluent fluent, KeyboardEvent event) { if (event.getKeyCode() == KeyboardEvent.KeyCode.ENTER) { String value = fluent.domValue().trim(); if (!value.isEmpty()) { addModel(value); fluent.att(Att.value, ""); } } }
Example #8
Source File: Controller.java From vertxui with GNU General Public License v3.0 | 5 votes |
public void onEditKey(Fluent fluent, KeyboardEvent event) { if (event.getKeyCode() != KeyboardEvent.KeyCode.ENTER) { return; } String value = fluent.domValue().trim(); Model model = state.getEditing(); if (!value.isEmpty()) { store.setText(model, value); } else { store.remove(model); } state.setEditing(null); view.syncModel(); view.syncState(); }
Example #9
Source File: GuidedTourHelper.java From core with GNU Lesser General Public License v2.1 | 5 votes |
static void init(BootstrapContext bootstrapContext) { String locale = Preferences.get(Preferences.Key.LOCALE, "en"); String url = bootstrapContext.getProperty(ApplicationProperties.GUIDED_TOUR) + "/" + (bootstrapContext.isStandalone() ? "standalone" : "domain") + "/step1.html?setLng=" + locale; Frame tourFrame = new Frame(url); tourFrame.setWidth("100%"); tourFrame.setHeight("100%"); guidedTour = new PopupPanel(true, true) { { Window.addResizeHandler(resizeEvent -> { if (isShowing()) { center(); } }); } @Override protected void onPreviewNativeEvent(Event.NativePreviewEvent event) { if (Event.ONKEYUP == event.getTypeInt()) { if (event.getNativeEvent().getKeyCode() == KeyboardEvent.KeyCode.ESC) { hide(); } } } }; guidedTour.setGlassEnabled(true); guidedTour.setAnimationEnabled(false); guidedTour.setWidget(tourFrame); guidedTour.setWidth("1120px"); guidedTour.setHeight("800px"); guidedTour.setStyleName("default-window"); exportCloseMethod(); }
Example #10
Source File: FluentBase.java From vertxui with GNU General Public License v3.0 | 3 votes |
/** * A convenient helper method for this event listener - also executes * event.stopPropagation(). * * @param listener * the listener * @return this */ public Fluent keyup(BiConsumer<Fluent, KeyboardEvent> listener) { return listen(Event.KEYUP, event -> { event.stopPropagation(); listener.accept((Fluent) this, (KeyboardEvent) event); }); }
Example #11
Source File: FluentBase.java From vertxui with GNU General Public License v3.0 | 3 votes |
/** * A convenient helper method for this event listener - also executes * event.stopPropagation(). * * @param listener * the listener * @return this */ public Fluent keydown(BiConsumer<Fluent, KeyboardEvent> listener) { return listen(Event.KEYDOWN, event -> { event.stopPropagation(); listener.accept((Fluent) this, (KeyboardEvent) event); }); }
Example #12
Source File: FluentBase.java From vertxui with GNU General Public License v3.0 | 3 votes |
/** * A convenient helper method for this event listener - also executes * event.stopPropagation(). * * @param listener * the listener * @return this */ public Fluent keypress(BiConsumer<Fluent, KeyboardEvent> listener) { return listen(Event.KEYPRESS, event -> { event.stopPropagation(); listener.accept((Fluent) this, (KeyboardEvent) event); }); }