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();
}
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)));
}
}
}
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;
}
}
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);
}
}
}
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;
}
Aggregations