public class

TextDocumentFragment

extends Object
implements ITextDocument
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.output.text.impl.TextDocumentFragment

Class Overview

Wrapper class that provide fragments of text documents. Any getPartXxx() method will return the entire fragment, regardless of the provided parameters.

Summary

Public Constructors
TextDocumentFragment(ITextDocument idoc, long anchorBegin, long anchorEnd)
Create a document fragment proxy object.
Public Methods
void addListener(IEventListener listener)
Register a listener.
ICoordinates addressToCoordinates(String address)
Convert a unit-specific address to document-specific text coordinates.
ICoordinates addressToCoordinates(String address, CoordinatesConversionPrecision precision)
Convert a unit-specific address to document-specific text coordinates.
final String coordinatesToAddress(ICoordinates coordinates)
Convert document-specific text coordinates to a unit-specific address using a default conversion precision.
String coordinatesToAddress(ICoordinates coordinates, AddressConversionPrecision precision)
Convert document-specific text coordinates to a unit-specific address.
int countListeners()
Get the numbers of objects listening to this event source.
void dispose()
Dispose of resources and handles used by this document.
String format()
Format this text document.
long getAnchorCount()
Get the range of anchor points in the document.
ITextDocumentPart getDocumentPart(long anchorId, int linesAfter)
Retrieve a document part.
ITextDocumentPart getDocumentPart(long anchorId, int linesAfter, int linesBefore)
Retrieve a document part.
ITextDocumentPart getDocumentPart2(long anchorBegin, long anchorEnd)
Retrieve the document part located between two anchor references.
long getFirstAnchor()
Get the first anchor identifier of the document.
long getInitialAnchor()
Get the anchor identifier that would represent the first logical section of a document (meaning the anchor to focus on when opening a document).
List<? extends IEventListener> getListeners()
Get a copy of the list of listeners.
IEventSource getParentSource()
Get the parent source.
IPropertyManager getPropertyManager()
Provide the optional property manager to customize rendering of the document.
IUnit getUnit()
If available, retrieve the unit that backs up this document.
void insertListener(int index, IEventListener listener)
Register a listener.
void notifyListeners(IEvent e)
Notify listeners that an event has occurred.
void removeListener(IEventListener listener)
Unregister a listener.
void setParentSource(IEventSource parentSource)
Set a parent source.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pnfsoftware.jeb.core.output.IGenericDocument
From interface com.pnfsoftware.jeb.core.output.text.ITextDocument
From interface com.pnfsoftware.jeb.util.events.IEventSource

Public Constructors

public TextDocumentFragment (ITextDocument idoc, long anchorBegin, long anchorEnd)

Create a document fragment proxy object.

Parameters
idoc source document, which must implement getDocumentPart2(long, long).

Public Methods

public void addListener (IEventListener listener)

Register a listener. The listener is appended to the existing list of listeners. The implementor may allow duplicates.

Parameters
listener a listener of events generated by this source

public ICoordinates addressToCoordinates (String address)

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.

Parameters
address a textual address
Returns
  • the text coordinates, null on error

public ICoordinates addressToCoordinates (String address, CoordinatesConversionPrecision precision)

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.

Parameters
address a textual address
Returns
  • the text coordinates, null on error

public final String coordinatesToAddress (ICoordinates coordinates)

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.

Parameters
coordinates the coordinates
Returns
  • the address, null on error

public String coordinatesToAddress (ICoordinates coordinates, AddressConversionPrecision precision)

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.

Parameters
coordinates the coordinates
precision indicate the precision of the address ( COARSE will return a raw address, with a faster result while FINE will return a more precise address that can be a bit longer). If 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

public int countListeners ()

Get the numbers of objects listening to this event source.

Returns
  • the number of listeners

public void dispose ()

Dispose of resources and handles used by this document. The object creator should call this method upon destruction.

public String format ()

Format this text document.

public long getAnchorCount ()

Get the range of anchor points in the document. Returning 1 means that the document returns a single part, holding the entire contents.

Note that the anchor at "getFirstAnchor() + getAnchorCount()" is the "end" anchor (one after the last), and lies outside the document. It is not a valid anchor.

Returns
  • the count/range of anchors in this document, must be greater than zero

public ITextDocumentPart getDocumentPart (long anchorId, int linesAfter)

Retrieve a document part. Equivalent to getDocumentPart(anchorId, linesAfter) .

Parameters
anchorId the anchor id
linesAfter number of lines after
Returns
  • the document part

public ITextDocumentPart getDocumentPart (long anchorId, int linesAfter, int linesBefore)

Retrieve a document part. Clients call this method to retrieve a document part starting at a specific anchor, and containing the given amount of lines after and before the anchor. It is the responsibility of the implementor to sanitize the input (eg, negative number of lines, invalid anchor, etc.) and provide appropriate response (eg, truncating). It is recommended that implementors try not to raise an exception on error. In the worst case scenario, an empty document can be returned.

Parameters
anchorId the anchor identifier
linesAfter hint lines count to return after the given anchor, could be more or less
linesBefore hint lines count to return before the given anchor, could be more or less
Returns
  • a document part containing as many anchors as required to honor the client requests. If linesAfter is non-null, the first anchor within the document part may not be anchorId, but one anchor before that. THis method should return null if an invalid anchor was provided

public ITextDocumentPart getDocumentPart2 (long anchorBegin, long anchorEnd)

Retrieve the document part located between two anchor references. This method is optional.

Parameters
anchorBegin start anchor, inclusive
anchorEnd final anchor, exclusive
Returns
  • the document part

public long getFirstAnchor ()

Get the first anchor identifier of the document. Most document will want to have 0 as their first anchor identifier.

Returns
  • an integer greater or equal than zero

public long getInitialAnchor ()

Get the anchor identifier that would represent the first logical section of a document (meaning the anchor to focus on when opening a document). If not specified, the first anchor is considered to be the initial anchor.

Returns
  • an integer, 0 if not specified

public List<? extends IEventListener> getListeners ()

Get a copy of the list of listeners.

public IEventSource getParentSource ()

Get the parent source.

Returns
  • the parent source, or null if none

public IPropertyManager getPropertyManager ()

Provide the optional property manager to customize rendering of the document. Available properties can be retrieved by retrieving the PDM provided by the property manager.

Returns
  • a PM, null if none

public IUnit getUnit ()

If available, retrieve the unit that backs up this document.

Returns
  • an optional unit reference (may be null)

public void insertListener (int index, IEventListener listener)

Register a listener. The implementor may allow duplicates.

Parameters
index insertion point
listener a listener of events generated by this source

public void notifyListeners (IEvent e)

Notify listeners that an event has occurred.

Parameters
e the event to be propagated

public void removeListener (IEventListener listener)

Unregister a listener. If the implementor allows duplicates in addListener(), it should deal with those consistently.

Parameters
listener the listener to be removed

public void setParentSource (IEventSource parentSource)

Set a parent source.

Parameters
parentSource the optional parent source