Search in sources :

Example 11 with Node

use of com.google.gwt.dom.client.Node in project che by eclipse.

the class OutputConsoleViewImpl method print.

@Override
public void print(final String text, boolean carriageReturn, String color) {
    if (this.carriageReturn) {
        Node lastChild = consoleLines.getElement().getLastChild();
        if (lastChild != null) {
            lastChild.removeFromParent();
        }
    }
    this.carriageReturn = carriageReturn;
    final SafeHtml colorOutput = new SafeHtml() {

        @Override
        public String asString() {
            if (Strings.isNullOrEmpty(text)) {
                return " ";
            }
            for (final Pair<RegExp, String> pair : output2Color) {
                final MatchResult matcher = pair.first.exec(text);
                if (matcher != null) {
                    return text.replaceAll(matcher.getGroup(1), "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
                }
            }
            return text;
        }
    };
    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerSafeHtml(colorOutput);
    if (color != null) {
        pre.getStyle().setColor(color);
    }
    consoleLines.getElement().appendChild(pre);
    followOutput();
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) PreElement(com.google.gwt.dom.client.PreElement) Node(com.google.gwt.dom.client.Node) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 12 with Node

use of com.google.gwt.dom.client.Node in project rstudio by rstudio.

the class DocTabLayoutPanel method ensureSelectedTabIsVisible.

public void ensureSelectedTabIsVisible(boolean animate) {
    if (currentAnimation_ != null) {
        currentAnimation_.cancel();
        currentAnimation_ = null;
    }
    Element selectedTab = (Element) DomUtils.findNode(getElement(), true, false, new NodePredicate() {

        public boolean test(Node n) {
            if (n.getNodeType() != Node.ELEMENT_NODE)
                return false;
            return ((Element) n).getClassName().contains("gwt-TabLayoutPanelTab-selected");
        }
    });
    if (selectedTab == null) {
        return;
    }
    selectedTab = selectedTab.getFirstChildElement().getFirstChildElement();
    Element tabBar = getTabBarElement();
    if (!isVisible() || !isAttached() || tabBar.getOffsetWidth() == 0)
        // not yet loaded
        return;
    final Element tabBarParent = tabBar.getParentElement();
    final int start = tabBarParent.getScrollLeft();
    int end = DomUtils.ensureVisibleHoriz(tabBarParent, selectedTab, padding_, padding_ + rightMargin_, true);
    // When tabs are closed, the overall width shrinks, and this can lead
    // to cases where there's too much empty space on the screen
    Node lastTab = getLastChildElement(tabBar);
    if (lastTab == null || lastTab.getNodeType() != Node.ELEMENT_NODE)
        return;
    int edge = DomUtils.getRelativePosition(tabBarParent, Element.as(lastTab)).x + Element.as(lastTab).getOffsetWidth();
    end = Math.min(end, Math.max(0, edge - (tabBarParent.getOffsetWidth() - rightMargin_)));
    if (edge <= tabBarParent.getOffsetWidth() - rightMargin_)
        end = 0;
    if (start != end) {
        if (!animate) {
            tabBarParent.setScrollLeft(end);
        } else {
            final int finalEnd = end;
            currentAnimation_ = new Animation() {

                @Override
                protected void onUpdate(double progress) {
                    double delta = (finalEnd - start) * progress;
                    tabBarParent.setScrollLeft((int) (start + delta));
                }

                @Override
                protected void onComplete() {
                    if (this == currentAnimation_) {
                        tabBarParent.setScrollLeft(finalEnd);
                        currentAnimation_ = null;
                    }
                }
            };
            currentAnimation_.run(Math.max(200, Math.min(1500, Math.abs(end - start) * 2)));
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node) Animation(com.google.gwt.animation.client.Animation) Point(org.rstudio.core.client.Point) NodePredicate(org.rstudio.core.client.dom.DomUtils.NodePredicate)

Example 13 with Node

use of com.google.gwt.dom.client.Node in project rstudio by rstudio.

the class ShellWidget method consolePrompt.

public void consolePrompt(String prompt, boolean showInput) {
    if (prompt != null)
        prompt = VirtualConsole.consolify(prompt);
    prompt_.getElement().setInnerText(prompt);
    //input_.clear() ;
    ensureInputVisible();
    // Deal gracefully with multi-line prompts
    int promptLines = StringUtil.notNull(prompt).split("\\n").length;
    input_.asWidget().getElement().getStyle().setPaddingTop((promptLines - 1) * 15, Unit.PX);
    input_.setPasswordMode(!showInput);
    clearErrors_ = true;
    // make sure we're starting on a new line
    if (virtualConsole_ != null) {
        Node child = virtualConsole_.getParent().getLastChild();
        if (child != null && child.getNodeType() == Node.ELEMENT_NODE && !Element.as(child).getInnerText().endsWith("\n")) {
            virtualConsole_.submit("\n");
        }
        // clear the virtual console so we start with a fresh slate
        virtualConsole_ = null;
    }
}
Also used : Node(com.google.gwt.dom.client.Node)

Example 14 with Node

use of com.google.gwt.dom.client.Node in project rstudio by rstudio.

the class ShellWidget method consoleWriteError.

public void consoleWriteError(final String error) {
    clearPendingInput();
    output(error, getErrorClass(), false);
    // Pick up the last element emitted to the console. If we get extended
    // information for this error, we'll need to swap out the simple error
    // element for the extended error element. 
    Element outputElement = output_.getElement();
    if (outputElement.hasChildNodes()) {
        // the last output group includes a <span> for each output type; pick
        // up the one referring to the error we just emitted
        Node lastNode = outputElement.getChild(outputElement.getChildCount() - 1);
        if (lastNode.hasChildNodes()) {
            Node errorNode = lastNode.getChild(lastNode.getChildCount() - 1);
            if (clearErrors_) {
                errorNodes_.clear();
                clearErrors_ = false;
            }
            errorNodes_.put(error, errorNode);
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) SpanElement(com.google.gwt.dom.client.SpanElement) Node(com.google.gwt.dom.client.Node)

Example 15 with Node

use of com.google.gwt.dom.client.Node in project rstudio by rstudio.

the class PdfJsWindow method getBoundaryCoordinates.

private static SyncTexCoordinates getBoundaryCoordinates(PdfJsWindow win, boolean top) {
    Element container = getViewerContainer(win);
    int scrollY = container.getScrollTop();
    // linear probe our way to the current page
    Element viewerEl = win.getDocument().getElementById("viewer");
    for (int i = 1; i < viewerEl.getChildCount(); i += 2) {
        Node childNode = viewerEl.getChild(i);
        if (Element.is(childNode)) {
            Element el = Element.as(childNode);
            if (DomUtils.bottomRelativeTo(container, el) > scrollY) {
                int pageNum = getContainerPageNum(el);
                int pageY = scrollY - DomUtils.topRelativeTo(container, el);
                if (pageY < 0)
                    pageY = 0;
                if (!top)
                    pageY += container.getClientHeight();
                return new SyncTexCoordinates(pageNum, 0, (int) ((pageY / win.getCurrentScale() / 96) * 72));
            }
        }
    }
    return null;
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node)

Aggregations

Node (com.google.gwt.dom.client.Node)15 Element (com.google.gwt.dom.client.Element)9 DivElement (com.google.gwt.dom.client.DivElement)2 EventTarget (com.google.gwt.dom.client.EventTarget)2 PreElement (com.google.gwt.dom.client.PreElement)2 Point (com.gwtmobile.ui.client.utils.Point)2 Animation (com.google.gwt.animation.client.Animation)1 SpanElement (com.google.gwt.dom.client.SpanElement)1 Text (com.google.gwt.dom.client.Text)1 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 RegExp (com.google.gwt.regexp.shared.RegExp)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 RadioButton (com.google.gwt.user.client.ui.RadioButton)1 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HotKeyItem (org.eclipse.che.ide.api.hotkeys.HotKeyItem)1 Point (org.rstudio.core.client.Point)1