Class AbstractTextDocument

java.lang.Object
com.pnfsoftware.jeb.util.events.EventSource
com.pnfsoftware.jeb.core.output.text.impl.AbstractTextDocument
All Implemented Interfaces:
IGenericDocument, ITextDocument, IEventSource
Direct Known Subclasses:
AsciiDocument, CodeDocument, HexDumpDocument, StaticTextDocument

@Ser public abstract class AbstractTextDocument extends EventSource implements ITextDocument
A skeleton implementation of a text document. In order to minimize code breakage on API changes, it is recommended plugins extend this class instead of implements ITextDocument from scratch.

The first anchor is 0. By default, the addressing scheme mirrors document coordinates:

 coordinates: (anchor, line, column) <-> address: "a,y,x"
 
  • Constructor Details

    • AbstractTextDocument

      public AbstractTextDocument()
  • Method Details

    • dispose

      public void dispose()
      The default implementation does nothing.
      Specified by:
      dispose in interface IGenericDocument
    • getPropertyManager

      public IPropertyManager getPropertyManager()
      The default implementation returns null.
      Specified by:
      getPropertyManager in interface IGenericDocument
      Returns:
      a PM, null if none
    • getInitialAnchor

      public long getInitialAnchor()
      The default implementation returns the first anchor as the initial anchor.
      Specified by:
      getInitialAnchor in interface ITextDocument
      Returns:
      an integer, 0 if not specified
    • getFirstAnchor

      public long getFirstAnchor()
      The default implementation returns 0.
      Specified by:
      getFirstAnchor in interface ITextDocument
      Returns:
      an integer greater or equal than zero
    • getDocumentPart

      public ITextDocumentPart getDocumentPart(long anchorId, int linesAfter)
      Description copied from interface: ITextDocument
      Retrieve a document part. Equivalent to getDocumentPart(anchorId, linesAfter) .
      Specified by:
      getDocumentPart in interface ITextDocument
      Parameters:
      anchorId - the anchor id
      linesAfter - number of lines after
      Returns:
      the document part
    • getDocumentPart2

      public ITextDocumentPart getDocumentPart2(long anchorBegin, long anchorEnd) throws NotImplementedException
      The default implementation throws.
      Specified by:
      getDocumentPart2 in interface ITextDocument
      Parameters:
      anchorBegin - start anchor, inclusive
      anchorEnd - final anchor, exclusive
      Returns:
      the document part
      Throws:
      NotImplementedException - implementations should throw if this method is not implemented
    • useLineDelta

      protected boolean useLineDelta()
      Specify if coordinatesToAddress(ICoordinates, AddressConversionPrecision) and addressToCoordinates(String, CoordinatesConversionPrecision) will use the line Delta. Default is true, but implementations can decide to use only one line for an anchor.
      Returns:
      true to encode line deltas in addresses
    • useDisplayLineNumber

      protected boolean useDisplayLineNumber()
      Specify if coordinatesToAddress(ICoordinates, AddressConversionPrecision) and addressToCoordinates(String, CoordinatesConversionPrecision) will use the anchor inner value or should display as a text editor (where first line is line 1). Line Delta and column offset are not modified.
    • coordinatesToAddress

      public final String coordinatesToAddress(ICoordinates coordinates)
      Description copied from interface: ITextDocument
      Convert document-specific text coordinates to a unit-specific address using a default conversion precision.

      Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.

      Specified by:
      coordinatesToAddress in interface ITextDocument
      Parameters:
      coordinates - the coordinates
      Returns:
      the address, null on error
    • coordinatesToAddress

      public String coordinatesToAddress(ICoordinates coordinates, AddressConversionPrecision precision)
      Description copied from interface: ITextDocument
      Convert document-specific text coordinates to a unit-specific address.

      Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.

      Specified by:
      coordinatesToAddress in interface ITextDocument
      Parameters:
      coordinates - the coordinates
      precision - indicate the precision of the address ( AddressConversionPrecision.COARSE will return a raw address, with a faster result while AddressConversionPrecision.FINE will return a more precise address that can be a bit longer). If AddressConversionPrecision.COARSE can not be retrieved, it may return a null result, and the user will need to recall this method with another precision.
      Returns:
      the address, null on error
    • addressToCoordinates

      public final ICoordinates addressToCoordinates(String address)
      Description copied from interface: ITextDocument
      Convert a unit-specific address to document-specific text coordinates. It is recommended to return canonical coordinates. The implementation might return approximate coordinates, ie the closest coordinates (in terms of distance) calculated as part of a best effort approach to minimize the return of null values.

      Note: The addressing scheme is unit specific, and defined by the plugin developer. Addresses should not start with the reserved '@' prefix.

      Specified by:
      addressToCoordinates in interface ITextDocument
      Parameters:
      address - a textual address
      Returns:
      the text coordinates, null on error
    • addressToCoordinates

      public ICoordinates addressToCoordinates(String address, CoordinatesConversionPrecision precision)
      Precision is not used - Use an exact address
      Specified by:
      addressToCoordinates in interface ITextDocument
      Parameters:
      address - a textual address
      precision - requested conversion strategy
      Returns:
      the text coordinates, null on error
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • format

      public String format()
      Description copied from interface: ITextDocument
      Format this text document.
      Specified by:
      format in interface ITextDocument
      Returns:
      the formatted textual contents of the document