List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml
public SafeHtml toSafeHtml()
From source file:com.github.gwtbootstrap.client.ui.CodeBlock.java
License:Apache License
/** * Sets the widget's text./* w ww . ja v a2 s .c o m*/ * <p> * Any HTML content is escaped and displayed as text. * * @param html * the text to be set */ public void setHTML(String html) { String[] lines = html.split("\\\\n"); SafeHtmlBuilder shb = new SafeHtmlBuilder(); for (String s : lines) { shb.appendEscaped(s); shb.appendHtmlConstant("<br/>"); } if (getStyleName().contains("prettyprinted")) { removeStyleName("prettyprinted"); } getElement().setInnerHTML(shb.toSafeHtml().asString()); if (isAttached()) { helper.configure(linenums); } }
From source file:com.google.api.explorer.client.auth.AuthView.java
License:Apache License
/** * Rebuild the popup from scratch with all of the scopes that we have from the last time we were * presented./*from w w w . java 2 s . co m*/ */ private void buildScopePopup() { scopePanel.clear(); additionalScopePanel.clear(); Set<TextBox> oldEditors = Sets.newLinkedHashSet(freeFormEditors); freeFormEditors.clear(); // Hide the service scopes label if there aren't any. hasScopesText.setVisible(!scopesFromDiscovery.isEmpty()); noScopesText.setVisible(scopesFromDiscovery.isEmpty()); // Show different text on the free-form scopes section when there are discovery scopes. optionalAdditionalScopes.setVisible(!scopesFromDiscovery.isEmpty()); for (final Map.Entry<String, AuthScope> scope : scopesFromDiscovery.entrySet()) { // Add the check box to the table. CheckBox scopeToggle = new CheckBox(); SafeHtmlBuilder safeHtml = new SafeHtmlBuilder(); safeHtml.appendEscaped(scope.getKey()).appendHtmlConstant("<br><span>") .appendEscaped(scope.getValue().getDescription()).appendHtmlConstant("</span>"); scopeToggle.setHTML(safeHtml.toSafeHtml()); scopeToggle.addStyleName(style.discoveryScopeSelector()); scopePanel.add(scopeToggle); // When the box is checked, add our scope to the selected list. scopeToggle.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { CheckBox checkBox = (CheckBox) event.getSource(); if (checkBox.getValue()) { selectedScopes.add(scope.getKey()); } else { selectedScopes.remove(scope.getKey()); } } }); // Enable the check box if the scope is selected. scopeToggle.setValue(selectedScopes.contains(scope.getKey())); } // Process any scopes that are extra. for (TextBox editor : oldEditors) { if (!editor.getValue().trim().isEmpty()) { addFreeFormEditorRow(editor.getValue(), true); } } // There should always be one empty editor. addFreeFormEditorRow("", false); }
From source file:com.google.gerrit.client.ui.HighlightSuggestion.java
License:Apache License
@Override public String getDisplayString() { int start = 0; int keyLen = keyword.length(); SafeHtmlBuilder builder = new SafeHtmlBuilder(); for (;;) {/*from ww w . j a v a 2s.c o m*/ int index = value.indexOf(keyword, start); if (index == -1) { builder.appendEscaped(value.substring(start)); break; } builder.appendEscaped(value.substring(start, index)); builder.appendHtmlConstant("<strong>"); start = index + keyLen; builder.appendEscaped(value.substring(index, start)); builder.appendHtmlConstant("</strong>"); } return builder.toSafeHtml().asString(); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CompositeContactCell.java
private static HasCell<ContactInfo, Boolean> createStar(final CwCellList.Images images) { return new HasCell<ContactInfo, Boolean>() { @Override//from w w w .ja va 2s. c om public Cell<Boolean> getCell() { return new AbstractCell<Boolean>(BrowserEvents.CLICK) { private ImageResourceRenderer renderer = new ImageResourceRenderer(); @Override public void render(Cell.Context context, Boolean value, SafeHtmlBuilder sb) { if (value != null) { sb.append(renderer.render(value ? images.star() : images.starOutline())); } } @Override public void onBrowserEvent(Cell.Context context, Element parent, Boolean value, NativeEvent event, ValueUpdater<Boolean> valueUpdater) { // Let AbstractCell handle the keydown event. super.onBrowserEvent(context, parent, value, event, valueUpdater); // Handle the click event. if (BrowserEvents.CLICK.equals(event.getType())) { // Ignore clicks that occur outside of the outermost element. EventTarget eventTarget = event.getEventTarget(); if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) { boolean newValue = !value; valueUpdater.update(newValue); SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, newValue, sb); parent.setInnerSafeHtml(sb.toSafeHtml()); } } } }; } @Override public FieldUpdater<ContactInfo, Boolean> getFieldUpdater() { return new FieldUpdater<ContactInfo, Boolean>() { @Override public void update(int index, ContactInfo contact, Boolean value) { contact.setStarred(value); } }; } @Override public Boolean getValue(ContactInfo contact) { return contact.isStarred(); } }; }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java
License:Apache License
/** * Add a {@link TreeItem} to a root item. * //from w ww .j a v a 2s . c o m * @param root the root {@link TreeItem} * @param image the icon for the new child item * @param label the label for the child icon */ @ShowcaseSource private void addItem(TreeItem root, ImageResource image, String label) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(image).getHTML())); sb.appendEscaped(" ").appendEscaped(label); root.addItem(sb.toSafeHtml()); }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java
License:Apache License
/** * Create the list of Contacts./*from ww w .j a v a 2 s . c om*/ * * @param images the {@link Images} used in the Contacts * @return the list of contacts */ @ShowcaseSource private Widget createContactsItem(Images images) { // Create a popup to show the contact info when a contact is clicked HorizontalPanel contactPopupContainer = new HorizontalPanel(); contactPopupContainer.setSpacing(5); contactPopupContainer.add(new Image(images.defaultContact())); final HTML contactInfo = new HTML(); contactPopupContainer.add(contactInfo); final PopupPanel contactPopup = new PopupPanel(true, false); contactPopup.setWidget(contactPopupContainer); // Create the list of contacts VerticalPanel contactsPanel = new VerticalPanel(); contactsPanel.setSpacing(4); String[] contactNames = constants.cwStackLayoutPanelContacts(); String[] contactEmails = constants.cwStackLayoutPanelContactsEmails(); for (int i = 0; i < contactNames.length; i++) { final String contactName = contactNames[i]; final String contactEmail = contactEmails[i]; final Anchor contactLink = new Anchor(contactName); contactsPanel.add(contactLink); // Open the contact info popup when the user clicks a contact contactLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // Set the info about the contact SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendEscaped(contactName); sb.appendHtmlConstant("<br><i>"); sb.appendEscaped(contactEmail); sb.appendHtmlConstant("</i>"); contactInfo.setHTML(sb.toSafeHtml()); // Show the popup of contact info int left = contactLink.getAbsoluteLeft() + 14; int top = contactLink.getAbsoluteTop() + 14; contactPopup.setPopupPosition(left, top); contactPopup.show(); } }); } return new SimplePanel(contactsPanel); }
From source file:com.google.gwt.uibinder.test.client.UiRendererUi.java
License:Apache License
public SafeHtml render(String value) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); getRenderer().render(sb, new Foo(value)); return sb.toSafeHtml(); }
From source file:com.google.javascript.jscomp.debugger.gwt.DebuggerGwtMain.java
License:Apache License
private void createCheckboxes(CellPanel checkboxPanel) { for (CompilationParam.ParamGroup group : CompilationParam.ParamGroup.values()) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant("<b>"); builder.appendEscaped(group.name); builder.appendHtmlConstant("</b>"); checkboxPanel.add(new HTML(builder.toSafeHtml())); for (final CompilationParam param : CompilationParam.getGroupedSortedValues().get(group)) { CheckBox cb = new CheckBox(param.toString()); if (param.getJavaInfo() != null) { cb.setTitle("Java API equivalent: " + param.getJavaInfo()); }// w ww . j av a 2s .co m cb.setValue(param.getDefaultValue()); param.apply(options, param.getDefaultValue()); cb.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { boolean checked = ((CheckBox) event.getSource()).getValue(); param.apply(options, checked); doCompile(); } }); checkboxPanel.add(cb); } } }
From source file:com.google.maps.gwt.samples.basics.client.MapCoordinates.java
License:Apache License
private String createInfoWindowContent() { int numTiles = 1 << (int) map.getZoom(); MercatorProjection projection = new MercatorProjection(); Point worldCoordinate = projection.fromLatLngToPoint(CHICAGO); Point pixelCoordinate = Point.create(worldCoordinate.getX() * numTiles, worldCoordinate.getY() * numTiles); Point tileCoordinate = Point.create(Math.floor(pixelCoordinate.getX() / TILE_SIZE), Math.floor(pixelCoordinate.getY() / TILE_SIZE)); SafeHtmlBuilder returnString = new SafeHtmlBuilder(); returnString.appendHtmlConstant("Chicago, IL<br>"); returnString.appendHtmlConstant("LatLng: "); returnString.append(CHICAGO.lat());//from w w w.j a v a 2 s . com returnString.appendHtmlConstant(", "); returnString.append(CHICAGO.lng()); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("World Coordinate: "); returnString.append(worldCoordinate.getX()); returnString.appendHtmlConstant(", "); returnString.append(worldCoordinate.getY()); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("Pixel Coordinate: "); returnString.append(Math.floor(pixelCoordinate.getX())); returnString.appendHtmlConstant(", "); returnString.append(Math.floor(pixelCoordinate.getY())); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("Tile Coordinate: "); returnString.append(Math.floor(tileCoordinate.getX())); returnString.appendHtmlConstant(", "); returnString.append(Math.floor(tileCoordinate.getY())); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("at Zoom Level: "); returnString.append(map.getZoom()); return returnString.toSafeHtml().asString(); }
From source file:com.google.maps.gwt.samples.overlays.client.PolygonArrays.java
License:Apache License
private void showArrays(MouseEvent event) { // Since this Polygon only has one path, we can call getPath() // to return the MVCArray of LatLngs MVCArray<LatLng> vertices = bermudaTriangle.getPath(); SafeHtmlBuilder contentString = new SafeHtmlBuilder(); contentString.appendHtmlConstant("<b>Bermuda Triangle Polygon</b><br />"); contentString.appendHtmlConstant("Clicked Location: <br />"); contentString.append(event.getLatLng().lat()); contentString.appendHtmlConstant(","); contentString.append(event.getLatLng().lng()); contentString.appendHtmlConstant("<br />"); // Iterate over the vertices. for (int i = 0; i < vertices.getLength(); i++) { LatLng xy = vertices.getAt(i);/* w w w .j ava 2 s . c om*/ contentString.appendHtmlConstant("<br /> Coordinate: "); contentString.append(i); contentString.appendHtmlConstant("<br />"); contentString.append(xy.lat()); contentString.appendHtmlConstant(","); contentString.append(xy.lng()); } // Replace our Info Window's content and position infowindow.setContent(contentString.toSafeHtml().asString()); infowindow.setPosition(event.getLatLng()); infowindow.open(map); }