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 Platform
Release 3.5

org.eclipse.jface.text.formatter
Class ContentFormatter

java.lang.Object
  extended by 
org.eclipse.jface.text.formatter.ContentFormatter
All Implemented Interfaces:
IContentFormatter

public class ContentFormatter
extends Object
implements IContentFormatter

Standard implementation of IContentFormatter. The formatter supports two operation modes: partition aware and partition unaware.

In the partition aware mode, the formatter determines the partitioning of the document region to be formatted. For each partition it determines all document positions which are affected when text changes are applied to the partition. Those which overlap with the partition are remembered as character positions. These character positions are passed over to the formatting strategy registered for the partition's content type. The formatting strategy returns a string containing the formatted document partition as well as the adapted character positions. The formatted partition replaces the old content of the partition. The remembered document positions are updated with the adapted character positions. In addition, all other document positions are accordingly adapted to the formatting changes.

In the partition unaware mode, the document's partitioning is ignored and the document is considered consisting of only one partition of the content type IDocument.DEFAULT_CONTENT_TYPE. The formatting process is similar to the partition aware mode, with the exception of having only one partition.

Usually, clients instantiate this class and configure it before using it.

See Also:
IContentFormatter, IDocument, ITypedRegion, Position

Constructor Summary
ContentFormatter ()
          Creates a new content formatter.
 
Method Summary
 void enablePartitionAwareFormatting (boolean enable)
          Sets the formatter's operation mode.
 void format ( IDocument document, IRegion region)
          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.
  IFormattingStrategy getFormattingStrategy ( String contentType)
          Returns the formatting strategy registered for the given content type.
protected  boolean positionAboutToBeAdded ( IDocument document, String category, Position position)
          The given position is about to be added to the given position category of the given document.
 void setDocumentPartitioning ( String partitioning)
          Sets the document partitioning to be used by this formatter.
 void setFormattingStrategy ( IFormattingStrategy strategy, String contentType)
          Registers a strategy for a particular content type.
 void setPartitionManagingPositionCategories ( String[] categories)
          Deprecated. incompatible with an open set of document partitionings. The provided information is only used if this formatter can not compute the partition managing position categories.
protected  void updateAffectedPositions ( IDocument document, int[] positions, int offset)
          Updates all the overlapping positions.
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentFormatter

public ContentFormatter()
Creates a new content formatter. The content formatter operates by default in the partition-aware mode. There are no preconfigured formatting strategies. Will use the default document partitioning if not further configured.

Method Detail

setFormattingStrategy

public void setFormattingStrategy(
IFormattingStrategy strategy,
                                  
String contentType)
Registers a strategy for a particular content type. If there is already a strategy registered for this type, the new strategy is registered instead of the old one. If the given content type is null the given strategy is registered for all content types as is called only once per formatting session.

Parameters:
strategy - the formatting strategy to register, or null to remove an existing one
contentType - the content type under which to register

setPartitionManagingPositionCategories

public void setPartitionManagingPositionCategories(
String[] categories)
Deprecated. incompatible with an open set of document partitionings. The provided information is only used if this formatter can not compute the partition managing position categories.

Informs this content formatter about the names of those position categories which are used to manage the document's partitioning information and thus should be ignored when this formatter updates positions.

Parameters:
categories - the categories to be ignored

setDocumentPartitioning

public void setDocumentPartitioning(
String partitioning)
Sets the document partitioning to be used by this formatter.

Parameters:
partitioning - the document partitioning
Since:
3.0

enablePartitionAwareFormatting

public void enablePartitionAwareFormatting(boolean enable)
Sets the formatter's operation mode.

Parameters:
enable - indicates whether the formatting process should be partition ware

getFormattingStrategy

public 
IFormattingStrategy getFormattingStrategy(
String contentType)
Description copied from interface: IContentFormatter
Returns the formatting strategy registered for the given content type.

Specified by:
getFormattingStrategy in interface IContentFormatter
Parameters:
contentType - 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

format

public void format(
IDocument document,
                   
IRegion region)
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 interface IContentFormatter
Parameters:
document - the document to be formatted
region - the region within the document to be formatted

updateAffectedPositions

protected void updateAffectedPositions(
IDocument document,
                                       int[] positions,
                                       int offset)
Updates all the overlapping positions. Note, all other positions are automatically updated by their document position updaters.

Parameters:
document - the document to has been formatted
positions - the adapted character positions to be used to update the document positions
offset - the offset of the document region that has been formatted

positionAboutToBeAdded

protected boolean positionAboutToBeAdded(
IDocument document,
                                         
String category,
                                         
Position position)
The given position is about to be added to the given position category of the given document.

This default implementation return true.

Parameters:
document - the document
category - the position category
position - the position that will be added
Returns:
true if the position can be added, false if it should be ignored

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