Search in sources :

Example 46 with Composite

use of java.awt.Composite in project cytoscape-impl by cytoscape.

the class ArrowAnnotationImpl method drawArrow.

public void drawArrow(Graphics g, boolean isPrinting) {
    if ((source == null || target == null) && !usedForPreviews)
        return;
    if (!usedForPreviews && !isPrinting)
        updateBounds();
    else
        arrowLine = getArrowLine(target, source);
    // Draw the line
    Graphics2D g2 = (Graphics2D) g;
    // Get the stroke
    float border = (float) (lineWidth / 2.0);
    if (!isPrinting && border < 1.0f)
        border = 1.0f;
    g2.setPaint(lineColor);
    g2.setStroke(new BasicStroke(border, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_ROUND, 10.0f));
    Line2D relativeLine = arrowLine != null ? getRelativeLine(arrowLine, 0.0, 0.0, 1.0, border) : null;
    if (relativeLine != null) {
        // Handle opacity
        if (lineColor instanceof Color) {
            int alpha = ((Color) lineColor).getAlpha();
            float opacity = (float) alpha / (float) 255;
            final Composite originalComposite = g2.getComposite();
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
            g2.draw(relativeLine);
            g2.setComposite(originalComposite);
        } else {
            g2.draw(relativeLine);
        }
    }
    g2.setStroke(new BasicStroke(border));
    // Add the head
    if (sourceType != ArrowType.NONE) {
        if (sourceColor == null)
            sourceColor = lineColor;
        GraphicsUtilities.drawArrow(g, relativeLine, ArrowEnd.SOURCE, sourceColor, sourceSize * 10.0 * getZoom(), sourceType);
    }
    if (targetType != ArrowType.NONE) {
        if (targetColor == null)
            targetColor = lineColor;
        GraphicsUtilities.drawArrow(g, relativeLine, ArrowEnd.TARGET, targetColor, targetSize * 10.0 * getZoom(), targetType);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 47 with Composite

use of java.awt.Composite in project cytoscape-impl by cytoscape.

the class AbstractChartLayer method draw.

@Override
public void draw(final Graphics2D g, final Shape shape, final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
    // Give JFreeChart a larger area to draw into, so the proportions of the chart elements looks better
    final double scale = 2.0;
    Rectangle2D newBounds = new Rectangle2D.Double(bounds.getX() * scale, bounds.getY() * scale, bounds.getWidth() * scale, bounds.getHeight() * scale);
    // Of course, we also have to ask Graphics2D to apply the inverse transformation
    final double invScale = 1.0 / scale;
    final AffineTransform at = new AffineTransform();
    at.scale(invScale, invScale);
    g.transform(at);
    // Check to see if we have a current alpha composite
    Composite comp = g.getComposite();
    if (comp instanceof AlphaComposite) {
        float alpha = ((AlphaComposite) comp).getAlpha();
        JFreeChart fc = getChart();
        Plot plot = fc.getPlot();
        plot.setForegroundAlpha(alpha);
        fc.draw(g, newBounds);
    } else {
        getChart().draw(g, newBounds);
    }
    // Make sure Graphics2D is "back to normal" before returning
    try {
        at.invert();
    } catch (NoninvertibleTransformException e) {
        e.printStackTrace();
    }
    g.transform(at);
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) JFreeChart(org.jfree.chart.JFreeChart)

Example 48 with Composite

use of java.awt.Composite in project cytoscape-impl by cytoscape.

the class OldGraphGraphics method clear.

/**
 * Clears image area with background paint specified and sets an appropriate
 * transformation of coordinate systems. See the class description for a
 * definition of the two coordinate systems: the node coordinate system and
 * the image coordinate system.
 * <p>
 * The background paint is not blended with colors that may already be on
 * the underlying image; if a translucent color is used in the background
 * paint, the underlying image itself becomes translucent.
 * <p>
 * It is mandatory to call this method before making the first rendering
 * call.
 *
 * @param bgPaint
 *            paint to use when clearing the image before painting a new
 *            frame; translucency is honored, provided that the underlying
 *            image supports it.
 * @param xCenter
 *            the X component of the translation transform for the frame
 *            about to be rendered; a node whose center is at the X
 *            coordinate xCenter will be rendered exactly in the middle of
 *            the image going across; increasing X values (in the node
 *            coordinate system) result in movement towards the right on the
 *            image.
 * @param yCenter
 *            the Y component of the translation transform for the frame
 *            about to be rendered; a node whose center is at the Y
 *            coordinate yCenter will be rendered exactly in the middle of
 *            the image going top to bottom; increasing Y values (in the
 *            node coordinate system) result in movement towards the bottom
 *            on the image.
 * @param scaleFactor
 *            the scaling that is to take place when rendering; a distance
 *            of 1 in node coordinates translates to a distance of
 *            scaleFactor in the image coordinate system (usually one unit
 *            in the image coordinate system equates to one pixel width).
 * @exception IllegalArgumentException
 *                if scaleFactor is not positive.
 */
public final void clear(final Paint bgPaint, final double xCenter, final double yCenter, final double scaleFactor) {
    if (m_debug) {
        if (!EventQueue.isDispatchThread()) {
            throw new IllegalStateException("calling thread is not AWT event dispatcher");
        }
        if (!(scaleFactor > 0.0d)) {
            throw new IllegalArgumentException("scaleFactor is not positive");
        }
    }
    if (m_gMinimal != null) {
        m_gMinimal.dispose();
        m_gMinimal = null;
    }
    if (m_g2d != null) {
        m_g2d.dispose();
    }
    m_g2d = (Graphics2D) image.getGraphics();
    final Composite origComposite = m_g2d.getComposite();
    m_g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
    m_g2d.setPaint(bgPaint);
    m_g2d.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    m_g2d.setComposite(origComposite);
    m_g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    m_g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    m_g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    m_g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    m_g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    setStroke(0.0f, 0.0f, BasicStroke.CAP_ROUND, true);
    m_currXform.setToTranslation(0.5d * image.getWidth(null), 0.5d * image.getHeight(null));
    m_currXform.scale(scaleFactor, scaleFactor);
    m_currXform.translate(-xCenter, -yCenter);
    m_g2d.transform(m_currXform);
    m_currNativeXform.setTransform(m_g2d.getTransform());
    m_cleared = true;
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite)

Example 49 with Composite

use of java.awt.Composite in project cytoscape-impl by cytoscape.

the class TextAnnotationImpl method drawAnnotation.

@Override
public void drawAnnotation(Graphics g, double x, double y, double scaleFactor) {
    if (text == null)
        return;
    super.drawAnnotation(g, x, y, scaleFactor);
    Graphics2D g2 = (Graphics2D) g;
    // System.out.println("drawAnnotation: setting text color to: "+textColor);
    g2.setPaint(textColor);
    // Font tFont = font.deriveFont(((float)(scaleFactor/getZoom()))*font.getSize2D());
    Font tFont = font.deriveFont(((float) (scaleFactor / getZoom())) * font.getSize2D());
    FontMetrics fontMetrics = g.getFontMetrics(tFont);
    int width = (int) ((double) getWidth() * scaleFactor / getZoom());
    int halfWidth = (width - fontMetrics.stringWidth(text)) / 2;
    // Note, this is + because we start at the baseline
    int height = (int) ((double) getHeight() * scaleFactor / getZoom());
    int halfHeight = (height + fontMetrics.getHeight() / 2) / 2;
    int xLoc = (int) (x * scaleFactor + halfWidth);
    int yLoc = (int) (y * scaleFactor + halfHeight);
    g2.setFont(tFont);
    // Handle opacity
    int alpha = textColor.getAlpha();
    float opacity = (float) alpha / (float) 255;
    final Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
    g2.drawString(text, xLoc, yLoc);
    g2.setComposite(originalComposite);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 50 with Composite

use of java.awt.Composite in project cytoscape-impl by cytoscape.

the class BoundedTextAnnotationImpl method drawAnnotation.

@Override
public void drawAnnotation(Graphics g, double x, double y, double scaleFactor) {
    super.drawAnnotation(g, x, y, scaleFactor);
    if (text == null || textColor == null || font == null)
        return;
    // For now, we put the text in the middle of the shape.  At some point, we may
    // want to add other options
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(textColor);
    int width = (int) ((double) getWidth() * scaleFactor / getZoom());
    int height = (int) ((double) getHeight() * scaleFactor / getZoom());
    Font tFont = font.deriveFont(((float) (scaleFactor / getZoom())) * font.getSize2D());
    FontMetrics fontMetrics = g.getFontMetrics(tFont);
    int halfWidth = (width - (int) (fontMetrics.stringWidth(text))) / 2;
    // Note, this is + because we start at the baseline
    // int halfHeight = ((int)(getHeight()*scaleFactor)+fontMetrics.getHeight()/2)/2;
    int halfHeight = (height + fontMetrics.getHeight() / 2) / 2;
    int xLoc = (int) (x * scaleFactor) + halfWidth;
    int yLoc = (int) (y * scaleFactor) + halfHeight;
    g2.setFont(tFont);
    // Handle opacity
    int alpha = textColor.getAlpha();
    float opacity = (float) alpha / (float) 255;
    final Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
    g2.drawString(text, xLoc, yLoc);
    g2.setComposite(originalComposite);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) Paint(java.awt.Paint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Aggregations

Composite (java.awt.Composite)294 AlphaComposite (java.awt.AlphaComposite)279 Graphics2D (java.awt.Graphics2D)134 Paint (java.awt.Paint)103 Rectangle2D (java.awt.geom.Rectangle2D)103 Color (java.awt.Color)81 Shape (java.awt.Shape)80 BasicStroke (java.awt.BasicStroke)55 Stroke (java.awt.Stroke)52 BufferedImage (java.awt.image.BufferedImage)51 AffineTransform (java.awt.geom.AffineTransform)39 Line2D (java.awt.geom.Line2D)38 Point (java.awt.Point)36 Rectangle (java.awt.Rectangle)36 Font (java.awt.Font)33 Point2D (java.awt.geom.Point2D)31 GradientPaint (java.awt.GradientPaint)27 Iterator (java.util.Iterator)26 PlotOrientation (org.jfree.chart.plot.PlotOrientation)25 GeneralPath (java.awt.geom.GeneralPath)24