⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultstyleddocument.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* DefaultStyledDocument.java --   Copyright (C) 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.text;import java.awt.Color;import java.awt.Font;import java.io.Serializable;import java.util.Enumeration;import java.util.Vector;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.DocumentEvent;import javax.swing.undo.AbstractUndoableEdit;import javax.swing.undo.UndoableEdit;/** * The default implementation of {@link StyledDocument}. * * The document is modeled as an {@link Element} tree, which has * a {@link SectionElement} as single root, which has one or more * {@link AbstractDocument.BranchElement}s as paragraph nodes * and each paragraph node having one or more * {@link AbstractDocument.LeafElement}s as content nodes. * * @author Michael Koch (konqueror@gmx.de) * @author Roman Kennke (roman@kennke.org) */public class DefaultStyledDocument extends AbstractDocument  implements StyledDocument{  /**   * An {@link UndoableEdit} that can undo attribute changes to an element.   *   * @author Roman Kennke (kennke@aicas.com)   */  public static class AttributeUndoableEdit    extends AbstractUndoableEdit  {    /**     * A copy of the old attributes.     */    protected AttributeSet copy;    /**     * The new attributes.     */    protected AttributeSet newAttributes;    /**     * If the new attributes replaced the old attributes or if they only were     * added to them.     */    protected boolean isReplacing;    /**     * The element that has changed.     */    protected Element element;    /**     * Creates a new <code>AttributeUndoableEdit</code>.     *     * @param el the element that changes attributes     * @param newAtts the new attributes     * @param replacing if the new attributes replace the old or only append to     *        them     */    public AttributeUndoableEdit(Element el, AttributeSet newAtts,                                 boolean replacing)    {      element = el;      newAttributes = newAtts;      isReplacing = replacing;      copy = el.getAttributes().copyAttributes();    }    /**     * Undos the attribute change. The <code>copy</code> field is set as     * attributes on <code>element</code>.     */    public void undo()    {      super.undo();      AttributeSet atts = element.getAttributes();      if (atts instanceof MutableAttributeSet)        {          MutableAttributeSet mutable = (MutableAttributeSet) atts;          mutable.removeAttributes(atts);          mutable.addAttributes(copy);        }    }    /**     * Redos an attribute change. This adds <code>newAttributes</code> to the     * <code>element</code>'s attribute set, possibly clearing all attributes     * if <code>isReplacing</code> is true.     */    public void redo()    {      super.undo();      AttributeSet atts = element.getAttributes();      if (atts instanceof MutableAttributeSet)        {          MutableAttributeSet mutable = (MutableAttributeSet) atts;          if (isReplacing)            mutable.removeAttributes(atts);          mutable.addAttributes(newAttributes);        }    }  }  /**   * Carries specification information for new {@link Element}s that should   * be created in {@link ElementBuffer}. This allows the parsing process   * to be decoupled from the <code>Element</code> creation process.   */  public static class ElementSpec  {    /**     * This indicates a start tag. This is a possible value for     * {@link #getType}.     */    public static final short StartTagType = 1;    /**     * This indicates an end tag. This is a possible value for     * {@link #getType}.     */    public static final short EndTagType = 2;    /**     * This indicates a content element. This is a possible value for     * {@link #getType}.     */    public static final short ContentType = 3;    /**     * This indicates that the data associated with this spec should be joined     * with what precedes it. This is a possible value for     * {@link #getDirection}.     */    public static final short JoinPreviousDirection = 4;    /**     * This indicates that the data associated with this spec should be joined     * with what follows it. This is a possible value for     * {@link #getDirection}.     */    public static final short JoinNextDirection = 5;    /**     * This indicates that the data associated with this spec should be used     * to create a new element. This is a possible value for     * {@link #getDirection}.     */    public static final short OriginateDirection = 6;    /**     * This indicates that the data associated with this spec should be joined     * to the fractured element. This is a possible value for     * {@link #getDirection}.     */    public static final short JoinFractureDirection = 7;    /**     * The type of the tag.     */    short type;    /**     * The direction of the tag.     */    short direction;    /**     * The offset of the content.     */    int offset;    /**     * The length of the content.     */    int length;    /**     * The actual content.     */    char[] content;    /**     * The attributes for the tag.     */    AttributeSet attributes;    /**     * Creates a new <code>ElementSpec</code> with no content, length or     * offset. This is most useful for start and end tags.     *     * @param a the attributes for the element to be created     * @param type the type of the tag     */    public ElementSpec(AttributeSet a, short type)    {      this(a, type, 0);    }    /**     * Creates a new <code>ElementSpec</code> that specifies the length but     * not the offset of an element. Such <code>ElementSpec</code>s are     * processed sequentially from a known starting point.     *     * @param a the attributes for the element to be created     * @param type the type of the tag     * @param len the length of the element     */    public ElementSpec(AttributeSet a, short type, int len)    {      this(a, type, null, 0, len);    }     /**     * Creates a new <code>ElementSpec</code> with document content.     *     * @param a the attributes for the element to be created     * @param type the type of the tag     * @param txt the actual content     * @param offs the offset into the <code>txt</code> array     * @param len the length of the element     */    public ElementSpec(AttributeSet a, short type, char[] txt, int offs,                       int len)    {      attributes = a;      this.type = type;      offset = offs;      length = len;      content = txt;      direction = OriginateDirection;    }    /**     * Sets the type of the element.     *     * @param type the type of the element to be set     */    public void setType(short type)    {      this.type = type;    }    /**     * Returns the type of the element.     *     * @return the type of the element     */    public short getType()    {      return type;    }    /**     * Sets the direction of the element.     *     * @param dir the direction of the element to be set     */    public void setDirection(short dir)    {      direction = dir;    }    /**     * Returns the direction of the element.     *     * @return the direction of the element     */    public short getDirection()    {      return direction;    }    /**     * Returns the attributes of the element.     *     * @return the attributes of the element     */    public AttributeSet getAttributes()    {      return attributes;    }    /**     * Returns the actual content of the element.     *     * @return the actual content of the element     */    public char[] getArray()    {      return content;    }    /**     * Returns the offset of the content.     *     * @return the offset of the content     */    public int getOffset()    {      return offset;    }    /**     * Returns the length of the content.     *     * @return the length of the content     */    public int getLength()    {      return length;    }    /**     * Returns a String representation of this <code>ElementSpec</code>     * describing the type, direction and length of this     * <code>ElementSpec</code>.     *     * @return a String representation of this <code>ElementSpec</code>     */    public String toString()    {      StringBuilder b = new StringBuilder();      b.append('<');      switch (type)        {        case StartTagType:          b.append("StartTag");          break;        case EndTagType:          b.append("EndTag");          break;        case ContentType:          b.append("Content");          break;        default:          b.append("??");          break;        }      b.append(':');      switch (direction)        {        case JoinPreviousDirection:          b.append("JoinPrevious");          break;        case JoinNextDirection:          b.append("JoinNext");          break;        case OriginateDirection:          b.append("Originate");          break;        case JoinFractureDirection:          b.append("Fracture");          break;        default:          b.append("??");          break;        }      b.append(':');      b.append(length);      return b.toString();    }  }  /**   * Performs all <em>structural</code> changes to the <code>Element</code>   * hierarchy.   */  public class ElementBuffer implements Serializable  {    /** The serialization UID (compatible with JDK1.5). */    private static final long serialVersionUID = 1688745877691146623L;    /** The root element of the hierarchy. */    private Element root;    /** Holds the offset for structural changes. */    private int offset;    /** Holds the length of structural changes. */    private int length;    /**     * Holds fractured elements during insertion of end and start tags.     * Inserting an end tag may lead to fracturing of the current paragraph     * element. The elements that have been cut off may be added to the     * next paragraph that is created in the next start tag.     */    Element[] fracture;    /**     * The ElementChange that describes the latest changes.     */    DefaultDocumentEvent documentEvent;    /**     * Creates a new <code>ElementBuffer</code> for the specified     * <code>root</code> element.     *     * @param root the root element for this <code>ElementBuffer</code>     */    public ElementBuffer(Element root)    {      this.root = root;    }    /**     * Returns the root element of this <code>ElementBuffer</code>.     *     * @return the root element of this <code>ElementBuffer</code>     */    public Element getRootElement()    {      return root;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -