本文整理匯總了Java中com.google.gwt.dom.client.Node.getNextSibling方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getNextSibling方法的具體用法?Java Node.getNextSibling怎麽用?Java Node.getNextSibling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.dom.client.Node
的用法示例。
在下文中一共展示了Node.getNextSibling方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setOnlyChild
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* Ensures the given container contains exactly one child, the given one.
* Provides the important property that if the container is already the parent
* of the given child, then the child is not removed and re-added, it is left
* there; any siblings, if present, are removed.
*
* @param container
* @param child
*/
public static void setOnlyChild(Element container, Node child) {
if (child.getParentElement() != container) {
// simple case
emptyElement(container);
container.appendChild(child);
} else {
// tricky case - avoid removing then re-appending the same child
while (child.getNextSibling() != null) {
child.getNextSibling().removeFromParent();
}
while (child.getPreviousSibling() != null) {
child.getPreviousSibling().removeFromParent();
}
}
}
示例2: NOTE
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
@SuppressWarnings("unused") // NOTE(user): may be used later
private Point<Node> linearSearchForRange(JsTextRangeIE target, Element parent) {
try {
// We'll iterate through the parent's children while moving
// a new collapsed range, attempt, through the points before
// each child.
Node child = parent.getFirstChild();
// Start attempt at beginning of parent
JsTextRangeIE attempt = JsTextRangeIE.create().moveToElementText(parent).collapse(true);
while (child != null) {
// Treat text node children separately
if (DomHelper.isTextNode(child)) {
// Move attempt to end of the text node
int len = child.<Text> cast().getLength();
attempt.move(character, len);
// Test if attempt is now at or past target
if (attempt.compareEndPoints(StartToStart, target) >= 0) {
// Target is in this text node. Compute the offset by creating a new
// text range from target to attempt and measuring the length of the
// text in that range
JsTextRangeIE dup =
attempt.duplicate().setEndPoint(StartToStart, target)
.setEndPoint(EndToEnd, attempt);
return Point.inText(child, len - dup.getText().length());
}
} else {
// Child is an element. Move attempt before child, and test
// if attempt is at or past range
attempt.moveToElementText(child.<Element> cast()).collapse(true);
if (attempt.compareEndPoints(StartToStart, target) >= 0) {
// Return the point before child
return Point.inElement(parent, child);
} else {
// Move attempt past child
// We use our inline, non-empty marker element to do this.
// We also leave it in the dom for max reliability until it's needed
// later, or gets taken out in the finally clause at the end of this method
child.getParentNode().insertAfter(setter, child);
// skip pass the setter.
child = child.getNextSibling();
attempt.moveToElementText(setter).collapse(false);
}
}
// Move to next child
child = child.getNextSibling();
}
// We didn't find target before or in children; return point at end of
// parent
return Point.<Node> end(parent);
// TODO(user): look out for other corner cases
// TODO(user, danilatos): implement danilatos' optimisation of first
// checking inside the last text node that held a point.
// TODO(user): consider binary rather than linear search for target
// TODO(user): does this handle the end of a <p>ab[</p><p>]cd</p> type
// selection?
// TODO(danilatos): When someone selects the "newline" at the edge
// of a <p>, e.g. <p>abc[</p><p>]def</p> (where [ ] is the sel)
// this reports the selection still as <p>abc[]</p><p>def</p>
// It appears to be a detectable scenario when the first line
// is not empty, but it isn't when both lines are empty. However,
// I did notice a difference before when I was experimenting with
// getBookmark(), so perhaps we could resort to tricks with checking
// bookmarks around paragraph boundaries...
// TODO(user, danilatos): consider making attempt and other ranges
// used here static singletons
} finally {
setter.removeFromParent();
}
}
示例3: print
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/**
* @param n Node to pretty print
* @param selection Selection to mark in pretty print
* @param indent Indentation level to print with.
* @param multiLine True if output should be multi-line
* @return A pretty-print HTML string (with '<' and '>' already escaped)
*/
private static String print(Node n, PointRange<Node> selection, int indent, boolean multiLine) {
// Inspect selection's relevance to this element
boolean collapsed = selection != null && selection.isCollapsed();
boolean printStartMarker =
selection != null && selection.getFirst().getContainer().equals(n);
boolean printEndMarker =
selection != null && !collapsed && selection.getSecond().getContainer().equals(n);
String startMarker =
printStartMarker ? (collapsed ? "|" : "[") : "";
String endMarker = printEndMarker ? "]" : "";
if (DomHelper.isTextNode(n)) {
// Print text node as 'value'
String value = displayWhitespace(n.getNodeValue());
int startOffset = printStartMarker ? selection.getFirst().getTextOffset() : 0;
int endOffset = printEndMarker ? selection.getSecond().getTextOffset() : value.length();
String ret = "'" + value.substring(0, startOffset)
+ startMarker
+ value.substring(startOffset, endOffset)
+ endMarker
+ value.substring(endOffset, value.length())
+ "'" ;
return multiLine ? StringUtil.xmlEscape(ret) : ret;
} else {
Element e = n.cast();
if (e.getChildCount() == 0) {
// Print child-less element as self-closing tag
return startTag(e, true, multiLine);
} else {
boolean singleLineHtml = multiLine &&
(e.getChildCount() == 1 &&
e.getFirstChild()
.getChildCount() == 0);
// Print element w/ children. One line each for start tag, child, end tag
String pretty = startTag(e, false, multiLine);
Node child = e.getFirstChild();
Node startNodeAfter = selection.getFirst().getNodeAfter();
Node endNodeAfter = selection.getSecond().getNodeAfter();
while (child != null) {
pretty += (multiLine && !singleLineHtml ? newLine(indent + 1) : "")
+ (printStartMarker && child.equals(startNodeAfter) ? startMarker : "")
+ (printEndMarker && child.equals(endNodeAfter) ? endMarker : "")
+ print(child, selection, indent + 1, multiLine);
child = child.getNextSibling();
}
if (printEndMarker && endNodeAfter == null) {
pretty += endMarker;
}
return pretty + (multiLine && !singleLineHtml ? newLine(indent) : "")
+ endTag(e, multiLine);
}
}
}
示例4: getNextSibling
import com.google.gwt.dom.client.Node; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public Node getNextSibling(Node node) {
return node.getNextSibling();
}