📄 abstractdocument.java
字号:
{ synchronized (documentCV) { if (Thread.currentThread().equals(currentWriter)) { currentWriter = null; documentCV.notifyAll(); } } } /** * Returns the currently installed {@link DocumentFilter} for this * <code>Document</code>. * * @return the currently installed {@link DocumentFilter} for this * <code>Document</code> * * @since 1.4 */ public DocumentFilter getDocumentFilter() { return documentFilter; } /** * Sets the {@link DocumentFilter} for this <code>Document</code>. * * @param filter the <code>DocumentFilter</code> to set * * @since 1.4 */ public void setDocumentFilter(DocumentFilter filter) { this.documentFilter = filter; } /** * Dumps diagnostic information to the specified <code>PrintStream</code>. * * @param out the stream to write the diagnostic information to */ public void dump(PrintStream out) { ((AbstractElement) getDefaultRootElement()).dump(out, 0); } /** * Defines a set of methods for managing text attributes for one or more * <code>Document</code>s. * * Replicating {@link AttributeSet}s throughout a <code>Document</code> can * be very expensive. Implementations of this interface are intended to * provide intelligent management of <code>AttributeSet</code>s, eliminating * costly duplication. * * @see StyleContext */ public interface AttributeContext { /** * Returns an {@link AttributeSet} that contains the attributes * of <code>old</code> plus the new attribute specified by * <code>name</code> and <code>value</code>. * * @param old the attribute set to be merged with the new attribute * @param name the name of the attribute to be added * @param value the value of the attribute to be added * * @return the old attributes plus the new attribute */ AttributeSet addAttribute(AttributeSet old, Object name, Object value); /** * Returns an {@link AttributeSet} that contains the attributes * of <code>old</code> plus the new attributes in <code>attributes</code>. * * @param old the set of attributes where to add the new attributes * @param attributes the attributes to be added * * @return an {@link AttributeSet} that contains the attributes * of <code>old</code> plus the new attributes in * <code>attributes</code> */ AttributeSet addAttributes(AttributeSet old, AttributeSet attributes); /** * Returns an empty {@link AttributeSet}. * * @return an empty {@link AttributeSet} */ AttributeSet getEmptySet(); /** * Called to indicate that the attributes in <code>attributes</code> are * no longer used. * * @param attributes the attributes are no longer used */ void reclaim(AttributeSet attributes); /** * Returns a {@link AttributeSet} that has the attribute with the specified * <code>name</code> removed from <code>old</code>. * * @param old the attribute set from which an attribute is removed * @param name the name of the attribute to be removed * * @return the attributes of <code>old</code> minus the attribute * specified by <code>name</code> */ AttributeSet removeAttribute(AttributeSet old, Object name); /** * Removes all attributes in <code>attributes</code> from <code>old</code> * and returns the resulting <code>AttributeSet</code>. * * @param old the set of attributes from which to remove attributes * @param attributes the attributes to be removed from <code>old</code> * * @return the attributes of <code>old</code> minus the attributes in * <code>attributes</code> */ AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes); /** * Removes all attributes specified by <code>names</code> from * <code>old</code> and returns the resulting <code>AttributeSet</code>. * * @param old the set of attributes from which to remove attributes * @param names the names of the attributes to be removed from * <code>old</code> * * @return the attributes of <code>old</code> minus the attributes in * <code>attributes</code> */ AttributeSet removeAttributes(AttributeSet old, Enumeration names); } /** * A sequence of data that can be edited. This is were the actual content * in <code>AbstractDocument</code>'s is stored. */ public interface Content { /** * Creates a {@link Position} that keeps track of the location at * <code>offset</code>. * * @return a {@link Position} that keeps track of the location at * <code>offset</code>. * * @throw BadLocationException if <code>offset</code> is not a valid * location in this <code>Content</code> model */ Position createPosition(int offset) throws BadLocationException; /** * Returns the length of the content. * * @return the length of the content */ int length(); /** * Inserts a string into the content model. * * @param where the offset at which to insert the string * @param str the string to be inserted * * @return an <code>UndoableEdit</code> or <code>null</code> if undo is * not supported by this <code>Content</code> model * * @throws BadLocationException if <code>where</code> is not a valid * location in this <code>Content</code> model */ UndoableEdit insertString(int where, String str) throws BadLocationException; /** * Removes a piece of content from the content model. * * @param where the offset at which to remove content * @param nitems the number of characters to be removed * * @return an <code>UndoableEdit</code> or <code>null</code> if undo is * not supported by this <code>Content</code> model * * @throws BadLocationException if <code>where</code> is not a valid * location in this <code>Content</code> model */ UndoableEdit remove(int where, int nitems) throws BadLocationException; /** * Returns a piece of content. * * @param where the start offset of the requested fragment * @param len the length of the requested fragment * * @return the requested fragment * @throws BadLocationException if <code>offset</code> or * <code>offset + len</code>is not a valid * location in this <code>Content</code> model */ String getString(int where, int len) throws BadLocationException; /** * Fetches a piece of content and stores it in <code>txt</code>. * * @param where the start offset of the requested fragment * @param len the length of the requested fragment * @param txt the <code>Segment</code> where to fragment is stored into * * @throws BadLocationException if <code>offset</code> or * <code>offset + len</code>is not a valid * location in this <code>Content</code> model */ void getChars(int where, int len, Segment txt) throws BadLocationException; } /** * An abstract base implementation of the {@link Element} interface. */ public abstract class AbstractElement implements Element, MutableAttributeSet, TreeNode, Serializable { /** The serialization UID (compatible with JDK1.5). */ private static final long serialVersionUID = 1712240033321461704L; /** The number of characters that this Element spans. */ int count; /** The starting offset of this Element. */ int offset; /** The attributes of this Element. */ AttributeSet attributes; /** The parent element. */ Element element_parent; /** The parent in the TreeNode interface. */ TreeNode tree_parent; /** The children of this element. */ Vector tree_children; /** * Creates a new instance of <code>AbstractElement</code> with a * specified parent <code>Element</code> and <code>AttributeSet</code>. * * @param p the parent of this <code>AbstractElement</code> * @param s the attributes to be assigned to this * <code>AbstractElement</code> */ public AbstractElement(Element p, AttributeSet s) { element_parent = p; AttributeContext ctx = getAttributeContext(); attributes = ctx.getEmptySet(); if (s != null) attributes = ctx.addAttributes(attributes, s); } /** * Returns the child nodes of this <code>Element</code> as an * <code>Enumeration</code> of {@link TreeNode}s. * * @return the child nodes of this <code>Element</code> as an * <code>Enumeration</code> of {@link TreeNode}s */ public abstract Enumeration children(); /** * Returns <code>true</code> if this <code>AbstractElement</code> * allows children. * * @return <code>true</code> if this <code>AbstractElement</code> * allows children */ public abstract boolean getAllowsChildren(); /** * Returns the child of this <code>AbstractElement</code> at * <code>index</code>. * * @param index the position in the child list of the child element to * be returned * * @return the child of this <code>AbstractElement</code> at * <code>index</code> */ public TreeNode getChildAt(int index) { return (TreeNode) tree_children.get(index); } /** * Returns the number of children of this <code>AbstractElement</code>. * * @return the number of children of this <code>AbstractElement</code> */ public int getChildCount() { return tree_children.size(); } /** * Returns the index of a given child <code>TreeNode</code> or * <code>-1</code> if <code>node</code> is not a child of this * <code>AbstractElement</code>. * * @param node the node for which the index is requested * * @return the index of a given child <code>TreeNode</code> or * <code>-1</code> if <code>node</code> is not a child of this * <code>AbstractElement</code> */ public int getIndex(TreeNode node) { return tree_children.indexOf(node); } /** * Returns the parent <code>TreeNode</code> of this * <code>AbstractElement</code> or <code>null</code> if this element * has no parent. * * @return the parent <code>TreeNode</code> of this * <code>AbstractElement</code> or <code>null</code> if this * element has no parent */ public TreeNode getParent() { return tree_parent; } /** * Returns <code>true</code> if this <code>AbstractElement</code> is a * leaf element, <code>false</code> otherwise. * * @return <code>true</code> if this <code>AbstractElement</code> is a * leaf element, <code>false</code> otherwise */ public abstract boolean isLeaf(); /** * Adds an attribute to this element. * * @param name the name of the attribute to be added * @param value the value of the attribute to be added */ public void addAttribute(Object name, Object value) { attributes = getAttributeContext().addAttribute(attributes, name, value); } /** * Adds a set of attributes to this element. * * @param attrs the attributes to be added to this element */ public void addAttributes(AttributeSet attrs) { attributes = getAttributeContext().addAttributes(attributes, attrs); } /** * Removes an attribute from this element. * * @param name the name of the attribute to be removed */ public void removeAttribute(Object name) { attributes = getAttributeContext().removeAttribute(attributes, name); } /** * Removes a set of attributes from this element. * * @param attrs the attributes to be removed */ public void removeAttributes(AttributeSet attrs) { attributes = getAttributeContext().removeAttributes(attributes, attrs); } /** * Removes a set of attribute from this element. * * @param names the names of the attributes to be removed */ public void removeAttributes(Enumeration names) { attributes = getAttributeContext().removeAttributes(attributes, names); } /** * Sets the parent attribute set against which the element can resolve * attributes that are not defined in itself. * * @param parent the resolve parent to set */ public void setResolveParent(AttributeSet parent) { attributes = getAttributeContext().addAttribute(attributes, ResolveAttribute, parent); } /** * Returns <code>true</code> if this element contains the specified * attribute. * * @param name the name of the attribute to check * @param value the value of the attribute to check * * @return <code>true</code> if this element contains the specified * attribute */ public boolean containsAttribute(Object name, Object value) { return attributes.containsAttribute(name, value); } /** * Returns <code>true</code> if this element contains all of the * specified attributes. * * @param attrs the attributes to check * * @return <code>true</code> if this element contains all of the * specified attributes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -