Search in sources :

Example 1 with AnnotationData

use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.

the class AnnotationEditPolicy method getDirectEditCommand.

/**
 * {@inheritDoc}
 */
@Override
protected Command getDirectEditCommand(final DirectEditRequest edit) {
    StyledTextEditor ste = (StyledTextEditor) edit.getCellEditor();
    AnnotationData newAnnoData = (AnnotationData) ste.getValue();
    AnnotationEditPart annoPart = (AnnotationEditPart) getHost();
    Annotation oldAnno = annoPart.getModel();
    Rectangle oldFigBounds = annoPart.getFigure().getBounds().getCopy();
    // y-coordinate is the only dimension that doesn't change
    newAnnoData.setY(oldFigBounds.y);
    // trim was never really verified (was always 0 on my platform),
    // see also StyledTextEditorLocator#relocate
    Composite compositeEditor = (Composite) ste.getControl();
    org.eclipse.swt.graphics.Rectangle trim = compositeEditor.computeTrim(0, 0, 0, 0);
    if (annoPart instanceof NodeAnnotationEditPart) {
        // the width and height grow with the text entered
        newAnnoData.setX(compositeEditor.getBounds().x);
        newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
        newAnnoData.setWidth(compositeEditor.getBounds().width - trim.width);
    } else {
        // with workflow annotations only the height grows with the text
        newAnnoData.setX(oldFigBounds.x);
        newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
        newAnnoData.setWidth(oldFigBounds.width - trim.width);
    }
    if (hasAnnotationDataChanged(oldAnno, newAnnoData)) {
        return new AnnotationEditCommand(annoPart, oldAnno, newAnnoData);
    }
    return null;
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) Composite(org.eclipse.swt.widgets.Composite) AnnotationData(org.knime.core.node.workflow.AnnotationData) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Annotation(org.knime.core.node.workflow.Annotation) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 2 with AnnotationData

use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.

the class AnnotationEditPart method toSWTStyleRanges.

public static StyleRange[] toSWTStyleRanges(final AnnotationData t, final Font defaultFont) {
    AnnotationData.StyleRange[] knimeStyleRanges = t.getStyleRanges();
    ArrayList<StyleRange> swtStyleRange = new ArrayList<StyleRange>(knimeStyleRanges.length);
    for (AnnotationData.StyleRange knimeSR : knimeStyleRanges) {
        StyleRange swtStyle = new StyleRange();
        Font f = FontStore.INSTANCE.getAnnotationFont(knimeSR, defaultFont);
        swtStyle.font = f;
        if (knimeSR.getFgColor() >= 0) {
            int rgb = knimeSR.getFgColor();
            RGB rgbObj = RGBintToRGBObj(rgb);
            swtStyle.foreground = new Color(null, rgbObj);
        }
        swtStyle.start = knimeSR.getStart();
        swtStyle.length = knimeSR.getLength();
        swtStyleRange.add(swtStyle);
    }
    return swtStyleRange.toArray(new StyleRange[swtStyleRange.size()]);
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) RGB(org.eclipse.swt.graphics.RGB) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.draw2d.geometry.Point)

Example 3 with AnnotationData

use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.

the class AddAnnotationCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // adapt location to the viewport location and the zoom factor
    // this seems to be a workaround for a bug in the framework
    ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
    // adjust the location according to the viewport position
    // seems to be a workaround for a bug in the framework
    // (should imediately deliver the correct view position and not
    // the position of the viewport)
    PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
    WorkflowEditor.adaptZoom(zoomManager, location, true);
    m_anno = new WorkflowAnnotation();
    AnnotationData data = new AnnotationData();
    // it is a workflow annotation
    data.setBgColor(INITIAL_FLOWANNO_COLOR);
    data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
    data.setBorderColor(INITAL_FLOWBORDER_COLOR);
    data.setText(INITIAL_FLOWANNO_TEXT);
    data.setStyleRanges(new AnnotationData.StyleRange[0]);
    m_anno.copyFrom(data, true);
    WorkflowManager hostWFM = getHostWFM();
    hostWFM.addWorkflowAnnotation(m_anno);
    m_viewer.deselectAll();
    // select the new ones....
    if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
    }
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnnotationData(org.knime.core.node.workflow.AnnotationData) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 4 with AnnotationData

use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.

the class AnnotationEditPolicy method hasAnnotationDataChanged.

/**
 * Compares the content of the new and the old annotation data. If they
 * are equal, no change command is executed.
 * @param oldAnno Old annotation (may be a default node annotation)
 * @param newAnnoData The new annotation data (not a default one)
 * @return If they are equally (a default with "Node x" equals a non-default
 * with "Node x")
 */
private static boolean hasAnnotationDataChanged(final Annotation oldAnno, final AnnotationData newAnnoData) {
    AnnotationData oldAnnoRealData = new AnnotationData();
    // copy bounds, overwrite text later
    oldAnnoRealData.copyFrom(newAnnoData, true);
    oldAnnoRealData.copyFrom(oldAnno.getData(), false);
    // need to set text explicitely - default node annotations have
    // no text (it's determined during rendering)
    oldAnnoRealData.setText(AnnotationEditPart.getAnnotationText(oldAnno));
    return !oldAnnoRealData.equals(newAnnoData);
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData)

Example 5 with AnnotationData

use of org.knime.core.node.workflow.AnnotationData 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

AnnotationData (org.knime.core.node.workflow.AnnotationData)6 Color (org.eclipse.swt.graphics.Color)3 ArrayList (java.util.ArrayList)2 Point (org.eclipse.draw2d.geometry.Point)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 LineBorder (org.eclipse.draw2d.LineBorder)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 Font (org.eclipse.swt.graphics.Font)1 RGB (org.eclipse.swt.graphics.RGB)1 Composite (org.eclipse.swt.widgets.Composite)1 Annotation (org.knime.core.node.workflow.Annotation)1 TextAlignment (org.knime.core.node.workflow.AnnotationData.TextAlignment)1 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)1 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)1 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)1