I would like to Concatenate more TextPrint Object in order to print Text with different Colors , for example :
<blue>This is blue</blue><green>This is green</green>
The aim of this is to print the syntax Highlighting of my TextEditor.
I tried this with GribPrint but it is not the right solution because of the weight of the columns.
Do you have any Idea ?
Thanks
Woolite
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
text.append("This is blue", style.foreground(0x0000FF));
text.append("This is green", style.foreground(0x00FF00));
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For your Information, I had to extends the TextStyle class, to be able to have text with different foregrounds and FontData.
I first tried :
<code>
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
style.foreground(new RGB(0,0,255));
style.font(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
</code>
But this didn't work.
So I created a TextStyle2 class (See at the end of the message).
And wrote :
<code>
StyledTextPrint text = new StyledTextPrint();
TextStyle2 style = new TextStyle2();
style.setForeground(new RGB(0,0,255));
style.setFontData(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
</code>
This works fine :-)
Was it volunteer that we can't set the properties on a TextStyle class ?
Best Regards,
Woolite
<code>
//-------------------------------------
// The TextStyle2 class
protected class TextStyle2 extends TextStyle{
RGB foreground;
FontData font;
public RGB setForeground(RGB color){
this.foreground = color;
return color;
}
public RGB getForeground(){
return this.foreground;
}
public FontData setFontData(FontData font){
this.font = font;
return font;
}
public FontData getFontData(){
return this.font;
}
}
</code>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
TextStyle is immutable. Each method call creates a new TextStyle, which you should assign back to the local variable.
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
style = style.foreground(new RGB(0,0,255));
style = style.font(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
This pattern is intended to support styling text according to the difference from the main text style, e.g.:
style = new TextStyle().foreground(0x000000).fontHeight(12);
text.append("This word is ", style)
.append("green", style.foreground(0x00FF00))
.append(", this word is ", style)
.append("large", style.fontHeight(24))
.append(", and this word is ", style)
.append("both", style.foreground(0x00FF00).fontHeight(24));
Regards,
Matthew
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I would like to Concatenate more TextPrint Object in order to print Text with different Colors , for example :
<blue>This is blue</blue><green>This is green</green>
The aim of this is to print the syntax Highlighting of my TextEditor.
I tried this with GribPrint but it is not the right solution because of the weight of the columns.
Do you have any Idea ?
Thanks
Woolite
Have you looked at StyledTextPrint?
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
text.append("This is blue", style.foreground(0x0000FF));
text.append("This is green", style.foreground(0x00FF00));
Thanks Matthew,
It was exactly that I was looking for.
For your Information, I had to extends the TextStyle class, to be able to have text with different foregrounds and FontData.
I first tried :
<code>
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
style.foreground(new RGB(0,0,255));
style.font(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
</code>
But this didn't work.
So I created a TextStyle2 class (See at the end of the message).
And wrote :
<code>
StyledTextPrint text = new StyledTextPrint();
TextStyle2 style = new TextStyle2();
style.setForeground(new RGB(0,0,255));
style.setFontData(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
</code>
This works fine :-)
Was it volunteer that we can't set the properties on a TextStyle class ?
Best Regards,
Woolite
<code>
//-------------------------------------
// The TextStyle2 class
protected class TextStyle2 extends TextStyle{
RGB foreground;
FontData font;
public RGB setForeground(RGB color){
this.foreground = color;
return color;
}
public RGB getForeground(){
return this.foreground;
}
public FontData setFontData(FontData font){
this.font = font;
return font;
}
public FontData getFontData(){
return this.font;
}
}
</code>
TextStyle is immutable. Each method call creates a new TextStyle, which you should assign back to the local variable.
StyledTextPrint text = new StyledTextPrint();
TextStyle style = new TextStyle();
style = style.foreground(new RGB(0,0,255));
style = style.font(new FontData("Courier",6,SWT.BOLD));
text.append("This is blue", style);
This pattern is intended to support styling text according to the difference from the main text style, e.g.:
style = new TextStyle().foreground(0x000000).fontHeight(12);
text.append("This word is ", style)
.append("green", style.foreground(0x00FF00))
.append(", this word is ", style)
.append("large", style.fontHeight(24))
.append(", and this word is ", style)
.append("both", style.foreground(0x00FF00).fontHeight(24));
Regards,
Matthew
Thanks for the useful Help
Best Regards,
Woolite