Class FormattedDocument

  • All Implemented Interfaces:
    java.io.Serializable, javax.swing.text.Document

    public class FormattedDocument
    extends javax.swing.text.PlainDocument
    A formatted document that uses a user supplied Format object to control the format of the text in the document. For example, this document will ignore anything that isn't a number if a NumberFormat is supplied.

    Modified by: Joseph A. Huwaldt

    Version:
    August 3, 2018
    Author:
    Joseph A. Huwaldt, Date: February 24, 2000
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument

        javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
    • Field Summary

      • Fields inherited from class javax.swing.text.PlainDocument

        lineLimitAttribute, tabSizeAttribute
      • Fields inherited from class javax.swing.text.AbstractDocument

        BidiElementName, ContentElementName, ElementNameAttribute, ParagraphElementName, SectionElementName
      • Fields inherited from interface javax.swing.text.Document

        StreamDescriptionProperty, TitleProperty
    • Constructor Summary

      Constructors 
      Constructor Description
      FormattedDocument​(java.text.Format f)
      Construct a formatted document that uses the supplied Format object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.text.Format getFormat()
      Method that returns the Format used by this document.
      void insertString​(int offs, java.lang.String str, javax.swing.text.AttributeSet a)
      Inserts some content into the document using the documents Format to validate what has be inserted.
      void remove​(int offs, int len)
      Removes some content from the document.
      • Methods inherited from class javax.swing.text.PlainDocument

        getDefaultRootElement, getParagraphElement
      • Methods inherited from class javax.swing.text.AbstractDocument

        addDocumentListener, addUndoableEditListener, createPosition, dump, getAsynchronousLoadPriority, getBidiRootElement, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, putProperty, readLock, readUnlock, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FormattedDocument

        public FormattedDocument​(java.text.Format f)
        Construct a formatted document that uses the supplied Format object.
        Parameters:
        f - The format to use for this document.
    • Method Detail

      • getFormat

        public java.text.Format getFormat()
        Method that returns the Format used by this document.
        Returns:
        The format used by this document.
      • insertString

        public void insertString​(int offs,
                                 java.lang.String str,
                                 javax.swing.text.AttributeSet a)
                          throws javax.swing.text.BadLocationException
        Inserts some content into the document using the documents Format to validate what has be inserted. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock.
        Specified by:
        insertString in interface javax.swing.text.Document
        Overrides:
        insertString in class javax.swing.text.PlainDocument
        Parameters:
        offs - the starting offset >= 0
        str - the string to insert; does nothing with null/empty strings
        a - the attributes for the inserted content
        Throws:
        javax.swing.text.BadLocationException
      • remove

        public void remove​(int offs,
                           int len)
                    throws javax.swing.text.BadLocationException
        Removes some content from the document. Removing content causes a write lock to be held while the actual changes are taking place. Observers are notified of the change on the thread that called this method.
        Specified by:
        remove in interface javax.swing.text.Document
        Overrides:
        remove in class javax.swing.text.AbstractDocument
        Parameters:
        offs - the starting offset >= 0
        len - the number of characters to remove >= 0
        Throws:
        javax.swing.text.BadLocationException