Search in sources :

Example 1 with Bend

use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.

the class BendImpl method parseSerializableString.

public static Bend parseSerializableString(String strRepresentation) {
    final Bend bend = new BendImpl();
    // Validate
    if (strRepresentation == null)
        return bend;
    final String[] parts = strRepresentation.split("\\|");
    for (int i = 0; i < parts.length; i++) {
        final String str = parts[i];
        final Handle handle = HandleImpl.parseSerializableString(str);
        if (handle != null)
            bend.insertHandleAt(i, handle);
    }
    return bend;
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) Handle(org.cytoscape.view.presentation.property.values.Handle)

Example 2 with Bend

use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.

the class DEdgeView method numAnchors.

// Interface org.cytoscape.graph.render.immed.EdgeAnchors:
@Override
public int numAnchors() {
    final Bend bend;
    if (isValueLocked(DVisualLexicon.EDGE_BEND))
        bend = this.getVisualProperty(DVisualLexicon.EDGE_BEND);
    else
        bend = graphView.m_edgeDetails.getBend(model);
    final int numHandles = bend.getAllHandles().size();
    if (numHandles == 0)
        return 0;
    if (graphView.m_edgeDetails.getLineCurved(model) == EdgeView.CURVED_LINES)
        return numHandles;
    else
        return 2 * numHandles;
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint)

Example 3 with Bend

use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.

the class DEdgeView method removeHandle.

void removeHandle(int inx) {
    synchronized (graphView.m_lock) {
        final Bend bend = graphView.m_edgeDetails.getBend(model);
        bend.removeHandleAt(inx);
        if (selected) {
            graphView.m_spacialA.delete((model.getSUID() << 6) | inx);
            graphView.m_selectedAnchors.delete((model.getSUID() << 6) | inx);
            for (int j = inx; j < bend.getAllHandles().size(); j++) {
                graphView.m_spacialA.exists((model.getSUID() << 6) | (j + 1), graphView.m_extentsBuff, 0);
                graphView.m_spacialA.delete((model.getSUID() << 6) | (j + 1));
                graphView.m_spacialA.insert((model.getSUID() << 6) | j, graphView.m_extentsBuff[0], graphView.m_extentsBuff[1], graphView.m_extentsBuff[2], graphView.m_extentsBuff[3], 0.0);
                if (graphView.m_selectedAnchors.delete((model.getSUID() << 6) | (j + 1)))
                    graphView.m_selectedAnchors.insert((model.getSUID() << 6) | j);
            }
        }
        graphView.setContentChanged();
    }
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint)

Example 4 with Bend

use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.

the class DEdgeView method applyVisualProperty.

/**
 * This method sets a mapped value.  NOT Defaults.
 */
@SuppressWarnings("unchecked")
@Override
protected <T, V extends T> void applyVisualProperty(final VisualProperty<? extends T> vpOriginal, V value) {
    VisualProperty<?> vp = vpOriginal;
    // Check to make sure our view hasn't gotten disconnected somewhere along the line
    if (graphView.getEdgeView(this.getModel()) == null)
        return;
    // If value is null, simply use the VP's default value.
    if (value == null)
        value = (V) vp.getDefault();
    if (vp == DVisualLexicon.EDGE_STROKE_SELECTED_PAINT) {
        setSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) {
        setUnselectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_WIDTH) {
        final float w = ((Number) value).floatValue();
        setStrokeWidth(w);
        setStroke(DLineType.getDLineType(lineType).getStroke(w));
    } else if (vp == DVisualLexicon.EDGE_LINE_TYPE) {
        lineType = (LineType) value;
        final Stroke newStroke = DLineType.getDLineType(lineType).getStroke(graphView.m_edgeDetails.getWidth(model));
        setStroke(newStroke);
    } else if (vp == DVisualLexicon.EDGE_TRANSPARENCY) {
        setTransparency(((Number) value).intValue());
    } else if (vp == DVisualLexicon.EDGE_LABEL_TRANSPARENCY) {
        final int labelTransparency = ((Number) value).intValue();
        setLabelTransparency(labelTransparency);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SELECTED_PAINT) {
        setSourceEdgeEndSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SELECTED_PAINT) {
        setTargetEdgeEndSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_UNSELECTED_PAINT) {
        setSourceEdgeEndPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_UNSELECTED_PAINT) {
        setTargetEdgeEndPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SIZE) {
        setSourceArrowSize(((Number) value).doubleValue());
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SIZE) {
        setTargetArrowSize(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.EDGE_SELECTED) {
        setSelected((Boolean) value);
    } else if (vp == BasicVisualLexicon.EDGE_TARGET_ARROW_SHAPE) {
        final ArrowShape shape = (ArrowShape) value;
        final String shapeID = shape.getSerializableString();
        setTargetEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
    } else if (vp == BasicVisualLexicon.EDGE_SOURCE_ARROW_SHAPE) {
        final ArrowShape shape = (ArrowShape) value;
        final String shapeID = shape.getSerializableString();
        setSourceEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
    } else if (vp == BasicVisualLexicon.EDGE_LABEL) {
        setText(value.toString());
    } else if (vp == BasicVisualLexicon.EDGE_LABEL_WIDTH) {
        setLabelWidth(((Number) value).doubleValue());
    } else if (vp == DVisualLexicon.EDGE_TOOLTIP) {
        setToolTip(value.toString());
    } else if (vp == DVisualLexicon.EDGE_LABEL_FONT_FACE) {
        Font newFont = (Font) value;
        final Font f = getFont();
        if (f != null)
            newFont = f.deriveFont((float) f.getSize());
        setFont(newFont);
    } else if (vp == DVisualLexicon.EDGE_LABEL_FONT_SIZE) {
        float fontSize = ((Number) value).floatValue();
        final Font f = getFont();
        if (f != null)
            setFont(f.deriveFont(fontSize));
    } else if (vp == BasicVisualLexicon.EDGE_LABEL_COLOR) {
        setTextPaint((Paint) value);
    } else if (vp == BasicVisualLexicon.EDGE_VISIBLE) {
        if (((Boolean) value).booleanValue()) {
            graphView.showGraphObject(this);
            isVisible = true;
        } else {
            graphView.hideGraphObject(this);
            isVisible = false;
        }
    } else if (vp == DVisualLexicon.EDGE_CURVED) {
        final Boolean curved = (Boolean) value;
        if (curved)
            setLineCurved(EdgeView.CURVED_LINES);
        else
            setLineCurved(EdgeView.STRAIGHT_LINES);
    } else if (vp == DVisualLexicon.EDGE_BEND) {
        setBend((Bend) value);
    }
}
Also used : Stroke(java.awt.Stroke) AnimatedStroke(org.cytoscape.ding.impl.strokes.AnimatedStroke) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint) LineType(org.cytoscape.view.presentation.property.values.LineType) Font(java.awt.Font)

Example 5 with Bend

use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.

the class DEdgeView method addHandlePoint.

/**
 * Add a new handle and returns its index.
 *
 * @param pt location of handle
 * @return new handle index.
 */
protected int addHandlePoint(final Point2D pt) {
    synchronized (graphView.m_lock) {
        // Obtain existing Bend object
        final Bend bend = graphView.m_edgeDetails.getBend(model, true);
        if (bend.getAllHandles().size() == 0) {
            // anchors object is empty. Add first handle.
            addHandleInternal(0, pt);
            // Index of this handle, which is first (0)
            return 0;
        }
        final Point2D sourcePt = graphView.getDNodeView(getCyEdge().getSource()).getOffset();
        final Point2D targetPt = graphView.getDNodeView(getCyEdge().getTarget()).getOffset();
        final Handle firstHandle = bend.getAllHandles().get(0);
        final Point2D point = firstHandle.calculateHandleLocation(graphView.getViewModel(), this);
        double bestDist = (pt.distance(sourcePt) + pt.distance(point)) - sourcePt.distance(point);
        int bestInx = 0;
        for (int i = 1; i < bend.getAllHandles().size(); i++) {
            final Handle handle1 = bend.getAllHandles().get(i);
            final Handle handle2 = bend.getAllHandles().get(i - 1);
            final Point2D point1 = handle1.calculateHandleLocation(graphView.getViewModel(), this);
            final Point2D point2 = handle2.calculateHandleLocation(graphView.getViewModel(), this);
            final double distCand = (pt.distance(point2) + pt.distance(point1)) - point1.distance(point2);
            if (distCand < bestDist) {
                bestDist = distCand;
                bestInx = i;
            }
        }
        final int lastIndex = bend.getAllHandles().size() - 1;
        final Handle lastHandle = bend.getAllHandles().get(lastIndex);
        final Point2D lastPoint = lastHandle.calculateHandleLocation(graphView.getViewModel(), this);
        final double lastCand = (pt.distance(targetPt) + pt.distance(lastPoint)) - targetPt.distance(lastPoint);
        if (lastCand < bestDist) {
            bestDist = lastCand;
            bestInx = bend.getAllHandles().size();
        }
        addHandleInternal(bestInx, pt);
        return bestInx;
    }
}
Also used : Point2D(java.awt.geom.Point2D) Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint) Handle(org.cytoscape.view.presentation.property.values.Handle)

Aggregations

Bend (org.cytoscape.view.presentation.property.values.Bend)19 Handle (org.cytoscape.view.presentation.property.values.Handle)8 Paint (java.awt.Paint)5 Point2D (java.awt.geom.Point2D)5 Point (java.awt.Point)3 CyEdge (org.cytoscape.model.CyEdge)3 Font (java.awt.Font)2 Icon (javax.swing.Icon)2 DArrowShape (org.cytoscape.ding.DArrowShape)2 ViewChangeEdit (org.cytoscape.ding.ViewChangeEdit)2 CyNode (org.cytoscape.model.CyNode)2 LongEnumerator (org.cytoscape.util.intr.LongEnumerator)2 ArrowShape (org.cytoscape.view.presentation.property.values.ArrowShape)2 LineType (org.cytoscape.view.presentation.property.values.LineType)2 Color (java.awt.Color)1 Stroke (java.awt.Stroke)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 JLabel (javax.swing.JLabel)1