/** * Sets an event handler for an {@code Element}. All previous event handlers of this type of event are removed. * @param element The element to bind the event handler for * @param eventType The event type (e.g. {@code ClickEvent.getType()}) * @param handler The handler that handler the event */ public static <H extends EventHandler> void setEventHandler(final Element element, DomEvent.Type<H> eventType, H handler) { if (element == null) { return; } HandlerManager hm = handlerManagers.get(element); if (hm == null) { handlerManagers.put(element, hm = new HandlerManager(element)); DOM.setEventListener(element, new EventListener() { @Override public void onBrowserEvent(Event event) { DomEvent.fireNativeEvent(event, handlerManagers.get(element), element); } }); } DOM.sinkBitlessEvent(element, eventType.getName()); while (hm.getHandlerCount(eventType) > 0) { hm.removeHandler(eventType, hm.getHandler(eventType, 0)); } hm.addHandler(eventType, handler); }
private void updateEventHandler(final ContentElement element, String eventHandlerId) { Element implNodelet = element.getImplNodelet(); final EventHandler handler = eventHandlerId == null ? null : AnnotationPaint.eventHandlerRegistry.get(eventHandlerId); if (handler != null) { DOM.sinkEvents(DomHelper.castToOld(implNodelet), MOUSE_LISTENER_EVENTS); DOM.setEventListener(DomHelper.castToOld(implNodelet), new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onEvent(element, event); } }); } else { removeListener(DomHelper.castToOld(implNodelet)); } }
protected void addActivityTimer() { if (CMDBSession.get().getConfig().getDesktopLockTimeout() < 0) { return; } lastActivityTime = System.currentTimeMillis(); //add event capture to detect user activity and reset idle timeout DOM.setEventListener(RootPanel.get().getElement(), new EventListener() { public void onBrowserEvent(Event event) { lastActivityTime = System.currentTimeMillis(); } }); DOM.sinkEvents(RootPanel.get().getElement(), Event.ONMOUSEDOWN); }
@Override protected void onLoad() { super.onLoad(); // Set page title & description setLayoutTitle(cons.sideMenuTitle()); setLayoutDescription(cons.sideMenuDescription()); // Inject layout stylesheet res.sideMenuLayoutCssResource().ensureInjected(); // Bind click event to menu button DOM.setEventListener(menuLink, new EventListener() { @Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONCLICK) { toggleClass(layout.getElement(), res.sideMenuLayoutCssResource().active()); toggleClass(menu, res.sideMenuLayoutCssResource().active()); toggleClass(menuLink, res.sideMenuLayoutCssResource().active()); event.preventDefault(); } } }); DOM.sinkEvents(menuLink, Event.ONCLICK); }
@Override public final HandlerRegistration addConnectivityHandler(final ConnectivityEvent.Handler handler) { EventListener el = new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onConnectivity((ConnectivityEventJsoImpl) event.cast()); } }; final HandlerRegistration hr1 = register(this, "online", el); final HandlerRegistration hr2 = register(this, "offline", el); return new HandlerRegistration() { @Override public void removeHandler() { hr1.removeHandler(); hr2.removeHandler(); } }; }
private Element convertItemToOpenable (String key, SafeHtml title) { activateItem(key, false); Element element = getItem(key); ensureItems().remove(key); element.setClassName("dropdown"); final AnchorElement a = AnchorElement .as(element.getFirstChildElement()); a.removeAttribute("href"); Event.sinkEvents(a, Event.ONCLICK); Event.setEventListener(a, new EventListener() { @Override public void onBrowserEvent (Event event) { openableClick(a); event.stopPropagation(); } }); a.addClassName("dropdown-toggle"); a.setInnerSafeHtml(title); Element ul = Document.get().createULElement(); ul.addClassName("dropdown-menu"); element.appendChild(ul); ensureOpenables().put(key, element); return element; }
public EventListener acquireLockOnDemand(final Element element) { Event.sinkEvents(element, lockDemandDetector.getLockDemandEventTypes()); EventListener lockDemandListener = new EventListener() { @Override public void onBrowserEvent(Event event) { if (isLockedByCurrentUser()) { return; } if (lockDemandDetector.isLockRequired(event)) { acquireLock(); } } }; Event.setEventListener(element, lockDemandListener); return lockDemandListener; }
private void addButton(String id, final Image image, VerticalPanel iconsPanel) { Element element = layout.getElement(id); image.setStyleName(STYLE_CLICKABLE); if (element==null) { image.addClickHandler(mainClickHandler); iconsPanel.add(image); iconsPanel.setCellHeight(image, "1%"); iconsPanel.setCellWidth(image, "100%"); } else { com.google.gwt.user.client.Element el = (com.google.gwt.user.client.Element) element; DOM.sinkEvents(el,Event.ONCLICK); DOM.setEventListener(el, new EventListener(){ public void onBrowserEvent(Event event) { processClick(image); } }); layout.addStyle(id, PlayerLayout.BUTTON_ON_STYLE); } }
private void appendInSpan(final Widget widget, boolean wordWrap) { Element el = DOM.createSpan(); Element oldEl = widget.getElement(); DOM.setInnerHTML(el, DOM.getInnerHTML(oldEl)); String style = widget.getStyleName(); if (style != null && style.length()>0) { DOM.setElementProperty(el, "className", style); } if (wordWrap) { DOM.setStyleAttribute(el, "whiteSpace", "normal"); } else { DOM.setStyleAttribute(el, "whiteSpace", "nowrap"); } EventListener eventListener = new EventListener() { public void onBrowserEvent(Event event) { widget.onBrowserEvent(event); } }; DOM.setEventListener(el, eventListener); DOM.sinkEvents(el, DOM.getEventsSunk(oldEl)); DOM.appendChild(getElement(), el); }
@Override protected void onLoad() { super.onLoad(); // Set page title & description setLayoutTitle(cons.sideMenuTitle()); setLayoutDescription(cons.sideMenuDescription()); // Inject layout stylesheet SandboxResourceBundle.INSTANCE.sideMenuLayoutCssResource().ensureInjected(); // Bind click event to menu button DOM.setEventListener(menuLink, new EventListener() { @Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONCLICK) { toggleClass(layout.getElement(), res.sideMenuLayoutCssResource().active()); toggleClass(menu, res.sideMenuLayoutCssResource().active()); toggleClass(menuLink, res.sideMenuLayoutCssResource().active()); event.preventDefault(); } } }); DOM.sinkEvents(menuLink, Event.ONCLICK); }
public ImageTracker(String imageUrl) { m_image = new Image(imageUrl); Event.setEventListener(m_image.getElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { if(Event.ONLOAD == event.getTypeInt()) { callHandlers(); m_loadComplete = true; } } }); Element div = Document.get().getElementById(m_trackerDivId); div.appendChild(m_image.getElement()); //Document.get().getBody().appendChild(m_image.getElement()); }
public void upload(final Renderer3d renderer3d, final Texture texture, final int activeTexture) { if ((texture.status & GpuObjectStatus.TEXTURE_UPLOADING) == 0) { texture.status |= GpuObjectStatus.TEXTURE_UPLOADING; Integer Integer = gl.createTexture(); textures.put(texture, Integer); ImageElement textureImage = resourceLoader.getImage(texture.image); if (textureImage == null) { Window.alert("Texture image not found in resources: " + texture.image); } else { textureImages.put(texture, textureImage); Event.setEventListener(textureImage, new EventListener() { @Override public void onBrowserEvent(Event event) { textureLoaded(renderer3d, texture, activeTexture); } }); Event.sinkEvents(textureImage, Event.ONLOAD); } } }
public void upload(final Renderer3d renderer3d, final CubeMapTexture cubeMapTexture, final int activeTexture) { if ((cubeMapTexture.status & GpuObjectStatus.TEXTURE_UPLOADING) == 0) { cubeMapTexture.status |= GpuObjectStatus.TEXTURE_UPLOADING; Integer texture = gl.createTexture(); cubeMapTextures.put(cubeMapTexture, texture); ImageElement[] textureImages = new ImageElement[6]; cubeMapImages.put(cubeMapTexture, textureImages); for (int i = 0; i < 6; i++) { textureImages[i] = resourceLoader.getImage(cubeMapTexture.images[i]); Event.setEventListener(textureImages[i], new EventListener() { @Override public void onBrowserEvent(Event event) { cubeTextureLoaded(renderer3d, cubeMapTexture, activeTexture); } }); Event.sinkEvents(textureImages[i], Event.ONLOAD); } } }
public void addModule(final String entered) { if (modules.add(entered)) { final Element clone = Element.as(moduleTemplate.getElement().cloneNode(true)); clone.removeClassName(res.css().hidden()); Element el = clone.getFirstChildElement().getNextSiblingElement(); el.setInnerText(entered); com.google.gwt.user.client.Element image = el.getNextSiblingElement().cast(); DOM.setEventListener(image, new EventListener() { @Override public void onBrowserEvent(Event event) { modules.remove(entered); clone.removeFromParent(); } }); DOM.sinkEvents(image, Event.ONCLICK | Event.ONKEYDOWN); selectedModules.appendChild(clone); } }
public WebcamConnector() { getWidget().setClickListener(new EventListener() { @Override public void onBrowserEvent(Event event) { // Commanded by the user clicking the client-side widget. captureNow(); } }); registerRpc(WebcamClientRpc.class, new WebcamClientRpc() { @Override public void capture() { // Commanded by the server-side component. captureNow(); } }); }
/** * private implementation of adding an {@link EventListener} as the recipient * of event dispatches for a specific event type on a specific element. * * @param type * @param sourceElem * @param listener * @return */ private static native EventRemover addEventListenerImpl(String type, JavaScriptObject sourceElem, EventListener listener) /*-{ var f = function(event) { listener. @com.google.gwt.user.client.EventListener::onBrowserEvent(Lcom/google/gwt/user/client/Event;) (event); } // Hang an expando that allows us to unhook this event f.remove = function() { sourceElem.removeEventListener(type,f,false); } // Register the event listener sourceElem.addEventListener(type,f,false); return f; }-*/;
private void draw() { while (element.getFirstChild() != null) { element.removeChild(element.getFirstChild()); } for (int i = 0; i < mAdapter.getCount(); i++) { final View v = mAdapter.getView(i, null, null); final int index = i; final long id = mAdapter.getItemId(i); Event.setEventListener(v.getElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { if (listener != null) { listener.onItemClick(null, v, index, id); } } }); Event.sinkEvents(v.getElement(), Event.ONCLICK); element.appendChild(v.getElement()); } }
public Image(String url) { this(url, null, false); if (url == null) { throw new NullPointerException("The url parameter can not be null."); } final Element e = DOM.createImg(); DOM.setEventListener((com.google.gwt.user.client.Element) e, new EventListener() { @Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONLOAD) { width = Integer.parseInt(e.getPropertyString("width")); height = Integer.parseInt(e.getPropertyString("height")); loaded = true; onLoad.fireEvent(new EventArgs(this)); } } }); DOM.sinkEvents((com.google.gwt.user.client.Element) e, Event.ONLOAD); DOM.setImgSrc((com.google.gwt.user.client.Element) e, url); }
private void addClickHandler(Set<String> ids, final VizClickHandler handler) { for (String nodeId : ids) { Element svgNode = DOM.getElementById(nodeId); Event.sinkEvents(svgNode, Event.ONCLICK); Event.setEventListener(svgNode, new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onClick(event); } }); } }
private static void focus(NativeEvent event) { Element e = Element.as(event.getEventTarget()); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof Unified) { ((Unified) l).getCmFromSide(DisplaySide.A).focus(); event.stopPropagation(); } } }
private static void focus(NativeEvent event, DisplaySide side) { Element e = Element.as(event.getEventTarget()); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof SideBySide) { ((SideBySide) l).getCmFromSide(side).focus(); event.stopPropagation(); } } }
private Reviewers getReviewers() { Element e = DOM.getParent(getElement()); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof ChangeScreen) { ChangeScreen screen = (ChangeScreen) l; return screen.reviewers; } } return null; }
static ChangeScreen get(NativeEvent in) { Element e = in.getEventTarget().cast(); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof ChangeScreen) { return (ChangeScreen) l; } } return null; }
private static PatchSetsBox getRevisionBox(NativeEvent event) { Element e = event.getEventTarget().cast(); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof PatchSetsBox) { return (PatchSetsBox) l; } } return null; }
private static MyTable getMyTable(NativeEvent event) { Element e = event.getEventTarget().cast(); for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) { EventListener l = DOM.getEventListener(e); if (l instanceof MyTable) { return (MyTable) l; } } return null; }
private GPixmap decodeJPEG(CachedInputStream iff) throws IOException { final GPixmap result = new GPixmap(); final Image image = new Image(); final ImageElement imageElement = image.getElement().cast(); imageElement.getStyle().setProperty("visibility", "hidden"); Event.setEventListener(imageElement, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONLOAD == event.getTypeInt()) { final int w = imageElement.getWidth(), h = imageElement.getHeight(); final Canvas canvas = Canvas.createIfSupported(); canvas.setWidth(w + "px"); canvas.setCoordinateSpaceWidth(w); canvas.setHeight(h + "px"); canvas.setCoordinateSpaceHeight(h); canvas.getContext2d().drawImage(imageElement, 0, 0); result.init(h, w, null); //TODO result.setImageData(canvas.getContext2d().getImageData(0, 0, w, h)); } } }); StringBuilder data = new StringBuilder(); int b; while ((b = iff.read()) != -1) { data.append((char) b); } String dataURL = "data:image/jpeg;base64," + btoa(data.toString()); image.setUrl(dataURL); return result; }
@Override public final HandlerRegistration addErrorHandler(final ErrorEvent.Handler handler) { return register(this, "error", new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onError((ErrorEventJsoImpl) event.cast()); } }); }
@Override public final HandlerRegistration addLanguageChangeHandler(final LanguageChangeEvent.Handler handler) { return register(this, "languagechange", new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onLanguageChange((LanguageChangeEventJsoImpl) event.cast()); } }); }
@Override public final HandlerRegistration addMessageHandler(final MessageHandler handler) { return register(this, "message", new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onMessage((MessageEventJsoImpl) event.cast()); } }); }
@Override public final HandlerRegistration addConnectHandler(final ConnectHandler handler) { return register(this, "connect", new EventListener() { @Override public void onBrowserEvent(Event event) { handler.onConnect((MessageEventJsoImpl) event.cast()); } }); }
private Element addOpenable (Element parent, SafeHtml title, SafeUri href) { String key = href.asString().replaceFirst("#", ""); final Element got; final Element element = (got = getOpenable(key)) == null ? Document.get().createLIElement() : got; element.setClassName("dropdown"); parent.appendChild(element); final Element a = Document.get().createAnchorElement(); element.appendChild(a); Event.sinkEvents(a, Event.ONCLICK); Event.setEventListener(a, new EventListener() { @Override public void onBrowserEvent (Event event) { openableClick(a); event.stopPropagation(); } }); a.addClassName("dropdown-toggle"); a.setInnerSafeHtml(title); Element ul = Document.get().createULElement(); ul.addClassName("dropdown-menu"); element.appendChild(ul); ensureOpenables().put(key, element); return element; }
public void setStackHeader(int row, String name, String icon_url, String title,EventListener sortListener) { StringBuffer buffer = new StringBuffer(); buffer.append("<div class=\"notes_panel_header_left\">"); buffer.append("<div class=\"notes_panel_header_right\" >"); buffer.append("<div class=\"notes_panel_header_inside\">"); buffer.append("<img src=\""); buffer.append(icon_url); buffer.append("\"/>"); buffer.append(name); if (sortListener != null) { buffer.append("<img src=\""); buffer.append(Images.SORT); buffer.append("\" title=\""); buffer.append(AppLocale.getAppConstants().sort()); buffer.append("\"/>"); } buffer.append("</div></div></div>"); setStackText(row, buffer.toString(), true); Element wrapper = getHeaderWrapper(row); if (sortListener != null) { Element tdWrapper = DOM.getChild(wrapper, 0); tdWrapper = DOM.getChild(tdWrapper,0); tdWrapper = DOM.getChild(tdWrapper,0); tdWrapper = DOM.getChild(tdWrapper,0); tdWrapper = DOM.getChild(tdWrapper,1); DOM.sinkEvents(tdWrapper,Event.ONCLICK); DOM.setEventListener(tdWrapper, sortListener); } DOM.setStyleAttribute(wrapper, "height", "20px"); setTitle(row, title); selectHeader(row, false); }
/** * Creates a control styled by a specified CSS class selector name. Performs * the inputed action on click. * * @param cssClassName * @param action */ public void addControl(String cssClassName, EventListener action) { DivElement control = Document.get().createDivElement(); control.setClassName(resources.controlBarCss().control() + " " + cssClassName); DomUtils.addEventListener("click", control, action); controls.add(control); }
/** * Attaches an EventListener to the resize event on the Window. */ private void hookResizeListener() { DomUtils.getWindow().addResizeListener(new EventListener() { public void onBrowserEvent(Event event) { doResize(); } }); }
/** * Creates the controls to be added to a TaskDetails. */ public static Controls createControls(final Controller controller, TaskDetails.Resources resources) { TaskDetails.Css css = resources.taskDetailsCss(); Controls controls = new Controls(resources); controls.addControl(css.back(), new EventListener() { public void onBrowserEvent(Event event) { controller.goToTaskList(); } }); return controls; }
public static Widget getWidget(Element element) { EventListener listener = DOM.getEventListener(element); if (listener == null) { return null; } if (listener instanceof Widget) { return (Widget)listener; } return null; }