Search in sources :

Example 61 with IFigure

use of org.eclipse.draw2d.IFigure in project knime-core by knime.

the class InPortConnectionAnchor method getBox.

/**
 * @return The chop box for the in port figure
 */
@Override
protected Rectangle getBox() {
    IFigure owner = getOwner();
    if (!(owner instanceof AbstractPortFigure)) {
        return super.getBox();
    }
    AbstractPortFigure port = (AbstractPortFigure) owner;
    return port.computePortShapeBounds(port.getBounds());
}
Also used : AbstractPortFigure(org.knime.workbench.editor2.figures.AbstractPortFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 62 with IFigure

use of org.eclipse.draw2d.IFigure in project knime-core by knime.

the class SnapIconToGrid method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
    PrecisionRectangle r = rect;
    if (request instanceof ChangeBoundsRequest) {
        EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
        if (refPart instanceof NodeContainerEditPart) {
            // adjust the rectangle to snap the center of the icon of the node
            NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
            NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
            Point iconOffset = getIconOffset(fig);
            r = rect.getPreciseCopy();
            r.translate(iconOffset);
        } else if (refPart instanceof NodeAnnotationEditPart) {
            // the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
            NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
            WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
            IFigure annoFig = annoPart.getFigure();
            NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
            NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
            NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
            Point iconOffset = getIconOffset(nodeFig);
            int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
            xOff += iconOffset.x;
            int yOff = iconOffset.y - nodeFig.getBounds().height;
            r = rect.getPreciseCopy();
            r.translate(new Point(xOff, yOff));
        }
    }
    return super.snapRectangle(request, snapLocations, r, result);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 63 with IFigure

use of org.eclipse.draw2d.IFigure in project knime-core by knime.

the class NodeContainerFigure method setLabelText.

/**
 * Sets the text of the heading label.
 *
 * @param text The text to set.
 */
@SuppressWarnings("unchecked")
public void setLabelText(final String text) {
    m_label = text;
    m_headingContainer.removeAll();
    // needed, otherwise labels disappear after font size has changed
    m_headingContainer.setBounds(new Rectangle(0, 0, 0, 0));
    Font boldFont = FontStore.INSTANCE.getDefaultFontBold(FontStore.getFontSizeFromKNIMEPrefPage());
    m_headingContainer.setFont(boldFont);
    int width = 0;
    for (String s : wrapText(text).split("\n")) {
        Label l = new Label(s) {

            /**
             * {@inheritDoc}
             */
            @Override
            public Dimension getPreferredSize(final int wHint, final int hHint) {
                Dimension d = super.getPreferredSize(wHint, hHint).getCopy();
                // headings labels are too small when the editor is zoomed.
                d.width = (int) (d.width * 1.1);
                return d;
            }
        };
        l.setForegroundColor(ColorConstants.black);
        l.setFont(boldFont);
        m_headingContainer.add(l);
        Dimension size = l.getPreferredSize();
        width = Math.max(width, size.width);
    }
    int height = 0;
    for (IFigure child : (List<IFigure>) m_headingContainer.getChildren()) {
        Dimension size = child.getPreferredSize();
        int offset = (width - size.width) / 2;
        child.setBounds(new Rectangle(offset, height, size.width, size.height));
        height += size.height;
    }
    m_headingContainer.setBounds(new Rectangle(0, 0, width, height));
    repaint();
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Label(org.eclipse.draw2d.Label) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 64 with IFigure

use of org.eclipse.draw2d.IFigure in project knime-core by knime.

the class ProgressFigure method mouseEntered.

@Override
public void mouseEntered(final MouseEvent me) {
    m_mouseEvent = me;
    // tooltip
    if (m_currentProgressMessage != null && !m_currentProgressMessage.equals("") && m_mouseEvent != null) {
        IFigure tip = new Label(m_currentProgressMessage);
        getToolTipHelper().displayToolTipNear(ProgressFigure.this, tip, m_mouseEvent.x, m_mouseEvent.y);
    }
}
Also used : Label(org.eclipse.draw2d.Label) IFigure(org.eclipse.draw2d.IFigure)

Example 65 with IFigure

use of org.eclipse.draw2d.IFigure in project knime-core by knime.

the class WorkflowEditor method getClosestGridLocation.

/**
 * Returns the closest location that is located on the grid.
 *
 * @param loc reference point for the closest grid location, must be translated relative to the container
 * @return closest grid point
 */
public Point getClosestGridLocation(final Point loc) {
    Point location = loc.getCopy();
    IFigure gridContainer = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getFigure();
    gridContainer.translateToRelative(location);
    Point result = location.getCopy();
    int locX = loc.x;
    int gridX = getEditorGridX();
    if (gridX > 1) {
        // distance to the left grid line (or right, if locX is negative)
        int leftGrid = (locX / gridX) * gridX;
        if (Math.abs(locX - leftGrid) <= (gridX / 2)) {
            result.x = leftGrid;
        } else {
            // location is closer to the next grid (right of the location, or left if x is negative)
            result.x = leftGrid + (((int) Math.signum(locX)) * gridX);
        }
    }
    int locY = loc.y;
    int gridY = getEditorGridY();
    if (gridY > 1) {
        // distance to the next upper grid line (or lower line, if y is negative)
        int upperGrid = (locY / gridY) * gridY;
        if (Math.abs(locY - upperGrid) <= (gridY / 2)) {
            // location is closer to the upper grid line (or lower line, if y is negative)
            result.y = upperGrid;
        } else {
            // location is closer to the next lower grid
            result.y = upperGrid + (((int) Math.signum(locY)) * gridY);
        }
    }
    return result;
}
Also used : WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IFigure (org.eclipse.draw2d.IFigure)225 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)61 Rectangle (org.eclipse.draw2d.geometry.Rectangle)42 Point (org.eclipse.draw2d.geometry.Point)36 Dimension (org.eclipse.draw2d.geometry.Dimension)30 PropertyChangeEvent (java.beans.PropertyChangeEvent)25 PropertyChangeListener (java.beans.PropertyChangeListener)25 List (java.util.List)20 Figure (org.eclipse.draw2d.Figure)17 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)13 DefaultSizeNodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure)12 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)12 StackLayout (org.eclipse.draw2d.StackLayout)11 Iterator (java.util.Iterator)10 VType (org.diirt.vtype.VType)10 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)9 OPIColor (org.csstudio.opibuilder.util.OPIColor)9 EditPart (org.eclipse.gef.EditPart)9 ArrayList (java.util.ArrayList)7 Label (org.eclipse.draw2d.Label)7