站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

PositionsBag (Editor Library 2) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib2/1 1.3 2

org.netbeans.spi.editor.highlighting.support
Class PositionsBag

java.lang.Object
  extended by org.netbeans.spi.editor.highlighting.support.AbstractHighlightsContainer
      extended by org.netbeans.spi.editor.highlighting.support.PositionsBag
All Implemented Interfaces:
HighlightsContainer

public final class PositionsBag
extends AbstractHighlightsContainer

A bag of highlighted areas specified by their document Positions.

The highlighted areas (highlights) are determined by their starting and ending positions in a document and the set of attributes that should be used for rendering that area. The highlights can be arbitrarily added to and remove from the bag.

The PositionsBag is designed to work over a single document, which is passed in to the constructor. All the Positions accepted by various methods in this class must refer to positions within this document. Since there is no way how this could be checked it is up to the users of this class to make sure that Positions they pass in to the bag are from the same Document, which they used for creating the bag.

The PositionsBag can operate in two modes depending on a value passed in its construtor. The mode determines how the bag will treat newly added highlights that overlap with existing highlights in the bag.

Trimming mode: In the trimming mode the bag will trim any existing highlights that would overlap with a newly added highlight. In this mode the newly added highlights always replace the existing highlights if they overlap.

Merging mode: In the merging mode the bag will merge attributes of the overlapping highlights. The area where the new highlight overlaps with some existing highlights will then constitute a new highlight and its attributes will be a composition of the attributes of both the new and existing highlight. Should there be attributes with the same name the attribute values from the newly added highlight will take precedence.


Field Summary
 
Fields inherited from interface org.netbeans.spi.editor.highlighting.HighlightsContainer
ATTR_EXTENDS_EMPTY_LINE, ATTR_EXTENDS_EOL
 
Constructor Summary
PositionsBag(Document document)
          Creates a new instance of PositionsBag, which trims highlights as they are added.
PositionsBag(Document document, boolean mergeHighlights)
          Creates a new instance of PositionsBag.
 
Method Summary
 void addAllHighlights(PositionsBag bag)
          Adds all highlights from the bag passed in.
 void addHighlight(Position startPosition, Position endPosition, AttributeSet attributes)
          Adds a highlight to this bag.
 void clear()
          Removes all highlights previously added to this bag.
 HighlightsSequence getHighlights(int startOffset, int endOffset)
          Gets highlights from an area of a document.
 void removeHighlights(int startOffset, int endOffset)
          Removes highlights in the specific area.
 void removeHighlights(Position startPosition, Position endPosition, boolean clip)
          Removes highlights in the specific area.
 void setHighlights(PositionsBag bag)
          Resets this sequence to use the new set of highlights.
 
Methods inherited from class org.netbeans.spi.editor.highlighting.support.AbstractHighlightsContainer
addHighlightsChangeListener, fireHighlightsChange, removeHighlightsChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionsBag

public PositionsBag(Document document)
Creates a new instance of PositionsBag, which trims highlights as they are added. It calls the PositionsBag(Document, boolean) constructore passing false as a parameter.

Parameters:
document - The document that should be highlighted.

PositionsBag

public PositionsBag(Document document,
                    boolean mergeHighlights)
Creates a new instance of PositionsBag.

Parameters:
document - The document that should be highlighted.
mergeHighlights - Determines whether highlights should be merged or trimmed.
Method Detail

addHighlight

public void addHighlight(Position startPosition,
                         Position endPosition,
                         AttributeSet attributes)
Adds a highlight to this bag. The highlight is specified by its staring and ending Position and by its attributes. Adding a highlight that overlaps with one or more existing highlights can have a different result depending on the value of the mergingHighlights parameter used for constructing this bag.

Parameters:
startPosition - The beginning of the highlighted area.
endPosition - The end of the highlighted area.
attributes - The attributes to use for highlighting.

addAllHighlights

public void addAllHighlights(PositionsBag bag)
Adds all highlights from the bag passed in. This method is equivalent to calling addHighlight for all the highlights in the bag except that the changes are done atomically.

Parameters:
bag - The highlights that will be atomically added to this bag.

setHighlights

public void setHighlights(PositionsBag bag)
Resets this sequence to use the new set of highlights. This method drops all the existing highlights in this bag and adds all highlights from the bag passed in as a parameter. The changes are done atomically.

Parameters:
bag - The new highlights.

removeHighlights

public void removeHighlights(Position startPosition,
                             Position endPosition,
                             boolean clip)
Removes highlights in the specific area. All existing highlights that are positioned within the area specified by the startOffset and endOffset parameters are removed from this bag. The highlights that only partialy overlap with the area are treated according to the value of the clip parameter.
  • If clip == true : the overlapping highlights will remain in this sequence but will be clipped so that they do not overlap anymore
  • If clip == false : the overlapping highlights will be removed from this sequence

Parameters:
startPosition - The beginning of the area to clear.
endPosition - The end of the area to clear.

removeHighlights

public void removeHighlights(int startOffset,
                             int endOffset)
Removes highlights in the specific area. All existing highlights that are positioned within the area specified by the startOffset and endOffset parameters are removed from this sequence. The highlights that only partialy overlap with the area will be removed as well.

Parameters:
startOffset - The beginning of the area to clear.
endOffset - The end of the area to clear.

getHighlights

public HighlightsSequence getHighlights(int startOffset,
                                        int endOffset)
Gets highlights from an area of a document. The HighlightsSequence is computed using all the highlights present in this bag between the startOffset and endOffset.

Specified by:
getHighlights in interface HighlightsContainer
Specified by:
getHighlights in class AbstractHighlightsContainer
Parameters:
startOffset - The beginning of the area.
endOffset - The end of the area.
Returns:
The HighlightsSequence which iterates through the highlights in the given area of this bag.

clear

public void clear()
Removes all highlights previously added to this bag.


org.netbeans.modules.editor.lib2/1 1.3 2

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.