Example usage for java.awt Graphics2D setStroke

List of usage examples for java.awt Graphics2D setStroke

Introduction

In this page you can find the example usage for java.awt Graphics2D setStroke.

Prototype

public abstract void setStroke(Stroke s);

Source Link

Document

Sets the Stroke for the Graphics2D context.

Usage

From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java

protected void noiseEffects(Graphics2D gfx, BufferedImage image) {
    // XOR circle
    int dx = randomInt(width, 2 * width);
    int dy = randomInt(width, 2 * height);
    int x = randomInt(0, width / 2);
    int y = randomInt(0, height / 2);

    gfx.setXORMode(Color.GRAY);/*from  w w  w .  j  a va2 s.  c o  m*/
    if (config.isFontSizeRandom())
        gfx.setStroke(new BasicStroke(randomInt(config.getFontSize() / 8, config.getFontSize() / 2)));
    else
        gfx.setStroke(new BasicStroke(config.getFontSize()));

    gfx.drawOval(x, y, dx, dy);

    WritableRaster rstr = image.getRaster();
    int[] vColor = new int[3];
    int[] oldColor = new int[3];
    Random vRandom = new Random(System.currentTimeMillis());
    // noise
    for (x = 0; x < width; x++) {
        for (y = 0; y < height; y++) {
            rstr.getPixel(x, y, oldColor);

            // hard noise
            vColor[0] = 0 + (int) (Math.floor(vRandom.nextFloat() * 1.03) * 255);
            // soft noise
            vColor[0] = vColor[0] ^ (170 + (int) (vRandom.nextFloat() * 80));
            // xor to image
            vColor[0] = vColor[0] ^ oldColor[0];
            vColor[1] = vColor[0];
            vColor[2] = vColor[0];

            rstr.setPixel(x, y, vColor);
        }
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void paintInteraction(Graphics2D g, StateRenderer2D source) {
    super.paintInteraction(g, source);
    g.setStroke(new BasicStroke(1f));
    paint(g, source);/* w w w. j a  v a2s  . c  o m*/
    AssetPosition pivot = intercepted;
    if (pivot != null) {
        Point2D pt = source.getScreenPosition(pivot.getLoc());
        g.setColor(Color.white);
        g.draw(new Ellipse2D.Double(pt.getX() - 6, pt.getY() - 6, 12, 12));
        if (assetProperties.containsKey(pivot.getAssetName()))
            pivot.putExtra("Description", assetProperties.get(pivot.getAssetName()).description);
        if (assetProperties.containsKey(pivot.getAssetName()))
            pivot.putExtra("Friendly name", assetProperties.get(pivot.getAssetName()).friendly);

        lbl.setOpaque(true);
        lbl.setBackground(new Color(255, 255, 255, 128));
        lbl.setText(pivot.getHtml());
        Dimension d = lbl.getPreferredSize();
        lbl.setSize(d);
        Graphics copy = g.create();
        copy.translate(10, 10);
        lbl.paint(copy);
    }

    for (AssetTrack t : assets.values()) {
        AssetPosition prev = t.getLatest();
        AssetPosition pred = t.getPrediction();

        if (prev != null && pred != null) {
            if (prev.getTimestamp() < oldestTimestampSelection
                    || prev.getTimestamp() > newestTimestampSelection)
                continue;
            g.setColor(new Color(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue(), 128));
            Point2D pt1 = source.getScreenPosition(prev.getLoc());
            Point2D pt2 = source.getScreenPosition(pred.getLoc());
            if (pt1.distance(pt2) < 1000)
                g.draw(new Line2D.Double(pt1, pt2));
        }
    }
}

From source file:TransformTranslation.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from   w  ww.  ja v  a 2  s .c  o m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    g2.transform(AffineTransform.getTranslateInstance(150, 0));

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformersRotation.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from   w ww .  j  ava2s  . co m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    g2.transform(AffineTransform.getRotateInstance(-Math.PI / 6));

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:business.ImageManager.java

public void doDrawCircle(Graphics2D big, int x, int y, Color color) {
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(new BasicStroke());
    big.setColor(color);/*  w w  w. jav a  2 s .  c om*/

    //draw on graph
    big.drawOval(x, x, y, y);
}

From source file:FontRenderContextRenderingHints.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2D.setRenderingHints(qualityHints);

    AffineTransform at = new AffineTransform();
    at.setToTranslation(-300, -400);/*from w ww.j ava2  s  . c o  m*/
    at.shear(-0.5, 0.0);
    FontRenderContext frc = new FontRenderContext(at, false, false);
    TextLayout tl = new TextLayout("World!", font, frc);
    Shape outline = tl.getOutline(null);
    g2D.setColor(Color.blue);

    BasicStroke wideStroke = new BasicStroke(2.0f);
    g2D.setStroke(wideStroke);
    g2D.draw(outline);

}

From source file:business.ImageManager.java

public ImageIcon getArrow(double angle) {
    BufferedImage img = new BufferedImage(40, 40, BufferedImage.TRANSLUCENT);
    Graphics2D big = img.createGraphics();
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(
            new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 5f }, 0f));
    big.setColor(Color.red);/*from   w w  w . j  a v  a2s  .  co  m*/

    int cx = this.getYellowBall().getIconWidth() / 2;
    int cy = this.getYellowBall().getIconHeight() / 2;
    AffineTransform at = AffineTransform.getTranslateInstance(cx, cy);
    at.rotate(Math.toRadians(angle));
    //        at.scale(2.0, 2.0);
    Shape shape = at.createTransformedShape(createArrow());
    big.setPaint(Color.red);
    big.draw(shape);
    ImageIcon ret = new ImageIcon(img);
    return (ret);
    //        tenta com o icone...angle.
}

From source file:business.ImageManager.java

private void doDrawPath(Graphics2D big, Point ori, Point dest, Color color) {
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(new BasicStroke(0.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f,
            new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f));
    big.setColor(color);/*  ww w . j  ava  2 s .c o  m*/
    //draw path
    Path2D.Double path = new Path2D.Double();
    path.moveTo(ori.getX(), ori.getY());
    path.lineTo(dest.getX(), dest.getY());

    //draw on graph
    big.draw(path);
}

From source file:business.ImageManager.java

private void doDrawPathOrdem(Graphics2D big, Point ori, Point dest, Color color) {
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(new BasicStroke(1.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f,
            new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f));
    big.setColor(color);/*  w ww .  ja va2 s.  c  o m*/
    //draw path
    Path2D.Double path = new Path2D.Double();
    path.moveTo(ori.getX(), ori.getY());
    path.curveTo(dest.getX() - 20, dest.getY() + 20, dest.getX() + 20, dest.getY() - 20, dest.getX() + 12,
            dest.getY());
    //path.lineTo(dest.getX(), dest.getY());

    //draw on graph
    big.draw(path);
}

From source file:business.ImageManager.java

private void doDrawRastro(Graphics2D big, int direcao, int x, int y, Color color) {
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(
            new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 5f }, 0f));
    big.setColor(color);/*from   ww w. j  a  va 2 s  . c  om*/

    //draw path
    Path2D.Double path = new Path2D.Double();
    path.moveTo(x + 38, y + 38);
    path.lineTo(x + coordRastros[direcao - 1][0], y + coordRastros[direcao - 1][1]);

    //draw on graph
    big.draw(path);
}