[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: StyledText and TextPresentation
|
Sections spanning multiple lines are best considered document partitions.
A code snippet:
public class BlockPartitionScanner extends BufferedRuleBasedScanner {
public final static String BLOCK_TYPE= "blockType";
public BlockPartitionScanner() {
super();
setRules(new IRule[] {
new MultiLineRule("//*BEGIN*", "//*END*", new
Token(BLOCK_TYPE)) });
}
}
IDocumentPartitioner yourPartitioner= new RuleBasedPartitioner(
new BlockPartitionerScanner(),
new String[] { BlockPartitionenScanner.BLOCK_TYPE });
All documents your create should have set yourPartitioner as
their document partitioner.
Having that you can configure the source viewer you're
using with a presentation reconciler that has an appropriate
presentation damager and presentation repairer registered for
partitions of type BlockPartitionenScanner.BLOCK_TYPE.
See
org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getPresentationReconci
ler
as one example how to achieve this.
The basic rule is that every presentation "token" spanning more than one
line
should correspond to a partition. The reason for this is that for each text
change
the region to be recolored must be computed. To simplify the computation the
boundaries
of the presentation "token" should be remembered and updated. This is
exactly what
partitioning provides you with.
Kai
"David Sanders" <dsanders@xxxxxxxxxxx> wrote in message
news:3B9995FC.E8AC448E@xxxxxxxxxxxxxx
> What would be the best way to color 'full lines' between rule tokens?
>
> For instance:
>
> //*BEGIN* - special begin token
>
> ... - Each line's background
> color set to //*BEGIN* token StyledRange color
>
> //*END* - special end token
>
>
> Regards,
>
> David
>
>