Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Changing color of text in editor
Changing color of text in editor [message #324159] Thu, 17 January 2008 22:51 Go to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Hi everyone,

At the moment I'm using the following code to allow a user to change a highlighted piece of text (in the standard Java editor) to uppercase:

IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInp ut());
ISelectionProvider selectionProvider = editor.getSelectionProvider();
ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
String text = selection.getText();
String newText = text.toUpperCase();
document.replace(selection.getOffset(), selection.getLength(), newText);

What i really want to do however, is change the color of the selected text, instead of the case. Does anyone know how I might do this?

Cheers.
Re: Changing color of text in editor [message #324219 is a reply to message #324159] Sun, 20 January 2008 15:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Does anyone know if this is actually possible to begin with?
Re: Changing color of text in editor [message #324221 is a reply to message #324219] Sun, 20 January 2008 15:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Shane,

I think the colorization is controlled by the Java editor which
tokenizes the text and colorizes based on those tokens so I'm not sure
you can interfere with that...


Shane wrote:
> Does anyone know if this is actually possible to begin with?
>
Re: Changing color of text in editor [message #324235 is a reply to message #324159] Mon, 21 January 2008 07:07 Go to previous messageGo to next message
Eclipse UserFriend
Shane wrote:

>Hi everyone,
>
>At the moment I'm using the following code to allow a user to change a highlighted piece of text (in the standard Java editor) to uppercase:
>
>IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInp ut());
> ISelectionProvider selectionProvider = editor.getSelectionProvider();
> ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
> String text = selection.getText();
> String newText = text.toUpperCase();
>document.replace(selection.getOffset(), selection.getLength(), newText);
>
>What i really want to do however, is change the color of the selected text, instead of the case.
>
When should it change?

Dani

> Does anyone know how I might do this?
>
>Cheers.
>
>
Re: Changing color of text in editor [message #324267 is a reply to message #324235] Mon, 21 January 2008 15:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Thanks for the replies guys.

The color should change in response to the click of a button on the toolbar (I'm using the actionSets package). I essentially want to handle the color changes in the run method if that is possible.
Re: Changing color of text in editor [message #324280 is a reply to message #324267] Tue, 22 January 2008 02:52 Go to previous messageGo to next message
Eclipse UserFriend
Shane wrote:

>Thanks for the replies guys.
>
>The color should change in response to the click of a button on the toolbar (I'm using the actionSets package). I essentially want to handle the color changes in the run method if that is possible.
>
>
I the text read-only? If not, what should happen if the user types?

Dani
Re: Changing color of text in editor [message #324323 is a reply to message #324280] Tue, 22 January 2008 15:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

The text is in an editor. If the user types, the input will be displayed in the editor window.
Re: Changing color of text in editor [message #324371 is a reply to message #324323] Wed, 23 January 2008 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Shane wrote:

>The text is in an editor. If the user types, the input will be displayed in the editor window.
>
>
OK, so what would you expect to happen with your previous highlighting?

Dani
Re: Changing color of text in editor [message #324393 is a reply to message #324371] Wed, 23 January 2008 15:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Ok, here's what I want to happen. The user types text into the editor window. He then selects a section of text by highlighting it with his mouse (click and drag). He then presses a button on the toolbar and the selected text changes color. The code I posted does the above, except it changes case instead of color, and I want it to change color.

Cheers.
Re: Changing color of text in editor [message #324472 is a reply to message #324393] Thu, 24 January 2008 15:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Anybody?
Re: Changing color of text in editor [message #324656 is a reply to message #324472] Wed, 30 January 2008 05:24 Go to previous messageGo to next message
Eclipse UserFriend
Shane wrote:

>Anybody?
>
>
If it's your editor you can get the text viewer and then its text
widget. On that widget you can apply styles using one of the
StyledText.setStyleRange* methods. This still leaves open my previous
question about what you expect to happen when the user continues typing
e.g. inside such a range. There exist higher level approaches to color
text but without having more information it's hard to shoot in the dark.

Dani
Re: Changing color of text in editor [message #324699 is a reply to message #324656] Wed, 30 January 2008 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nazdak9.gmail.com

Hi Dani.

First of all thanks for your responses.
I see what you mean now by users continuing to type within a range. If they do so their input will be displayed as normal, without any color changes (i.e. back to the default black).

The code I posted does what I want, except it changes case instead of color.

Unfortunately, the editor is not mine, but rather the default JDT java editor in eclipse. I just thought that as there is a way to capture text and change case, their must be a way to change color also.

Any ideas?
Re: Changing color of text in editor [message #324722 is a reply to message #324699] Thu, 31 January 2008 04:33 Go to previous message
Eclipse UserFriend
Shane wrote:

>Hi Dani.
>
>First of all thanks for your responses.
>I see what you mean now by users continuing to type within a range. If they do so their input will be displayed as normal, without any color changes (i.e. back to the default black).
>
>The code I posted does what I want, except it changes case instead of color.
>
>Unfortunately, the editor is not mine, but rather the default JDT java editor in eclipse. I just thought that as there is a way to capture text and change case, their must be a way to change color also.
>
>Any ideas?
>
>
You can do it via annotation: instead of getting the document from the
doc provider you ask for the annotation model and add an annotation of
your newly defined annotation type.
See the following extension points:
org.eclipse.ui.editors.annotationTypes
org.eclipse.ui.editors.markerAnnotationSpecification

Dani
Previous Topic:how to disable dynamically new wizards?
Next Topic:[PDE] Externalizing Strings dialog and ignore pattern
Goto Forum:
  


Current Time: Thu Jul 17 01:14:09 EDT 2025

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

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

Back to the top