Search in sources :

Example 1 with NodeShape

use of org.cytoscape.graph.render.immed.nodeshape.NodeShape in project cytoscape-impl by cytoscape.

the class GraphGraphics method drawNodeFull.

/**
 * Draws a node with medium to high detail, depending on parameters
 * specified. The xMin, yMin, xMax, and yMax parameters specify the extents
 * of the node shape (in the node coordinate system), including the border
 * width. That is, the drawn border won't extend beyond the extents
 * specified.
 * <p>
 * There is an imposed constraint on borderWidth which, using the
 * implemented algorithms, prevents strange-looking borders. The constraint
 * is that borderWidth may not exceed the minimum of the node width and node
 * height divided by six. In addition, for custom node shapes, this
 * requirement may be more constrained, depending on the kinks in the custom
 * node shape.
 * <p>
 * There is a constraint that only applies to SHAPE_ROUNDED_RECTANGLE which
 * imposes that the maximum of the width and height be strictly less than
 * twice the minimum of the width and height of the node.
 * <p>
 * This method will not work unless clear() has been called at least once
 * previously.
 *
 * @param nodeShape
 *            the shape of the node to draw (one of the SHAPE_* constants or
 *            a custom node shape).
 * @param xMin
 *            an extent of the node shape to draw, in node coordinate space;
 *            the drawn shape will theoretically contain a point that lies
 *            on this X coordinate.
 * @param yMin
 *            an extent of the node shape to draw, in node coordinate space;
 *            the drawn shape will theoretically contain a point that lies
 *            on this Y coordinate.
 * @param xMax
 *            an extent of the node shape to draw, in node coordinate space;
 *            the drawn shape will theoretically contain a point that lies
 *            on this X coordinate.
 * @param yMax
 *            an extent of the node shape to draw, in node coordinate space;
 *            the drawn shape will theoretically contain a point that lies
 *            on this Y coordinate.
 * @param fillPaint
 *            the paint to use when drawing the node area minus the border
 *            (the "interior" of the node).
 * @param borderWidth
 *            the border width, in node coordinate space; if this value is
 *            zero, the rendering engine skips over the process of rendering
 *            the border, which gives a significant performance boost.
 * @param borderPaint
 *            if borderWidth is not zero, this paint is used for rendering
 *            the node border; otherwise, this parameter is ignored (and may
 *            be null).
 * @exception IllegalArgumentException
 *                if xMin is not less than xMax or if yMin is not less than
 *                yMax, if borderWidth is negative or is greater than
 *                Math.min(xMax - xMin, yMax - yMin) / 6 (for custom node
 *                shapes borderWidth may be even more limited, depending on
 *                the specific shape), if nodeShape is
 *                SHAPE_ROUNDED_RECTANGLE and the condition max(width,
 *                height) < 2 * min(width, height) does not hold, or if
 *                nodeShape is neither one of the SHAPE_* constants nor a
 *                previously defined custom node shape.
 */
public final Shape drawNodeFull(final byte nodeShape, final float xMin, final float yMin, final float xMax, final float yMax, final Paint fillPaint, final float borderWidth, final Stroke borderStroke, final Paint borderPaint) {
    if (m_debug) {
        checkDispatchThread();
        checkCleared();
        checkOrder(xMin, xMax, "x");
        checkOrder(yMin, yMax, "y");
        if (!(borderWidth >= 0.0f)) {
            throw new IllegalArgumentException("borderWidth not zero or positive");
        }
        if (!((6.0d * borderWidth) <= Math.min(((double) xMax) - xMin, ((double) yMax) - yMin))) {
            throw new IllegalArgumentException("borderWidth is not less than the minimum of node width and node " + "height divided by six");
        }
    }
    // border offset
    final float off = borderWidth / 2.0f;
    final Shape sx = getShape(nodeShape, xMin + off, yMin + off, xMax - off, yMax - off);
    // Draw border only when width is not zero.
    if (borderWidth > 0.0f) {
        m_g2d.setPaint(borderPaint);
        if (borderStroke != null)
            m_g2d.setStroke(borderStroke);
        else
            m_g2d.setStroke(getStroke(borderWidth));
        m_g2d.draw(sx);
    }
    // System.out.println("Node shape = "+sx);
    // System.out.println("Node bounds = "+sx.getBounds2D());
    // System.out.println("Paint = "+fillPaint);
    m_g2d.setPaint(fillPaint);
    m_g2d.fill(sx);
    return sx;
}
Also used : 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)

Example 2 with NodeShape

use of org.cytoscape.graph.render.immed.nodeshape.NodeShape 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 3 with NodeShape

use of org.cytoscape.graph.render.immed.nodeshape.NodeShape in project cytoscape-impl by cytoscape.

the class GraphGraphics method computeEdgeIntersection.

/**
 * Computes the intersection point between a node outline and a line
 * segment; one point of the line segment lies at the center of the node
 * outline.
 * <p>
 * There is a constraint that only applies to SHAPE_ROUNDED_RECTANGLE which
 * imposes that the maximum of the width and height be strictly less than
 * twice the minimum of the width and height of the node.
 *
 * @param nodeShape
 *            the shape of the node in question; this must be one of the
 *            SHAPE_* constants or a custom node shape.
 * @param xMin
 *            an extent of the node in question, in node coordinate space.
 * @param yMin
 *            an extent of the node in question, in node coordinate space.
 * @param xMax
 *            an extent of the node in question, in node coordinate space.
 * @param yMax
 *            an extent of the node in question, in node coordinate space.
 * @param offset
 *            most of the time this value will be zero, in which case the
 *            point computed is the exact intersection point of line segment
 *            and node outline; if this value is greater than zero, the
 *            point computed is one that lies on the line segment, is
 *            "outside" of the node outline, and is distance offset from the
 *            node outline.
 * @param ptX
 *            specifies the X coordinate of the endpoint of the line segment
 *            that is not the endpoint lying in the center of the node
 *            shape.
 * @param ptY
 *            specifies the Y coordinate of the endpoint of the line segment
 *            that is not the endpoint lying in the center of the node
 *            shape.
 * @param returnVal
 *            if true is returned, returnVal[0] is set to be the X
 *            coordinate of the computed point and returnVal[1] is set to be
 *            the Y coordinate of the computed point; if false is returned,
 *            this array is not modified.
 * @return true if and only if a point matching our criteria exists.
 * @exception IllegalArgumentException
 *                if xMin is not less than xMax or if yMin is not less than
 *                yMax, if offset is negative, if nodeShape is
 *                SHAPE_ROUNDED_RECTANGLE and the condition max(width,
 *                height) < 2 * min(width, height) does not hold, or if
 *                nodeShape is neither one of the SHAPE_* constants nor a
 *                previously defined custom node shape.
 */
public final boolean computeEdgeIntersection(final byte nodeShape, final float xMin, final float yMin, final float xMax, final float yMax, final float offset, final float ptX, final float ptY, final float[] returnVal) {
    if (m_debug) {
        checkDispatchThread();
        checkOrder(xMin, xMax, "x");
        checkOrder(yMin, yMax, "y");
        if (offset < 0.0f) {
            throw new IllegalArgumentException("offset < 0");
        }
    }
    NodeShape ns = nodeShapes.get(nodeShape);
    if (ns == null)
        return false;
    else
        return ns.computeEdgeIntersection(xMin, yMin, xMax, yMax, ptX, ptY, returnVal);
}
Also used : DiamondNodeShape(org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape) RoundedRectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape) HexagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape) NodeShape(org.cytoscape.graph.render.immed.nodeshape.NodeShape) 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) RectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape) TriangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape)

Example 4 with NodeShape

use of org.cytoscape.graph.render.immed.nodeshape.NodeShape in project cytoscape-impl by cytoscape.

the class GraphGraphics method getNodeShapes.

/**
 * get list of node shapes.
 *
 * @return A map of node shape bytes to Shape objects.
 */
public static Map<Byte, Shape> getNodeShapes() {
    final Map<Byte, Shape> shapeMap = new HashMap<Byte, Shape>();
    for (NodeShape ns : nodeShapes.values()) {
        final Shape shape = ns.getShape(0f, 0f, DEF_SHAPE_SIZE, DEF_SHAPE_SIZE);
        shapeMap.put(ns.getType(), new GeneralPath(shape));
    }
    return shapeMap;
}
Also used : 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) GeneralPath(java.awt.geom.GeneralPath) HashMap(java.util.HashMap) DiamondNodeShape(org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape) RoundedRectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape) HexagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape) NodeShape(org.cytoscape.graph.render.immed.nodeshape.NodeShape) 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) RectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape) TriangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape)

Aggregations

DiamondNodeShape (org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape)4 EllipseNodeShape (org.cytoscape.graph.render.immed.nodeshape.EllipseNodeShape)4 HexagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape)4 LegacyCustomNodeShape (org.cytoscape.graph.render.immed.nodeshape.LegacyCustomNodeShape)4 NodeShape (org.cytoscape.graph.render.immed.nodeshape.NodeShape)4 OctagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.OctagonNodeShape)4 ParallelogramNodeShape (org.cytoscape.graph.render.immed.nodeshape.ParallelogramNodeShape)4 RectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape)4 RoundedRectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape)4 TriangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape)4 VeeNodeShape (org.cytoscape.graph.render.immed.nodeshape.VeeNodeShape)4 Shape (java.awt.Shape)3 PaintedShape (org.cytoscape.view.presentation.customgraphics.PaintedShape)3 ArrowShape (org.cytoscape.view.presentation.property.values.ArrowShape)3 Paint (java.awt.Paint)1 Rectangle (java.awt.Rectangle)1 TexturePaint (java.awt.TexturePaint)1 GeneralPath (java.awt.geom.GeneralPath)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1