abstractdocument.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 893 行 · 第 1/2 页
JAVA
893 行
{ element_parent = p; attributes = s; } // TreeNode implementation public abstract Enumeration children(); public abstract boolean getAllowsChildren(); public TreeNode getChildAt(int index) { return (TreeNode) tree_children.get(index); } public int getChildCount() { return tree_children.size(); } public int getIndex(TreeNode node) { return tree_children.indexOf(node); } public TreeNode getParent() { return tree_parent; } public abstract boolean isLeaf(); // MutableAttributeSet support public void addAttribute(Object name, Object value) { attributes = getAttributeContext().addAttribute(attributes, name, value); } public void addAttributes(AttributeSet attrs) { attributes = getAttributeContext().addAttributes(attributes, attrs); } public void removeAttribute(Object name) { attributes = getAttributeContext().removeAttribute(attributes, name); } public void removeAttributes(AttributeSet attrs) { attributes = getAttributeContext().removeAttributes(attributes, attrs); } public void removeAttributes(Enumeration names) { attributes = getAttributeContext().removeAttributes(attributes, names); } public void setResolveParent(AttributeSet parent) { attributes = getAttributeContext().addAttribute(attributes, ResolveAttribute, parent); } // AttributeSet interface support public boolean containsAttribute(Object name, Object value) { return attributes.containsAttribute(name, value); } public boolean containsAttributes(AttributeSet attrs) { return attributes.containsAttributes(attrs); } public AttributeSet copyAttributes() { return attributes.copyAttributes(); } public Object getAttribute(Object key) { return attributes.getAttribute(key); } public int getAttributeCount() { return attributes.getAttributeCount(); } public Enumeration getAttributeNames() { return attributes.getAttributeNames(); } public AttributeSet getResolveParent() { return attributes.getResolveParent(); } public boolean isDefined(Object attrName) { return attributes.isDefined(attrName); } public boolean isEqual(AttributeSet attrs) { return attributes.isEqual(attrs); } // Element interface support public AttributeSet getAttributes() { return attributes; } public Document getDocument() { return AbstractDocument.this; } public abstract Element getElement(int index); public String getName() { return (String) getAttribute(NameAttribute); } public Element getParentElement() { return element_parent; } public abstract int getEndOffset(); public abstract int getElementCount(); public abstract int getElementIndex(int offset); public abstract int getStartOffset(); private void dumpElement(PrintStream stream, String indent, Element element) { System.out.println(indent + "<" + element.getName() +">"); if (element.isLeaf()) { int start = element.getStartOffset(); int end = element.getEndOffset(); String text = ""; try { text = getContent().getString(start, end - start); } catch (BadLocationException e) { } System.out.println(indent + " [" + start + "," + end + "][" + text + "]"); } else { for (int i = 0; i < element.getElementCount(); ++i) dumpElement(stream, indent + " ", element.getElement(i)); } } public void dump(PrintStream stream, int indent) { String indentStr = ""; for (int i = 0; i < indent; ++i) indentStr += " "; dumpElement(stream, indentStr, this); } } public class BranchElement extends AbstractElement { private static final long serialVersionUID = -8595176318868717313L; private Element[] children = new Element[0]; public BranchElement(Element parent, AttributeSet attributes) { super(parent, attributes); } public Enumeration children() { if (children.length == 0) return null; Vector tmp = new Vector(); for (int index = 0; index < children.length; ++index) tmp.add(children[index]); return tmp.elements(); } public boolean getAllowsChildren() { return true; } public Element getElement(int index) { if (index < 0 || index >= children.length) return null; return children[index]; } public int getElementCount() { return children.length; } public int getElementIndex(int offset) { // XXX: There is surely a better algorithm // as beginning from first element each time. for (int index = 0; index < children.length; ++index) { Element elem = children[index]; if ((elem.getStartOffset() <= offset) && (offset < elem.getEndOffset())) return index; } return 0; } public int getEndOffset() { return children[children.length - 1].getEndOffset(); } public String getName() { return ParagraphElementName; } public int getStartOffset() { return children[0].getStartOffset(); } public boolean isLeaf() { return false; } public Element positionToElement(int position) { // XXX: There is surely a better algorithm // as beginning from first element each time. for (int index = 0; index < children.length; ++index) { Element elem = children[index]; if ((elem.getStartOffset() <= position) && (position < elem.getEndOffset())) return elem; } return null; } public void replace(int offset, int length, Element[] elements) { Element[] target = new Element[children.length - length + elements.length]; System.arraycopy(children, 0, target, 0, offset); System.arraycopy(elements, 0, target, offset, elements.length); System.arraycopy(children, offset + length, target, offset + elements.length, children.length - offset - length); children = target; } public String toString() { return ("BranchElement(" + getName() + ") " + getStartOffset() + "," + getEndOffset() + "\n"); } } public class DefaultDocumentEvent extends CompoundEdit implements DocumentEvent { private static final long serialVersionUID = -7406103236022413522L; private int offset; private int length; private DocumentEvent.EventType type; public DefaultDocumentEvent(int offset, int length, DocumentEvent.EventType type) { this.offset = offset; this.length = length; this.type = type; } public Document getDocument() { return AbstractDocument.this; } public int getLength() { return length; } public int getOffset() { return offset; } public DocumentEvent.EventType getType() { return type; } public DocumentEvent.ElementChange getChange(Element elem) { return null; } } public static class ElementEdit extends AbstractUndoableEdit implements DocumentEvent.ElementChange { private static final long serialVersionUID = -1216620962142928304L; private Element elem; private int index; private Element[] removed; private Element[] added; public ElementEdit(Element elem, int index, Element[] removed, Element[] added) { this.elem = elem; this.index = index; this.removed = removed; this.added = added; } public Element[] getChildrenAdded() { return added; } public Element[] getChildrenRemoved() { return removed; } public Element getElement() { return elem; } public int getIndex() { return index; } } public class LeafElement extends AbstractElement { private static final long serialVersionUID = 5115368706941283802L; private int start; private int end; public LeafElement(Element parent, AttributeSet attributes, int start, int end) { super(parent, attributes); this.start = start; this.end = end; } public Enumeration children() { return null; } public boolean getAllowsChildren() { return false; } public Element getElement(int index) { return null; } public int getElementCount() { return 0; } public int getElementIndex(int offset) { return -1; } public int getEndOffset() { return end; } public String getName() { return ContentElementName; } public int getStartOffset() { return start; } public boolean isLeaf() { return true; } public String toString() { return ("LeafElement(" + getName() + ") " + getStartOffset() + "," + getEndOffset() + "\n"); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?