Implements the abstract part of an element. By default elements
support attributes by having a field that represents the immutable
part of the current attribute set for the element. The element itself
implements MutableAttributeSet which can be used to modify the set
by fetching a new immutable set. The immutable sets are provided
by the AttributeContext associated with the document.
| Method from javax.swing.text.AbstractDocument$AbstractElement Detail: |
public void addAttribute(Object name,
Object value) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
attributes = context.addAttribute(attributes, name, value);
}
Adds an attribute to the element. |
public void addAttributes(AttributeSet attr) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
attributes = context.addAttributes(attributes, attr);
}
Adds a set of attributes to the element. |
abstract public Enumeration children()
Returns the children of the receiver as an
Enumeration. |
public boolean containsAttribute(Object name,
Object value) {
return attributes.containsAttribute(name, value);
}
Checks whether a given attribute name/value is defined. |
public boolean containsAttributes(AttributeSet attrs) {
return attributes.containsAttributes(attrs);
}
Checks whether the element contains all the attributes. |
public AttributeSet copyAttributes() {
return attributes.copyAttributes();
}
Copies a set of attributes. |
public void dump(PrintStream psOut,
int indentAmount) {
PrintWriter out;
try {
out = new PrintWriter(new OutputStreamWriter(psOut,"JavaEsc"),
true);
} catch (UnsupportedEncodingException e){
out = new PrintWriter(psOut,true);
}
indent(out, indentAmount);
if (getName() == null) {
out.print("< ??");
} else {
out.print("< " + getName());
}
if (getAttributeCount() > 0) {
out.println("");
// dump the attributes
Enumeration names = attributes.getAttributeNames();
while (names.hasMoreElements()) {
Object name = names.nextElement();
indent(out, indentAmount + 1);
out.println(name + "=" + getAttribute(name));
}
indent(out, indentAmount);
}
out.println(" >");
if (isLeaf()) {
indent(out, indentAmount+1);
out.print("[" + getStartOffset() + "," + getEndOffset() + "]");
Content c = getContent();
try {
String contentStr = c.getString(getStartOffset(),
getEndOffset() - getStartOffset())/*.trim()*/;
if (contentStr.length() > 40) {
contentStr = contentStr.substring(0, 40) + "...";
}
out.println("["+contentStr+"]");
} catch (BadLocationException e) {
;
}
} else {
int n = getElementCount();
for (int i = 0; i < n; i++) {
AbstractElement e = (AbstractElement) getElement(i);
e.dump(psOut, indentAmount+1);
}
}
}
Dumps a debugging representation of the element hierarchy. |
abstract public boolean getAllowsChildren()
Returns true if the receiver allows children. |
public Object getAttribute(Object attrName) {
Object value = attributes.getAttribute(attrName);
if (value == null) {
// The delegate nor it's resolvers had a match,
// so we'll try to resolve through the parent
// element.
AttributeSet a = (parent != null) ? parent.getAttributes() : null;
if (a != null) {
value = a.getAttribute(attrName);
}
}
return value;
}
Gets the value of an attribute. |
public int getAttributeCount() {
return attributes.getAttributeCount();
}
Gets the number of attributes that are defined. |
public Enumeration getAttributeNames() {
return attributes.getAttributeNames();
}
Gets the names of all attributes. |
public AttributeSet getAttributes() {
return this;
}
Gets the attributes for the element. |
public TreeNode getChildAt(int childIndex) {
return (TreeNode)getElement(childIndex);
}
Returns the child TreeNode at index
childIndex. |
public int getChildCount() {
return getElementCount();
}
Returns the number of children TreeNode's
receiver contains. |
public Document getDocument() {
return AbstractDocument.this;
}
Retrieves the underlying model. |
abstract public Element getElement(int index)
|
abstract public int getElementCount()
Gets the number of children for the element. |
abstract public int getElementIndex(int offset)
Gets the child element index closest to the given model offset. |
abstract public int getEndOffset()
Gets the ending offset in the model for the element. |
public int getIndex(TreeNode node) {
for(int counter = getChildCount() - 1; counter >= 0; counter--)
if(getChildAt(counter) == node)
return counter;
return -1;
}
Returns the index of node in the receivers children.
If the receiver does not contain node, -1 will be
returned. |
public String getName() {
if (attributes.isDefined(ElementNameAttribute)) {
return (String) attributes.getAttribute(ElementNameAttribute);
}
return null;
}
Gets the name of the element. |
public TreeNode getParent() {
return (TreeNode)getParentElement();
}
Returns the parent TreeNode of the receiver. |
public Element getParentElement() {
return parent;
}
Gets the parent of the element. |
public AttributeSet getResolveParent() {
AttributeSet a = attributes.getResolveParent();
if ((a == null) && (parent != null)) {
a = parent.getAttributes();
}
return a;
}
Gets the resolving parent.
If not overridden, the resolving parent defaults to
the parent element. |
abstract public int getStartOffset()
Gets the starting offset in the model for the element. |
public boolean isDefined(Object attrName) {
return attributes.isDefined(attrName);
}
Checks whether a given attribute is defined. |
public boolean isEqual(AttributeSet attr) {
return attributes.isEqual(attr);
}
Checks whether two attribute sets are equal. |
abstract public boolean isLeaf()
Checks whether the element is a leaf. |
public void removeAttribute(Object name) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
attributes = context.removeAttribute(attributes, name);
}
Removes an attribute from the set. |
public void removeAttributes(Enumeration names) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
attributes = context.removeAttributes(attributes, names);
}
Removes a set of attributes for the element. |
public void removeAttributes(AttributeSet attrs) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
if (attrs == this) {
attributes = context.getEmptySet();
} else {
attributes = context.removeAttributes(attributes, attrs);
}
}
Removes a set of attributes for the element. |
public void setResolveParent(AttributeSet parent) {
checkForIllegalCast();
AttributeContext context = getAttributeContext();
if (parent != null) {
attributes =
context.addAttribute(attributes, StyleConstants.ResolveAttribute,
parent);
} else {
attributes =
context.removeAttribute(attributes, StyleConstants.ResolveAttribute);
}
}
Sets the resolving parent. |