How to clone/deep copy a StyledString? [message #691274] |
Fri, 01 July 2011 06:44 |
|
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
|
|
|
(no subject) [message #692153 is a reply to message #691274] |
Sun, 03 July 2011 17:56 |
Sebastian Zarnekow Messages: 3118 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
>
|
|
|
Powered by
FUDForum. Page generated in 0.01940 seconds