abstractdocument.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 893 行 · 第 1/2 页

JAVA
893
字号
/* AbstractDocument.java --   Copyright (C) 2002, 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., 59 Temple Place, Suite 330, Boston, MA02111-1307 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.io.PrintStream;import java.io.Serializable;import java.util.Dictionary;import java.util.Enumeration;import java.util.EventListener;import java.util.Vector;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.swing.event.EventListenerList;import javax.swing.event.UndoableEditEvent;import javax.swing.event.UndoableEditListener;import javax.swing.tree.TreeNode;import javax.swing.undo.AbstractUndoableEdit;import javax.swing.undo.CompoundEdit;import javax.swing.undo.UndoableEdit;public abstract class AbstractDocument  implements Document, Serializable{  private static final long serialVersionUID = -116069779446114664L;    protected static final String BAD_LOCATION = "document location failure";    public static final String BidiElementName = "bidi level";  public static final String ContentElementName = "content";  public static final String ParagraphElementName = "paragraph";  public static final String SectionElementName = "section";  public static final String ElementNameAttribute = "$ename";  Content content;  AttributeContext context;  DocumentFilter documentFilter;    protected EventListenerList listenerList = new EventListenerList();  protected AbstractDocument(Content doc)  {    this(doc, StyleContext.getDefaultStyleContext());  }  protected AbstractDocument(Content doc, AttributeContext ctx)  {    content = doc;    context = ctx;  }  // These still need to be implemented by a derived class:  public abstract Element getParagraphElement(int pos);  public abstract Element getDefaultRootElement();  protected Element createBranchElement(Element parent,					AttributeSet attributes)  {    return new BranchElement(parent, attributes);  }  protected Element createLeafElement(Element parent, AttributeSet attributes,				      int start, int end)  {    return new LeafElement(parent, attributes, start, end);  }  public Position createPosition(final int offset) throws BadLocationException  {    if (offset < 0 || offset > getLength())      throw new BadLocationException(getText(0, getLength()), offset);    return new Position()      {	public int getOffset()	{	  return offset;	}      };  }  protected void fireChangedUpdate(DocumentEvent event)  {    DocumentListener[] listeners = getDocumentListeners();    for (int index = 0; index < listeners.length; ++index)      listeners[index].changedUpdate(event);  }  protected void fireInsertUpdate(DocumentEvent event)  {    DocumentListener[] listeners = getDocumentListeners();    for (int index = 0; index < listeners.length; ++index)      listeners[index].insertUpdate(event);  }  protected void fireRemoveUpdate(DocumentEvent event)  {    DocumentListener[] listeners = getDocumentListeners();    for (int index = 0; index < listeners.length; ++index)      listeners[index].removeUpdate(event);  }  protected void fireUndoableEditUpdate(UndoableEditEvent event)  {    UndoableEditListener[] listeners = getUndoableEditListeners();    for (int index = 0; index < listeners.length; ++index)      listeners[index].undoableEditHappened(event);  }  public int getAsynchronousLoadPriority()  {    return 0;  }  protected AttributeContext getAttributeContext()  {    return context;  }  public Element getBidiRootElement()  {    return null;  }  protected Content getContent()  {    return content;  }  protected Thread getCurrentWriter()  {    return null;  }  public Dictionary getDocumentProperties()  {    return null;  }  public Position getEndPosition()  {    return new Position()       {                public int getOffset()         {           return getLength();         }       };  }  public int getLength()  {    return content.length() - 1;  }  public EventListener[] getListeners(Class listenerType)  {    return listenerList.getListeners(listenerType);  }  public Object getProperty(Object key)  {    return null;  }  public Element[] getRootElements()  {    Element[] elements = new Element[1];    elements[0] = getDefaultRootElement();    return elements;  }  public Position getStartPosition()  {    return new Position()       {                public int getOffset()         {           return 0;         }       };  }  public String getText(int offset, int length) throws BadLocationException  {    return content.getString(offset, length);  }  public void getText(int offset, int length, Segment segment)    throws BadLocationException  {    content.getChars(offset, length, segment);  }  public void insertString(int offset, String text, AttributeSet attributes)    throws BadLocationException  {    // Just return when no text to insert was given.    if (text == null || text.length() == 0)      return;        DefaultDocumentEvent event =      new DefaultDocumentEvent(offset, text.length(),			       DocumentEvent.EventType.INSERT);    content.insertString(offset, text);    insertUpdate(event, attributes);    fireInsertUpdate(event);  }  protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)  {  }  protected void postRemoveUpdate(DefaultDocumentEvent chng)  {  }  public void putProperty(Object key, Object value)  {  }  public void readLock()  {  }  public void readUnlock()  {  }  public void remove(int offset, int length) throws BadLocationException  {    DefaultDocumentEvent event =      new DefaultDocumentEvent(offset, length,			       DocumentEvent.EventType.REMOVE);    removeUpdate(event);    content.remove(offset, length);    postRemoveUpdate(event);    fireRemoveUpdate(event);  }  /**   * Replaces some text in the document.   *   * @since 1.4   */  public void replace(int offset, int length, String text,		      AttributeSet attributes)    throws BadLocationException  {    remove(offset, length);    insertString(offset, text, attributes);  }  /**   * Adds a <code>DocumentListener</code> object to this document.   *   * @param listener the listener to add   */  public void addDocumentListener(DocumentListener listener)  {    listenerList.add(DocumentListener.class, listener);  }  /**   * Removes a <code>DocumentListener</code> object from this document.   *   * @param listener the listener to remove   */  public void removeDocumentListener(DocumentListener listener)  {    listenerList.remove(DocumentListener.class, listener);  }  /**   * Returns add added <code>DocumentListener</code> objects.   *   * @return an array of listeners   */  public DocumentListener[] getDocumentListeners()  {    return (DocumentListener[]) getListeners(DocumentListener.class);  }  /**   * Adds a <code>UndoableEditListener</code> object to this document.   *   * @param listener the listener to add   */  public void addUndoableEditListener(UndoableEditListener listener)  {    listenerList.add(UndoableEditListener.class, listener);  }  /**   * Removes a <code>UndoableEditListener</code> object from this document.   *   * @param listener the listener to remove   */  public void removeUndoableEditListener(UndoableEditListener listener)  {    listenerList.remove(UndoableEditListener.class, listener);  }  /**   * Returns add added <code>UndoableEditListener</code> objects.   *   * @return an array of listeners   */  public UndoableEditListener[] getUndoableEditListeners()  {    return (UndoableEditListener[]) getListeners(UndoableEditListener.class);  }  protected void removeUpdate(DefaultDocumentEvent chng)  {  }  public void render(Runnable r)  {  }  public void setAsynchronousLoadPriority(int p)  {  }  public void setDocumentProperties(Dictionary x)  {  }  protected void writeLock()  {  }  protected void writeUnlock()  {  }  /**   * @since 1.4   */  public DocumentFilter getDocumentFilter()  {    return documentFilter;  }  /**   * @since 1.4   */  public void setDocumentFilter(DocumentFilter filter)  {    this.documentFilter = filter;  }  public void dump(PrintStream out)  {    ((AbstractElement) getDefaultRootElement()).dump(out, 0);  }  public interface AttributeContext  {    AttributeSet addAttribute(AttributeSet old, Object name, Object value);    AttributeSet addAttributes(AttributeSet old, AttributeSet attributes);    AttributeSet getEmptySet();    void reclaim(AttributeSet attributes);    AttributeSet removeAttribute(AttributeSet old, Object name);    AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes);    AttributeSet removeAttributes(AttributeSet old, Enumeration names);  }  public interface Content  {    Position createPosition(int offset) throws BadLocationException;    int length();    UndoableEdit insertString(int where, String str)      throws BadLocationException;    UndoableEdit remove(int where, int nitems) throws BadLocationException;    String getString(int where, int len) throws BadLocationException;    void getChars(int where, int len, Segment txt) throws BadLocationException;  }  public abstract class AbstractElement    implements Element, MutableAttributeSet, TreeNode, Serializable  {    private static final long serialVersionUID = 1265312733007397733L;    int count;    int offset;    AttributeSet attributes;    Element element_parent;    TreeNode tree_parent;    Vector tree_children;    public AbstractElement(Element p, AttributeSet s)

⌨️ 快捷键说明

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