List of usage examples for com.google.gwt.safehtml.shared SafeUri asString
String asString();
From source file:com.github.gwtbootstrap.client.ui.Form.java
License:Apache License
/** * Sets the 'action' associated with this form. This is the URL to which it * will be submitted./*www.j a va2s . com*/ * * @param url * the form's action */ public void setAction(SafeUri url) { setAction(url.asString()); }
From source file:net.codemirror.lib.Loader.java
License:Apache License
static void injectScript(SafeUri js, final AsyncCallback<Void> callback) { final ScriptElement[] script = new ScriptElement[1]; script[0] = ScriptInjector.fromUrl(js.asString()).setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override/*from w ww . j a v a2 s . co m*/ public void onSuccess(Void result) { script[0].removeFromParent(); callback.onSuccess(result); } @Override public void onFailure(Exception reason) { error(reason); callback.onFailure(reason); } }).inject().cast(); }
From source file:nl.mpi.tg.eg.experiment.client.service.AudioPlayer.java
License:Open Source License
public AudioPlayer(AudioExceptionListner audioExceptionListner, SafeUri ogg, SafeUri mp3, boolean autoPlay) throws AudioException { this.audioExceptionListner = audioExceptionListner; this.autoPlay = autoPlay; try {/* w w w . j a v a 2 s . co m*/ createPlayer(); if (ogg != null) { final SourceElement sourceElement = audioPlayer.addSource(ogg.asString(), AudioElement.TYPE_OGG); onNoFoundSetup(sourceElement); } if (mp3 != null) { final SourceElement sourceElement = audioPlayer.addSource(mp3.asString(), AudioElement.TYPE_MP3); onNoFoundSetup(sourceElement); } //audioPlayer.setCurrentTime(0); // on android the if the ready state is not correct then this will fail and audio will not play audioPlayer.load(); // audioPlayer.pause(); } catch (AudioException audioException) { audioExceptionListner.audioExceptionFired(audioException); } }
From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java
License:Open Source License
public void addImage(SafeUri imagePath, final SafeUri linkUrl, int percentOfPage, int maxHeight, int maxWidth, String align) {//from w ww .j a va 2 s.c om final Image image = new Image(imagePath); addSizeAttributes(image.getElement(), percentOfPage, maxHeight, maxWidth); final SingleShotEventListner singleShotEventListner = new SingleShotEventListner() { @Override protected void singleShotFired() { Window.open(linkUrl.asString(), "_system", ""); } }; image.addClickHandler(singleShotEventListner); image.addTouchStartHandler(singleShotEventListner); image.addTouchMoveHandler(singleShotEventListner); image.addTouchEndHandler(singleShotEventListner); getActivePanel().add(image); }
From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java
License:Open Source License
public void addBackgroundImage(final SafeUri imagePath, final String styleName, final int postLoadMs, final TimedStimulusListener timedStimulusListener) { // final Image image = new Image(imagePath); // this.getElement().getStyle().setBackgroundColor("green"); if (imagePath == null) { this.getElement().getStyle().clearBackgroundImage(); } else {//from w w w .j a v a 2 s.c o m this.getElement().getStyle().setBackgroundImage("url(" + imagePath.asString() + ")"); } this.getElement().getStyle().setProperty("backgroundRepeat", "no-repeat"); // this.getElement().getStyle().setProperty("backgroundSize", "100% 100%"); this.getElement().getStyle().setProperty("backgroundRepeat", "no-repeat"); this.getElement().getStyle().setProperty("backgroundPosition", "50% 50%"); // remove the custom styles but keep the page width style this.setStyleName(this.getStyleName().contains("normalWidth") ? "normalWidth" : "narrowWidth"); if (styleName != null && !styleName.isEmpty()) { this.addStyleName(styleName); } else { this.getElement().getStyle().setProperty("backgroundSize", "cover"); // resizeView(); // this is to put back the screen size styles } // image.addLoadHandler(new LoadHandler() { // // @Override // public void onLoad(LoadEvent event) { Timer timer = new Timer() { @Override public void run() { timedStimulusListener.postLoadTimerFired(); } }; timerList.add(timer); timer.schedule(postLoadMs); // } // }); // outerPanel.add(image); }
From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java
License:Open Source License
public Element addTimedVideo(final TimedEventMonitor timedEventMonitor, final SafeUri oggPath, final SafeUri ogvPath, final SafeUri mp4Path, int percentOfPage, int maxHeight, int maxWidth, final String styleName, final boolean autoPlay, final boolean loop, final boolean showControls, final CancelableStimulusListener loadedStimulusListener, final CancelableStimulusListener failedStimulusListener, final CancelableStimulusListener playbackStartedStimulusListener, final CancelableStimulusListener playedStimulusListener, final String mediaId) { cancelableListnerList.add(loadedStimulusListener); cancelableListnerList.add(failedStimulusListener); cancelableListnerList.add(playbackStartedStimulusListener); cancelableListnerList.add(playedStimulusListener); final Element videoElement; if (timedEventMonitor != null) { timedEventMonitor.registerEvent("addTimedVideo"); }//w ww . j av a2 s . co m final Video video = Video.createIfSupported(); if (video == null) { failedStimulusListener.postLoadTimerFired(); videoElement = null; } else { video.setAutoplay(autoPlay); videoList.put(mediaId, video); // video.setPoster(poster); video.setControls(showControls); video.setPreload(MediaElement.PRELOAD_AUTO); if (styleName != null && !styleName.isEmpty()) { video.addStyleName(styleName); } else { addSizeAttributes(video.getElement(), percentOfPage, maxHeight, maxWidth); } getActivePanel().add(video); video.addCanPlayThroughHandler(new CanPlayThroughHandler() { boolean hasTriggeredOnLoaded = false; @Override public void onCanPlayThrough(CanPlayThroughEvent event) { if (!hasTriggeredOnLoaded) { if (timedEventMonitor != null) { timedEventMonitor.registerEvent("videoCanPlayThrough"); } hasTriggeredOnLoaded = true; loadedStimulusListener.postLoadTimerFired(); if (autoPlay) { video.play(); } if (video.getError() != null) { // todo: check that this method is functioning correctly and if not then use the method in audioPlayer.@nl.mpi.tg.eg.experiment.client.service.AudioPlayer::onAudioFailed()(); failedStimulusListener.postLoadTimerFired(); } } } }); new VideoPlayer().addNativeCallbacks(timedEventMonitor, video.getVideoElement(), playbackStartedStimulusListener); // todo: move the video handling code from here into the VideoPlayer class, in such a way is it can be used like the AudioPlayer class of the same package video.addEndedHandler(new EndedHandler() { private boolean triggered = false; @Override public void onEnded(EndedEvent event) { if (timedEventMonitor != null) { timedEventMonitor.registerEvent("videoEnded"); timedEventMonitor.registerMediaLength(mediaId, (long) (video.getCurrentTime() * 1000)); } // prevent multiple triggering if (!triggered) { triggered = true; // Timer timer = new Timer() { // public void run() { playedStimulusListener.postLoadTimerFired(); // } // }; // timerList.add(timer); // timer.schedule(postLoadMs); } } }); if (oggPath != null) { video.addSource(oggPath.asString(), "video/ogg"); } if (ogvPath != null) { video.addSource(ogvPath.asString(), "video/ogg"); } if (mp4Path != null) { video.addSource(mp4Path.asString(), "video/mp4"); } if (!autoPlay) { video.pause(); video.setCurrentTime(0); } video.setLoop(loop); video.load(); if (video.getError() != null) { // todo: check that this method is functioning correctly and if not then use the method in audioPlayer.@nl.mpi.tg.eg.experiment.client.service.AudioPlayer::onAudioFailed()(); failedStimulusListener.postLoadTimerFired(); } videoElement = video.getElement(); } return videoElement; }
From source file:org.jboss.hal.core.extension.ExtensionRegistry.java
License:Apache License
@JsIgnore public void verifyMetadata(String url, MetadataCallback metadataCallback) { SafeUri safeUrl = UriUtils.fromString(url); XMLHttpRequest xhr = new XMLHttpRequest(); xhr.onload = event -> {//from w w w. ja v a2 s .c o m int status = (int) xhr.status; if (status >= 200 && status < 400) { String responseText = xhr.responseText; if (Strings.isNullOrEmpty(responseText)) { metadataCallback.result(415, null); // 415 - Unsupported Media Type } else { JsonObject extensionJson = Json.parse(responseText); metadataCallback.result(status, extensionJson); } } else { metadataCallback.result(status, null); } }; xhr.addEventListener("error", event -> metadataCallback.result(503, null), false); //NON-NLS xhr.open(GET.name(), safeUrl.asString(), true); xhr.send(); }
From source file:org.kaaproject.avro.ui.gwt.client.widget.ActionsButton.java
License:Apache License
@UiConstructor public ActionsButton(ImageResource imageResource, String text) { super();/*www . j a v a2s .com*/ if (template == null) { template = GWT.create(Template.class); } getElement().getStyle().setPaddingRight(20, Unit.PX); int index = 0; if (imageResource != null) { getElement().getStyle().setPaddingLeft(20, Unit.PX); SafeUri uri = imageResource.getSafeUri(); int width = imageResource.getWidth(); int height = imageResource.getHeight(); int paddingLeft = width; String background = "url(\"" + uri.asString() + "\") no-repeat scroll right center"; Element imageSpan = DOM.createElement("span"); imageSpan.setInnerText(" "); imageSpan.getStyle().setProperty("background", background); imageSpan.getStyle().setWidth(width, Unit.PX); imageSpan.getStyle().setHeight(height, Unit.PX); imageSpan.getStyle().setPaddingLeft(paddingLeft, Unit.PX); imageSpan.getStyle().setMarginRight(10, Unit.PX); DOM.insertChild(getElement(), imageSpan, index++); } Element caretSpan = DOM.createElement("span"); caretSpan.setClassName(Utils.avroUiStyle.buttonCaret()); DOM.insertChild(getElement(), caretSpan, index); Element textElement = DOM.createElement("span"); textElement.setInnerText(text); DOM.insertChild(caretSpan, textElement, 0); actionsPopup = new PopupPanel(true, false); actionsPopup.addStyleName(Utils.avroUiStyle.actionPopup()); actionsPopup.setWidget(menu); actionsPopup.addCloseHandler(new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { ActionsButton.this.setDown(false); } }); actionsPopup.addAutoHidePartner(getElement()); addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (!actionsPopup.isShowing()) { // Instantiate the popup and show it. final Element parent = ActionsButton.this.getElement(); actionsPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { int left = parent.getAbsoluteLeft(); int top = parent.getAbsoluteTop() + parent.getOffsetHeight() + 2; if (left + actionsPopup.getOffsetWidth() > Window.getClientWidth()) { left = parent.getAbsoluteRight() - actionsPopup.getOffsetWidth(); } actionsPopup.setPopupPosition(left, top); } }); } else { actionsPopup.hide(); } } }); }
From source file:org.kaaproject.avro.ui.gwt.client.widget.ActionsButton.java
License:Apache License
public HandlerRegistration addMenuItem(ImageResource image, String text, final ActionMenuItemListener listener) { SafeHtml html = null;/*from w w w. j a v a 2s . c om*/ if (image != null) { SafeUri uri = image.getSafeUri(); int left = image.getLeft(); int top = image.getTop(); int width = image.getWidth(); int height = image.getHeight(); int paddingRight = width + 8; String background = "url(\"" + uri.asString() + "\") no-repeat " + (-left + "px ") + (-top + "px"); SafeStylesBuilder builder = new SafeStylesBuilder(); builder.trustedNameAndValue("background", background).width(width, Unit.PX).height(height, Unit.PX) .paddingRight(paddingRight, Unit.PX); SafeStyles style = SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()); html = template.menuImageItemContent(style, text); } else { html = template.menuItemContent(text); } final MenuItem item = new MenuItem(html, new Command() { @Override public void execute() { if (actionsPopup != null && actionsPopup.isVisible()) actionsPopup.hide(); listener.onMenuItemSelected(); } }); menu.addItem(item); HandlerRegistration registration = new HandlerRegistration() { @Override public void removeHandler() { menu.removeItem(item); } }; return registration; }
From source file:org.kaaproject.avro.ui.gwt.client.widget.grid.cell.ActionButtonCell.java
License:Apache License
public ActionButtonCell(ImageResource imageResource, String text, boolean small, ActionListener<T> listener, ActionValidator<T> validator) { super(CLICK, KEYDOWN); this.listener = listener; this.validator = validator; if (template == null) { template = GWT.create(Template.class); }//from w w w. ja v a 2s .c om SafeUri uri = imageResource.getSafeUri(); int width = imageResource.getWidth(); int height = imageResource.getHeight(); int paddingLeft = width; String background = "url(\"" + uri.asString() + "\") no-repeat scroll right center"; SafeStylesBuilder builder = new SafeStylesBuilder(); builder.trustedNameAndValue("background", background).width(width, Unit.PX).height(height, Unit.PX) .paddingLeft(paddingLeft, Unit.PX); SafeStyles style = SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()); if (small) { this.actionButtonHtml = template.actionButtonSmall(Utils.avroUiStyle.cellButton(), Utils.avroUiStyle.cellButtonSmall(), text, style); } else { this.actionButtonHtml = template.actionButton(Utils.avroUiStyle.cellButton(), text, style); } }