Search in sources :

Example 1 with ImageCustomGraphicLayer

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

the class GraphGraphics method drawCustomGraphicFull.

/**
 * Fills an arbitrary graphical shape with high detail.
 * <p>
 * This method will not work unless clear() has been called at least once
 * previously.
 *
 * @param nodeShape
 *            the node shape
 * @param cg
 *            the CustomGraphicLayer
 * @param xOffset
 *            in node coordinates, a value to add to the X coordinates of
 *            the shape's definition.
 * @param yOffset
 *            in node coordinates, a value to add to the Y coordinates of
 *            the shape's definition.
 */
public final void drawCustomGraphicFull(final CyNetworkView netView, final CyNode node, final Shape nodeShape, final CustomGraphicLayer cg, final float xOffset, final float yOffset) {
    if (m_debug) {
        checkDispatchThread();
        checkCleared();
    }
    m_g2d.translate(xOffset, yOffset);
    if (cg instanceof PaintedShape) {
        PaintedShape ps = (PaintedShape) cg;
        Shape shape = ps.getShape();
        if (ps.getStroke() != null) {
            Paint strokePaint = ps.getStrokePaint();
            if (strokePaint == null)
                strokePaint = Color.BLACK;
            m_g2d.setPaint(strokePaint);
            m_g2d.setStroke(ps.getStroke());
            m_g2d.draw(shape);
        }
        m_g2d.setPaint(ps.getPaint());
        m_g2d.fill(shape);
    } else if (cg instanceof Cy2DGraphicLayer) {
        Cy2DGraphicLayer layer = (Cy2DGraphicLayer) cg;
        final View<CyNode> view = (netView != null && node != null) ? netView.getNodeView(node) : null;
        layer.draw(m_g2d, nodeShape, netView, view);
    } else if (cg instanceof ImageCustomGraphicLayer) {
        Rectangle bounds = cg.getBounds2D().getBounds();
        final BufferedImage bImg = ((ImageCustomGraphicLayer) cg).getPaint(bounds).getImage();
        m_g2d.drawImage(bImg, bounds.x, bounds.y, bounds.width, bounds.height, null);
    } else {
        Rectangle2D bounds = nodeShape.getBounds2D();
        m_g2d.setPaint(cg.getPaint(bounds));
        m_g2d.fill(nodeShape);
    }
    m_g2d.setTransform(m_currNativeXform);
}
Also used : PaintedShape(org.cytoscape.view.presentation.customgraphics.PaintedShape) DiamondNodeShape(org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape) RoundedRectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape) Shape(java.awt.Shape) HexagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape) NodeShape(org.cytoscape.graph.render.immed.nodeshape.NodeShape) PaintedShape(org.cytoscape.view.presentation.customgraphics.PaintedShape) LegacyCustomNodeShape(org.cytoscape.graph.render.immed.nodeshape.LegacyCustomNodeShape) VeeNodeShape(org.cytoscape.graph.render.immed.nodeshape.VeeNodeShape) ParallelogramNodeShape(org.cytoscape.graph.render.immed.nodeshape.ParallelogramNodeShape) EllipseNodeShape(org.cytoscape.graph.render.immed.nodeshape.EllipseNodeShape) OctagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.OctagonNodeShape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) RectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape) TriangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape) Cy2DGraphicLayer(org.cytoscape.view.presentation.customgraphics.Cy2DGraphicLayer) ImageCustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ImageCustomGraphicLayer

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

the class CustomGraphicsInfo method syncSize.

private CustomGraphicLayer syncSize(final CustomGraphicLayer layer, double width, double height, float fitRatio) {
    final Rectangle2D originalBounds = layer.getBounds2D();
    // If this is just a paint, getBounds2D will return null and we can use our own width and height
    if (originalBounds == null)
        return layer;
    if (width == 0.0 || height == 0.0)
        return layer;
    final double cgW = originalBounds.getWidth();
    final double cgH = originalBounds.getHeight();
    // In case size is same, return the original.
    if (width == cgW && height == cgH)
        return layer;
    final AffineTransform xform;
    if (layer instanceof ImageCustomGraphicLayer) {
        // Case 1: Images - Find the maximum scale to which the graphics can be scaled while
        // fitting within the node's rectangle and maintaining its original aspect ratio
        double scale = Math.min(width / cgW, height / cgH);
        xform = AffineTransform.getScaleInstance(scale * fitRatio, scale * fitRatio);
    } else {
        // Case 2: If custom graphic is a vector or other implementation, fit to node's width and height
        xform = AffineTransform.getScaleInstance(fitRatio * width / cgW, fitRatio * height / cgH);
    }
    return layer.transform(xform);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) ImageCustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)2 ImageCustomGraphicLayer (org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer)2 Paint (java.awt.Paint)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 TexturePaint (java.awt.TexturePaint)1 AffineTransform (java.awt.geom.AffineTransform)1 BufferedImage (java.awt.image.BufferedImage)1 DiamondNodeShape (org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape)1 EllipseNodeShape (org.cytoscape.graph.render.immed.nodeshape.EllipseNodeShape)1 HexagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape)1 LegacyCustomNodeShape (org.cytoscape.graph.render.immed.nodeshape.LegacyCustomNodeShape)1 NodeShape (org.cytoscape.graph.render.immed.nodeshape.NodeShape)1 OctagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.OctagonNodeShape)1 ParallelogramNodeShape (org.cytoscape.graph.render.immed.nodeshape.ParallelogramNodeShape)1 RectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape)1 RoundedRectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape)1 TriangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape)1 VeeNodeShape (org.cytoscape.graph.render.immed.nodeshape.VeeNodeShape)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1