Java Graphics Draw drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts)

Here you can find the source of drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts)

Description

draw Boundary

License

Apache License

Declaration

public static void drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.*;

import java.awt.geom.*;

public class Main {
    public static void drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts) {
        Color smokey = new Color(128, 128, 128, 128);
        drawBoundary(g2d, bounds, pts, smokey, true);
    }/*from www  .j  av  a  2s .  c o m*/

    public static void drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts, Color color,
            boolean drawSqPt) {
        g2d.setPaint(Color.BLACK);
        BasicStroke basicStroke = new BasicStroke(0.25f);
        Stroke origStroke = g2d.getStroke();
        g2d.setStroke(basicStroke);
        g2d.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.draw(bounds);
        basicStroke = new BasicStroke(1.0f);
        g2d.setStroke(basicStroke);
        for (int i = 0; i < pts.length; i++) {
            if (drawSqPt)
                drawSquarePoint(g2d, pts[i], 1, color);
            else
                drawPoint(g2d, pts[i], 1, color);
        }
        g2d.setStroke(origStroke);
    }

    public static void drawSquarePoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color) {
        Color origColor = g2.getColor();
        g2.setColor(color);
        Rectangle2D.Double ptRect = new Rectangle2D.Double(pt.x - 4 * ptSize, pt.y - 4 * ptSize, 8 * ptSize,
                8 * ptSize);
        g2.fill(ptRect);
        g2.draw(ptRect);
        g2.setColor(origColor);
    }

    public static void drawPoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color) {
        AffineTransform affine = new AffineTransform();
        affine.setToIdentity();
        drawPoint(affine, g2, pt, ptSize, color);
    }

    public static void drawPoint(AffineTransform affine, Graphics2D g2, Point2D.Double point, int ptSize,
            Color color) {
        Point2D.Double pt = (Point2D.Double) affine.transform(point, null);
        Color origColor = g2.getColor();
        g2.setColor(color);
        g2.fill(new Ellipse2D.Double(pt.x - 4 * ptSize, pt.y - 4 * ptSize, 8 * ptSize, 8 * ptSize));
        g2.setColor(origColor);
    }
}

Related

  1. drawAngledLine(Graphics g, int x, int y, double angle, int length)
  2. drawAt(final Graphics2D g, final double x, final double y, final Shape s)
  3. drawAutoCompleteMarker(Graphics2D g2, int x, int y, int iconSize)
  4. drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright, boolean showMirror, boolean isDichroic)
  5. drawBeamVariableRadiusVertical(Graphics g, Color c, int midx, int y1, int y2, int r1, int r2)
  6. drawBoxOrBlockChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)
  7. drawBubbleHead(Graphics2D g, Point2D headPosition, double orientation, double size, Color color, Stroke stroke)
  8. drawBubbles(Graphics g, int nCode)
  9. drawChar(char c, int x, int y, Graphics g)