Search in sources :

Example 1 with TextAlignment

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;
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData) TextAlignment(org.knime.core.node.workflow.AnnotationData.TextAlignment) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

ArrayList (java.util.ArrayList)1 Point (org.eclipse.draw2d.geometry.Point)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 Color (org.eclipse.swt.graphics.Color)1 AnnotationData (org.knime.core.node.workflow.AnnotationData)1 TextAlignment (org.knime.core.node.workflow.AnnotationData.TextAlignment)1