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

📄 abstractdocument.java

📁 gcc的JAVA模块的源代码
💻 JAVA
字号:
/* AbstractDocument.java --    Copyright (C) 2002, 2004 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.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.UndoableEdit;public abstract class AbstractDocument implements Document{    Vector doc_list = new Vector();    Vector undo_list = new Vector();    // these still need to be implemented by a derived class:    public abstract  Element getParagraphElement(int pos);    public abstract  Element getDefaultRootElement();    // some inner classes sun says I should have:    abstract class AbstractElement implements Element, TreeNode    {	int count, offset;	AttributeSet attr;	Vector elts = new Vector();	String name;	Element parent;	Vector kids = new Vector();	TreeNode tree_parent;		public AbstractElement(Element p, AttributeSet s)	{ parent = p; attr = s; }	public Enumeration children()         { return kids.elements(); }	public boolean getAllowsChildren()    { return true; }	public TreeNode getChildAt(int index) { return (TreeNode) kids.elementAt(index); }	public int getChildCount()            { return kids.size(); }	public int getIndex(TreeNode  node)   { return kids.indexOf(node); }	public TreeNode getParent()           { return tree_parent; }	public AttributeSet getAttributes()      { return attr; }	public Document getDocument()            { return AbstractDocument.this; }	public Element getElement(int index)     { return (Element)elts.elementAt(index); }	public String getName()                  { return name; }	public Element getParentElement()        { return parent; }	public abstract boolean isLeaf();	public abstract int getEndOffset();	public abstract int getElementCount();	public abstract int getElementIndex(int offset);	public abstract int getStartOffset();    }    interface AttributeContext    {    }        class BranchElement extends AbstractElement    {	public BranchElement(Element e, AttributeSet a, int s, int end)	{  super(e, a);	}	public boolean isLeaf() { return false; }	public int getEndOffset() {  return 0; }	public int getElementCount() { return 0; }	public int getElementIndex(int offset) { return 0; }	public int getStartOffset() { return 0; }    }        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;    }        class DefaultDocumentEvent implements DocumentEvent    {	public int len, off;	public Document getDocument() { return AbstractDocument.this; }	public int getLength() { return len; }	public int getOffset() { return off; }	public DocumentEvent.EventType getType()  	              { return null; }	public DocumentEvent.ElementChange getChange(Element  elem)  { return null; }    }        static class ElementEdit    {    }            class LeafElement extends AbstractElement    {	LeafElement(Element e, AttributeSet a, int s, int end)	{  super(e, a);	}	public boolean isLeaf() { return true; }	public int getEndOffset() {  return 0; }	public int getElementCount() { return 0; }	public int getElementIndex(int offset) { return 0; }	public int getStartOffset() { return 0; }    }      Content content;    AbstractDocument(Content doc)    {	content = doc;    }        /********************************************************     *     *  the meat:     *     ***********/        public void addDocumentListener(DocumentListener listener)    {	doc_list.addElement(listener);    }      public void addUndoableEditListener(UndoableEditListener listener)    {	undo_list.addElement(listener);    }     protected  Element createBranchElement(Element parent, AttributeSet a)    {		return new BranchElement(parent, a, 0, 0);    }     protected  Element createLeafElement(Element parent, AttributeSet a, int p0, int p1)    {	return new LeafElement(parent, a, p0, p1-p0);    }    public Position createPosition(int offs)    {	final int a = offs;	return new Position() 	    {		public int getOffset()		{		    return a; 		}	    };    }      protected void fireChangedUpdate(DocumentEvent e)    {    }     protected  void fireInsertUpdate(DocumentEvent e)    {    }     protected  void fireRemoveUpdate(DocumentEvent e)    {    }     protected  void fireUndoableEditUpdate(UndoableEditEvent e)    {    }    int getAsynchronousLoadPriority()    {	return 0;    }     protected  AttributeContext getAttributeContext()    {	return null;    }        Element getBidiRootElement()    {	return null;    }     protected Content getContent()    {	return content;    }     protected  Thread getCurrentWriter()    {	return null;    }    public Dictionary getDocumentProperties()    {	return null;    }    public Position getEndPosition()    {	return null;    }    public int getLength()    {	return content.length();    }        public EventListener[] getListeners(Class listenerType)    {	return null;    }        public Object getProperty(Object key)    {	return null;    }    public Element[] getRootElements()    {	return null;    }        public Position getStartPosition()    {	return null;    }    public String getText(int offset, int length)    {	try {	    return content.getString(offset, length);	} catch (Exception e) {	    System.out.println("Hmmm, fail to getText: " + offset + " -> " + length);	    return null;	}    }      public void getText(int offset, int length, Segment txt)    {	String a = getText(offset, length);	if (a == null)	    {		txt.offset = 0;		txt.count = 0;		txt.array  = new char[0];		return;	    }	txt.offset = offset;	txt.count  = length;	char chars[] = new char[ a.length() ];		a.getChars(0, a.length(), chars, 0);		txt.array  = chars;	    }      public void insertString(int offs, String str, AttributeSet a)    {	try {	    content.insertString(offs, str);		} catch (Exception e) {	    System.err.println("FAILED TO INSERT-STRING: " + e + ", at:"+offs);	}    }     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 offs, int len)    {    }      public void removeDocumentListener(DocumentListener listener)    {    }      public void removeUndoableEditListener(UndoableEditListener listener)    {    }     protected void removeUpdate(DefaultDocumentEvent chng)    {    }      public void render(Runnable r)    {    }          void setAsynchronousLoadPriority(int p)    {    }      void setDocumentProperties(Dictionary x)    {    }     protected  void writeLock()    {    }     protected  void writeUnlock()    {    }}

⌨️ 快捷键说明

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