/[classpath]/classpath/javax/swing/text/AbstractDocument.java
ViewVC logotype

Diff of /classpath/javax/swing/text/AbstractDocument.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.27 by mark, Sun Sep 4 11:53:12 2005 UTC revision 1.28 by rabbit78, Tue Sep 13 23:44:49 2005 UTC
# Line 65  import javax.swing.undo.UndoableEdit; Line 65  import javax.swing.undo.UndoableEdit;
65   * @author original author unknown   * @author original author unknown
66   * @author Roman Kennke (roman@kennke.org)   * @author Roman Kennke (roman@kennke.org)
67   */   */
68  public abstract class AbstractDocument  public abstract class AbstractDocument implements Document, Serializable
   implements Document, Serializable  
69  {  {
70    /** The serial version UID for this class as of JDK1.4. */    /** The serialization UID (compatible with JDK1.5). */
71    private static final long serialVersionUID = -116069779446114664L;    private static final long serialVersionUID = 6842927725919637215L;
72    
73    /**    /**
74     * Standard error message to indicate a bad location.     * Standard error message to indicate a bad location.
# Line 332  public abstract class AbstractDocument Line 331  public abstract class AbstractDocument
331     * @see GapContent     * @see GapContent
332     * @see StringContent     * @see StringContent
333     */     */
334    protected Content getContent()    protected final Content getContent()
335    {    {
336      return content;      return content;
337    }    }
# Line 970  public abstract class AbstractDocument Line 969  public abstract class AbstractDocument
969    public abstract class AbstractElement    public abstract class AbstractElement
970      implements Element, MutableAttributeSet, TreeNode, Serializable      implements Element, MutableAttributeSet, TreeNode, Serializable
971    {    {
972      /** The serial version UID for AbstractElement. */      /** The serialization UID (compatible with JDK1.5). */
973      private static final long serialVersionUID = 1265312733007397733L;      private static final long serialVersionUID = 1712240033321461704L;
974    
975      /** The number of characters that this Element spans. */      /** The number of characters that this Element spans. */
976      int count;      int count;
# Line 1355  public abstract class AbstractDocument Line 1354  public abstract class AbstractDocument
1354      public abstract int getStartOffset();      public abstract int getStartOffset();
1355    
1356      /**      /**
      * Prints diagnostic information to the specified stream.  
      *  
      * @param stream the stream to dump to  
      * @param indent the indentation level  
      * @param element the element to be dumped  
      */  
     private void dumpElement(PrintStream stream, String indent,  
                              Element element)  
     {  
       // FIXME: Should the method be removed?  
       System.out.println(indent + "<" + element.getName() +">");  
   
       if (element.isLeaf())  
         {  
           int start = element.getStartOffset();  
           int end = element.getEndOffset();  
           String text = "";  
           try  
             {  
               text = getContent().getString(start, end - start);  
             }  
           catch (BadLocationException e)  
             {  
           AssertionError error =  
             new AssertionError("BadLocationException should not be "  
                                + "thrown here. start = " + start  
                                + ", end = " + end);  
           error.initCause(e);  
           throw error;  
             }  
           System.out.println(indent + "  ["  
                              + start + ","  
                              + end + "]["  
                              + text + "]");  
         }  
       else  
         {  
           for (int i = 0; i < element.getElementCount(); ++i)  
             dumpElement(stream, indent + "  ", element.getElement(i));  
         }  
     }  
   
     /**  
1357       * Prints diagnostic output to the specified stream.       * Prints diagnostic output to the specified stream.
1358       *       *
1359       * @param stream the stream to write to       * @param stream the stream to write to
# Line 1405  public abstract class AbstractDocument Line 1361  public abstract class AbstractDocument
1361       */       */
1362      public void dump(PrintStream stream, int indent)      public void dump(PrintStream stream, int indent)
1363      {      {
1364        String indentStr = "";        StringBuffer b = new StringBuffer();
1365        for (int i = 0; i < indent; ++i)        for (int i = 0; i < indent; ++i)
1366          indentStr += "  ";          b.append(' ');
1367        dumpElement(stream, indentStr, this);        b.append('<');
1368          b.append(getName());
1369          // Dump attributes if there are any.
1370          if (getAttributeCount() > 0)
1371            {
1372              b.append('\n');
1373              Enumeration attNames = getAttributeNames();
1374              while (attNames.hasMoreElements())
1375                {
1376                  for (int i = 0; i < indent + 2; ++i)
1377                    b.append(' ');
1378                  Object attName = attNames.nextElement();
1379                  b.append(attName);
1380                  b.append('=');
1381                  Object attribute = getAttribute(attName);
1382                  b.append(attribute);
1383                  b.append('\n');
1384                }
1385            }
1386          b.append(">\n");
1387    
1388          // Dump element content for leaf elements.
1389          if (isLeaf())
1390            {
1391              for (int i = 0; i < indent + 2; ++i)
1392                b.append(' ');
1393              int start = getStartOffset();
1394              int end = getEndOffset();
1395              b.append('[');
1396              b.append(start);
1397              b.append(',');
1398              b.append(end);
1399              b.append("][");
1400              try
1401                {
1402                  b.append(getDocument().getText(start, end - start));
1403                }
1404              catch (BadLocationException ex)
1405                {
1406                  AssertionError err = new AssertionError("BadLocationException "
1407                                                          + "must not be thrown "
1408                                                          + "here.");
1409                  err.initCause(ex);
1410                }
1411              b.append("]\n");
1412            }
1413          stream.print(b.toString());
1414    
1415          // Dump child elements if any.
1416          int count = getElementCount();
1417          for (int i = 0; i < count; ++i)
1418            {
1419              Element el = getElement(i);
1420              if (el instanceof AbstractElement)
1421                ((AbstractElement) el).dump(stream, indent + 2);
1422            }
1423      }      }
1424    }    }
1425    
# Line 1418  public abstract class AbstractDocument Line 1429  public abstract class AbstractDocument
1429     */     */
1430    public class BranchElement extends AbstractElement    public class BranchElement extends AbstractElement
1431    {    {
1432      /** The serial version UID for BranchElement. */      /** The serialization UID (compatible with JDK1.5). */
1433      private static final long serialVersionUID = -8595176318868717313L;      private static final long serialVersionUID = -6037216547466333183L;
1434    
1435      /** The child elements of this BranchElement. */      /** The child elements of this BranchElement. */
1436      private Element[] children = new Element[0];      private Element[] children = new Element[0];
# Line 1642  public abstract class AbstractDocument Line 1653  public abstract class AbstractDocument
1653    public class DefaultDocumentEvent extends CompoundEdit    public class DefaultDocumentEvent extends CompoundEdit
1654      implements DocumentEvent      implements DocumentEvent
1655    {    {
1656      /** The serial version UID of DefaultDocumentEvent. */      /** The serialization UID (compatible with JDK1.5). */
1657      private static final long serialVersionUID = -7406103236022413522L;      private static final long serialVersionUID = 5230037221564563284L;
1658    
1659      /** The starting offset of the change. */      /** The starting offset of the change. */
1660      private int offset;      private int offset;
# Line 1843  public abstract class AbstractDocument Line 1854  public abstract class AbstractDocument
1854     */     */
1855    public class LeafElement extends AbstractElement    public class LeafElement extends AbstractElement
1856    {    {
1857      /** The serial version UID of LeafElement. */      /** The serialization UID (compatible with JDK1.5). */
1858      private static final long serialVersionUID = 5115368706941283802L;      private static final long serialVersionUID = -8906306331347768017L;
1859    
1860      /** Manages the start offset of this element. */      /** Manages the start offset of this element. */
1861      Position startPos;      Position startPos;

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26