add highlight in pure programmatically

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

add highlight in pure programmatically

Peter Cheung
Hi
    Why the following code has no effect to add highlight?

EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
Document doc2 = ec.getDocument();
OffsetsBag bag = new OffsetsBag(doc2, true);
AttributeSet defaultColors = AttributesUtilities.createImmutable(StyleConstants.Background, new Color(0, 0, 255));
bag.addHighlight(5, 10, defaultColors);
AttributeSet defaultColors2 = AttributesUtilities.createImmutable(StyleConstants.Foreground, new Color(0, 255, 255));
bag.addHighlight(2, 5, defaultColors2);

Thanks
From Peter
Reply | Threaded
Open this post in threaded view
|

Re: add highlight in pure programmatically

Peter Cheung
This doesn't work too:

Highlighter highlighter = jTextComponent.getHighlighter();
HighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.CYAN);
highlighter.addHighlight(5, 10, highlightPainter);


From: Peter Cheung <[hidden email]>
Sent: Monday, September 18, 2017 12:52 AM
To: [hidden email]
Subject: [platform-dev] add highlight in pure programmatically
 
Hi
    Why the following code has no effect to add highlight?

EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
Document doc2 = ec.getDocument();
OffsetsBag bag = new OffsetsBag(doc2, true);
AttributeSet defaultColors = AttributesUtilities.createImmutable(StyleConstants.Background, new Color(0, 0, 255));
bag.addHighlight(5, 10, defaultColors);
AttributeSet defaultColors2 = AttributesUtilities.createImmutable(StyleConstants.Foreground, new Color(0, 255, 255));
bag.addHighlight(2, 5, defaultColors2);

Thanks
From Peter
Reply | Threaded
Open this post in threaded view
|

Re: add highlight in pure programmatically

Neil C Smith-2
In reply to this post by Peter Cheung
Hi,

On Sun, 17 Sep 2017, 17:53 Peter Cheung <[hidden email]> wrote:
Hi
    Why the following code has no effect to add highlight?

How are you registering your highlight layer factory and creating the highlight layer? I was getting my head around this last week to make a simple save-flash plugin - source here if it helps - https://github.com/praxis-live/praxis-live/tree/develop/praxis.live.editor.saveflash/src/net/neilcsmith/praxis/live/editor/saveflash

Best wishes, 

Neil

--
Neil C Smith
Artist & Technologist

Praxis LIVE - hybrid visual IDE for creative coding - www.praxislive.org
Reply | Threaded
Open this post in threaded view
|

Re: add highlight in pure programmatically

Peter Cheung

You example is correct, i registered the HightlightFactory by mimetype="", so all file types are hocked to my factory.

Thanks again Gentlemen




From: Neil C Smith <[hidden email]>
Sent: Monday, September 18, 2017 1:44 AM
To: [hidden email]
Subject: [platform-dev] Re: add highlight in pure programmatically
 
Hi,

On Sun, 17 Sep 2017, 17:53 Peter Cheung <[hidden email]> wrote:
Hi
    Why the following code has no effect to add highlight?

How are you registering your highlight layer factory and creating the highlight layer? I was getting my head around this last week to make a simple save-flash plugin - source here if it helps - https://github.com/praxis-live/praxis-live/tree/develop/praxis.live.editor.saveflash/src/net/neilcsmith/praxis/live/editor/saveflash

Best wishes, 

Neil

--
Neil C Smith
Artist & Technologist

Praxis LIVE - hybrid visual IDE for creative coding - www.praxislive.org