Is there an API for getting the color and font style of a character in an editor?

I want to enhance my Code Outline Plugin to show colors. I noticed that there are classes ColorKey and EditorColorsManager, but I can't figure out how to use those to get the color and font style for a single character in the editor.

Is there a way to do this?

14 comments

Keith Lea wrote:

I want to enhance my Code Outline Plugin to show colors. I noticed that there are classes ColorKey and EditorColorsManager, but I can't figure out how to use those to get the color and font style for a single character in the editor.

Is there a way to do this?

Keith,

ColorKey and TextAttributesKey are only keys that used to map a notions
like "background color" or "field reference attributes" to a concrete
colors and attributes being given a concrete color scheme. Actual
character colors are being calculated during editor painting and aren't
stored anywhere so you need either re-implement the editor drawing
algorithm (which I hope you wouldn't do :) ) or learn how to zoom
original editor component while it actually renders all the stuff. Is
that possible?

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Hello, Keith!
You wrote on Tue, 9 Nov 2004 01:30:11 +0300 (MSK):

KL> I want to enhance my Code Outline Plugin to show colors. I noticed
KL> that there are classes ColorKey and EditorColorsManager, but I can't
KL> figure out how to use those to get the color and font style for a
KL> single character in the editor.


The colors is ajustable by regions, not by symbols or keywords. You must
mark up regions with corresponding layer.
BTW, the PLUS library have configurable panel for EditorColorsScheme, maybe
you find it usefull.

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

Hello, Maxim!
You wrote on Tue, 09 Nov 2004 11:51:41 +0300:

MSJ> or learn how to zoom original editor component
MSJ> while it actually renders all the stuff. Is that possible?

The feature is very usefull :) Is it available in Irida? I would like have
"Focus Code" feature, that implemented in Eclipse, for example. The feature,
then you lockup code region in editor and work only with it (i belive, that
zooming is also).

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

Maxim,

..or learn how to zoom original editor component while it actually
renders all the stuff. Is that possible?

>

What do you mean by "zoom"?
If often wished we were able to plugin our own behaviour in the painting
sequence, to enrich the result graphically, with icons, frames, backgrounds.

CSS would be great.
For example, it would let us
- add frames around inner-classes, with a pale yellow background,
- insert a specific icon before accessors and constructors,
- make hyperlinks of words (ex: the parent class name, interface, ..-
- replace "return ;" by a red exit arrow
- ... add your wish here
just by customizing a CSS-like config file.

Alain

0

Alain Ravet wrote:

Maxim,

>> ..or learn how to zoom original editor component while it actually
>> renders all the stuff. Is that possible?
>>


What do you mean by "zoom"?
If often wished we were able to plugin our own behaviour in the painting
sequence, to enrich the result graphically, with icons, frames,
backgrounds.

CSS would be great.
For example, it would let us
- add frames around inner-classes, with a pale yellow background,
- insert a specific icon before accessors and constructors,
- make hyperlinks of words (ex: the parent class name, interface, ..-
- replace "return ;" by a red exit arrow
- ... add your wish here
just by customizing a CSS-like config file.

Alain


Nice ideas. The bad thing is we just cannot afford throwing away current
text editing implementation and come up with new one just for this.

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Hello, Maxim!
You wrote on Tue, 09 Nov 2004 14:48:16 +0300:

MSJ> Nice ideas. The bad thing is we just cannot afford throwing away
MSJ> current text editing implementation and come up with new one just
MSJ> for this.

But curently EditorColorsScheme - is exactly CSS, that Alain suggest. Is it
wrong?
Every editor has colors scheme, that contains mapping for highlighting keys.
This is just
like CSS...

We can get scheme from editor and change/get colors(or text attributes) from
it...

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

Alexey Efimov wrote:

But curently EditorColorsScheme - is exactly CSS, that Alain suggest. Is it
wrong?


Yep, but quite a limited one. You can only play with
foreground/background colors and a few decorations: underscore,
underwave, box. No icons, no custom drawing etc.

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Hello, Maxim!
You wrote on Tue, 09 Nov 2004 15:16:36 +0300:

MSJ> Yep, but quite a limited one. You can only play with
MSJ> foreground/background colors and a few decorations: underscore,
MSJ> underwave, box. No icons, no custom drawing etc.

Maybe just add TextAttributeRenderer interface into TextAttributes? :) To
perform such paintings...
As far i know, TextAttributes is used anyway to render text in editor, so, i
think, that it might be delegated to custom renderer and. If it possible in
current implementation :)

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

Maxim Shafirov (JetBrains) wrote:

> Alain Ravet wrote:
>> CSS would be great.
>
> Nice ideas. The bad thing is we just cannot afford throwing away
current text editing
> implementation and come up with new one just for this.


I understand CSS-like could be a "trowing away" feature, but may be
there are simpler ways 1/ for us to get most of the benefits 2/ without
you paying too much in code change.


What about adding a few more config options in the
IDE Settings.Color & Fonts
, for the JAVA section

In the left-side list, that defines the colouring criterias, add a few
higher level entries

- inner classes
- accessors
- constructors
- main() method
- copyright header
etc...

In the right-side actions check boxes, add
- frame around the area : thickness, colour, offset
- background : colour

and also
- icon : image, x/y-offset to U.R. corner.


Is is feasible, reasonably?
That would get us most of the benefits.



Alain

0

Hello, Alain!
You wrote on Tue, 09 Nov 2004 13:47:08 +0100:

About right side bar, i think that it is not good, if editor will define
drawing of this bar.
Editor must define colors for itself, but not for rightside bar, is bar of
code analizer, that used only code from editor.

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

ColorKey and TextAttributesKey are only keys that
used to map a notions
like "background color" or "field reference
attributes" to a concrete
colors and attributes being given a concrete color
scheme. Actual
character colors are being calculated during editor
painting and aren't
stored anywhere so you need either re-implement the
editor drawing
algorithm (which I hope you wouldn't do :) ) or learn
how to zoom
original editor component while it actually renders
all the stuff. Is
that possible?


I imagine that zooming the editor component itself would be too CPU intensive (don't you think rendering the entirety of a long file on file open would take a little bit?), but I could try it. I never thought about doing it this way because I assumed performance wouldn't be good.

Also, how would I be notified of changes in rendering-specific properties, like when code down lower in the file is highlighted red because of an error up higher?

0

Alexey,

>About right side bar, i think that it is not good,.. is bar of
>code analizer, that used only code from editor.
>

>

It's not the right bar, it's the right half:
left half = list of target (unused symbol, comment, etc..)
right half = "action": effect, font, background, foreground

Alain

0

Hello, Alain!
You wrote on Tue, 09 Nov 2004 15:15:41 +0100:

AR> It's not the right bar, it's the right half:
AR> left half = list of target (unused symbol, comment, etc..)
AR> right half = "action": effect, font, background, foreground

:) Hm, seems to be good, but i guess we realy need for Just Custom Renderer
in TextAttributes for it.

Thanks!
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru


0

Alexey,

>:) Hm, seems to be good, but i guess we realy need for Just Custom Renderer
>in TextAttributes for it.
>

>


I'm not sure: my suggestion is mostly about
- drawing - a frame - on top of the editor contents, or
- changing the background colour of a rectangular area.

Internally, it shares a lot with folding regions.

Alain

0

Please sign in to leave a comment.