| Colouring In A Custom Editor [message #444729] |
Mon, 20 February 2006 03:26  |
Dave Hewitson Messages: 56 Registered: July 2009 |
Member |
|
|
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 variables 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.
|
|
|
| Re: Colouring In A Custom Editor [message #444735 is a reply to message #444729] |
Mon, 20 February 2006 05: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/
|
|
|
|
|
| Re: Colouring In A Custom Editor [message #444748 is a reply to message #444743] |
Mon, 20 February 2006 08:43  |
Armen Polischuk Messages: 7 Registered: July 2009 |
Junior Member |
|
|
On Mon, 20 Feb 2006 14:45:42 +0200, Dave H <david.hewitson@cdl.co.uk>
wrote:
Ok. I see. In your document in some place are defined some vars, which
will be colored in others parts of the document.
So you should add single line rule in the scanner. Something like this:
rules.add(SingleLineRule("var ",";", token));
where var - specific word used to declare vars in your language.
So every time when user add text:
var i;
it will be colored.
How to color 'i' like var in the document I've already told.
|
|
|
Powered by
FUDForum. Page generated in 0.01806 seconds