Search in sources :

Example 91 with BasicStroke

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

the class GraphGraphicsTest method drawOldFull.

private long drawOldFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;
    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), Color.yellow);
    }
    long end = System.nanoTime();
    long nodeDur = end - begin;
    BasicStroke edgeStroke = new BasicStroke(1f);
    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f);
    }
    end = System.nanoTime();
    long duration = (end - begin) + nodeDur;
    return duration;
}
Also used : BasicStroke(java.awt.BasicStroke)

Example 92 with BasicStroke

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

the class OldGraphGraphics method setStroke.

private final void setStroke(final float width, final float dashLength, final int capType, final boolean ignoreCache) {
    if ((!ignoreCache) && (width == m_currStrokeWidth) && (dashLength == m_currDash[0]) && (capType == m_currCapType)) {
        return;
    }
    m_currStrokeWidth = width;
    m_currDash[0] = dashLength;
    m_currDash[1] = dashLength;
    m_currCapType = capType;
    // lots of new strokes if they constantly change.
    if (m_currDash[0] == 0.0f) {
        m_g2d.setStroke(new BasicStroke(width, capType, BasicStroke.JOIN_ROUND, 10.0f));
    } else {
        m_g2d.setStroke(new BasicStroke(width, capType, BasicStroke.JOIN_ROUND, 10.0f, m_currDash, 0.0f));
    }
}
Also used : BasicStroke(java.awt.BasicStroke)

Example 93 with BasicStroke

use of java.awt.BasicStroke in project AlgorithmsSolutions by Allenskoo856.

the class Draw method setPenRadius.

/**
 * Sets the radius of the pen to the given size.
 *
 * @param  r the radius of the pen
 * @throws IllegalArgumentException if r is negative
 */
public void setPenRadius(double r) {
    if (r < 0)
        throw new IllegalArgumentException("pen radius must be positive");
    penRadius = r * DEFAULT_SIZE;
    BasicStroke stroke = new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    // BasicStroke stroke = new BasicStroke((float) penRadius);
    offscreen.setStroke(stroke);
}
Also used : BasicStroke(java.awt.BasicStroke)

Example 94 with BasicStroke

use of java.awt.BasicStroke in project AlgorithmsSolutions by Allenskoo856.

the class StdDraw method setPenRadius.

/**
 * Sets the radius of the pen to the specified size.
 * The pen is circular, so that lines have rounded ends, and when you set the
 * pen radius and draw a point, you get a circle of the specified radius.
 * The pen radius is not affected by coordinate scaling.
 *
 * @param  radius the radius of the pen
 * @throws IllegalArgumentException if {@code radius} is negative
 */
public static void setPenRadius(double radius) {
    if (!(radius >= 0))
        throw new IllegalArgumentException("pen radius must be nonnegative");
    penRadius = radius;
    float scaledPenRadius = (float) (radius * DEFAULT_SIZE);
    BasicStroke stroke = new BasicStroke(scaledPenRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    // BasicStroke stroke = new BasicStroke(scaledPenRadius);
    offscreen.setStroke(stroke);
}
Also used : BasicStroke(java.awt.BasicStroke)

Example 95 with BasicStroke

use of java.awt.BasicStroke in project imagej1 by imagej.

the class OverlayBrushTool method mousePressed.

public void mousePressed(ImagePlus imp, MouseEvent e) {
    ImageCanvas ic = imp.getCanvas();
    float x = (float) ic.offScreenXD(e.getX());
    float y = (float) ic.offScreenYD(e.getY());
    xStart = x;
    yStart = y;
    oldWidth = width;
    int ctrlMask = IJ.isMacintosh() ? InputEvent.META_MASK : InputEvent.CTRL_MASK;
    int resizeMask = InputEvent.SHIFT_MASK | ctrlMask;
    if ((e.getModifiers() & resizeMask) == resizeMask) {
        mode = DO_RESIZE;
        return;
    } else if ((e.getModifiers() & ctrlMask) != 0) {
        // Pick the color from image or overlay
        // Limitiation: no sub-pixel accuracy here.
        // Don't use awt.robot to pick the color, it is influenced by screen color calibration
        int[] rgbValues = imp.flatten().getPixel((int) x, (int) y);
        Color color = new Color(rgbValues[0], rgbValues[1], rgbValues[2]);
        boolean altKeyDown = (e.getModifiers() & InputEvent.ALT_MASK) != 0;
        if (altKeyDown)
            Toolbar.setBackgroundColor(color);
        else {
            Toolbar.setForegroundColor(color);
            if (gd != null)
                options.setColor(color);
        }
        mode = IDLE;
        return;
    }
    // prepare drawing
    mode = UNCONSTRAINED;
    path = new GeneralPath();
    path.moveTo(x, y);
    newPath = true;
    stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, /*CAP_BUTT*/
    BasicStroke.JOIN_ROUND);
}
Also used : BasicStroke(java.awt.BasicStroke)

Aggregations

BasicStroke (java.awt.BasicStroke)571 Graphics2D (java.awt.Graphics2D)179 Color (java.awt.Color)164 Stroke (java.awt.Stroke)141 GradientPaint (java.awt.GradientPaint)96 Test (org.junit.Test)93 Rectangle2D (java.awt.geom.Rectangle2D)71 Paint (java.awt.Paint)64 Font (java.awt.Font)61 Point (java.awt.Point)47 Line2D (java.awt.geom.Line2D)47 BufferedImage (java.awt.image.BufferedImage)43 Shape (java.awt.Shape)39 Point2D (java.awt.geom.Point2D)38 AffineTransform (java.awt.geom.AffineTransform)34 JFreeChart (org.jfree.chart.JFreeChart)34 Rectangle (java.awt.Rectangle)27 Ellipse2D (java.awt.geom.Ellipse2D)27 RectangleInsets (org.jfree.ui.RectangleInsets)27 NumberAxis (org.jfree.chart.axis.NumberAxis)25