Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » TextEditor Background
TextEditor Background [message #284888] Wed, 04 May 2005 06:20 Go to next message
Eclipse UserFriend
Hi all,

I want to allow the users of my Eclipse 3.0 code editor to set the text
background.

For example, set the background to black and simulate a console/terminal
style.

Someone, in this newsgroup, previously suggested setting
AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.

This does work - just a little too much ;-) Every single editor (presumably
all those that derive from AbstractTextEditor) now have the colour I
specified in the preference store.

What I would like is, for my particular editor (which subclasses
org.eclipse.ui.editors.text.TextEditor) to have it's own background colour
that doesn't "overflow" into any other types of editor (all instances of
*my* editor can have this color, I just dont want the JDT/etc.. to use it!).

Q: Is this possible?
- If so, any hints?

I'm thinking that it might be a case of accessing the underlying SWT
widget(s) and manipulating their properties... but I can't find any obvious
route down to them (probably for a good reason).

Cheers,
Jack
Re: TextEditor Background [message #284908 is a reply to message #284888] Wed, 04 May 2005 13:56 Go to previous messageGo to next message
Eclipse UserFriend
Simply provide your own, private preference store in your text editor
implementation, and set the preference just in there, instead of using
the EditorsUI.getPreferenceStore

-tom

Jack Hoxley wrote:
> Hi all,
>
> I want to allow the users of my Eclipse 3.0 code editor to set the text
> background.
>
> For example, set the background to black and simulate a console/terminal
> style.
>
> Someone, in this newsgroup, previously suggested setting
> AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.
>
> This does work - just a little too much ;-) Every single editor (presumably
> all those that derive from AbstractTextEditor) now have the colour I
> specified in the preference store.
>
> What I would like is, for my particular editor (which subclasses
> org.eclipse.ui.editors.text.TextEditor) to have it's own background colour
> that doesn't "overflow" into any other types of editor (all instances of
> *my* editor can have this color, I just dont want the JDT/etc.. to use it!).
>
> Q: Is this possible?
> - If so, any hints?
>
> I'm thinking that it might be a case of accessing the underlying SWT
> widget(s) and manipulating their properties... but I can't find any obvious
> route down to them (probably for a good reason).
>
> Cheers,
> Jack
>
>
Re: TextEditor Background [message #286637 is a reply to message #284908] Mon, 13 June 2005 21:00 Go to previous messageGo to next message
Eclipse UserFriend
The problem with this is that your own preference store must provide all
other preferences that AbstractTextEditor also looks from the
EditorsUI's preference store, no?

May be one should write desired pref values into the EditorsUI.


Tom Eicher wrote:

> Simply provide your own, private preference store in your text editor
> implementation, and set the preference just in there, instead of using
> the EditorsUI.getPreferenceStore
>
> -tom
>
> Jack Hoxley wrote:
>
>> Hi all,
>>
>> I want to allow the users of my Eclipse 3.0 code editor to set the text
>> background.
>>
>> For example, set the background to black and simulate a console/terminal
>> style.
>>
>> Someone, in this newsgroup, previously suggested setting
>> AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.
>>
>> This does work - just a little too much ;-) Every single editor
>> (presumably
>> all those that derive from AbstractTextEditor) now have the colour I
>> specified in the preference store.
>>
>> What I would like is, for my particular editor (which subclasses
>> org.eclipse.ui.editors.text.TextEditor) to have it's own background
>> colour
>> that doesn't "overflow" into any other types of editor (all instances of
>> *my* editor can have this color, I just dont want the JDT/etc.. to use
>> it!).
>>
>> Q: Is this possible?
>> - If so, any hints?
>>
>> I'm thinking that it might be a case of accessing the underlying SWT
>> widget(s) and manipulating their properties... but I can't find any
>> obvious
>> route down to them (probably for a good reason).
>>
>> Cheers,
>> Jack
>>
>>
Re: TextEditor Background [message #286639 is a reply to message #284908] Mon, 13 June 2005 21:14 Go to previous messageGo to next message
Eclipse UserFriend
I think I found the solution.

Please http://www.eclipse.org/articles/Article-Preferences/preferen ces.htm
(See the section "Propagating Values With IPropertyChangeListener".)

Listen for the property changes in your pref settings. This means your
editor must install such listener. Once you get the change event, your
editor simple get the source viewer, which, in turns, can call
getControl() that returns a StyledText, then do a
StyledText.setBackgound(Color).

Tom Eicher wrote:

> Simply provide your own, private preference store in your text editor
> implementation, and set the preference just in there, instead of using
> the EditorsUI.getPreferenceStore
>
> -tom
>
> Jack Hoxley wrote:
>
>> Hi all,
>>
>> I want to allow the users of my Eclipse 3.0 code editor to set the text
>> background.
>>
>> For example, set the background to black and simulate a console/terminal
>> style.
>>
>> Someone, in this newsgroup, previously suggested setting
>> AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.
>>
>> This does work - just a little too much ;-) Every single editor
>> (presumably
>> all those that derive from AbstractTextEditor) now have the colour I
>> specified in the preference store.
>>
>> What I would like is, for my particular editor (which subclasses
>> org.eclipse.ui.editors.text.TextEditor) to have it's own background
>> colour
>> that doesn't "overflow" into any other types of editor (all instances of
>> *my* editor can have this color, I just dont want the JDT/etc.. to use
>> it!).
>>
>> Q: Is this possible?
>> - If so, any hints?
>>
>> I'm thinking that it might be a case of accessing the underlying SWT
>> widget(s) and manipulating their properties... but I can't find any
>> obvious
>> route down to them (probably for a good reason).
>>
>> Cheers,
>> Jack
>>
>>
Re: TextEditor Background [message #286641 is a reply to message #286637] Mon, 13 June 2005 21:36 Go to previous messageGo to next message
Eclipse UserFriend
Here is how:

Basically, override the texteditor's createPartControl()...(Make sure to
call super.createPartControl() then do your stuff!) At the end, before
exiting the method, call
getSourceViewer().getStyledText().setBackground(Color yourColor). That is.

The AbstractTextEditor reads a lot of preferences from the
EditorsPluin's preference store. It's not a good idea to give it a new
preference store unless you are able to provide all the other
preferences as well.

The above solution works well.


AL wrote:

> The problem with this is that your own preference store must provide all
> other preferences that AbstractTextEditor also looks from the
> EditorsUI's preference store, no?
>
> May be one should write desired pref values into the EditorsUI.
>
>
> Tom Eicher wrote:
>
>> Simply provide your own, private preference store in your text editor
>> implementation, and set the preference just in there, instead of using
>> the EditorsUI.getPreferenceStore
>>
>> -tom
>>
>> Jack Hoxley wrote:
>>
>>> Hi all,
>>>
>>> I want to allow the users of my Eclipse 3.0 code editor to set the text
>>> background.
>>>
>>> For example, set the background to black and simulate a console/terminal
>>> style.
>>>
>>> Someone, in this newsgroup, previously suggested setting
>>> AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.
>>>
>>> This does work - just a little too much ;-) Every single editor
>>> (presumably
>>> all those that derive from AbstractTextEditor) now have the colour I
>>> specified in the preference store.
>>>
>>> What I would like is, for my particular editor (which subclasses
>>> org.eclipse.ui.editors.text.TextEditor) to have it's own background
>>> colour
>>> that doesn't "overflow" into any other types of editor (all instances of
>>> *my* editor can have this color, I just dont want the JDT/etc.. to
>>> use it!).
>>>
>>> Q: Is this possible?
>>> - If so, any hints?
>>>
>>> I'm thinking that it might be a case of accessing the underlying SWT
>>> widget(s) and manipulating their properties... but I can't find any
>>> obvious
>>> route down to them (probably for a good reason).
>>>
>>> Cheers,
>>> Jack
>>>
>>>
>
Re: TextEditor Background [message #286650 is a reply to message #286637] Tue, 14 June 2005 03:27 Go to previous message
Eclipse UserFriend
You can use a org.eclipse.ui.texteditor.ChainedPreferenceStore to create
an aggregated view of multiple preference stores. Pass your custom
store as the first one in order to shadow the one from EditorsUI:

IPreferenceStore yourPluginPreferences= ...;
IPreferenceStore editorPrefs= EditorsUI.getPreferenceStore();
IPreferenceStore[] stores= { yourPluginPreferences, editorPrefs };
IPreferenceStore combined= new ChainedPreferenceStore(stores);

Now reading from 'combined' will return the preference found in your own
store if present, and will otherwise read through to the editor preferences.

-tom

AL wrote:
> The problem with this is that your own preference store must provide all
> other preferences that AbstractTextEditor also looks from the
> EditorsUI's preference store, no?
>
> May be one should write desired pref values into the EditorsUI.
>
>
> Tom Eicher wrote:
>
>> Simply provide your own, private preference store in your text editor
>> implementation, and set the preference just in there, instead of using
>> the EditorsUI.getPreferenceStore
>>
>> -tom
>>
>> Jack Hoxley wrote:
>>
>>> Hi all,
>>>
>>> I want to allow the users of my Eclipse 3.0 code editor to set the text
>>> background.
>>>
>>> For example, set the background to black and simulate a console/terminal
>>> style.
>>>
>>> Someone, in this newsgroup, previously suggested setting
>>> AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND via the IPreferenceStore.
>>>
>>> This does work - just a little too much ;-) Every single editor
>>> (presumably
>>> all those that derive from AbstractTextEditor) now have the colour I
>>> specified in the preference store.
>>>
>>> What I would like is, for my particular editor (which subclasses
>>> org.eclipse.ui.editors.text.TextEditor) to have it's own background
>>> colour
>>> that doesn't "overflow" into any other types of editor (all instances of
>>> *my* editor can have this color, I just dont want the JDT/etc.. to
>>> use it!).
>>>
>>> Q: Is this possible?
>>> - If so, any hints?
>>>
>>> I'm thinking that it might be a case of accessing the underlying SWT
>>> widget(s) and manipulating their properties... but I can't find any
>>> obvious
>>> route down to them (probably for a good reason).
>>>
>>> Cheers,
>>> Jack
>>>
>>>
>
Previous Topic:Syn and ASyn problem
Next Topic:Accessing Eclipse from separate Java Application
Goto Forum:
  


Current Time: Fri Jul 18 17:55:22 EDT 2025

Powered by FUDForum. Page generated in 0.04801 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top