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

The following examples show how to use java.awt.geom.Area#exclusiveOr() . 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: M.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Converts all points in @param area to ints by casting. */
static public final Area areaInInts(final Area area) {
	final Area a = new Area();
	for (final Polygon pol : M.getPolygons(area)) {
		a.exclusiveOr(new Area(pol));
	}
	return a;
}
 
Example 2
Source File: ImageUtils.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns shadow image based on provided shape.
 *
 * @param width       shadow image width
 * @param shape       shadow shape
 * @param shadowWidth shadow width
 * @param opacity     shadow opacity
 * @return shadow image based on provided shape
 */
@NotNull
public static BufferedImage createInnerShadowImage ( final int width, @NotNull final Shape shape, final int shadowWidth,
                                                     final float opacity )
{
    // Creating template image
    final BufferedImage bi = createCompatibleImage ( width, width, Transparency.TRANSLUCENT );
    final Graphics2D ig = bi.createGraphics ();
    GraphicsUtils.setupAntialias ( ig );
    final Area area = new Area ( new Rectangle ( 0, 0, width, width ) );
    area.exclusiveOr ( new Area ( shape ) );
    ig.setPaint ( Color.BLACK );
    ig.fill ( area );
    ig.dispose ();

    // Creating shadow image
    final ShadowFilter sf = new ShadowFilter ( shadowWidth, 0, 0, opacity );
    final BufferedImage shadow = sf.filter ( bi, null );

    // Clipping shadow image
    final Graphics2D g2d = shadow.createGraphics ();
    GraphicsUtils.setupAntialias ( g2d );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.setPaint ( ColorUtils.transparent () );
    g2d.fill ( area );
    g2d.dispose ();

    return shadow.getSubimage ( shadowWidth, shadowWidth, width - shadowWidth * 2, width - shadowWidth * 2 );
}
 
Example 3
Source File: ComponentHighlighter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Paints complex component area.
 *
 * @param g2d    graphics context
 * @param insets area insets
 * @param outer  outer area bounds
 * @param inner  inner area bounds
 * @param color  area color
 */
private void paintComplexArea ( @NotNull final Graphics2D g2d, @NotNull final Insets insets, @NotNull final Rectangle outer,
                                @NotNull final Rectangle inner, @NotNull final Color color )
{
    if ( !insets.equals ( emptyInsets ) )
    {
        g2d.setPaint ( color );
        final Area ma = new Area ( outer );
        ma.exclusiveOr ( new Area ( inner ) );
        g2d.fill ( ma );
    }
}
 
Example 4
Source File: WebShadow.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns inner shadow image based on provided shape.
 *
 * @param bounds  shadow bounds
 * @param width   shadow width
 * @param opacity shadow opacity
 * @param color   shadow color
 * @param shape   shadow shape
 * @return inner shadow image based on provided shape
 */
@NotNull
public static BufferedImage createInnerShadowImage ( @NotNull final Rectangle bounds, final int width, final float opacity,
                                                     @NotNull final Color color, @NotNull final Shape shape )
{
    final Rectangle b = new Rectangle ( bounds.x - width * 2, bounds.y - width * 2,
            bounds.width + width * 4, bounds.height + width * 4 );

    // Creating template image
    final BufferedImage bi = ImageUtils.createCompatibleImage ( b.width, b.height, Transparency.TRANSLUCENT );
    final Graphics2D ig = bi.createGraphics ();
    GraphicsUtils.setupAntialias ( ig );
    ig.translate ( -b.x, -b.y );
    final Area area = new Area ( new Rectangle ( b.x, b.y, b.width, b.height ) );
    area.exclusiveOr ( new Area ( shape ) );
    ig.setPaint ( Color.BLACK );
    ig.fill ( area );
    ig.dispose ();

    // Creating inner shadow image
    final ShadowFilter sf = new ShadowFilter ( width, 0, 0, opacity );
    sf.setShadowColor ( Color.BLACK.getRGB () );
    final BufferedImage shadow = sf.filter ( bi, null );

    // Clipping inner shadow image
    final Graphics2D g2d = shadow.createGraphics ();
    GraphicsUtils.setupAntialias ( g2d );
    g2d.translate ( -b.x, -b.y );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.setPaint ( ColorUtils.transparent () );
    g2d.fill ( area );
    g2d.setPaint ( color );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.fillRect ( 0, 0, b.width, b.height );
    g2d.dispose ();

    return shadow.getSubimage ( width * 2, width * 2, b.width - width * 4, b.height - width * 4 );
}
 
Example 5
Source File: RegionOps.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 6
Source File: WebDynamicMenuItem.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void paintComponent ( final Graphics g )
{
    super.paintComponent ( g );

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

    // final int w = getWidth ();
    final int h = getHeight ();
    final int iw = h - margin.top - margin.bottom;

    // Paint icon
    if ( icon != null )
    {
        // Paint icon border
        if ( isPaintBorder () )
        {
            final Area outer = new Area ( new Ellipse2D.Double ( 0, 0, h, h ) );
            final Ellipse2D.Double inner = new Ellipse2D.Double ( 2, 2, h - 4, h - 4 );
            outer.exclusiveOr ( new Area ( inner ) );

            g2d.setPaint ( isEnabled () ? getBorderColor () : getDisabledBorderColor () );
            g2d.fill ( outer );

            g2d.setPaint ( isEnabled () ? getBorderBackground () : getDisabledBorderBackground () );
            g2d.fill ( inner );
        }

        // Paint icon
        g2d.drawImage ( icon.getImage (), margin.left + iw / 2 - icon.getIconWidth () / 2,
                margin.top + iw / 2 - icon.getIconHeight () / 2, null );
    }

    // Paint text
    if ( text != null )
    {
        g2d.setFont ( getFont () );

        final FontMetrics fm = g2d.getFontMetrics ();
        final int tw = fm.stringWidth ( text );
        final int th = fm.getHeight ();
        final int ts = LafUtils.getTextCenterShiftY ( fm );

        // Calculating full text rectangle
        final int tx = margin.left + iw + iconTextGap;
        final int ty = margin.top + iw / 2 - th / 2 - textMargin.top;
        final Rectangle tr = new Rectangle ( tx, ty, textMargin.left + tw + textMargin.right, textMargin.top + th + textMargin.bottom );

        // Paint text border
        g2d.setPaint ( rollover ? getRolloverBackground () : getBackground () );
        g2d.fillRoundRect ( tr.x, tr.y, tr.width, tr.height, /*tr.height, tr.height*/ 6, 6 );

        final int ath = tr.height - textMargin.top - textMargin.bottom;
        g2d.setPaint ( getForeground () );
        g2d.drawString ( text, tr.x + textMargin.left, tr.y + textMargin.top + ath / 2 + ts );
    }

    GraphicsUtils.restoreAntialias ( g2d, aa );
}
 
Example 7
Source File: RegionOps.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 8
Source File: RegionOps.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 9
Source File: RegionOps.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 10
Source File: RegionOps.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 11
Source File: RegionOps.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 12
Source File: RegionOps.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 13
Source File: RegionOps.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 14
Source File: RegionOps.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 15
Source File: RegionOps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 16
Source File: RegionOps.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 17
Source File: RegionOps.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 18
Source File: RegionOps.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getExclusiveOr(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.exclusiveOr(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 19
Source File: Path.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Computes the area covered by the first or the second but not both given
 * areas.
 *
 * @param pa
 *            the first area to compute the xor for
 * @param pb
 *            the second area to compute the xor for
 * @return the exclusive-or of the areas
 */
public static Path exclusiveOr(Path pa, Path pb) {
	Area a = new Area(Geometry2AWT.toAWTPath(pa));
	Area b = new Area(Geometry2AWT.toAWTPath(pb));
	a.exclusiveOr(b);
	return AWT2Geometry.toPath(new Path2D.Double(a));
}