Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder.

Prototype

public SafeHtmlBuilder() 

Source Link

Document

Constructs an empty SafeHtmlBuilder.

Usage

From source file:com.sencha.gxt.core.client.dom.Layer.java

License:sencha.com license

private XElement createShadow() {
    XElement el;// ww  w .ja va  2s.  c o m
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    appearance.renderShadow(sb);
    el = XDOM.create(sb.toSafeHtml()).cast();
    el.hide();
    return el;
}

From source file:com.sencha.gxt.desktop.client.widget.DesktopLayoutContainer.java

License:sencha.com license

/**
 * Creates a desktop layout container with the specified appearance.
 * //  w  w w.j  a va  2 s. co  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 www  .j  a  va  2  s .  co  m

    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);//from  www .j  ava2 s  .  c  o  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();/*from w w w  .  j  a v  a  2  s . c om*/
    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());/*from ww  w.j ava 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.//w w w  .  java 2s  .c om
 *
 * @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   www  .  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.// www  .  j av  a2s . com
 * 
 * @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;
    }//from ww  w . ja va  2  s  .  c o  m
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    cell.render(createContext(), value, sb);
    getElement().setInnerSafeHtml(sb.toSafeHtml());
    onRedraw();
    return true;
}