use of org.knime.core.node.workflow.AnnotationData.TextAlignment in project knime-core by knime.
the class AnnotationEditPart method toAnnotationData.
/**
* @param s the component with the styled text to convert.
* @return
*/
public static AnnotationData toAnnotationData(final StyledText s) {
AnnotationData result = new AnnotationData();
result.setText(s.getText());
result.setBgColor(colorToRGBint(s.getBackground()));
result.setBorderColor(AnnotationEditPart.colorToRGBint(s.getMarginColor()));
// annotations have the same margin top/left/right/bottom.
result.setBorderSize(s.getRightMargin());
result.setDefaultFontSize(s.getFont().getFontData()[0].getHeight());
TextAlignment alignment;
switch(s.getAlignment()) {
case SWT.RIGHT:
alignment = TextAlignment.RIGHT;
break;
case SWT.CENTER:
alignment = TextAlignment.CENTER;
break;
default:
alignment = TextAlignment.LEFT;
}
result.setAlignment(alignment);
StyleRange[] swtStyleRange = s.getStyleRanges();
ArrayList<AnnotationData.StyleRange> wfStyleRanges = new ArrayList<AnnotationData.StyleRange>(swtStyleRange.length);
for (StyleRange sr : swtStyleRange) {
if (sr.isUnstyled()) {
continue;
}
AnnotationData.StyleRange waSr = new AnnotationData.StyleRange();
Color fg = sr.foreground;
if (fg != null) {
int rgb = colorToRGBint(fg);
waSr.setFgColor(rgb);
}
FontStore.saveAnnotationFontToStyleRange(waSr, sr.font);
waSr.setStart(sr.start);
waSr.setLength(sr.length);
wfStyleRanges.add(waSr);
}
result.setStyleRanges(wfStyleRanges.toArray(new AnnotationData.StyleRange[wfStyleRanges.size()]));
return result;
}
Aggregations