Search in sources :

Example 1 with CustomGraphicLayer

use of org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer in project cytoscape-impl by cytoscape.

the class DNodeView method applyVisualProperty.

@Override
@SuppressWarnings("unchecked")
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.getNodeView(this.getModel()) == null)
        return;
    // Null means set value to VP's default.
    if (value == null)
        value = (V) vp.getDefault();
    if (vp == DVisualLexicon.NODE_SHAPE) {
        setShape(((NodeShape) value));
    } else if (vp == DVisualLexicon.NODE_SELECTED_PAINT) {
        setSelectedPaint((Paint) value);
    } else if (vp == BasicVisualLexicon.NODE_SELECTED) {
        setSelected((Boolean) value);
    } else if (vp == BasicVisualLexicon.NODE_VISIBLE) {
        if (((Boolean) value).booleanValue()) {
            graphView.showGraphObject(this);
            isVisible = true;
        } else {
            graphView.hideGraphObject(this);
            isVisible = false;
        }
    } else if (vp == BasicVisualLexicon.NODE_FILL_COLOR) {
        setUnselectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.NODE_BORDER_PAINT) {
        setBorderPaint((Color) value);
    } else if (vp == DVisualLexicon.NODE_BORDER_TRANSPARENCY) {
        final Integer opacity = ((Number) value).intValue();
        setBorderTransparency(opacity);
    } else if (vp == DVisualLexicon.NODE_BORDER_WIDTH) {
        setBorderWidth(new Float(((Number) value).floatValue()));
    } else if (vp == DVisualLexicon.NODE_BORDER_LINE_TYPE) {
        final DLineType dLineType = DLineType.getDLineType((LineType) value);
        final float currentBorderWidth = graphView.m_nodeDetails.getBorderWidth(model);
        setBorder(dLineType.getStroke(currentBorderWidth));
    } else if (vp == DVisualLexicon.NODE_TRANSPARENCY) {
        setTransparency(((Number) value).intValue());
    } else if (vp == BasicVisualLexicon.NODE_WIDTH) {
        setWidth(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.NODE_HEIGHT) {
        setHeight(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.NODE_LABEL) {
        setText(value.toString());
    } else if (vp == BasicVisualLexicon.NODE_LABEL_WIDTH) {
        setLabelWidth(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.NODE_X_LOCATION) {
        setXPosition(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.NODE_Y_LOCATION) {
        setYPosition(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.NODE_Z_LOCATION) {
        setZPosition(((Number) value).doubleValue());
    } else if (vp == DVisualLexicon.NODE_TOOLTIP) {
        setToolTip(value.toString());
    } else if (vp == BasicVisualLexicon.NODE_LABEL_COLOR) {
        setTextPaint((Color) value);
    } else if (vp == BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) {
        final int opacity = ((Number) value).intValue();
        setLabelTransparency(opacity);
    } else if (vp == DVisualLexicon.NODE_LABEL_FONT_FACE) {
        final float currentFontSize = graphView.m_nodeDetails.getLabelFont(model, 0).getSize();
        final Font newFont = ((Font) value).deriveFont(currentFontSize);
        setFont(newFont);
    } else if (vp == DVisualLexicon.NODE_LABEL_FONT_SIZE) {
        final float newSize = ((Number) value).floatValue();
        final Font newFont = graphView.m_nodeDetails.getLabelFont(model, 0).deriveFont(newSize);
        setFont(newFont);
    } else if (vp == DVisualLexicon.NODE_LABEL_POSITION) {
        this.setLabelPosition((ObjectPosition) value);
    } else if (vp == BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE) {
        setNestedNetworkImgVisible(Boolean.TRUE.equals(value));
    } else if (vp instanceof CustomGraphicsVisualProperty) {
        setCustomGraphics((CustomGraphicsVisualProperty) vp, (CyCustomGraphics<CustomGraphicLayer>) value);
    } else if (vp instanceof ObjectPositionVisualProperty) {
        setCustomGraphicsPosition(vp, (ObjectPosition) value);
    } else if (CG_SIZE_PATTERN.matcher(vp.getIdString()).matches()) {
        setCustomGraphicsSize((VisualProperty<Double>) vp, (Double) value);
    }
}
Also used : CustomGraphicsVisualProperty(org.cytoscape.ding.impl.visualproperty.CustomGraphicsVisualProperty) Color(java.awt.Color) ObjectPositionVisualProperty(org.cytoscape.ding.impl.visualproperty.ObjectPositionVisualProperty) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) Font(java.awt.Font) ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape)

Example 2 with CustomGraphicLayer

use of org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer in project cytoscape-impl by cytoscape.

the class CustomGraphicsVisualProperty method parseSerializableString.

// Parse the string associated with our visual property.  Note that we depend on the first
// part of the string being the class name that was registered with the CyCustomGraphicsManager
@Override
@SuppressWarnings("unchecked")
public CyCustomGraphics<CustomGraphicLayer> parseSerializableString(String value) {
    CyCustomGraphics<CustomGraphicLayer> cg = null;
    if (value != null && !NullCustomGraphics.getNullObject().toString().equals(value) && !value.contains("NullCustomGraphics")) {
        String[] parts = value.split(":");
        // Skip over the chart/gradient factory id
        int offset = value.indexOf(":");
        // First check if it's a CyCustomGraphics2
        // ------------------------------
        // This is hack, but we've got no other way to get our hands on the
        // CyCustomGraphics2Manager this way, because the DVisualLexicon is created statically
        final CyCustomGraphics2ManagerImpl cfMgr = CyCustomGraphics2ManagerImpl.getInstance();
        final CyCustomGraphics2Factory<? extends CustomGraphicLayer> chartFactory = cfMgr.getCyCustomGraphics2Factory(parts[0]);
        if (chartFactory != null) {
            cg = (CyCustomGraphics<CustomGraphicLayer>) chartFactory.getInstance(value.substring(offset + 1));
        } else {
            // Then check if it's a CyCustomGraphics2
            // -------------------------------
            final CyCustomGraphics2ManagerImpl cgMgr = CyCustomGraphics2ManagerImpl.getInstance();
            final CyCustomGraphics2Factory<? extends CustomGraphicLayer> gradFactory = cgMgr.getCyCustomGraphics2Factory(parts[0]);
            if (gradFactory != null)
                cg = (CyCustomGraphics<CustomGraphicLayer>) gradFactory.getInstance(value.substring(offset + 1));
        }
        if (cg == null) {
            // Try to parse it as a regular custom graphics then
            // -------------------------------------------------
            // This is hack, but we've got no other way to get our hands on the
            // CyCustomGraphicsManager since the DVisualLexicon is created statically
            final CustomGraphicsManager cgMgr = CustomGraphicsManagerImpl.getInstance();
            parts = value.split(",");
            final CyCustomGraphicsFactory factory = cgMgr.getCustomGraphicsFactory(parts[0]);
            if (factory != null) {
                // Skip over the class name
                offset = value.indexOf(",");
                cg = factory.parseSerializableString(value.substring(offset + 1));
            }
        }
    }
    return cg != null ? cg : NullCustomGraphics.getNullObject();
}
Also used : CyCustomGraphics2ManagerImpl(org.cytoscape.ding.customgraphics.CyCustomGraphics2ManagerImpl) CyCustomGraphicsFactory(org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory) CyCustomGraphics(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) CustomGraphicsManager(org.cytoscape.ding.customgraphics.CustomGraphicsManager)

Example 3 with CustomGraphicLayer

use of org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer in project cytoscape-impl by cytoscape.

the class GradientOvalLayer method update.

public void update() {
    // First, remove all layers.
    layers.clear();
    shape = new Ellipse2D.Double(-width / 2, -height / 2, width, height);
    paintFactory = new RadialGradientPaintFactory(colorList, stopList);
    final CustomGraphicLayer cg = new PaintCustomGraphic(shape, paintFactory);
    layers.add(cg);
}
Also used : CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) RadialGradientPaintFactory(org.cytoscape.ding.customgraphics.paint.RadialGradientPaintFactory) Ellipse2D(java.awt.geom.Ellipse2D)

Example 4 with CustomGraphicLayer

use of org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer in project cytoscape-impl by cytoscape.

the class CustomGraphicsInfo method createLayers.

public List<CustomGraphicLayer> createLayers(final CyNetworkView netView, final View<CyNode> nodeView, final NodeDetails details, final Set<VisualPropertyDependency<?>> dependencies) {
    final List<CustomGraphicLayer> transformedLayers = new ArrayList<>();
    if (customGraphics == null)
        return transformedLayers;
    final List<? extends CustomGraphicLayer> originalLayers = customGraphics.getLayers(netView, nodeView);
    if (originalLayers == null || originalLayers.isEmpty())
        return transformedLayers;
    final CyNode node = nodeView.getModel();
    final float fitRatio = customGraphics.getFitRatio();
    // Check dependency. Sync size or not.
    boolean sync = syncToNode(dependencies);
    Double cgSize = size;
    ObjectPosition cgPos = position;
    final double nw = details.getWidth(node);
    final double nh = details.getHeight(node);
    for (CustomGraphicLayer layer : originalLayers) {
        // Assume it's a Ding layer
        CustomGraphicLayer finalLayer = layer;
        // Resize the layer
        double cgw = 0.0;
        double cgh = 0.0;
        if (sync) {
            // Size is locked to node size.
            final float bw = details.getBorderWidth(node);
            cgw = nw - bw;
            cgh = nh - bw;
        } else {
            // Width and height should be set to custom size
            if (cgSize == null) {
                final VisualProperty<Double> sizeVP = DVisualLexicon.getAssociatedCustomGraphicsSizeVP(visualProperty);
                cgSize = nodeView.getVisualProperty(sizeVP);
            }
            if (cgSize != null)
                cgw = cgh = cgSize;
        }
        if (cgw > 0.0 && cgh > 0.0)
            finalLayer = syncSize(layer, cgw, cgh, fitRatio);
        // Move the layer to the correct position
        if (cgPos == null)
            cgPos = ObjectPosition.DEFAULT_POSITION;
        finalLayer = moveLayer(finalLayer, cgPos, nw, nh);
        transformedLayers.add(finalLayer);
    }
    return transformedLayers;
}
Also used : ObjectPosition(org.cytoscape.view.presentation.property.values.ObjectPosition) ImageCustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode)

Example 5 with CustomGraphicLayer

use of org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer in project cytoscape-impl by cytoscape.

the class GraphRenderer method renderNodeHigh.

/**
 * Render node view with details, including custom graphics.
 */
@SuppressWarnings("rawtypes")
private static final void renderNodeHigh(final CyNetworkView netView, final GraphGraphics grafx, final CyNode cyNode, final float[] floatBuff1, final double[] doubleBuff1, final double[] doubleBuff2, final NodeDetails nodeDetails, final int lodBits, final Set<VisualPropertyDependency<?>> dependencies) {
    Shape nodeShape = null;
    if ((floatBuff1[0] != floatBuff1[2]) && (floatBuff1[1] != floatBuff1[3])) {
        // Compute visual attributes that do not depend on LOD.
        final byte shape = nodeDetails.getShape(cyNode);
        final Paint fillPaint = nodeDetails.getFillPaint(cyNode);
        // Compute node border information.
        final float borderWidth;
        final Paint borderPaint;
        Stroke borderStroke = null;
        if ((lodBits & LOD_NODE_BORDERS) == 0) {
            // Not rendering borders.
            borderWidth = 0.0f;
            borderPaint = null;
        } else {
            // Rendering node borders.
            borderWidth = nodeDetails.getBorderWidth(cyNode);
            borderStroke = nodeDetails.getBorderStroke(cyNode);
            if (borderWidth == 0.0f)
                borderPaint = null;
            else
                borderPaint = nodeDetails.getBorderPaint(cyNode);
        }
        // Draw the node.
        nodeShape = grafx.drawNodeFull(shape, floatBuff1[0], floatBuff1[1], floatBuff1[2], floatBuff1[3], fillPaint, borderWidth, borderStroke, borderPaint);
    }
    // Take care of custom graphic rendering.
    if ((lodBits & LOD_CUSTOM_GRAPHICS) != 0) {
        // draw any nested networks first
        final TexturePaint nestedNetworkPaint = nodeDetails.getNestedNetworkTexturePaint(cyNode);
        if (nestedNetworkPaint != null) {
            doubleBuff1[0] = floatBuff1[0];
            doubleBuff1[1] = floatBuff1[1];
            doubleBuff1[2] = floatBuff1[2];
            doubleBuff1[3] = floatBuff1[3];
            lemma_computeAnchor(Position.CENTER, doubleBuff1, doubleBuff2);
            grafx.drawCustomGraphicImage(nestedNetworkPaint.getAnchorRect(), (float) doubleBuff2[0], (float) doubleBuff2[1], nestedNetworkPaint);
        }
        // don't allow our custom graphics to mutate while we iterate over them:
        synchronized (nodeDetails.customGraphicsLock(cyNode)) {
            final View<CyNode> nodeView = netView.getNodeView(cyNode);
            // This method should return CustomGraphics in rendering order:
            final Map<VisualProperty<CyCustomGraphics>, CustomGraphicsInfo> cgMap = nodeDetails.getCustomGraphics(cyNode);
            final List<CustomGraphicsInfo> infoList = new ArrayList<>(cgMap.values());
            for (final CustomGraphicsInfo cgInfo : infoList) {
                final List<CustomGraphicLayer> layers = cgInfo.createLayers(netView, nodeView, nodeDetails, dependencies);
                // The graphic index used to retrieve non custom graphic info corresponds to the zero-based
                // index of the CustomGraphicLayer returned by the iterator:
                int graphicInx = 0;
                for (final CustomGraphicLayer layer : layers) {
                    final float offsetVectorX = nodeDetails.graphicOffsetVectorX(cyNode, graphicInx);
                    final float offsetVectorY = nodeDetails.graphicOffsetVectorY(cyNode, graphicInx);
                    doubleBuff1[0] = floatBuff1[0];
                    doubleBuff1[1] = floatBuff1[1];
                    doubleBuff1[2] = floatBuff1[2];
                    doubleBuff1[3] = floatBuff1[3];
                    lemma_computeAnchor(Position.CENTER, doubleBuff1, doubleBuff2);
                    float xOffset = (float) (doubleBuff2[0] + offsetVectorX);
                    float yOffset = (float) (doubleBuff2[1] + offsetVectorY);
                    nodeShape = createCustomGraphicsShape(nodeShape, layer, -xOffset, -yOffset);
                    grafx.drawCustomGraphicFull(netView, cyNode, nodeShape, layer, xOffset, yOffset);
                    graphicInx++;
                }
            }
        }
    }
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) ArrayList(java.util.ArrayList) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) CustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer) VisualProperty(org.cytoscape.view.model.VisualProperty) ArrowShapeVisualProperty(org.cytoscape.view.presentation.property.ArrowShapeVisualProperty) CyNode(org.cytoscape.model.CyNode)

Aggregations

CustomGraphicLayer (org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer)5 Paint (java.awt.Paint)2 TexturePaint (java.awt.TexturePaint)2 ArrayList (java.util.ArrayList)2 CyNode (org.cytoscape.model.CyNode)2 ObjectPosition (org.cytoscape.view.presentation.property.values.ObjectPosition)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1 Ellipse2D (java.awt.geom.Ellipse2D)1 CustomGraphicsManager (org.cytoscape.ding.customgraphics.CustomGraphicsManager)1 CyCustomGraphics2ManagerImpl (org.cytoscape.ding.customgraphics.CyCustomGraphics2ManagerImpl)1 RadialGradientPaintFactory (org.cytoscape.ding.customgraphics.paint.RadialGradientPaintFactory)1 CustomGraphicsVisualProperty (org.cytoscape.ding.impl.visualproperty.CustomGraphicsVisualProperty)1 ObjectPositionVisualProperty (org.cytoscape.ding.impl.visualproperty.ObjectPositionVisualProperty)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1 CyCustomGraphics (org.cytoscape.view.presentation.customgraphics.CyCustomGraphics)1 CyCustomGraphicsFactory (org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory)1 ImageCustomGraphicLayer (org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer)1