Example usage for com.google.gwt.dom.client TextAreaElement getScrollHeight

List of usage examples for com.google.gwt.dom.client TextAreaElement getScrollHeight

Introduction

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

Prototype

@Override
    public int getScrollHeight() 

Source Link

Usage

From source file:org.opencms.ui.client.CmsAutoGrowingTextAreaConnector.java

License:Open Source License

/**
 * Resize the text area.<p>/*from  w w w  . jav a  2s.  c  o m*/
 */
protected void handle() {

    Element e = m_widget.getElement();
    if (e instanceof TextAreaElement) {
        TextAreaElement elem = (TextAreaElement) e;
        int scrollHeight = elem.getScrollHeight();
        // allow text area to shrink
        if (m_lastValue.length() > elem.getValue().length()) {
            elem.setRows(getState().getMinRows());
        }
        int currentRows = elem.getRows();
        if (m_lineHeight == 0) {
            elem.setRows(2);
            int heightTwo = elem.getClientHeight();
            elem.setRows(1);
            int heightOne = elem.getClientHeight();
            m_lineHeight = heightTwo - heightOne;
            m_paddingHeight = heightOne - m_lineHeight;
            elem.setRows(currentRows);
        }
        if (m_lineHeight > 0) {
            int totalHeight = scrollHeight - m_paddingHeight;
            int requiredRows = ((scrollHeight - m_paddingHeight) / m_lineHeight);
            if ((totalHeight % m_lineHeight) > 0) {
                requiredRows++;
            }
            int minRows = getState().getMinRows();
            int maxRows = getState().getMaxRows();
            if ((requiredRows <= minRows) && (currentRows != minRows)) {
                elem.setRows(minRows);
            } else if ((requiredRows >= maxRows) && (currentRows != maxRows)) {
                elem.setRows(maxRows);
            } else if (requiredRows != currentRows) {
                elem.setRows(requiredRows);
            }
        }
    }
}

From source file:org.primordion.xholon.base.Xholon.java

License:Open Source License

/**
 * Print to a console./*from ww w  . j a  v  a2 s .c  o m*/
 * This can be very slow, so limit the number of calls,
 * for example by consolidating text using a StringBuilder before calling.
 * @param str A String to append to the end of the console.
 * @param scroll Whether or not to scroll to the bottom of the text area.
 */
protected void print2Console(String str, boolean scroll) {
    if (str.startsWith(PRINT2CONSOLE_IGNORE_ME)) {
        return;
    }
    Element element = HtmlElementCache.xhout;
    if (element != null) {
        element = element.getFirstChildElement();
    }
    if (element != null) {
        TextAreaElement textfield = element.cast();
        textfield.setValue(textfield.getValue() + str);
        // optionally scroll to the bottom of the text area
        if (scroll) {
            textfield.setScrollTop(textfield.getScrollHeight());
        }
    }
}

From source file:org.primordion.xholon.io.console.XholonConsole.java

License:Open Source License

/**
 * Set the result of the query into the XholonConsole GUI,
 * and make it visible to the user./*from  ww  w  . j  a  va  2  s . co  m*/
 * For now, the resultPane and commandPane are the same.
 * @param result
 * @param replace whether to replace current text (true), or append to end of current text (false)
 */
public void setResult(String result, boolean replace) {
    //Window.alert(result);

    // get the element
    Element ele = commandPane.getElement().getFirstChildElement();

    // <pre>
    //ele.setInnerText(ele.getInnerText() + result);

    // these leave the escaped chars in the text
    //ele.setInnerHTML(ele.getInnerHTML() + result);
    //ele.setInnerText(ele.getInnerText() + SafeHtmlUtils.htmlEscape(result));

    // textarea
    TextAreaElement ta = TextAreaElement.as(ele);
    if (replace) {
        ta.setValue(result);
    } else {
        ta.setValue(ta.getValue() + result);
    }
    // optionally scroll to the bottom of the text area
    if (isTerminalEnabled()) {
        ta.setScrollTop(ta.getScrollHeight());
    }
}