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.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) {
    g2.setPaint(Color.orange);/*  www .j  a  v a2s . c  om*/
    g2.setStroke(new BasicStroke(1));
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 30);
    g2.setPaint(fillColor);
    g2.fill(frame);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) {
    g2.setPaint(Color.orange);//from  w w w.  j ava 2  s .co  m
    g2.setStroke(new BasicStroke(1));
    Rectangle2D frame = mask.getRectangleFrame();
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 10);
    g2.setPaint(fillColor);
    g2.fill(mask.getShape());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawShapes(Graphics2D g2, Rectangle2D imageArea, Shape shape, JFreeChart chart) {
    Color color = Color.CYAN;
    Stroke oldStroke = g2.getStroke();
    g2.setStroke(new BasicStroke(2f));
    drawShape(g2, imageArea, shape, color, chart);
    g2.setStroke(oldStroke);//www  .  j  a  v a  2 s .  c o m
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Draws an arrow from <code>(xCenter,yCenter)</code> to <code>(x,y)</code>.
 * Code stolen from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135.
 * //from  w  ww .j a v a2 s  .  co  m
 * @param g the graphics context to draw in
 * @param headSize the size of the arrow head
 * @param xCenter the x-coord of the arrow tail
 * @param yCenter the y-coord of the arrow tail
 * @param x the x-coord of the arrow head's tip
 * @param y the y-coord of the arrow head's tip
 * @param stroke the <code>Stroke</code> to use
 */
public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y, int headSize, float stroke) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.addRenderingHints(hints);

    double aDir = Math.atan2(xCenter - x, yCenter - y);
    Stroke origStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(stroke)); // make the arrow head solid even if dash pattern has been specified
    g2d.drawLine(x, y, xCenter, yCenter);
    Polygon tmpPoly = new Polygon();
    int i1 = 2 * headSize + (int) stroke; //(stroke * 2);
    int i2 = headSize + (int) stroke; // make the arrow head the same size regardless of the length length
    tmpPoly.addPoint(x, y); // arrow tip
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);
    g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted
    g2d.setStroke(origStroke);
}

From source file:org.uva.itast.blended.omr.OMRUtils.java

public static void logFrame(PageImage pageImage, PagePoint topleft, PagePoint topright, PagePoint bottomleft,
        PagePoint bottomright, Color color, String label) {
    if (topleft == null || topright == null || bottomleft == null || bottomright == null)
        return;//from  w  w  w  . j a  v a2 s .  co m

    Graphics2D g = pageImage.getReportingGraphics();
    AffineTransform t = g.getTransform();
    g.setColor(color);
    g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));

    // Point framePxUL=pageImage.toPixels(topleft.getX(), topleft.getY());
    // Point framePxUR=pageImage.toPixels(topright.getX(), topright.getY());
    // Point framePxBL=pageImage.toPixels(bottomleft.getX(),
    // bottomleft.getY());
    // Point framePxBR=pageImage.toPixels(bottomright.getX(),
    // bottomright.getY());

    g.drawLine(topleft.getXpx(), topleft.getYpx(), topright.getXpx(), topright.getYpx());
    g.drawLine(topleft.getXpx(), topleft.getYpx(), bottomleft.getXpx(), bottomleft.getYpx());
    g.drawLine(topright.getXpx(), topright.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    g.drawLine(bottomleft.getXpx(), bottomleft.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    if (label != null) {
        g.drawString(label, topleft.getXpx(), topleft.getYpx());
    }
}

From source file:BasicStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3.0f));
    g2.setPaint(Color.blue);/*from w  w  w. ja  v a 2  s  . c o m*/

    Rectangle r = new Rectangle(5, 5, 200, 200);

    g2.draw(r);
}

From source file:ThickStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(8.0f));
    g2.setPaint(Color.blue);//w  w w  .  ja  v  a 2 s . c  o m

    Rectangle r = new Rectangle(5, 5, 200, 200);

    g2.draw(r);
}

From source file:Main.java

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

    g2.setPaint(Color.black);/*  w w w .ja  v a2 s  .  co  m*/
    g2.setStroke(new BasicStroke(8, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    g2.draw(new Ellipse2D.Double(20, 20, 50, 50));
}

From source file:Main.java

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

    g2.setPaint(Color.black);/*from  ww w  . j  a va2  s . c  om*/
    g2.setStroke(new BasicStroke());
    g2.draw(new Ellipse2D.Double(20, 20, 50, 50));
}

From source file:Main.java

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

    g2.setPaint(Color.black);//from  www.j  a v  a2s.  com
    g2.setStroke(new BasicStroke(8));
    g2.draw(new Ellipse2D.Double(20, 20, 50, 50));
}