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);
}
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);
}
Aggregations