Search in sources :

Example 6 with NodeAnnotation

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

the class AbstractWorkflowPortBarEditPart method getMinMaxXcoordInWorkflow.

/**
 * returns the minX coordinate and the maxX coordinate of all nodes, annotations and bendpoints in the flow (taking
 * the size of the elements into account). Or Integer.MIN/MAX_value if no elements exist.
 * @return new int[] {minX, maxX};
 */
protected int[] getMinMaxXcoordInWorkflow() {
    int maxX = Integer.MIN_VALUE;
    int minX = Integer.MAX_VALUE;
    // find the smallest and the biggest X coordinate in all the UI infos in the flow
    WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
    for (NodeContainerUI nc : manager.getNodeContainers()) {
        int nodeWidth = NodeContainerFigure.WIDTH;
        NodeAnnotation nodeAnno = nc.getNodeAnnotation();
        if ((nodeAnno != null) && (nodeAnno.getWidth() > nodeWidth)) {
            nodeWidth = nodeAnno.getWidth();
        }
        NodeUIInformation uiInfo = nc.getUIInformation();
        if (uiInfo != null) {
            int x = uiInfo.getBounds()[0];
            // right border of node
            x = x + (nodeWidth / 2);
            if (maxX < x) {
                maxX = x;
            }
            // left border of node
            x = x - nodeWidth;
            if (minX > x) {
                minX = x;
            }
        }
    }
    for (WorkflowAnnotation anno : manager.getWorkflowAnnotations()) {
        int x = anno.getX();
        if (minX > x) {
            minX = x;
        }
        x = x + anno.getWidth();
        if (maxX < x) {
            maxX = x;
        }
    }
    for (ConnectionContainerUI conn : manager.getConnectionContainers()) {
        ConnectionUIInformation uiInfo = conn.getUIInfo();
        if (uiInfo != null) {
            int[][] bendpoints = uiInfo.getAllBendpoints();
            if (bendpoints != null) {
                for (int[] b : bendpoints) {
                    if (maxX < b[0]) {
                        maxX = b[0];
                    }
                    if (minX > b[0]) {
                        minX = b[0];
                    }
                }
            }
        }
    }
    return new int[] { minX, maxX };
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 7 with NodeAnnotation

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

the class NodeContainerEditPart method getNodeAnnotationEditPart.

/**
 * @return The associated node annotation edit part (maybe null).
 */
public final NodeAnnotationEditPart getNodeAnnotationEditPart() {
    NodeAnnotation nodeAnnotation = getNodeContainer().getNodeAnnotation();
    NodeAnnotationEditPart nodeAnnotationEditPart = (NodeAnnotationEditPart) getViewer().getEditPartRegistry().get(nodeAnnotation);
    return nodeAnnotationEditPart;
}
Also used : NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation)

Example 8 with NodeAnnotation

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

the class NodeAnnotationFigure method newContent.

/**
 * @param annotation the new annotation content
 */
public void newContent(final Annotation annotation) {
    boolean isNodeAnnotation = (annotation instanceof NodeAnnotation);
    String text;
    AnnotationData.StyleRange[] sr;
    if (AnnotationEditPart.isDefaultNodeAnnotation(annotation)) {
        text = AnnotationEditPart.getAnnotationText(annotation);
        sr = new AnnotationData.StyleRange[0];
    } else {
        text = annotation.getText();
        if (annotation.getStyleRanges() != null) {
            sr = Arrays.copyOf(annotation.getStyleRanges(), annotation.getStyleRanges().length);
        } else {
            sr = new AnnotationData.StyleRange[0];
        }
    }
    Arrays.sort(sr, new Comparator<AnnotationData.StyleRange>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(final AnnotationData.StyleRange o1, final AnnotationData.StyleRange o2) {
            if (o1.getStart() == o2.getStart()) {
                NodeLogger.getLogger(NodeAnnotationFigure.class).error("Ranges overlap");
                return 0;
            } else {
                return o1.getStart() < o2.getStart() ? -1 : 1;
            }
        }
    });
    Color bg = AnnotationEditPart.RGBintToColor(annotation.getBgColor());
    setBackgroundColor(bg);
    m_page.setBackgroundColor(bg);
    if (isNodeAnnotation && AnnotationEditPart.DEFAULT_BG_NODE.equals(bg)) {
        // node annotation are white if
        setOpaque(false);
    } else {
        setOpaque(true);
    }
    int i = 0;
    List<TextFlow> segments = new ArrayList<TextFlow>(sr.length);
    // in old flow annotations didn't store the font if system default was used. New annotations always store font
    // info. For backward compatibility use the system font if no font is specified here.
    final Font defaultFont;
    if (isNodeAnnotation) {
        defaultFont = AnnotationEditPart.getNodeAnnotationDefaultFont();
    } else if (annotation.getVersion() < AnnotationData.VERSION_20151012) {
        defaultFont = FontStore.INSTANCE.getSystemDefaultFont();
    } else if (annotation.getVersion() < AnnotationData.VERSION_20151123) {
        defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
    } else {
        if (annotation.getDefaultFontSize() < 0) {
            defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
        } else {
            defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont(annotation.getDefaultFontSize());
        }
    }
    for (AnnotationData.StyleRange r : sr) {
        // create text from last range to beginning of this range
        if (i < r.getStart()) {
            String noStyle = text.substring(i, r.getStart());
            if (isNodeAnnotation) {
                segments.add(getNodeAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
            } else {
                segments.add(getWorkflowAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
            }
            i = r.getStart();
        }
        String styled = text.substring(i, r.getStart() + r.getLength());
        segments.add(getStyled(styled, r, bg, defaultFont));
        i = r.getStart() + r.getLength();
    }
    if (i < text.length()) {
        String noStyle = text.substring(i, text.length());
        if (isNodeAnnotation) {
            segments.add(getNodeAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
        } else {
            segments.add(getWorkflowAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
        }
    }
    BlockFlow bf = new BlockFlow();
    BlockFlowLayout bfl = new BlockFlowLayout(bf);
    bfl.setContinueOnSameLine(true);
    bf.setLayoutManager(bfl);
    int position;
    switch(annotation.getAlignment()) {
        case CENTER:
            position = PositionConstants.CENTER;
            break;
        case RIGHT:
            position = PositionConstants.RIGHT;
            break;
        default:
            position = PositionConstants.LEFT;
    }
    bf.setHorizontalAligment(position);
    bf.setOrientation(SWT.LEFT_TO_RIGHT);
    bf.setBackgroundColor(bg);
    for (TextFlow tf : segments) {
        bf.add(tf);
    }
    m_page.removeAll();
    m_page.add(bf);
    m_page.setVisible(true);
    revalidate();
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) Font(org.eclipse.swt.graphics.Font) BlockFlowLayout(org.eclipse.draw2d.text.BlockFlowLayout) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) BlockFlow(org.eclipse.draw2d.text.BlockFlow) TextFlow(org.eclipse.draw2d.text.TextFlow)

Aggregations

NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)8 Annotation (org.knime.core.node.workflow.Annotation)3 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)3 ArrayList (java.util.ArrayList)2 EditPart (org.eclipse.gef.EditPart)2 Font (org.eclipse.swt.graphics.Font)2 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)2 ConnectionContainerUI (org.knime.core.ui.node.workflow.ConnectionContainerUI)2 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)2 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)2 List (java.util.List)1 IFigure (org.eclipse.draw2d.IFigure)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)1 BlockFlow (org.eclipse.draw2d.text.BlockFlow)1