List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml
public SafeHtml toSafeHtml()
From source file:com.sencha.gxt.desktop.client.widget.DesktopLayoutContainer.java
License:sencha.com license
/** * Creates a desktop layout container with the specified appearance. * /*ww w . java 2 s .c o m*/ * @param appearance the desktop layout container appearance */ public DesktopLayoutContainer(DesktopLayoutContainerAppearance appearance) { this.appearance = appearance; forceLayoutOnResize = true; setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); setVBoxLayoutAlign(VBoxLayoutAlign.CENTER); SafeHtmlBuilder sb = new SafeHtmlBuilder(); appearance.render(sb); setElement((Element) XDOM.create(sb.toSafeHtml())); }
From source file:com.sencha.gxt.dnd.core.client.Insert.java
License:sencha.com license
protected Insert(InsertAppearance appearance) { this.appearance = appearance; SafeHtmlBuilder sb = new SafeHtmlBuilder(); appearance.render(sb);//from ww w .j av a 2 s. c om setElement((Element) XDOM.create(sb.toSafeHtml())); setShadow(false); hide(); }
From source file:com.sencha.gxt.dnd.core.client.StatusProxy.java
License:sencha.com license
protected StatusProxy(StatusProxyAppearance appearance) { this.appearance = appearance; SafeHtmlBuilder builder = new SafeHtmlBuilder(); appearance.render(builder);/*w w w. j a va 2 s .co m*/ setElement((Element) XDOM.create(builder.toSafeHtml())); setStatus(false); setShadow(true); }
From source file:com.sencha.gxt.theme.base.client.button.ButtonCellDefaultAppearance.java
License:sencha.com license
@Override public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) { String constantHtml = cell.getHTML(); boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0; boolean isBoolean = value != null && value instanceof Boolean; // is a boolean always a toggle button? SafeHtml valueHtml = SafeHtmlUtils.fromTrustedString(hasConstantHtml ? cell.getText() : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : ""); ImageResource icon = cell.getIcon(); IconAlign iconAlign = cell.getIconAlign(); String cls = style.button();/* ww w . j a va 2 s .c o m*/ String arrowCls = ""; if (cell.getMenu() != null) { if (cell instanceof SplitButtonCell) { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.split(); break; case BOTTOM: arrowCls = style.splitBottom(); break; default: // empty } } else { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.arrow(); break; case BOTTOM: arrowCls = style.arrowBottom(); break; } } } ButtonScale scale = cell.getScale(); switch (scale) { case SMALL: cls += " " + style.small(); break; case MEDIUM: cls += " " + style.medium(); break; case LARGE: cls += " " + style.large(); break; default: // empty } SafeStylesBuilder stylesBuilder = new SafeStylesBuilder(); int width = -1; if (cell.getWidth() != -1) { int w = cell.getWidth(); if (w < cell.getMinWidth()) { w = cell.getMinWidth(); } stylesBuilder.appendTrustedString("width:" + w + "px;"); cls += " " + style.hasWidth() + " x-has-width"; width = w; } else { if (cell.getMinWidth() != -1) { TextMetrics.get().bind(style.text()); int length = TextMetrics.get().getWidth(valueHtml); length += 6; // frames if (icon != null) { switch (iconAlign) { case LEFT: case RIGHT: length += icon.getWidth(); break; default: // empty } } if (cell.getMinWidth() > length) { stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;"); cls += " " + style.hasWidth() + " x-has-width"; width = cell.getMinWidth(); } } } final int height = cell.getHeight(); if (height != -1) { stylesBuilder.appendTrustedString("height:" + height + "px;"); } if (icon != null) { switch (iconAlign) { case TOP: arrowCls += " " + style.iconTop(); break; case BOTTOM: arrowCls += " " + style.iconBottom(); break; case LEFT: arrowCls += " " + style.iconLeft(); break; case RIGHT: arrowCls += " " + style.iconRight(); break; } } else { arrowCls += " " + style.noIcon(); } // toggle button if (value == Boolean.TRUE) { cls += " " + frame.pressedClass(); } sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles())); SafeHtmlBuilder inside = new SafeHtmlBuilder(); String innerWrap = arrowCls; inside.appendHtmlConstant("<div class='" + innerWrap + "'>"); inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>"); boolean hasText = valueHtml != null && !valueHtml.equals(""); if (icon != null) { switch (iconAlign) { case LEFT: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeValue(inside, valueHtml, w, height); } inside.appendHtmlConstant("</tr>"); break; case RIGHT: inside.appendHtmlConstant("<tr>"); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeValue(inside, valueHtml, w, height); } writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; case TOP: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); if (hasText) { inside.appendHtmlConstant("<tr>"); writeValue(inside, valueHtml, width, height); inside.appendHtmlConstant("</tr>"); } break; case BOTTOM: if (hasText) { inside.appendHtmlConstant("<tr>"); writeValue(inside, valueHtml, width, height); inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; } } else { inside.appendHtmlConstant("<tr>"); if (valueHtml != null) { writeValue(inside, valueHtml, width, height); } inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("</table>"); inside.appendHtmlConstant("</div>"); frame.render(sb, new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()), inside.toSafeHtml()); sb.appendHtmlConstant("</div>"); }
From source file:com.sencha.gxt.theme.base.client.field.FieldLabelDefaultAppearance.java
License:sencha.com license
@Override public void onUpdateOptions(XElement parent, FieldLabelOptions options) { LabelAlign labelAlign = options.getLabelAlign(); XElement fieldElement = getChildElementWrapper(parent); XElement labelElement = getLabelElement(parent); // Adjust for label content, label separator SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.append(options.getContent());/* w w w . j a va 2 s .co m*/ sb.appendEscaped(options.getLabelSeparator()); labelElement.setInnerSafeHtml(sb.toSafeHtml()); // Adjust for label alignment if (labelAlign == LabelAlign.TOP) { parent.addClassName(style.fieldItemLabelTop()); } else { parent.removeClassName(style.fieldItemLabelTop()); } // Adjust for label width if (labelAlign == LabelAlign.TOP) { labelElement.getStyle().setProperty("width", "auto"); fieldElement.getStyle().setPaddingLeft(0, Unit.PX); } else { int pad = options.getLabelPad(); if (pad == 0) pad = 5; labelElement.getStyle().setWidth(options.getLabelWidth(), Unit.PX); fieldElement.getStyle().setPaddingLeft(options.getLabelWidth() + pad, Unit.PX); } // Adjust for label word wrap labelElement.getStyle().setProperty("whiteSpace", options.getWordWrap() ? "normal" : "nowrap"); }
From source file:com.sencha.gxt.widget.core.client.box.MessageBox.java
License:sencha.com license
/** * Creates a message box with the specified heading HTML, message HTML and * windowAppearance. It is the caller's responsibility to ensure the HTML is CSS * safe.//from w w w .j av a 2s .c o m * * @param headingHtml the HTML to display for the message box heading * @param messageHtml the HTML to display in the message box * @param windowAppearance the message box window windowAppearance * @param messageBoxAppearance the message box content windowAppearance */ public MessageBox(SafeHtml headingHtml, SafeHtml messageHtml, WindowAppearance windowAppearance, MessageBoxAppearance messageBoxAppearance) { super(windowAppearance); setMinWidth(300); this.messageBoxAppearance = messageBoxAppearance; setHeading(headingHtml); setBlinkModal(true); init(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); messageBoxAppearance.render(sb); windowAppearance.getContentElem(getElement()).setInnerSafeHtml(sb.toSafeHtml()); messageBoxAppearance.getMessageElement(getElement()).setId(getId() + "-content"); setMessage(messageHtml); }
From source file:com.sencha.gxt.widget.core.client.button.ButtonGroup.java
License:sencha.com license
public ButtonGroup(ButtonGroupAppearance appearance) { super(true);/*from w w w.ja v a2 s . com*/ this.appearance = appearance; setDeferHeight(true); SafeHtmlBuilder builder = new SafeHtmlBuilder(); this.appearance.render(builder); setElement((Element) XDOM.create(builder.toSafeHtml())); // addStyleName("x-toolbar-mark"); }
From source file:com.sencha.gxt.widget.core.client.button.IconButton.java
License:sencha.com license
/** * Creates a new icon button./*from ww w . j a v a2 s. co m*/ * * @param appearance the icon button appearance * @param config the icon configuration */ public IconButton(IconButtonAppearance appearance, IconConfig config) { this.config = config; this.appearance = appearance; SafeHtmlBuilder sb = new SafeHtmlBuilder(); this.appearance.render(sb); setElement((Element) XDOM.create(sb.toSafeHtml())); // mark element to not start drags addStyleName(CommonStyles.get().nodrag()); addStyleName(config.style); sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS | Event.ONKEYUP); addGestureRecognizer(new TapGestureRecognizer() { @Override protected void onTap(TouchData touchData) { super.onTap(touchData); onClick(touchData.getLastNativeEvent().<Event>cast()); } }); }
From source file:com.sencha.gxt.widget.core.client.cell.CellComponent.java
License:sencha.com license
protected boolean redraw(boolean force) { if (!force && (!init || !rendered)) { return false; }// ww w. java 2 s.c om SafeHtmlBuilder sb = new SafeHtmlBuilder(); cell.render(createContext(), value, sb); getElement().setInnerSafeHtml(sb.toSafeHtml()); onRedraw(); return true; }
From source file:com.sencha.gxt.widget.core.client.CollapsePanel.java
License:sencha.com license
/** * Creates a {@link CollapsePanel} that acts as a stand-in for the given panel * when it is collapsed./*from www .java 2 s. c o m*/ * * @param appearance the appearance instance to use when rendering and updating the dom * @param panel the content panel * @param data layout data describing a region in a border panel * @param region the region this panel occupies in the border panel */ public CollapsePanel(CollapsePanelAppearance appearance, ContentPanel panel, BorderLayoutData data, LayoutRegion region) { this.panel = panel; this.panelData = data; this.region = region; this.appearance = appearance; monitorWindowResize = true; SafeHtmlBuilder builder = new SafeHtmlBuilder(); this.appearance.render(builder, region, data.isCollapseHeaderVisible()); setElement((Element) XDOM.create(builder.toSafeHtml())); sinkEvents(Event.ONCLICK); IconConfig config = ToolButton.DOUBLERIGHT; switch (region) { case EAST: config = ToolButton.DOUBLELEFT; break; case NORTH: config = ToolButton.DOUBLEDOWN; break; case SOUTH: config = ToolButton.DOUBLEUP; break; default: // do nothing } expandBtn = new ToolButton(config); expandBtn.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { if (expanded) { disableAnimations = false; collapse(); disableAnimations = true; } onExpandButton(); } }); appearance.iconWrap(getElement()).appendChild(expandBtn.getElement()); appearance.textWrap(getElement()).setInnerSafeHtml(panel.getHeading()); }