Class MultiPassContentFormatter
- All Implemented Interfaces:
IContentFormatter
,IContentFormatterExtension
Two kinds of formatting strategies can be registered with this formatter:
- one master formatting strategy for the default content type
- one formatting strategy for each non-default content type
IFormattingStrategyExtension
.
Regions to be formatted with the master formatting strategy always have an offset aligned to the line start. Regions to be formatted with slave formatting strategies are aligned on partition boundaries.
- Since:
- 3.0
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Position updater that shifts otherwise deleted positions to the next non-whitespace character. -
Constructor Summary
ConstructorDescriptionMultiPassContentFormatter
(String partitioning, String type) Creates a new content formatter. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
format
(IDocument medium, IFormattingContext context) Formats the given region of the specified document.final void
Formats the given region of the specified document.The formatter may safely assume that it is the only subject that modifies the document at this point in time.protected void
formatMaster
(IFormattingContext context, IDocument document, int offset, int length) Formats the document specified in the formatting context with the master formatting strategy.protected void
formatSlave
(IFormattingContext context, IDocument document, int offset, int length, String type) Formats the document specified in the formatting context with the formatting strategy registered for the content type.protected void
formatSlaves
(IFormattingContext context, IDocument document, int offset, int length) Formats the document specified in the formatting context with the slave formatting strategies.final IFormattingStrategy
getFormattingStrategy
(String type) Returns the formatting strategy registered for the given content type.final void
setMasterStrategy
(IFormattingStrategy strategy) Registers a master formatting strategy.final void
setSlaveStrategy
(IFormattingStrategy strategy, String type) Registers a slave formatting strategy for a certain content type.
-
Constructor Details
-
MultiPassContentFormatter
Creates a new content formatter.- Parameters:
partitioning
- the document partitioning for this formattertype
- the default content type
-
-
Method Details
-
format
Description copied from interface:IContentFormatterExtension
Formats the given region of the specified document.The formatter may safely assume that it is the only subject that modifies the document at this point in time. This method is fully reentrant, but not thread-safe.
The formatting process performed by
format(IDocument, IFormattingContext)
happens as follows:- In a first pass the content formatter formats the range of the document to be formatted by using the master formatting strategy. This happens regardless of the content type of the underlying partition.
- In the second pass, the range is formatted again, this time using the registered slave formatting strategies. For each partition contained in the range to be formatted, the content formatter determines its content type and formats the partition with the correct formatting strategy.
- Specified by:
format
in interfaceIContentFormatterExtension
- Parameters:
medium
- the document to be formattedcontext
- the formatting context to pass to the formatting strategies. This argument must not benull
.
-
format
Description copied from interface:IContentFormatter
Formats the given region of the specified document.The formatter may safely assume that it is the only subject that modifies the document at this point in time.- Specified by:
format
in interfaceIContentFormatter
- Parameters:
medium
- the document to be formattedregion
- the region within the document to be formatted
-
formatMaster
Formats the document specified in the formatting context with the master formatting strategy.The master formatting strategy covers all regions of the document. The offset of the region to be formatted is aligned on line start boundaries, whereas the end index of the region remains the same. For this formatting type the document partitioning is not taken into account.
- Parameters:
context
- The formatting context to usedocument
- The document to operate onoffset
- The offset of the region to formatlength
- The length of the region to format
-
formatSlave
protected void formatSlave(IFormattingContext context, IDocument document, int offset, int length, String type) Formats the document specified in the formatting context with the formatting strategy registered for the content type.For this formatting type only slave strategies are used. The region to be formatted is aligned on partition boundaries of the underlying content type. The exact formatting strategy is determined by the underlying content type of the document partitioning.
- Parameters:
context
- The formatting context to usedocument
- The document to operate onoffset
- The offset of the region to formatlength
- The length of the region to formattype
- The content type of the region to format
-
formatSlaves
Formats the document specified in the formatting context with the slave formatting strategies.For each content type of the region to be formatted in the document partitioning, the registered slave formatting strategy is used to format that particular region. The region to be formatted is aligned on partition boundaries of the underlying content type. If the content type is the document's default content type, nothing happens.
- Parameters:
context
- The formatting context to usedocument
- The document to operate onoffset
- The offset of the region to formatlength
- The length of the region to format
-
getFormattingStrategy
Description copied from interface:IContentFormatter
Returns the formatting strategy registered for the given content type.- Specified by:
getFormattingStrategy
in interfaceIContentFormatter
- Parameters:
type
- the content type for which to look up the formatting strategy- Returns:
- the formatting strategy for the given content type, or
null
if there is no such strategy
-
setMasterStrategy
Registers a master formatting strategy.The strategy may already be registered with a certain content type as slave strategy. The master strategy is registered for the default content type of documents. If a master strategy has already been registered, it is overridden by the new one.
- Parameters:
strategy
- The master formatting strategy, must implementIFormattingStrategyExtension
-
setSlaveStrategy
Registers a slave formatting strategy for a certain content type.The strategy may already be registered as master strategy. An already registered slave strategy for the specified content type will be replaced. However, the same strategy may be registered with several content types. Slave strategies cannot be registered for the default content type of documents.
- Parameters:
strategy
- The slave formatting strategytype
- The content type to register this strategy with, must implementIFormattingStrategyExtension
-