Example usage for java.awt.geom Area add

List of usage examples for java.awt.geom Area add

Introduction

In this page you can find the example usage for java.awt.geom Area add.

Prototype

public void add(Area rhs) 

Source Link

Document

Adds the shape of the specified Area to the shape of this Area .

Usage

From source file:BasicShapes.java

public static void main(String[] args) {
    Area shape = new Area(new Rectangle(1, 1, 1, 1));
    shape.add(new Area(new Rectangle(1, 1, 1, 1)));
    shape.subtract(new Area(new Rectangle(1, 1, 1, 1)));
    shape.intersect(new Area(new Rectangle(1, 1, 1, 1)));
    shape.exclusiveOr(new Area(new Rectangle(1, 1, 1, 1)));
}

From source file:Main.java

public static void main(String[] args) {
    Area shape = new Area(new Rectangle(1, 1, 1, 1));
    shape.add(new Area(new Rectangle(1, 1, 1, 1)));
    shape.subtract(new Area(new Rectangle(1, 1, 1, 1)));
    shape.intersect(new Area(new Rectangle(1, 1, 1, 1)));
    shape.exclusiveOr(new Area(new Rectangle(1, 1, 1, 1)));

    System.out.println(shape.intersects(new Rectangle(1, 1, 1, 1)));
}

From source file:fr.romainf.QRCode.java

/**
 * Renders the QRCode data in an SVG document.
 *
 * @param matrix      BitMatrix BitMatrix of the encoded QRCode
 * @param pixelColour Color The colour of pixels representing bits
 * @return SVGGraphics2D/*w  w w .j  av a 2  s  . c  om*/
 */
private static SVGGraphics2D renderSVG(BitMatrix matrix, Color pixelColour) {
    DOMImplementation implementation = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document document = implementation.createDocument(svgNS, "svg", null);

    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

    int width = matrix.getWidth();
    int height = matrix.getHeight();

    Area area = new Area();
    for (int x = 0; x < width; x += 1) {
        for (int y = 0; y < height; y += 1) {
            if (matrix.get(x, y)) {
                area.add(new Area(new Rectangle(x, y, 1, 1)));
            }
        }
    }

    svgGenerator.setPaint(pixelColour);
    svgGenerator.fill(area);
    return svgGenerator;
}

From source file:Main.java

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

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area();
    Area a2 = new Area(e2);

    a1.add(a2);

    g2.setColor(Color.orange);/*from  w  w w.  ja  v  a  2s  .c o  m*/
    g2.fill(a1);
}

From source file:Main.java

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

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.add(a2);

    g2.setColor(Color.orange);//  ww  w  . j  a v  a2s.co m
    g2.fill(a1);
}

From source file:MainClass.java

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

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.add(a2);

    g2.setColor(Color.orange);//ww w. ja  v a 2  s.  c o  m
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("Union", 20, 140);

}

From source file:CombiningShapes.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String option = (String) mOptions.getSelectedItem();
    if (option.equals("outline")) {
        // draw the outlines and return.
        g2.draw(mShapeOne);/* www . java  2s .c o m*/
        g2.draw(mShapeTwo);
        return;
    }

    // Create Areas from the shapes.
    Area areaOne = new Area(mShapeOne);
    Area areaTwo = new Area(mShapeTwo);
    // Combine the Areas according to the selected option.
    if (option.equals("add"))
        areaOne.add(areaTwo);
    else if (option.equals("intersection"))
        areaOne.intersect(areaTwo);
    else if (option.equals("subtract"))
        areaOne.subtract(areaTwo);
    else if (option.equals("exclusive or"))
        areaOne.exclusiveOr(areaTwo);

    // Fill the resulting Area.
    g2.setPaint(Color.orange);
    g2.fill(areaOne);
    // Draw the outline of the resulting Area.
    g2.setPaint(Color.black);
    g2.draw(areaOne);
}

From source file:com.t3.model.LightSource.java

/**
 * Area for all lights combined// w w w  .j  a va 2  s.c o m
 */
public Area getArea(Token token, Zone zone, Direction position) {
    Area area = new Area();
    for (Light light : getLightList()) {
        area.add(light.getArea(token, zone));
    }
    return getArea(token, zone, position, area);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java

private static Shape createShape(double x, double y, Rectangle2D hotspot) {
    Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(),
            hotspot.getHeight(), 8, 8));

    boolean right = hotspot.getMinX() > x;

    Polygon po = new Polygon();
    po.addPoint(0, 0);/*from  w  w w  . ja va  2 s .c  om*/
    po.addPoint(0, 10);
    po.addPoint(10, 0);
    AffineTransform af = new AffineTransform();
    if (right) {
        af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(-Math.PI / 4);
    } else {
        af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(Math.PI * 3 / 4);
    }

    Shape shape = af.createTransformedShape(po);
    result.add(new Area(shape));
    return result;
}

From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java

/**
 * {@inheritDoc}//from  w  w  w .jav  a2s.c om
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT);

    // Define the content rectangle
    int x0 = pointerLeft ? pad + pointerWidth : pad;
    RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth,
            height - 2 * pad, cornerRadius, cornerRadius);

    // Define the pointer triangle
    int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth;
    int yp = pad + height - pointerFromBottom;
    Polygon pointer = new Polygon();
    pointer.addPoint(xp, yp);
    pointer.addPoint(xp, yp - pointerHeight);
    pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2);

    // Combine content rectangle and pointer into one area
    Area area = new Area(content);
    area.add(new Area(pointer));

    // Fill the pop-up background
    Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter();
    g2.setColor(col);
    g2.fill(area);

}