java.awt.geom.Area Java Examples

The following examples show how to use java.awt.geom.Area. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CmmnJsonConverter.java    From flowable-engine with Apache License 2.0 7 votes vote down vote up
protected Area createGateway(GraphicInfo graphicInfo) {
    Area outerGatewayArea = new Area(
            createGatewayShape(graphicInfo.getX(), graphicInfo.getY(), graphicInfo.getWidth(), graphicInfo.getHeight())
    );
    Area innerGatewayArea = new Area(
            createGatewayShape(graphicInfo.getX() + lineWidth, graphicInfo.getY() + lineWidth,
                    graphicInfo.getWidth() - 2 * lineWidth, graphicInfo.getHeight() - 2 * lineWidth)
    );
    outerGatewayArea.subtract(innerGatewayArea);
    return outerGatewayArea;
}
 
Example #2
Source File: AreaList.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Returns the bounds of this object as it shows in the given layer. */
@Override
public Rectangle getBounds(final Rectangle r, final Layer layer) {
	if (null == layer) return super.getBounds(r, null);
	final Area area = (Area)ht_areas.get(layer.getId());
	if (null == area) {
		if (null == r) return new Rectangle();
		r.x = 0;
		r.y = 0;
		r.width = 0;
		r.height = 0;
		return r;
	}
	final Rectangle b = area.createTransformedArea(this.at).getBounds();
	if (null == r) return b;
	r.setBounds(b.x, b.y, b.width, b.height);
	return r;
}
 
Example #3
Source File: ShapedAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This constructor supports shape definition via an ellipse
 * 
 * @param oSource
 * @param boEllipse
 * @param clipping
 */
public ShapedAction( StructureSource oSource, Bounds boEllipse,
		Shape clipping )
{
	_oSource = oSource;
	if ( clipping != null )
	{
		Area ar1 = new Area( clipping );
		Area ar2 = new Area( new Ellipse2D.Double( boEllipse.getLeft( ),
				boEllipse.getTop( ),
				boEllipse.getWidth( ),
				boEllipse.getHeight( ) ) );
		ar2.intersect( ar1 );
		_sh = ar2;
	}
	else
	{
		_sh = new Ellipse2D.Double( boEllipse.getLeft( ),
				boEllipse.getTop( ),
				boEllipse.getWidth( ),
				boEllipse.getHeight( ) );
	}
}
 
Example #4
Source File: ShapedAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This constructor supports polygon shapes Future shapes (and corresponding
 * constructors) will be added later
 * 
 * @param source
 * @param loa
 * @param clipping
 */
public ShapedAction( StructureSource oSource, Location[] loa, Shape clipping )
{
	_oSource = oSource;
	if ( clipping != null )
	{
		Area ar1 = new Area( clipping );
		Area ar2 = new Area( G2dRendererBase.getPolygon2D( loa ) );
		ar2.intersect( ar1 );
		_sh = ar2;
	}
	else
	{
		_sh = G2dRendererBase.getPolygon2D( loa );
	}
}
 
Example #5
Source File: ArcDialFrame.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the frame.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);

}
 
Example #6
Source File: PDGraphicsState.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Modify the current clipping path by intersecting it with the given path.
 * @param area area to intersect with the clipping path
 */
public void intersectClippingPath(Area area)
{
    // lazy cloning of clipping path for performance
    if (!isClippingPathDirty)
    {
        // deep copy (can't use clone() as it performs only a shallow copy)
        Area cloned = new Area();
        cloned.add(clippingPath);
        clippingPath = cloned;

        isClippingPathDirty = true;
    }

    // intersection as usual
    clippingPath.intersect(area);
}
 
Example #7
Source File: NoteHeadsBuilder.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Retrieve the competitors intersected by the provided horizontal slice.
 *
 * @param area the horizontal slice
 * @return the list of competitors, sorted by abscissa.
 */
private List<Inter> getCompetitorsSlice (Area area)
{
    List<Inter> rawComps = Inters.intersectedInters(
            systemCompetitors,
            GeoOrder.BY_ORDINATE,
            area);

    // Keep only the "really good" competitors
    List<Inter> kept = new ArrayList<>();

    for (Inter inter : rawComps) {
        if (inter.isGood()) {
            kept.add(inter);
        }
    }

    // Sort by abscissa for more efficient lookup
    Collections.sort(kept, Inters.byAbscissa);

    return kept;
}
 
Example #8
Source File: GraphicsUtils.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
public static Shape subtractClip ( final Graphics g, final Shape clip, final boolean shouldSetup )
{
    if ( shouldSetup && clip != null )
    {
        final Shape oldClip = g.getClip ();
        if ( oldClip != null )
        {
            // Area-based substraction
            final Area finalClip = new Area ( oldClip );
            finalClip.subtract ( new Area ( clip ) );
            g.setClip ( finalClip );
        }
        return oldClip;
    }
    else
    {
        return null;
    }
}
 
Example #9
Source File: DoubleCrosshairFootprint.java    From tracker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the icon.
 *
 * @param w width of the icon
 * @param h height of the icon
 * @return the icon
 */
public Icon getIcon(int w, int h) {
  int scale = FontSizer.getIntegerFactor();
  w *= scale;
  h *= scale;
	if (stroke==null || stroke.getLineWidth()!=scale*baseStroke.getLineWidth()) {
		stroke = new BasicStroke(scale*baseStroke.getLineWidth());
	}
	transform.setToScale(scale, scale);
  Shape target = stroke.createStrokedShape(transform.createTransformedShape(targetShape));
  Area area = new Area(target);
  double x0 = scale*(size+2)-w;
  double y0 = h-scale*(size+2);
  double d = Math.sqrt(x0*x0+y0*y0);
  double x1 = x0*scale*size/d;
  double y1 = y0*scale*size/d;
  Line2D line = new Line2D.Double(x0, y0, x1, y1);
  area.add(new Area(stroke.createStrokedShape(line)));
  ShapeIcon icon = new ShapeIcon(area, w, h);
  icon.setColor(color);
  return icon;
}
 
Example #10
Source File: ArcDialFrame.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the frame.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);
    
    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);
    
    
}
 
Example #11
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draw pie
 *
 * @param aPoint Start point
 * @param width Width
 * @param height Height
 * @param startAngle Start angle
 * @param sweepAngle Sweep angle
 * @param aPGB Polygon break
 * @param wedgeWidth Wedge width
 * @param g Graphics2D
 */
public static void drawPie(PointF aPoint, float width, float height, float startAngle,
        float sweepAngle, PolygonBreak aPGB, float wedgeWidth, Graphics2D g) {
    Color aColor = aPGB.getColor();
    Arc2D.Float arc2D = new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE);
    Area area1 = new Area(arc2D);
    Ellipse2D e2 = new Ellipse2D.Float(aPoint.X + wedgeWidth, aPoint.Y + wedgeWidth, width - wedgeWidth * 2,
            height - wedgeWidth * 2);
    Area area2 = new Area(e2);
    area1.subtract(area2);
    if (aPGB.isDrawFill()) {
        g.setColor(aColor);
        g.fill(area1);
    }
    if (aPGB.isDrawOutline()) {
        g.setColor(aPGB.getOutlineColor());
        g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
        g.draw(area1);
    }
}
 
Example #12
Source File: CommandLayer.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void drawArea(Area area) {
	PathIterator iter = area.getPathIterator(null);
	Path2D.Float poly = new Path2D.Float();
	double[] firstPoint = null;
	while (!iter.isDone()) {
		double point[] = new double[2]; // x, y
		int type = iter.currentSegment(point);
        point[0] = t.xToScreen(point[0]);
        point[1] = t.yToScreen(point[1]);
		if (type == PathIterator.SEG_MOVETO) {
			firstPoint = point;
			poly.moveTo(point[0], point[1]);
		} else if (type == PathIterator.SEG_CLOSE) {
			poly.lineTo(firstPoint[0], firstPoint[1]);
			g.draw(poly);
			poly.reset();
		} else {
			poly.lineTo(point[0], point[1]);
		}
		iter.next();
	}
}
 
Example #13
Source File: StarmapScreen.java    From open-ig with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draw the exploration limit rectangle borders.
 * @param g2 the graphics context
 */
void renderExplorationLimits(Graphics2D g2) {
	if (player().explorationOuterLimit != null) {
		
		Area a = new Area(new Rectangle(0, 0, world().galaxyModel.map.getWidth(), world().galaxyModel.map.getHeight()));
		a.subtract(new Area(player().explorationOuterLimit));

		g2.setColor(new Color(0x80000000, true));
		
		drawShape(g2, a, true);
		
		g2.setColor(Color.RED);
		drawRect(g2, player().explorationOuterLimit, false);
	} else
	if (player().explorationInnerLimit != null) {
		g2.setColor(new Color(0x80000000, true));
		drawRect(g2, player().explorationInnerLimit, true);
	}
}
 
Example #14
Source File: SWTGraphics2D.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns <code>true</code> if the rectangle (in device space) intersects
 * with the shape (the interior, if <code>onStroke</code> is false, 
 * otherwise the stroked outline of the shape).
 * 
 * @param rect  a rectangle (in device space).
 * @param s the shape.
 * @param onStroke  test the stroked outline only?
 * 
 * @return A boolean. 
 */
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
    AffineTransform transform = getTransform();
    Shape ts;
    if (onStroke) {
        Stroke stroke = getStroke();
        ts = transform.createTransformedShape(stroke.createStrokedShape(s));
    } else {
        ts = transform.createTransformedShape(s);
    }
    if (!rect.getBounds2D().intersects(ts.getBounds2D())) {
        return false;
    }
    Area a1 = new Area(rect);
    Area a2 = new Area(ts);
    a1.intersect(a2);
    return !a1.isEmpty();
}
 
Example #15
Source File: StandardDialFrame.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02,
            this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(),
            f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}
 
Example #16
Source File: Mask.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
private Table.UnsignedByte computeRelevantPoints (Area area)
{
    Table.UnsignedByte table = new Table.UnsignedByte(rect.width, rect.height);
    Point loc = rect.getLocation();
    table.fill(PixelFilter.BACKGROUND);

    for (int y = 0; y < rect.height; y++) {
        int ay = y + loc.y; // Absolute ordinate

        for (int x = 0; x < rect.width; x++) {
            int ax = x + loc.x; // Absolute abscissa

            if (area.contains(ax, ay)) {
                table.setValue(x, y, 0);
                pointCount++;
            }
        }
    }

    return table;
}
 
Example #17
Source File: FcgVertex.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void buildFullShape() {

		// Note: this method assumes all bounds have been set
		Area parent = new Area();

		Area v = new Area(vertexShape);
		Area name = new Area(nameLabel.getBounds());
		parent.add(v);
		parent.add(name);

		// for now, the buttons only appear on hover, but if we want to avoid clipping when 
		// painting, we need to account for them in the shape's overall bounds
		Area in = new Area(toggleInsButton.getBounds());
		Area out = new Area(toggleOutsButton.getBounds());
		parent.add(in);
		parent.add(out);

		fullShape = parent;
	}
 
Example #18
Source File: LayerSet.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Find ZDisplayable objects of the given class that intersect the given area in the given layer.
 *  If @param instance_of is true, use c.isAssignableFrom instead of class equality. */
public Collection<Displayable> findZDisplayables(final Class<?> c, final Layer layer, final Area aroi, final boolean visible_only, final boolean instance_of) {
	final LayerBucket lb;
	synchronized (lbucks) {
		lb = lbucks.get(layer);
	}
	if (null != lb) return lb.root.find(c, aroi, layer, visible_only, instance_of);
	else nbmsg(layer);

	final ArrayList<Displayable> al = new ArrayList<Displayable>();
	for (final ZDisplayable zd : al_zdispl) {
		if (visible_only && !zd.isVisible()) continue;
		if (instance_of) {
			if (!c.isAssignableFrom(zd.getClass())) continue;
		} else if (zd.getClass() != c) continue;
		if (zd.intersects(layer, aroi)) al.add(zd);
	}
	return al;
}
 
Example #19
Source File: NpcAggroAreaPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private Area generateSafeArea()
{
	final Area area = new Area();

	for (WorldPoint wp : safeCenters)
	{
		if (wp == null)
		{
			continue;
		}

		Polygon poly = new Polygon();
		poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() - SAFE_AREA_RADIUS);
		poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() + SAFE_AREA_RADIUS + 1);
		poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() + SAFE_AREA_RADIUS + 1);
		poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() - SAFE_AREA_RADIUS);
		area.add(new Area(poly));
	}

	return area;
}
 
Example #20
Source File: IfcTools2D.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static float getArea(Area area) {
		float sum = 0;
		PathIterator pathIterator = area.getPathIterator(null);
		float[] coords = new float[6];
		float[] last = null;
		float[] first = null;
		float[] lastMoveTo = null;
		while (!pathIterator.isDone()) {
			int currentSegment = pathIterator.currentSegment(coords);
			if (currentSegment == PathIterator.SEG_CLOSE) {
//				sum += lastMoveTo[0] * coords[1] - lastMoveTo[1] * coords[0];
				last = new float[]{coords[0], coords[1]};
			} else if (currentSegment == PathIterator.SEG_MOVETO) {
				lastMoveTo = new float[]{coords[0], coords[1]};
				last = new float[]{coords[0], coords[1]};
				if (first == null) {
					first = new float[]{coords[0], coords[1]};
				}
			} else if (currentSegment == PathIterator.SEG_LINETO) {
				if (last != null) {
					sum += last[0] * coords[1] - last[1] * coords[0];
				}

				last = new float[]{coords[0], coords[1]};
			} else {
				LOGGER.info("Unimplemented segment: " + currentSegment);
			}
			pathIterator.next();
		}
		if (last != null && first != null) {
			sum += last[0] * first[1] - last[1] * first[0];
		}
		return Math.abs(sum / 2f);
	}
 
Example #21
Source File: NoteHeadsBuilder.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Check whether the provided rectangle would intersect area of frozen
 * barline/connector.
 *
 * @param rect provided rectangle
 * @return true if area hit
 */
private boolean barInvolved (Rectangle rect)
{
    for (Area a : barAreas) {
        if (a.intersects(rect)) {
            return true;
        }
    }

    return false;
}
 
Example #22
Source File: BpmnJsonConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Collection<java.awt.geom.Point2D> getIntersections(java.awt.geom.Line2D line, Area shape) {
    Area intersectionArea = new Area(getLineShape(line));
    intersectionArea.intersect(shape);
    if (!intersectionArea.isEmpty()) {
        Rectangle2D bounds2D = intersectionArea.getBounds2D();
        HashSet<java.awt.geom.Point2D> intersections = new HashSet<>(1);
        intersections.add(new java.awt.geom.Point2D.Double(bounds2D.getX(), bounds2D.getY()));
        return intersections;
    }
    return Collections.EMPTY_SET;
}
 
Example #23
Source File: MacIntelliJTextBorder.java    From consulo with Apache License 2.0 5 votes vote down vote up
void clipForBorder(Component c, Graphics2D g2, int width, int height) {
  Area area = new Area(new Rectangle2D.Double(0, 0, width, height));
  double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0;
  area.subtract(new Area(new Rectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw,
                                                width - JBUI.scale(6) - lw * 2,
                                                height - JBUI.scale(6) - lw * 2)));
  area.intersect(new Area(g2.getClip()));
  g2.setClip(area);
}
 
Example #24
Source File: ArrowBuilder.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
static void drawArrow(Graphics g, Rectangle startRect, Rectangle endRect) {

        final Composite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f);

        final int startX = startRect.x + (startRect.width / 2);
        final int startY = startRect.y + (startRect.height / 2);
        final int endX = endRect.x;
        final int endY = endRect.y + (endRect.height / 2);

        float ex = endX - startX;
        float ey = endY - startY;
        if (ex == 0 && ey == 0) return;
        float length = (float)Math.sqrt(ex * ex + ey * ey);
        float bendPercent = (float)Math.asin(ey / length);
        if (endX > startX) bendPercent = -bendPercent;

        Area arrow = getArrow(length, -bendPercent);

        Graphics2D g2d = (Graphics2D) g.create();
        g2d.translate(startX, startY);
        g2d.rotate(Math.atan2(ey, ex));
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setComposite(composite);
        g2d.setColor(Color.RED);
        g2d.fill(arrow);
        g2d.setColor(Color.BLACK);
        g2d.draw(arrow);
        g2d.dispose();

    }
 
Example #25
Source File: PdfGraphics2D.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @see Graphics2D#hit(Rectangle, Shape, boolean)
 */
@Override
public boolean hit( final Rectangle rect, Shape s, final boolean onStroke ) {
  if ( onStroke ) {
    s = stroke.createStrokedShape( s );
  }
  s = transform.createTransformedShape( s );
  final Area area = new Area( s );
  if ( clip != null ) {
    area.intersect( clip );
  }
  return area.intersects( rect.x, rect.y, rect.width, rect.height );
}
 
Example #26
Source File: AbstractGraphics2D.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
	if (onStroke) {
		return hit(rect, getStroke().createStrokedShape(s), false);
	}

	Area area = new Area(s);
	return area.intersects(rect);
}
 
Example #27
Source File: Layer.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns an Area in world coordinates that represents the inside of all Patches. */
public Area getPatchArea(final boolean visible_only) {
	final Area area = new Area(); // with width,height zero
	for (final Patch p: getAll(Patch.class)) {
		if (visible_only && p.isVisible()) {
			area.add(p.getArea());
		}
	}
	return area;
}
 
Example #28
Source File: AreaList.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<Area> getAreas(final Layer layer, final Rectangle box) {
	final Area a = (Area) ht_areas.get(layer.getId());
	if (null == a) return null;
	final ArrayList<Area> l = new ArrayList<Area>();
	l.add(a);
	return l;
}
 
Example #29
Source File: NoteHeadsBuilder.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Build the list of areas around connectors and frozen barlines.
 *
 * @return the bar-centered areas
 */
private List<Area> getBarAreas (Area area)
{
    List<Area> kept = new ArrayList<>();
    for (Area r : systemBarAreas) {
        if (area.intersects(r.getBounds())) {
            kept.add(r);
        }
    }
    return kept;
}
 
Example #30
Source File: AreaList.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns whether the point x,y is contained in this object at the given Layer. */
@Override
public boolean contains(final Layer layer, final double x, final double y) {
	Object ob = ht_areas.get(new Long(layer.getId()));
	if (null == ob) return false;
	if (AreaList.UNLOADED == ob) {
		ob = loadLayer(layer.getId());
		if (null == ob) return false;
	}
	Area area = (Area)ob;
	if (!this.at.isIdentity()) area = area.createTransformedArea(this.at);
	return area.contains(x, y);
}