java.awt.geom.Area#subtract ( )源码实例Demo

下面列出了java.awt.geom.Area#subtract ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ramus   文件: ScrollPanePreview.java
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);
}
 
源代码2 项目: flowable-engine   文件: CmmnJsonConverter.java
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;
}
 
源代码3 项目: flowable-engine   文件: CmmnJsonConverter.java
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;
}
 
源代码4 项目: darklaf   文件: ColorTriangle.java
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;
}
 
源代码5 项目: mil-sym-java   文件: Radarc.java
@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;
}
 
源代码6 项目: java-swing-tips   文件: MainPanel.java
@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();
}
 
源代码7 项目: flowable-engine   文件: BpmnJsonConverter.java
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;
}
 
源代码8 项目: netbeans   文件: BalloonManager.java
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;
}
 
源代码9 项目: TrakEM2   文件: M.java
/** 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));
}
 
源代码10 项目: netbeans   文件: AquaVectorTabControlIcon.java
/**
 * 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;
}
 
源代码11 项目: java-swing-tips   文件: MainPanel.java
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();
}
 
源代码12 项目: TranskribusCore   文件: ImgUtils.java
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;        
}
 
源代码13 项目: pumpernickel   文件: BasicQOptionPaneUI.java
@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);
	}
}
 
源代码14 项目: jdk8u-dev-jdk   文件: RegionOps.java
public RectListImpl getDifference(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.subtract(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
源代码15 项目: material-ui-swing   文件: RoundedCornerBorder.java
@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();
}
 
源代码16 项目: weblaf   文件: WebGlassPane.java
/**
 * 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 );
}
 
源代码17 项目: FlatLaf   文件: FlatWindowRestoreIcon.java
@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 );
}
 
源代码18 项目: SIMVA-SoS   文件: StandardDialFrame.java
/**
 * 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);
}
 
源代码19 项目: dsworkbench   文件: AnimatedVillageInfoRenderer.java
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;
        }


    }
 
源代码20 项目: weblaf   文件: SelectorUtils.java
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 );
}