本文整理汇总了Java中org.w3c.dom.ranges.Range类的典型用法代码示例。如果您正苦于以下问题:Java Range类的具体用法?Java Range怎么用?Java Range使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于org.w3c.dom.ranges包,在下文中一共展示了Range类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeObject
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/**
* @serialData Serialized fields. Convert Maps to Hashtables and Lists
* to Vectors for backward compatibility.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
// Convert Maps to Hashtables, Lists to Vectors
Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);
Hashtable<NodeImpl, Vector<LEntry>> el = null;
if (eventListeners != null) {
el = new Hashtable<>();
for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
el.put(e.getKey(), new Vector<>(e.getValue()));
}
}
// Write serialized fields
ObjectOutputStream.PutField pf = out.putFields();
pf.put("iterators", it);
pf.put("ranges", r);
pf.put("eventListeners", el);
pf.put("mutationEvents", mutationEvents);
out.writeFields();
}
示例2: readObject
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// We have to read serialized fields first.
ObjectInputStream.GetField gf = in.readFields();
Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
Hashtable<NodeImpl, Vector<LEntry>> el =
(Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);
mutationEvents = gf.get("mutationEvents", false);
//convert Hashtables back to HashMaps and Vectors to Lists
if (it != null) iterators = new ArrayList<>(it);
if (r != null) ranges = new ArrayList<>(r);
if (el != null) {
eventListeners = new HashMap<>();
for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
}
}
}
示例3: getSelectionRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
public Range getSelectionRange() {
if (this.dotInfo == null || this.dotInfo.range == null) {
return null;
}
Range r = docRange.createRange();
// some xml parsers don't allow end<start in the same text node. So,
// handle dot<mark here
if (this.markInfo.range.compareBoundaryPoints(Range.START_TO_START, this.dotInfo.range) <= 0) {
r.setStart(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset());
r.setEnd(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
} else {
r.setStart(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
r.setEnd(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset());
}
return r;
}
示例4: getTarget
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
protected Node getTarget(){
Node target = null;
Range range = getRange();
if (range != null) {
target = range.getEndContainer();
}
if (target == null) {
target = getFocusedNode();
}
//if target is still null at this point, check to see if this is a drop to source action.
if(target == null){
//if it is, run the drop to source setup and get a valid drop target node back.
target = getSelectedNodeFromSource();
}
return target;
}
示例5: removeRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/** Not a client function. Called by Range.detach(),
* so a Range can remove itself from the list of
* Ranges.
*/
void removeRange(Range range) {
if (range == null) return;
if (ranges == null) return;
removeStaleRangeReferences();
Iterator i = ranges.iterator();
while (i.hasNext()) {
Object otherRange = ((Reference) i.next()).get();
if (otherRange == range) {
i.remove();
return;
}
// Remove stale reference from the list.
else if (otherRange == null) {
i.remove();
}
}
}
示例6: removeRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/** Not a client function. Called by Range.detach(),
* so a Range can remove itself from the list of
* Ranges.
*/
void removeRange(Range range) {
if (range == null) return;
if (ranges == null) return;
ranges.removeElement(range);
}
示例7: cloneRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
public Range cloneRange(){
if( fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
Range range = fDocument.createRange();
range.setStart(fStartContainer, fStartOffset);
range.setEnd(fEndContainer, fEndOffset);
return range;
}
示例8: removeRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/** Not a client function. Called by Range.detach(),
* so a Range can remove itself from the list of
* Ranges.
*/
void removeRange(Range range) {
if (range == null) return;
if (ranges == null) return;
ranges.remove(range);
}
示例9: cloneRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
public Range cloneRange(){
if( fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
Range range = fDocument.createRange();
range.setStart(fStartContainer, fStartOffset);
range.setEnd(fEndContainer, fEndOffset);
return range;
}
示例10: selectAll
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
public void selectAll() {
if (this.getComponent() == null || this.getComponent().getWidth() == 0
|| this.getComponent().getHeight() == 0) {
return;
}
checkDocument();
NodeIterator nodeIterator = this.docTraversal.createNodeIterator(this.document.getDocumentElement(),
NodeFilter.SHOW_TEXT, null, false);
Text firstText = null;
Text lastText = null;
while (true) {
Node n = nodeIterator.nextNode();
if (n == null) {
break;
}
if (!textInlineMap.containsKey(n)) {
continue;
}
lastText = (Text) n;
if (firstText == null) {
firstText = lastText;
}
}
if (firstText == null) {
return;
}
Range r = docRange.createRange();
r.setStart(firstText, 0);
ViewModelInfo firstPoint = new ViewModelInfo(r, (InlineText) ((List) textInlineMap.get(firstText)).get(0));
r = docRange.createRange();
try {
// possibly some dom impls don't handle this?
r.setStart(lastText, lastText.getLength());
} catch (Exception e) {
r.setStart(lastText, Math.max(0, lastText.getLength() - 1));
}
List l = (List) textInlineMap.get(firstText);
ViewModelInfo lastPoint = new ViewModelInfo(r, (InlineText) l.get(l.size() - 1));
setDot(firstPoint);
moveDot(lastPoint);
}
示例11: ViewModelInfo
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
ViewModelInfo(Range range, InlineText text) {
this.range = range;
this.text = text;
}
示例12: resolve
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
public String resolve(String infileAddress,
String content,
String mimeType) throws AddressException{
try{
// get the start and end of the text to find
String pieces[] = infileAddress.split("\\.\\.\\.");
if(pieces == null || pieces.length != 2){
throw new AddressException("Invalid quote address: "
+ infileAddress);
}
String start = pieces[0];
String end = pieces[1];
//System.out.println("start="+start);
//System.out.println("end="+end);
// parse content into a DOM
Document document = parseDocument(content);
// now find the beginning and end of the ranges that
// match this text
Node body = document.getElementsByTagName("body").item(0);
Range range = ((DocumentRange)document).createRange();
DocumentTraversal traverse = (DocumentTraversal)document;
NodeFilter filter = null;
NodeIterator nodes =
traverse.createNodeIterator(body,
NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_TEXT,
filter, true);
boolean results = findString(range, START, nodes, start);
if(results == false){
throw new AddressException("Unable to find start of quote range: "
+ start);
}
// jump the node iterator backwards one; this is for cases
// where the start and end text are in the same node
nodes.previousNode();
//System.out.println("nodes="+nodes);
results = findString(range, END, nodes, end);
if(results == false){
throw new AddressException("Unable to find end of quote range: "
+ end);
}
// get the fragment represented by this range
DocumentFragment fragment = range.cloneContents();
// serialize fragment into string
//System.out.println("fragment="+fragment);
return serialize((Node)fragment);
}catch(Exception e){
e.printStackTrace();
throw new AddressException(e);
}
}
示例13: findString
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
protected boolean findString(Range range, int rangePos,
NodeIterator nodes, String fullString){
return findString(range, rangePos, nodes, fullString,
null, null, null);
}
示例14: createRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/**
*/
public Range createRange() {
if (ranges == null) {
ranges = new LinkedList();
rangeReferenceQueue = new ReferenceQueue();
}
Range range = new RangeImpl(this);
removeStaleRangeReferences();
ranges.add(new WeakReference(range, rangeReferenceQueue));
return range;
}
示例15: createRange
import org.w3c.dom.ranges.Range; //导入依赖的package包/类
/**
*/
public Range createRange() {
if (ranges == null) {
ranges = new ArrayList<>();
}
Range range = new RangeImpl(this);
ranges.add(range);
return range;
}