Example usage for com.google.gwt.dom.client PreElement getStyle

List of usage examples for com.google.gwt.dom.client PreElement getStyle

Introduction

In this page you can find the example usage for com.google.gwt.dom.client PreElement getStyle.

Prototype

@Override
    public Style getStyle() 

Source Link

Usage

From source file:org.eclipse.che.ide.console.OutputConsoleViewImpl.java

License:Open Source License

@Override
public void print(final String text, boolean carriageReturn, String color) {
    if (this.carriageReturn) {
        Node lastChild = consoleLines.getElement().getLastChild();
        if (lastChild != null) {
            lastChild.removeFromParent();
        }/*from  ww  w . j a va 2  s.  c  om*/
    }

    this.carriageReturn = carriageReturn;

    final SafeHtml colorOutput = new SafeHtml() {
        @Override
        public String asString() {

            if (Strings.isNullOrEmpty(text)) {
                return " ";
            }

            String encoded = SafeHtmlUtils.htmlEscape(text);
            if (delegate != null) {
                if (delegate.getCustomizer() != null) {
                    if (delegate.getCustomizer().canCustomize(encoded)) {
                        encoded = delegate.getCustomizer().customize(encoded);
                    }
                }
            }

            for (final Pair<RegExp, String> pair : output2Color) {
                final MatchResult matcher = pair.first.exec(encoded);

                if (matcher != null) {
                    return encoded.replaceAll(matcher.getGroup(1),
                            "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
                }
            }

            return encoded;
        }
    };

    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerSafeHtml(colorOutput);
    if (color != null) {
        pre.getStyle().setColor(color);
    }
    consoleLines.getElement().appendChild(pre);

    followOutput();
}

From source file:org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputPartViewImpl.java

License:Open Source License

@Override
public void print(String text, String color) {
    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerText(text.isEmpty() ? "&nbsp;" : text);

    try {/*from ww  w  .  ja  va2s.com*/
        pre.getStyle().setColor(SimpleHtmlSanitizer.sanitizeHtml(color).asString());
    } catch (Exception e) {
        Log.error(getClass(), "Unable to set color [" + color + "]", e);
    }

    consoleLines.getElement().appendChild(pre);
}