Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to clone/deep copy a StyledString?
How to clone/deep copy a StyledString? [message #691274] Fri, 01 July 2011 06:44 Go to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 230
Registered: July 2009
Senior Member
Hi,

I'm working on a subwords completion engine for JDT.

I'd like to get a copy of a StyledString but couldn't find simple means to do that. Is there any API that copies an existing StyledString including its style ranges?

StyledText doesn't support clone() nor has a constructor that takes another StyledString as template. Thus, I tried to use #getStyleRanges() but this seems to be not a great solution:

        StyledString copy = new StyledString(displayString.getString());
        for (StyleRange range : displayString.getStyleRanges()) {
            copy.setStyle(range.start, range.length, new Styler() {

                @Override
                public void applyStyles(TextStyle textStyle) {
                    // copy values from style range and apply them here again? Seems odd and tedious
                }
            });
        }


Does anyone have an idea or code that copies a StyledString?

Thanks for hints!
Marcel

index.php/fa/3202/0/

http://goo.gl/KioHN


tw: @MarcelBruch
tw: @Recommenders
(no subject) [message #692153 is a reply to message #691274] Sun, 03 July 2011 17:56 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Hi Marcel,

probably not the most convenient solution, but I'd try to access the
StyleRunList reflectivly, clone that one and assign the new list to the
private field of the new StyledString.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 01.07.11 08:44, Marcel Bruch wrote:
> Hi,
>
> I'm working on a subwords completion engine for JDT.
>
> I'd like to get a copy of a StyledString but couldn't find simple means to do that. Is there any API that copies an existing StyledString including its style ranges?
>
> StyledText doesn't support clone() nor has a constructor that takes another StyledString as template. Thus, I tried to use #getStyleRanges() but this seems to be not a great solution:
>
>
> StyledString copy = new StyledString(displayString.getString());
> for (StyleRange range : displayString.getStyleRanges()) {
> copy.setStyle(range.start, range.length, new Styler() {
>
> @Override
> public void applyStyles(TextStyle textStyle) {
> // copy values from style range and apply them here again? Seems odd and tedious
> }
> });
> }
>
>
> Does anyone have an idea or code that copies a StyledString?
>
> Thanks for hints!
> Marcel
>
>
>
> http://goo.gl/KioHN
>
Previous Topic:Stuck in Building Workspace (Eclipse + android)
Next Topic:How to use the wildcard character * in templates
Goto Forum:
  


Current Time: Mon Dec 22 03:32:51 GMT 2014

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

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