Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Plug-in Developer Guide
Previous Page Home Next Page


Eclipse Platform
Release 3.5

Package org.eclipse.jface.text.formatter

Provides a content formatter add-on for an ITextViewer.

See:
           Description

Interface Summary
IContentFormatter The interface of a document content formatter.
IContentFormatterExtension Extension interface for IContentFormatter.
IFormattingContext Formatting context used in formatting strategies implementing interface IFormattingStrategyExtension.
IFormattingStrategy A formatting strategy is assumed to be specialized on formatting text of a particular content type.
IFormattingStrategyExtension Extension interface for IFormattingStrategy.
 

Class Summary
ContentFormatter Standard implementation of IContentFormatter.
ContextBasedFormattingStrategy Formatting strategy for context based content formatting.
FormattingContext Default implementation of IFormattingContext.
FormattingContextProperties Keys used by IFormattingContext objects to register specific properties needed during the formatting process of a content formatter implementing IContentFormatterExtension.
MultiPassContentFormatter Content formatter for edit-based formatting strategies.
 

Package org.eclipse.jface.text.formatter Description

Provides a content formatter add-on for an ITextViewer. A content formatter changes the formatting of a document region while preserving and correctly updating the positions of the document.

Package Specification

IContentFormatter defines the concept of a text formatter. It collaborates with content type specific formatting stratgies (IFormattingStrategy) which for a given document region format the subregion with the matching content type. The package contains a default implementation of IContentFormatter (ContentFormatter).
Additionally, an implementation of IContentFormatterExtension is provided for text edit based formatting strategies. This implementation only accepts formatting strategies implementing the extension interface IFormattingStrategyExtension. These formatting strategies are required to handle the position updating of the document. To facilitate the work with these text edit based formatting strategies, a default implementation called ContextBasedFormattingStrategy is provided. Formatting strategies inheriting from this class are text edit based and behave context dependent. Depending on the formatting context that is passed to the content formatter, different preferences and modes can be used to format different parts of a document.

To set up a proper working text edit based content formatter, the following steps are needed:

  • Create an instance of IFormattingContext. The default implementation FormattingContext already provides support for the conversion of preferences from a preference store to a map and vice versa. The method getPreferenceKeys usually has to be overridden to return the appropriate keys of the preferences used during the formatting process. Then register a map of preferences with the formatting context by calling setProperty(String, Object) with the property identifier FormattingContextProperties.CONTEXT_PREFERENCES.
  • Create an instance of the text edit based content formatter class MultiPassContentFormatter. The document partitioning and its associated default content type have to be passed to the constructor. This information is needed since the content formatter is able to format documents according to arbitrary partitionings and default content types.
  • Register the formatting strategies for the content types that have to be formatted. If a formatting strategy is registered as master strategy, it is automatically associated with the default content type of the specified partitioning. If the formatting strategy is registered as slave strategy, it is associated with the indicated content type during the registration. Note that the master strategy can also be registered as a slave strategy for a content type other than the default content type.
  • Specify the proper formatting mode (see FormattingContextProperties):
    • For whole document formatting set the property CONTEXT_DOCUMENT of the created formatting context to true. This is equivalent to setting CONTEXT_REGION with a region spanning the whole document.
    • For multiple region formatting set the property CONTEXT_REGION of the formatting context. Note that the content formatter automatically aligns the offset of a region to a line start for the master formatting strategy, it also completes eventual partitions covered only partially by the region for the slave formatting strategies.
    • For explicit formatting of a partition with the formatting strategy registered for a certain content type use the property CONTEXT_PARTITION. Note that the region denoted by this property must correspond to a partition relative to the specified partitioning in the document to be formatted. The content type of this property overrides the content type of the partition in the document.
  • Call the method MultiPassContentFormatter#format(IDocument, IFormattingContext) with the created formatting context and the document to be formatted.


Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire