Java Code Examples for java.awt.geom.Area#subtract()

The following examples show how to use java.awt.geom.Area#subtract() . 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: ScrollPanePreview.java    From ramus with GNU General Public License v3.0 8 votes vote down vote up
protected void paintComponent(Graphics g1D) {
    if (theImage == null || theRectangle == null)
        return;
    Graphics2D g = (Graphics2D) g1D;
    Insets insets = getInsets();
    int xOffset = insets.left;
    int yOffset = insets.top;
    int availableWidth = getWidth() - insets.left - insets.right;
    int availableHeight = getHeight() - insets.top - insets.bottom;
    g.drawImage(theImage, xOffset, yOffset, null);
    Color tmpColor = g.getColor();
    Area area = new Area(new Rectangle(xOffset, yOffset, availableWidth,
            availableHeight));
    area.subtract(new Area(theRectangle));
    g.setColor(new Color(200, 200, 200, 128));
    g.fill(area);
    g.setColor(Color.BLACK);
    g.draw(theRectangle);
    g.setColor(tmpColor);
}
 
Example 2
Source File: BpmnJsonConverter.java    From flowable-engine with Apache License 2.0 7 votes vote down vote up
protected Area createEllipse(GraphicInfo sourceInfo, double halfWidth, double halfHeight) {
    Area outerCircle = new Area(new Ellipse2D.Double(
            sourceInfo.getX(), sourceInfo.getY(), 2 * halfWidth, 2 * halfHeight
    ));
    Area innerCircle = new Area(new Ellipse2D.Double(
            sourceInfo.getX() + lineWidth, sourceInfo.getY() + lineWidth, 2 * (halfWidth - lineWidth), 2 * (halfHeight - lineWidth)
    ));
    outerCircle.subtract(innerCircle);
    return outerCircle;
}
 
Example 3
Source File: ImgUtils.java    From TranskribusCore with GNU General Public License v3.0 7 votes vote down vote up
public static File killBorder(BufferedImage baseImage, Polygon p, String outPng) throws IOException {		
       // Creates a background BufferedImage with an Alpha layer so that AlphaCompositing works
   	final int height = baseImage.getHeight();
	final int width = baseImage.getWidth();
       BufferedImage bg = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB);
       // Sets AlphaComposite to type SRC_OUT with a transparency of 100%
       // Convert BufferedImage to G2D. Effects applied to G2D are applied to the original BufferedImage automatically.
       Graphics2D g2d = bg.createGraphics();
       //create Area with dimension of the image to be cropped
       Area wholeImageArea = new Area(new Rectangle(width, height));
       //create Area from given polygon 
       Area psArea = new Area(p);
       //invert the printspace area
       wholeImageArea.subtract(psArea);
       // Covers the whole image to provide a layer to be cropped, revealing the imported image underneath
       g2d.fill(wholeImageArea);
       g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT, 1.0f));
       // Draws the imported image into the background BufferedImage (bg).
       g2d.drawImage(baseImage, 0, 0, null);
       // Writes the image to a PNG
       if(!outPng.endsWith(".png")){
       	outPng += ".png";
       }
       File out = new File(outPng);
       if(!ImageIO.write(bg, "png", out)){
       	//should not happen with png
       	throw new IOException("No appropriate writer was found!");
       }
       return out;        
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 7 votes vote down vote up
public void paint(Graphics g, ImageObserver observer) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

  double w2 = imageSz.width / 2d;
  double h2 = imageSz.height / 2d;
  AffineTransform at = AffineTransform.getTranslateInstance(centerPt.getX() - w2, centerPt.getY() - h2);
  at.rotate(radian, w2, h2);

  g2.setPaint(BORDER_COLOR);
  g2.setStroke(BORDER_STROKE);
  Shape s = at.createTransformedShape(polaroid);
  g2.fill(s);
  g2.draw(s);

  g2.drawImage(image, at, observer);

  if (rotatorHover) {
    Area donut = new Area(outer);
    donut.subtract(new Area(inner));
    g2.setPaint(HOVER_COLOR);
    g2.fill(donut);
  } else if (moverHover) {
    g2.setPaint(HOVER_COLOR);
    g2.fill(inner);
  }

  g2.setPaint(BORDER_COLOR);
  g2.setStroke(BORDER_STROKE);
  g2.draw(at.createTransformedShape(border));
  g2.dispose();
}
 
Example 5
Source File: AquaVectorTabControlIcon.java    From netbeans with Apache License 2.0 7 votes vote down vote up
/**
 * Make a small window symbol. This is used in several of the icons here. All coordinates are
 * in device pixels.
 */
private Area getWindowSymbol(double scaling, int x, int y, int width, int height) {
    /* Pick a thickness that will make the window symbol border 2 physical pixels wide at 200%
    scaling, to look consistent with the rest of the UI, including borders and icons that do not
    have any special Retina support. */
    int borderThickness = round(0.8 * scaling);
    int titleBarHeight =
            (buttonId == TabControlButton.ID_SLIDE_GROUP_BUTTON ||
            buttonId == TabControlButton.ID_PIN_BUTTON)
            ? borderThickness
            : Math.max(round(1.6 * scaling), borderThickness + height / 7);
    int windowX = round(x);
    int windowY = round(y);
    Area ret = new Area(new Rectangle2D.Double(
            windowX, windowY, width, height));
    ret.subtract(new Area(new Rectangle2D.Double(
            windowX + borderThickness, windowY + titleBarHeight,
            width - borderThickness * 2,
            height - borderThickness - titleBarHeight)));
    if (buttonId == TabControlButton.ID_SLIDE_GROUP_BUTTON) {
        ret.add(new Area(new Rectangle2D.Double(
            windowX + borderThickness * 2,
            windowY + height - borderThickness * 4,
            round((width - borderThickness * 4) * 0.67),
            borderThickness * 2)));
    } else if (buttonId == TabControlButton.ID_PIN_BUTTON) {
        int marginX = round(width * 0.3);
        int marginY = round(height * 0.3);
        ret.add(new Area(new Rectangle2D.Double(
            windowX + marginX, windowY + marginY,
            width - marginX * 2,
            height - marginY * 2)));
    }
    return ret;
}
 
Example 6
Source File: M.java    From TrakEM2 with GNU General Public License v3.0 7 votes vote down vote up
/** Apply in place the @param ict to the Area @param a, but only for the part that intersects the roi. */
static final public void apply(final mpicbg.models.CoordinateTransform ict, final Area roi, final Area a) {
	final Area intersection = new Area(a);
	intersection.intersect(roi);
	a.subtract(intersection);
	a.add(M.transform(ict, intersection));
}
 
Example 7
Source File: BalloonManager.java    From netbeans with Apache License 2.0 7 votes vote down vote up
private Shape getShadowMask( Shape parentMask ) {
    Area area = new Area(parentMask);

    AffineTransform tx = new AffineTransform();
    tx.translate(SHADOW_SIZE, SHADOW_SIZE );//Math.sin(ANGLE)*(getHeight()+SHADOW_SIZE), 0);
    area.transform(tx);
    area.subtract(new Area(parentMask));
    return area;
}
 
Example 8
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 9
Source File: MainPanel.java    From java-swing-tips with MIT License 7 votes vote down vote up
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  if (c instanceof JPopupMenu) {
    g2.clearRect(x, y, width, height);
  }
  double r = ARC;
  double w = width - 1d;
  double h = height - 1d;

  Area round = new Area(new RoundRectangle2D.Double(x, y, w, h, r, r));
  Rectangle b = round.getBounds();
  b.setBounds(b.x, b.y + ARC, b.width, b.height - ARC);
  round.add(new Area(b));

  Container parent = c.getParent();
  if (Objects.nonNull(parent)) {
    g2.setPaint(parent.getBackground());
    Area corner = new Area(new Rectangle2D.Double(x, y, width, height));
    corner.subtract(round);
    g2.fill(corner);
  }

  g2.setPaint(c.getForeground());
  g2.draw(round);
  g2.dispose();
}
 
Example 10
Source File: Radarc.java    From mil-sym-java with Apache License 2.0 7 votes vote down vote up
@Override
protected Shape createShape() {
	GeoArc arc = new GeoArc(pivot, radiusMeters * 2, radiusMeters * 2, leftAzimuthDegrees, rightAzimuthDegrees,
			maxDistanceMeters, flatnessDistanceMeters, limit);
	Area shape = new Area(arc);
	GeoEllipse ellipse = new GeoEllipse(pivot, minRadiusMeters * 2, minRadiusMeters * 2, maxDistanceMeters,
			flatnessDistanceMeters, limit);
	shape.subtract(new Area(ellipse));
	return shape;
}
 
Example 11
Source File: ColorTriangle.java    From darklaf with MIT License 7 votes vote down vote up
protected Shape calculateCircleShape(final double x, final double y, final int size, final int outerSize) {
    outerRadius = size / 2.0;
    innerRadius = outerRadius - outerSize;
    if (!circleInfo.update(x, y, size, outerSize) && circleShape != null) return circleShape;

    Area outer = new Area(new Ellipse2D.Double(x, y, size, size));
    Area inner = new Area(new Ellipse2D.Double(x + outerSize, y + outerSize,
                                               size - 2 * outerSize,
                                               size - 2 * outerSize));
    outer.subtract(inner);
    return outer;
}
 
Example 12
Source File: CmmnJsonConverter.java    From flowable-engine with Apache License 2.0 7 votes vote down vote up
protected Area createEllipse(GraphicInfo sourceInfo, double halfWidth, double halfHeight) {
    Area outerCircle = new Area(new Ellipse2D.Double(
            sourceInfo.getX(), sourceInfo.getY(), 2 * halfWidth, 2 * halfHeight
    ));
    Area innerCircle = new Area(new Ellipse2D.Double(
            sourceInfo.getX() + lineWidth, sourceInfo.getY() + lineWidth, 2 * (halfWidth - lineWidth), 2 * (halfHeight - lineWidth)
    ));
    outerCircle.subtract(innerCircle);
    return outerCircle;
}
 
Example 13
Source File: FlatWindowRestoreIcon.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintIconAt1x( Graphics2D g, int x, int y, int width, int height, double scaleFactor ) {
	int iwh = (int) (10 * scaleFactor);
	int ix = x + ((width - iwh) / 2);
	int iy = y + ((height - iwh) / 2);
	int thickness = (int) scaleFactor;

	int rwh = (int) (8 * scaleFactor);
	int ro2 = iwh - rwh;

	Path2D r1 = FlatUIUtils.createRectangle( ix + ro2, iy, rwh, rwh, thickness );
	Path2D r2 = FlatUIUtils.createRectangle( ix, iy + ro2, rwh, rwh, thickness );

	Area area = new Area( r1 );
	area.subtract( new Area( new Rectangle2D.Float( ix, iy + ro2, rwh, rwh ) ) );
	g.fill( area );

	g.fill( r2 );
}
 
Example 14
Source File: StandardDialFrame.java    From SIMVA-SoS with Apache License 2.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 15
Source File: AnimatedVillageInfoRenderer.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
private void renderNoteInfo(Village pCurrentVillage, Graphics2D g2d) {

        pRise = mVillage != null && mVillage.equals(pCurrentVillage);
        int noteCount = NoteManager.getSingleton().getNotesForVillage(mVillage).size();
        double deg = 0;
        if (noteCount != 0) {
            deg = 360 / noteCount;
        }
        int cnt = 0;
        int centerX = (int) Math.floor(mCurrentLocation.getCenterX());
        int centerY = (int) Math.floor(mCurrentLocation.getCenterY());

        int iNoteDiameter = 0;
        if (iDiameter >= 40) {
            iNoteDiameter = 40;
        }

        if (iNoteDiameter == 40) {
            Color c = g2d.getColor();
            Composite com = g2d.getComposite();
            Area a = new Area();

            /*a.add(new Area(new Ellipse2D.Double(centerX - 50, centerY - 50, 100, 100)));
            a.subtract(new Area(new Ellipse2D.Double(centerX - 30, centerY - 30, 60, 60)));*/
            a.add(new Area(new Ellipse2D.Double(centerX - (int) Math.round((40.0 + iDiameter) / 2), centerY - (int) Math.round((40.0 + iDiameter) / 2), 40 + iDiameter, 40 + iDiameter)));
            a.subtract(new Area(new Ellipse2D.Double(centerX - (int) Math.round(iDiameter / 2.0), centerY - (int) Math.round(iDiameter / 2.0), iDiameter, iDiameter)));
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
            g2d.setColor(Constants.DS_BACK_LIGHT);
            g2d.fill(a);
            g2d.setComposite(com);
            g2d.setColor(Constants.DS_BACK);
            g2d.drawOval(centerX - (int) Math.round((40.0 + iDiameter) / 2), centerY - (int) Math.round((40.0 + iDiameter) / 2), 40 + iDiameter, 40 + iDiameter);
            g2d.drawOval(centerX - (int) Math.round(iDiameter / 2.0), centerY - (int) Math.round(iDiameter / 2.0), iDiameter, iDiameter);
            g2d.setColor(c);
        }
        for (Note note : NoteManager.getSingleton().getNotesForVillage(mVillage)) {
            //take next degree
            double cd = cnt * deg + deltaDeg;
            int noteX = (int) Math.rint(centerX + iNoteDiameter * Math.cos(2 * Math.PI * cd / 360) - 8);
            int noteY = (int) Math.rint(centerY + iNoteDiameter * Math.sin(2 * Math.PI * cd / 360) - 8);
            int noteIcon = note.getMapMarker();
            //   g2d.copyArea(noteIcon * 32, pCopyPosition + 68, 32, 32, noteX - noteIcon * 32, noteY - pCopyPosition - 68);
            g2d.drawImage(ImageManager.getNoteIcon(noteIcon).getScaledInstance(16, 16, BufferedImage.SCALE_DEFAULT), noteX, noteY, null);
            cnt++;
        }
        deltaDeg += 1;
        if (deltaDeg == 360) {
            deltaDeg = 0;
        }


    }
 
Example 16
Source File: WebGlassPane.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints WebGlassPane content.
 *
 * @param g graphics context.
 */
@Override
protected void paintComponent ( final Graphics g )
{
    super.paintComponent ( g );

    final Graphics2D g2d = ( Graphics2D ) g;
    final Object aa = GraphicsUtils.setupAntialias ( g2d );

    if ( highlightedComponents.size () > 0 )
    {
        final Rectangle baseBounds = CoreSwingUtils.getRelativeBounds ( highlightBase, WebGlassPane.this );
        final Area area =
                new Area ( new Rectangle ( baseBounds.x - 1, baseBounds.y - 1, baseBounds.width + 1, baseBounds.height + 1 ) );
        for ( final Component component : highlightedComponents )
        {
            if ( component.isShowing () )
            {
                final Rectangle bounds = CoreSwingUtils.getRelativeBounds ( component, WebGlassPane.this );
                final RoundRectangle2D.Double shape =
                        new RoundRectangle2D.Double ( bounds.x - highlightSpacing, bounds.y - highlightSpacing,
                                bounds.width + highlightSpacing * 2 - 1, bounds.height + highlightSpacing * 2 - 1, 8, 8 );
                area.subtract ( new Area ( shape ) );
            }
        }

        // Fill
        g2d.setPaint ( new Color ( 128, 128, 128, 128 ) );
        g2d.fill ( area );

        // Border
        g2d.setStroke ( new BasicStroke ( 1.5f ) );
        g2d.setPaint ( Color.GRAY );
        g2d.draw ( area );
    }

    if ( imageOpacity != 0 && paintedImage != null && imageLocation != null )
    {
        final Composite c = g2d.getComposite ();
        if ( imageOpacity != 100 )
        {
            g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, ( float ) imageOpacity / 100 ) );
        }

        g2d.drawImage ( paintedImage, imageLocation.x, imageLocation.y, null );

        if ( imageOpacity != 100 )
        {
            g2d.setComposite ( c );
        }
    }

    GraphicsUtils.restoreAntialias ( g2d, aa );
}
 
Example 17
Source File: RoundedCornerBorder.java    From material-ui-swing with MIT License 6 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setStroke(new BasicStroke(withBorder));
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int r = arch;
    int w = width - 1;
    int h = height - 1;

    Area round = new Area(new RoundRectangle2D.Float(x, y, w, h, r, r));
    if (c instanceof JPopupMenu) {
        g2.setPaint(c.getBackground());
        g2.fill(round);
    } else {
        Container parent = c.getParent();
        if (Objects.nonNull(parent)) {
            g2.setPaint(parent.getBackground());
            Area corner = new Area(new Rectangle2D.Float(x, y, width, height));
            corner.subtract(round);
            g2.fill(corner);
        }
    }
    g2.setPaint(colorLine);
    g2.draw(round);
    g2.dispose();
}
 
Example 18
Source File: SelectorUtils.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
public static void drawWebSelection ( final Graphics2D g2d, final Color color, Rectangle selection, final boolean resizableLR,
                                      final boolean resizableUD, final boolean drawConnectors, final boolean drawSideControls )
{
    selection = validateRect ( selection );

    final Object aa = GraphicsUtils.setupAntialias ( g2d );

    final Area buttonsShape = new Area ();

    // Top
    if ( resizableUD )
    {
        if ( resizableLR )
        {
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x - halfButton, selection.y - halfButton, halfButton * 2, halfButton * 2 ) ) );
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x + selection.width - halfButton, selection.y - halfButton, halfButton * 2,
                            halfButton * 2 ) ) );
        }
        if ( drawSideControls )
        {
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x + selection.width / 2 - halfButton, selection.y - halfButton, halfButton * 2,
                            halfButton * 2 ) ) );
        }
    }

    // Middle
    if ( resizableLR && drawSideControls )
    {
        buttonsShape.add ( new Area (
                new Ellipse2D.Double ( selection.x - halfButton, selection.y + selection.height / 2 - halfButton, halfButton * 2,
                        halfButton * 2 ) ) );
        buttonsShape.add ( new Area (
                new Ellipse2D.Double ( selection.x + selection.width - halfButton, selection.y + selection.height / 2 - halfButton,
                        halfButton * 2, halfButton * 2 ) ) );
    }

    // Bottom
    if ( resizableUD )
    {
        if ( resizableLR )
        {
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x - halfButton, selection.y + selection.height - halfButton, halfButton * 2,
                            halfButton * 2 ) ) );
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x + selection.width - halfButton, selection.y + selection.height - halfButton,
                            halfButton * 2, halfButton * 2 ) ) );
        }
        if ( drawSideControls )
        {
            buttonsShape.add ( new Area (
                    new Ellipse2D.Double ( selection.x + selection.width / 2 - halfButton, selection.y + selection.height - halfButton,
                            halfButton * 2, halfButton * 2 ) ) );
        }
    }

    // Button connectors
    if ( drawConnectors )
    {
        final Area selectionShape = new Area (
                new RoundRectangle2D.Double ( selection.x - halfLine, selection.y - halfLine, selection.width + halfLine * 2,
                        selection.height + halfLine * 2, 5, 5 ) );
        selectionShape.subtract ( new Area (
                new RoundRectangle2D.Double ( selection.x + halfLine, selection.y + halfLine, selection.width - halfLine * 2,
                        selection.height - halfLine * 2, 3, 3 ) ) );
        buttonsShape.add ( selectionShape );
    }

    // Shade
    GraphicsUtils.drawShade ( g2d, buttonsShape, Color.GRAY, shadeWidth );

    // Border
    g2d.setPaint ( Color.GRAY );
    g2d.draw ( buttonsShape );

    // Background
    g2d.setPaint ( color );
    g2d.fill ( buttonsShape );

    GraphicsUtils.restoreAntialias ( g2d, aa );
}
 
Example 19
Source File: RegionOps.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public RectListImpl getDifference(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.subtract(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 20
Source File: BasicQOptionPaneUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@SuppressWarnings("unused")
public void paintBorder(Component c, Graphics g0, int x, int y,
		int width, int height) {
	Graphics2D g = (Graphics2D) g0;
	Area area = new Area(new Rectangle(x, y, width, height));
	area.subtract(new Area(new Rectangle(x + insets.left, y
			+ insets.top, width - insets.left - insets.right, height
			- insets.top - insets.bottom)));
	if (c.isOpaque()) {
		Color bkgnd = c.getBackground();
		g.setColor(bkgnd);
		g.fill(area);
	}
	if (false) {
		g.setColor(debugColor);
		g.fill(area);
	}
}