|
Re: Colouring In A Custom Editor [message #444735 is a reply to message #444729] |
Mon, 20 February 2006 10:25 |
Armen Polischuk Messages: 7 Registered: July 2009 |
Junior Member |
|
|
On Mon, 20 Feb 2006 10:26:43 +0200, Dave H <david.hewitson@cdl.co.uk> =
wrote:
> Hi, I'm trying to create a custom source editor for my users and have =
=
> nearly completed it with keyword colouring etc, but I'm struggling to =
=
> fulfill one requirement.
>
> This source is for a bespoke language, and contains a list of variable=
s =
> at the end after a line that looks like this [Local Variables].
>
> As this can be edited and not a fixed list like the keywords, I have =
> tried to work out a way to do this but can't find any examples. Can =
> anyone point me in the right direction?
>
> Thanks for any help.
>
> Dave.
>
>
>
I don't know which widget you use, but I use SourceViewer from jdt.
In such case you just should install object , implemented =
SourceViewerConfiguration class:
editor =3D new SourceViewer(parent, null, SWT.V_SCROLL | SWT.WRAP);
configuration =3D new MessageEditorConfiguration(editor);
editor.configure(configuration);
And you should overrride method
public IPresentationReconciler getPresentationReconciler(ISourceViewer =
sourceViewer)
from SourceViewerConfiguration
I have same task - colouring some words. For this, you could use :
DefaultDamagerRepairer repairer =3D new DefaultDamagerRepairer(<your =
scanner>);
PresentationReconciler reconciler =3D new PresentationReconcile=
r();
reconciler.setDocumentPartitioning(<your partition>);
reconciler.setDamager(repairer, IDocument.DEFAULT_CONTENT_TYPE)=
;
reconciler.setRepairer(repairer, IDocument.DEFAULT_CONTENT_TYPE=
);
return reconciler;
Next step - writing scanner which will be scann text and seek your =
predefined words. You could write your own scanner or
extend RuleBasedScanner;
Simply override constructor: create token( set color, font), and create =
=
rules for each word like this:
List<IRule> rules =3D new LinkedList<IRule>();
final WordRule wordRule =3D new WordRule(<detector>);
for (int i =3D 0; i < <your words>.length; i++) {
wordRule.addWord(<your words>[i], token);
}
rules.add(wordRule);
setRules(rules.toArray(new IRule[0]));
where <your words> - array your predefined words, which you could read =
from prefs or file
<detector> - class which implements interface IWordDetector. Exactly =
there you should define when your word starts and finishes.
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.16349 seconds