Search in sources :

Example 16 with Bend

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

the class VisualPropertyIconFactory method createIcon.

public static <V> Icon createIcon(V value, int w, int h) {
    if (value == null)
        return null;
    Icon icon = null;
    if (value instanceof Color) {
        icon = new ColorIcon((Color) value, w, h, value.toString());
    } else if (value instanceof NodeShape) {
        final DNodeShape dShape;
        if (NodeShapeVisualProperty.isDefaultShape((NodeShape) value))
            dShape = DNodeShape.getDShape((NodeShape) value);
        else
            dShape = (DNodeShape) value;
        icon = new NodeIcon(dShape.getShape(), w, h, dShape.getDisplayName());
    } else if (value instanceof LineType) {
        icon = new StrokeIcon(DLineType.getDLineType((LineType) value).getStroke(2f), w, h, value.toString());
    } else if (value instanceof CyCustomGraphics) {
        final String name = ((CyCustomGraphics) value).getDisplayName();
        if (name != null)
            icon = new CustomGraphicsIcon(((CyCustomGraphics) value), w, h, name);
    } else if (value instanceof ObjectPosition) {
        icon = new ObjectPositionIcon((ObjectPosition) value, w, h, "Label");
    } else if (value instanceof Font) {
        icon = new FontFaceIcon((Font) value, w, h, "");
    } else if (value instanceof ArrowShape) {
        final ArrowShape arrowShape = (ArrowShape) value;
        final DArrowShape dShape;
        if (ArrowShapeVisualProperty.isDefaultShape(arrowShape))
            dShape = DArrowShape.getArrowShape(arrowShape);
        else
            dShape = DArrowShape.NONE;
        if (dShape.getShape() == null)
            // No arrow
            icon = new TextIcon(value, w, h, "");
        else
            icon = new ArrowIcon(dShape.getShape(), w, h, dShape.getDisplayName());
    } else if (value instanceof Bend) {
        icon = new EdgeBendIcon((Bend) value, w, h, value.toString());
    } else {
        // If not found, use return value of toString() as icon.
        icon = new TextIcon(value, w, h, value.toString());
    }
    return icon;
}
Also used : CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) Bend(org.cytoscape.view.presentation.property.values.Bend) Color(java.awt.Color) Font(java.awt.Font) ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) DNodeShape(org.cytoscape.ding.DNodeShape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) DNodeShape(org.cytoscape.ding.DNodeShape) Icon(javax.swing.Icon) LineType(org.cytoscape.view.presentation.property.values.LineType) DLineType(org.cytoscape.ding.impl.DLineType)

Example 17 with Bend

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

the class EdgeBendPropertyEditor method editBend.

private void editBend() {
    final Bend newVal = valueEditor.showEditor(null, bend);
    if (newVal != null) {
        setValue(newVal);
        firePropertyChange(null, newVal);
    }
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend)

Example 18 with Bend

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

the class EdgeBundlerTask method render.

private final void render(final Collection<View<CyEdge>> edges, final HandleFactory hf, final BendFactory bf, final VisualMappingManager vmm, final VisualMappingFunctionFactory discreteFactory) {
    final VisualStyle style = vmm.getVisualStyle(view);
    // Check existing mapping
    VisualMappingFunction<?, Bend> bendMapping = style.getVisualMappingFunction(EDGE_BEND);
    final Map<Long, Bend> mappingValues;
    Map<Long, Bend> existingMap = null;
    if (bendMapping != null && bendMapping instanceof DiscreteMapping) {
        final String columnName = bendMapping.getMappingColumnName();
        if (columnName.equals(BEND_MAP_COLUMN)) {
            existingMap = ((DiscreteMapping<Long, Bend>) bendMapping).getAll();
        } else {
            bendMapping = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
        }
    }
    mappingValues = new HashMap<>();
    final CyNetwork network = view.getModel();
    final CyTable edgeTable = network.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS);
    final CyColumn bendMapColumn = edgeTable.getColumn(BEND_MAP_COLUMN);
    if (bendMapColumn == null) {
        edgeTable.createColumn(BEND_MAP_COLUMN, Long.class, false);
    }
    int ei = 0;
    for (final View<CyEdge> edge : edges) {
        final Long edgeId = edge.getModel().getSUID();
        final View<CyNode> eSource = view.getNodeView(edge.getModel().getSource());
        final View<CyNode> eTarget = view.getNodeView(edge.getModel().getTarget());
        network.getRow(edge.getModel()).set(BEND_MAP_COLUMN, edgeId);
        // Ignore self-edge
        if (eSource.getSUID().equals(eTarget.getSUID()))
            continue;
        final Bend bend = bf.createBend();
        final List<Handle> hlist = bend.getAllHandles();
        for (int ni = 0; ni < numNubs; ni++) {
            final double x = nubs[ni][0][ei];
            final double y = nubs[ni][1][ei];
            final Handle h = hf.createHandle(view, edge, x, y);
            hlist.add(h);
        }
        mappingValues.put(edgeId, bend);
        ei++;
    }
    if (bendMapping == null) {
        // Create new discrete mapping for edge SUID to Edge Bend
        final DiscreteMapping<Long, Bend> function = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
        style.addVisualMappingFunction(function);
        function.putAll(mappingValues);
    } else {
        if (existingMap != null) {
            mappingValues.putAll(existingMap);
        }
        ((DiscreteMapping<Long, Bend>) bendMapping).putAll(mappingValues);
    }
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) Handle(org.cytoscape.view.presentation.property.values.Handle) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 19 with Bend

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

the class GenericXGMMLReader method setEdgeViewProperties.

protected void setEdgeViewProperties(final CyNetworkView netView, final View<CyEdge> edgeView) {
    final CyEdge edge = edgeView.getModel();
    final Map<String, String> atts = readDataMgr.getGraphicsAttributes(edge);
    setVisualProperties(netView, edgeView, atts);
    // For 2.x compatibility
    final Bend bend = edgeView.getVisualProperty(BasicVisualLexicon.EDGE_BEND);
    if (bend != null && bend != EdgeBendVisualProperty.DEFAULT_EDGE_BEND) {
        final List<Handle> handles = bend.getAllHandles();
        for (final Handle handle : handles) handle.defineHandle(netView, edgeView, Double.NaN, Double.NaN);
    }
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) CyEdge(org.cytoscape.model.CyEdge) 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