Home » Eclipse Projects » Eclipse Platform » update syntax coloring in a texteditor
update syntax coloring in a texteditor [message #310612] |
Mon, 11 December 2006 15:45  |
Eclipse User |
|
|
|
Originally posted by: drojomar.notes.banesto.es
I have a texteditor, with syntax coloring. I have a scanner that scan
the document, and assign a different color depending on the token type.
Besides, I have a preference page that allow users to choose the color
of each token. My problem is after I change a color (in the preference
page), I don't know how to refresh the color in the document.
I have created an IPropertyChangeListener, but I don't know how to scann
the document again in order to change to the new colors.
any ideas?
Thanks
|
|
|
Re: update syntax coloring in a texteditor [message #310616 is a reply to message #310612] |
Mon, 11 December 2006 17:31   |
Eclipse User |
|
|
|
David Rojo wrote:
> I have a texteditor, with syntax coloring. I have a scanner that scan
> the document, and assign a different color depending on the token type.
>
> Besides, I have a preference page that allow users to choose the color
> of each token. My problem is after I change a color (in the preference
> page), I don't know how to refresh the color in the document.
>
> I have created an IPropertyChangeListener, but I don't know how to scann
> the document again in order to change to the new colors.
>
> any ideas?
>
> Thanks
Dave,
Once you get the notification of the preference change, do something
like the below. This way all the editor instances will automatically
change to the color you want.
Now if your editor has colored keywords, then all you have to do is to
change the color to those tokens you assigned in your rules.
Below is just to show you how to change the background and forground
colors when a preference change occurs. The key is to get the
getSourceViewer().
// ------------------------------------------------------------ -------------
// setBackgroundColor
//
------------------------------------------------------------ -------------
private void setBackgroundColor()
{
IPreferenceStore ps =
EditorPlugin.getInstance().getPreferenceStore();
boolean hasValues =
ps.contains(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
if (hasValues == true)
{
String rgbStr =
ps.getString(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
try
{
RGB rgb = StringConverter.asRGB(rgbStr);
getSourceViewer().getTextWidget().setBackground(new
Color(Display.getCurrent(), rgb));
}
catch (Exception e)
{
// Nothing
}
}
}
//
------------------------------------------------------------ -------------
// setSelectionBackgroundColor
//
------------------------------------------------------------ -------------
private void setSelectionBackgroundColor()
{
IPreferenceStore ps =
EditorPlugin.getInstance().getPreferenceStore();
boolean hasValues =
ps.contains(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF) ;
if (hasValues == true)
{
String rgbStr =
ps.getString(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF );
try
{
RGB rgb = StringConverter.asRGB(rgbStr);
getSourceViewer().getTextWidget().setSelectionBackground(new
Color(Display.getCurrent(), rgb));
}
catch (Exception e)
{
// Nothing
}
}
}
|
|
|
Re: update syntax coloring in a texteditor [message #310618 is a reply to message #310616] |
Mon, 11 December 2006 18:20   |
Eclipse User |
|
|
|
One more thing...Make sure you're color set for the tokens are
statically declared, so that ALL your editor instances share the same
color set. This will save lots of memory and work. For each preference
notification, check to see first if the color is already is the same
color before changing.
AL wrote:
> David Rojo wrote:
>
>> I have a texteditor, with syntax coloring. I have a scanner that scan
>> the document, and assign a different color depending on the token type.
>>
>> Besides, I have a preference page that allow users to choose the color
>> of each token. My problem is after I change a color (in the preference
>> page), I don't know how to refresh the color in the document.
>>
>> I have created an IPropertyChangeListener, but I don't know how to
>> scann the document again in order to change to the new colors.
>>
>> any ideas?
>>
>> Thanks
>
>
> Dave,
>
> Once you get the notification of the preference change, do something
> like the below. This way all the editor instances will automatically
> change to the color you want.
>
> Now if your editor has colored keywords, then all you have to do is to
> change the color to those tokens you assigned in your rules.
>
> Below is just to show you how to change the background and forground
> colors when a preference change occurs. The key is to get the
> getSourceViewer().
>
>
> //
> ------------------------------------------------------------ -------------
> // setBackgroundColor
> //
> ------------------------------------------------------------ -------------
>
> private void setBackgroundColor()
> {
> IPreferenceStore ps =
> EditorPlugin.getInstance().getPreferenceStore();
> boolean hasValues =
> ps.contains(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
> if (hasValues == true)
> {
> String rgbStr =
> ps.getString(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
> try
> {
> RGB rgb = StringConverter.asRGB(rgbStr);
> getSourceViewer().getTextWidget().setBackground(new
> Color(Display.getCurrent(), rgb));
> }
> catch (Exception e)
> {
> // Nothing
> }
> }
> }
>
> //
> ------------------------------------------------------------ -------------
> // setSelectionBackgroundColor
> //
> ------------------------------------------------------------ -------------
>
> private void setSelectionBackgroundColor()
> {
> IPreferenceStore ps =
> EditorPlugin.getInstance().getPreferenceStore();
> boolean hasValues =
> ps.contains(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF) ;
> if (hasValues == true)
> {
> String rgbStr =
> ps.getString(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF );
> try
> {
> RGB rgb = StringConverter.asRGB(rgbStr);
>
> getSourceViewer().getTextWidget().setSelectionBackground(new
> Color(Display.getCurrent(), rgb));
> }
> catch (Exception e)
> {
> // Nothing
> }
> }
> }
|
|
| | |
Re: update syntax coloring in a texteditor [message #310810 is a reply to message #310618] |
Fri, 15 December 2006 14:36   |
Eclipse User |
|
|
|
Originally posted by: drojomar.notes.banesto.es
I'm sorry but I can't see it. I have differents colors for differents
token types.
I use a scanner that I can't control, it gives me a token types list so
I create a dinamic preference page. When the scanner find a token,
returns me the token id, i go to the preference page, check the colour
and assign to the token (only the color).
I've been looking a way to ask the scanner to scan the page again but I
couldn't find anything.....
AL escribió:
> One more thing...Make sure you're color set for the tokens are
> statically declared, so that ALL your editor instances share the same
> color set. This will save lots of memory and work. For each preference
> notification, check to see first if the color is already is the same
> color before changing.
>
> AL wrote:
>
>> David Rojo wrote:
>>
>>> I have a texteditor, with syntax coloring. I have a scanner that scan
>>> the document, and assign a different color depending on the token type.
>>>
>>> Besides, I have a preference page that allow users to choose the
>>> color of each token. My problem is after I change a color (in the
>>> preference page), I don't know how to refresh the color in the document.
>>>
>>> I have created an IPropertyChangeListener, but I don't know how to
>>> scann the document again in order to change to the new colors.
>>>
>>> any ideas?
>>>
>>> Thanks
>>
>>
>> Dave,
>>
>> Once you get the notification of the preference change, do something
>> like the below. This way all the editor instances will automatically
>> change to the color you want.
>>
>> Now if your editor has colored keywords, then all you have to do is to
>> change the color to those tokens you assigned in your rules.
>>
>> Below is just to show you how to change the background and forground
>> colors when a preference change occurs. The key is to get the
>> getSourceViewer().
>>
>>
>> //
>> ------------------------------------------------------------ -------------
>> // setBackgroundColor
>> //
>> ------------------------------------------------------------ -------------
>>
>> private void setBackgroundColor()
>> {
>> IPreferenceStore ps =
>> EditorPlugin.getInstance().getPreferenceStore();
>> boolean hasValues =
>> ps.contains(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
>> if (hasValues == true)
>> {
>> String rgbStr =
>> ps.getString(IPreferenceConstants.MY_EDITOR_BG_COLOR_PREF);
>> try
>> {
>> RGB rgb = StringConverter.asRGB(rgbStr);
>> getSourceViewer().getTextWidget().setBackground(new
>> Color(Display.getCurrent(), rgb));
>> }
>> catch (Exception e)
>> {
>> // Nothing
>> }
>> }
>> }
>>
>> //
>> ------------------------------------------------------------ -------------
>> // setSelectionBackgroundColor
>> //
>> ------------------------------------------------------------ -------------
>>
>> private void setSelectionBackgroundColor()
>> {
>> IPreferenceStore ps =
>> EditorPlugin.getInstance().getPreferenceStore();
>> boolean hasValues =
>> ps.contains(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF) ;
>> if (hasValues == true)
>> {
>> String rgbStr =
>> ps.getString(IPreferenceConstants.MY_SELECTION_BG_COLOR_PREF );
>> try
>> {
>> RGB rgb = StringConverter.asRGB(rgbStr);
>>
>> getSourceViewer().getTextWidget().setSelectionBackground(new
>> Color(Display.getCurrent(), rgb));
>> }
>> catch (Exception e)
>> {
>> // Nothing
>> }
>> }
>> }
|
|
|
Re: update syntax coloring in a texteditor [message #310815 is a reply to message #310809] |
Sat, 16 December 2006 07:07  |
Eclipse User |
|
|
|
Originally posted by: drojomar.notes.banesto.es
I found the problem...when I initialize the editor, I miss the line
setPreferenceStore(MyEditorPlugin.getDefault().getPreference Store());
now it works perfectly,
thanks
David Rojo escribió:
> I have overrided the method, but it is not called when I change the
> preferences. Do I have to do something special to get it??
> Daniel Megert escribió:
>> David Rojo wrote:
>>
>>> I have a texteditor, with syntax coloring. I have a scanner that scan
>>> the document, and assign a different color depending on the token type.
>>
>>>
>>> Besides, I have a preference page that allow users to choose the
>>> color of each token. My problem is after I change a color (in the
>>> preference page), I don't know how to refresh the color in the document.
>>>
>>> I have created an IPropertyChangeListener, but I don't know how to
>>> scann the document again in order to change to the new colors.
>>
>> The only thing you need to do is implement override
>> affectsTextPresentation(...) in your editor. This will kick the
>> scanner to do its work (assuming it has been correctly fed with the
>> new preferences).
>>
>> Dani
>>
>>>
>>> any ideas?
>>>
>>> Thanks
|
|
|
Goto Forum:
Current Time: Sat May 03 07:17:51 EDT 2025
Powered by FUDForum. Page generated in 0.03956 seconds
|