java.awt.Rectangle#isEmpty ( )源码实例Demo

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

源代码1 项目: jdk8u-jdk   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码2 项目: jdk1.8-source-analysis   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码3 项目: dragonwell8_jdk   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码4 项目: openjdk-8-source   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
{

    if(thumbBounds.isEmpty() || !scrollbar.isEnabled())     {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w-1, h-1);

    g.setColor(thumbHighlightColor);
    g.drawLine(0, 0, 0, h-1);
    g.drawLine(1, 0, w-1, 0);

    g.setColor(thumbLightShadowColor);
    g.drawLine(1, h-1, w-1, h-1);
    g.drawLine(w-1, 1, w-1, h-2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码5 项目: hottub   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码6 项目: jdk8u-dev-jdk   文件: MotifScrollBarUI.java
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
源代码7 项目: runelite   文件: WidgetOverlay.java
@Override
public Rectangle getBounds()
{
	final Rectangle bounds = super.getBounds();
	final Rectangle parent = getParentBounds(client.getWidget(widgetInfo));

	if (parent.isEmpty())
	{
		return bounds;
	}

	int x = bounds.x;
	int y = bounds.y;
	x = Math.max(parent.x, x);
	y = Math.max(parent.y, y);
	x = Math.min((int)parent.getMaxX() - bounds.width, x);
	y = Math.min((int)parent.getMaxY() - bounds.height, y);
	bounds.setLocation(x, y);
	return bounds;
}
 
源代码8 项目: hottub   文件: RepaintArea.java
/**
 * Adds a <code>Rectangle</code> to this <code>RepaintArea</code>.
 * PAINT Rectangles are divided into mostly vertical and mostly horizontal.
 * Each group is unioned together.
 * UPDATE Rectangles are unioned.
 *
 * @param   r   the specified <code>Rectangle</code>
 * @param   id  possible values PaintEvent.UPDATE or PaintEvent.PAINT
 * @since   1.3
 */
public synchronized void add(Rectangle r, int id) {
    // Make sure this new rectangle has positive dimensions
    if (r.isEmpty()) {
        return;
    }
    int addTo = UPDATE;
    if (id == PaintEvent.PAINT) {
        addTo = (r.width > r.height) ? HORIZONTAL : VERTICAL;
    }
    if (paintRects[addTo] != null) {
        paintRects[addTo].add(r);
    } else {
        paintRects[addTo] = new Rectangle(r);
    }
}
 
源代码9 项目: jdk8u-jdk   文件: BufferedImage.java
/**
 * Sets a rectangular region of the image to the contents of the
 * specified <code>Raster</code> <code>r</code>, which is
 * assumed to be in the same coordinate space as the
 * <code>BufferedImage</code>. The operation is clipped to the bounds
 * of the <code>BufferedImage</code>.
 * @param r the specified <code>Raster</code>
 * @see #getData
 * @see #getData(Rectangle)
*/
public void setData(Raster r) {
    int width = r.getWidth();
    int height = r.getHeight();
    int startX = r.getMinX();
    int startY = r.getMinY();

    int[] tdata = null;

    // Clip to the current Raster
    Rectangle rclip = new Rectangle(startX, startY, width, height);
    Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
    Rectangle intersect = rclip.intersection(bclip);
    if (intersect.isEmpty()) {
        return;
    }
    width = intersect.width;
    height = intersect.height;
    startX = intersect.x;
    startY = intersect.y;

    // remind use get/setDataElements for speed if Rasters are
    // compatible
    for (int i = startY; i < startY+height; i++)  {
        tdata = r.getPixels(startX,i,width,1,tdata);
        raster.setPixels(startX,i,width,1, tdata);
    }
}
 
源代码10 项目: Bytecoder   文件: BufferedImage.java
/**
 * Sets a rectangular region of the image to the contents of the
 * specified {@code Raster r}, which is
 * assumed to be in the same coordinate space as the
 * {@code BufferedImage}. The operation is clipped to the bounds
 * of the {@code BufferedImage}.
 * @param r the specified {@code Raster}
 * @see #getData
 * @see #getData(Rectangle)
*/
public void setData(Raster r) {
    int width = r.getWidth();
    int height = r.getHeight();
    int startX = r.getMinX();
    int startY = r.getMinY();

    int[] tdata = null;

    // Clip to the current Raster
    Rectangle rclip = new Rectangle(startX, startY, width, height);
    Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
    Rectangle intersect = rclip.intersection(bclip);
    if (intersect.isEmpty()) {
        return;
    }
    width = intersect.width;
    height = intersect.height;
    startX = intersect.x;
    startY = intersect.y;

    // remind use get/setDataElements for speed if Rasters are
    // compatible
    for (int i = startY; i < startY+height; i++)  {
        tdata = r.getPixels(startX,i,width,1,tdata);
        raster.setPixels(startX,i,width,1, tdata);
    }
}
 
源代码11 项目: openjdk-jdk9   文件: RepaintArea.java
/**
 * Subtracts subtr from rect. If the result is rectangle
 * changes rect and returns true. Otherwise false.
 */
static boolean subtract(Rectangle rect, Rectangle subtr) {
    if (rect == null || subtr == null) {
        return true;
    }
    Rectangle common = rect.intersection(subtr);
    if (common.isEmpty()) {
        return true;
    }
    if (rect.x == common.x && rect.y == common.y) {
        if (rect.width == common.width) {
            rect.y += common.height;
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.x += common.width;
            rect.width -= common.width;
            return true;
        }
    } else
    if (rect.x + rect.width == common.x + common.width
        && rect.y + rect.height == common.y + common.height)
    {
        if (rect.width == common.width) {
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.width -= common.width;
            return true;
        }
    }
    return false;
}
 
源代码12 项目: jdk8u-jdk   文件: RepaintArea.java
/**
 * Subtracts subtr from rect. If the result is rectangle
 * changes rect and returns true. Otherwise false.
 */
static boolean subtract(Rectangle rect, Rectangle subtr) {
    if (rect == null || subtr == null) {
        return true;
    }
    Rectangle common = rect.intersection(subtr);
    if (common.isEmpty()) {
        return true;
    }
    if (rect.x == common.x && rect.y == common.y) {
        if (rect.width == common.width) {
            rect.y += common.height;
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.x += common.width;
            rect.width -= common.width;
            return true;
        }
    } else
    if (rect.x + rect.width == common.x + common.width
        && rect.y + rect.height == common.y + common.height)
    {
        if (rect.width == common.width) {
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.width -= common.width;
            return true;
        }
    }
    return false;
}
 
源代码13 项目: openjdk-8-source   文件: RepaintArea.java
/**
 * Subtracts subtr from rect. If the result is rectangle
 * changes rect and returns true. Otherwise false.
 */
static boolean subtract(Rectangle rect, Rectangle subtr) {
    if (rect == null || subtr == null) {
        return true;
    }
    Rectangle common = rect.intersection(subtr);
    if (common.isEmpty()) {
        return true;
    }
    if (rect.x == common.x && rect.y == common.y) {
        if (rect.width == common.width) {
            rect.y += common.height;
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.x += common.width;
            rect.width -= common.width;
            return true;
        }
    } else
    if (rect.x + rect.width == common.x + common.width
        && rect.y + rect.height == common.y + common.height)
    {
        if (rect.width == common.width) {
            rect.height -= common.height;
            return true;
        } else
        if (rect.height == common.height) {
            rect.width -= common.width;
            return true;
        }
    }
    return false;
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: BufferedImage.java
/**
 * Sets a rectangular region of the image to the contents of the
 * specified <code>Raster</code> <code>r</code>, which is
 * assumed to be in the same coordinate space as the
 * <code>BufferedImage</code>. The operation is clipped to the bounds
 * of the <code>BufferedImage</code>.
 * @param r the specified <code>Raster</code>
 * @see #getData
 * @see #getData(Rectangle)
*/
public void setData(Raster r) {
    int width = r.getWidth();
    int height = r.getHeight();
    int startX = r.getMinX();
    int startY = r.getMinY();

    int[] tdata = null;

    // Clip to the current Raster
    Rectangle rclip = new Rectangle(startX, startY, width, height);
    Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
    Rectangle intersect = rclip.intersection(bclip);
    if (intersect.isEmpty()) {
        return;
    }
    width = intersect.width;
    height = intersect.height;
    startX = intersect.x;
    startY = intersect.y;

    // remind use get/setDataElements for speed if Rasters are
    // compatible
    for (int i = startY; i < startY+height; i++)  {
        tdata = r.getPixels(startX,i,width,1,tdata);
        raster.setPixels(startX,i,width,1, tdata);
    }
}
 
源代码15 项目: jdk8u60   文件: BufferedImage.java
/**
 * Sets a rectangular region of the image to the contents of the
 * specified <code>Raster</code> <code>r</code>, which is
 * assumed to be in the same coordinate space as the
 * <code>BufferedImage</code>. The operation is clipped to the bounds
 * of the <code>BufferedImage</code>.
 * @param r the specified <code>Raster</code>
 * @see #getData
 * @see #getData(Rectangle)
*/
public void setData(Raster r) {
    int width = r.getWidth();
    int height = r.getHeight();
    int startX = r.getMinX();
    int startY = r.getMinY();

    int[] tdata = null;

    // Clip to the current Raster
    Rectangle rclip = new Rectangle(startX, startY, width, height);
    Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
    Rectangle intersect = rclip.intersection(bclip);
    if (intersect.isEmpty()) {
        return;
    }
    width = intersect.width;
    height = intersect.height;
    startX = intersect.x;
    startY = intersect.y;

    // remind use get/setDataElements for speed if Rasters are
    // compatible
    for (int i = startY; i < startY+height; i++)  {
        tdata = r.getPixels(startX,i,width,1,tdata);
        raster.setPixels(startX,i,width,1, tdata);
    }
}
 
源代码16 项目: snap-desktop   文件: ComputeMaskAreaAction.java
private MaskAreaStatistics computeMaskAreaStatistics(ProgressMonitor pm) {
    final MultiLevelImage maskImage = mask.getSourceImage();

    final int minTileX = maskImage.getMinTileX();
    final int minTileY = maskImage.getMinTileY();

    final int numXTiles = maskImage.getNumXTiles();
    final int numYTiles = maskImage.getNumYTiles();

    final int w = mask.getRasterWidth();
    final int h = mask.getRasterHeight();
    final Rectangle imageRect = new Rectangle(0, 0, w, h);

    final PixelPos[] pixelPoints = new PixelPos[5];
    final GeoPos[] geoPoints = new GeoPos[5];
    for (int i = 0; i < geoPoints.length; i++) {
        pixelPoints[i] = new PixelPos();
        geoPoints[i] = new GeoPos();
    }

    GeoCoding geoCoding = mask.getGeoCoding();
    AreaCalculator areaCalculator = new AreaCalculator(geoCoding);
    MaskAreaStatistics areaStatistics = new MaskAreaStatistics(areaCalculator.getEarthRadius() / 1000.0);
    pm.beginTask("Computing Mask area...", numXTiles * numYTiles);
    try {
        for (int tileX = minTileX; tileX < minTileX + numXTiles; ++tileX) {
            for (int tileY = minTileY; tileY < minTileY + numYTiles; ++tileY) {
                if (pm.isCanceled()) {
                    break;
                }
                final Rectangle tileRectangle = new Rectangle(
                        maskImage.getTileGridXOffset() + tileX * maskImage.getTileWidth(),
                        maskImage.getTileGridYOffset() + tileY * maskImage.getTileHeight(),
                        maskImage.getTileWidth(), maskImage.getTileHeight());

                final Rectangle r = imageRect.intersection(tileRectangle);
                if (!r.isEmpty()) {
                    Raster maskTile = maskImage.getTile(tileX, tileY);
                    for (int y = r.y; y < r.y + r.height; y++) {
                        for (int x = r.x; x < r.x + r.width; x++) {
                            if (maskTile.getSample(x, y, 0) != 0) {
                                double pixelArea = areaCalculator.calculatePixelSize(x, y) / Math.pow(1000.0, 2);
                                areaStatistics.setPixelAreaMin(Math.min(areaStatistics.getPixelAreaMin(), pixelArea));
                                areaStatistics.setPixelAreaMax(Math.max(areaStatistics.getPixelAreaMax(), pixelArea));
                                areaStatistics.setMaskArea(areaStatistics.getMaskArea() + pixelArea);
                                areaStatistics.setNumPixels(areaStatistics.getNumPixels() + 1);
                            }
                        }
                    }
                }
                pm.worked(1);
            }
        }
    } finally {
        pm.done();
    }
    return areaStatistics;
}
 
源代码17 项目: openjdk-jdk9   文件: TIFFImageWriter.java
public void prepareReplacePixels(int imageIndex,
                                 Rectangle region) throws IOException {
    synchronized(replacePixelsLock) {
        // Check state and parameters vis-a-vis ImageWriter specification.
        if (stream == null) {
            throw new IllegalStateException("Output not set!");
        }
        if (region == null) {
            throw new IllegalArgumentException("region == null!");
        }
        if (region.getWidth() < 1) {
            throw new IllegalArgumentException("region.getWidth() < 1!");
        }
        if (region.getHeight() < 1) {
            throw new IllegalArgumentException("region.getHeight() < 1!");
        }
        if (inReplacePixelsNest) {
            throw new IllegalStateException
                ("In nested call to prepareReplacePixels!");
        }

        // Read the IFD for the pixel replacement index.
        TIFFIFD replacePixelsIFD = readIFD(imageIndex);

        // Ensure that compression is "none".
        TIFFField f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
        int compression = f.getAsInt(0);
        if (compression != BaselineTIFFTagSet.COMPRESSION_NONE) {
            throw new UnsupportedOperationException
                ("canReplacePixels(imageIndex) == false!");
        }

        // Get the image dimensions.
        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_WIDTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageWidth field.");
        }
        int w = f.getAsInt(0);

        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_LENGTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageHeight field.");
        }
        int h = f.getAsInt(0);

        // Create image bounds.
        Rectangle bounds = new Rectangle(0, 0, w, h);

        // Intersect region with bounds.
        region = region.intersection(bounds);

        // Check for empty intersection.
        if(region.isEmpty()) {
            throw new IIOException("Region does not intersect image bounds");
        }

        // Save the region.
        replacePixelsRegion = region;

        // Get the tile offsets.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
        }
        replacePixelsTileOffsets = f.getAsLongs();

        // Get the byte counts.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
        }
        replacePixelsByteCounts = f.getAsLongs();

        replacePixelsOffsetsPosition =
            replacePixelsIFD.getStripOrTileOffsetsPosition();
        replacePixelsByteCountsPosition =
            replacePixelsIFD.getStripOrTileByteCountsPosition();

        // Get the image metadata.
        replacePixelsMetadata = new TIFFImageMetadata(replacePixelsIFD);

        // Save the image index.
        replacePixelsIndex = imageIndex;

        // Set the pixel replacement flag.
        inReplacePixelsNest = true;
    }
}
 
源代码18 项目: jdk8u-jdk   文件: JLightweightFrame.java
/**
 * Constructs a new, initially invisible {@code JLightweightFrame}
 * instance.
 */
public JLightweightFrame() {
    super();
    copyBufferEnabled = "true".equals(AccessController.
        doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true")));

    add(rootPane, BorderLayout.CENTER);
    setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
    if (getGraphicsConfiguration().isTranslucencyCapable()) {
        setBackground(new Color(0, 0, 0, 0));
    }

    layoutSizeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            Dimension d = (Dimension)e.getNewValue();

            if ("preferredSize".equals(e.getPropertyName())) {
                content.preferredSizeChanged(d.width, d.height);

            } else if ("maximumSize".equals(e.getPropertyName())) {
                content.maximumSizeChanged(d.width, d.height);

            } else if ("minimumSize".equals(e.getPropertyName())) {
                content.minimumSizeChanged(d.width, d.height);
            }
        }
    };

    repaintListener = (JComponent c, int x, int y, int w, int h) -> {
        Window jlf = SwingUtilities.getWindowAncestor(c);
        if (jlf != JLightweightFrame.this) {
            return;
        }
        Point p = SwingUtilities.convertPoint(c, x, y, jlf);
        Rectangle r = new Rectangle(p.x, p.y, w, h).intersection(
                new Rectangle(0, 0, bbImage.getWidth() / scaleFactor,
                              bbImage.getHeight() / scaleFactor));

        if (!r.isEmpty()) {
            notifyImageUpdated(r.x, r.y, r.width, r.height);
        }
    };

    SwingAccessor.getRepaintManagerAccessor().addRepaintListener(
        RepaintManager.currentManager(this), repaintListener);
}
 
源代码19 项目: Pixelitor   文件: AbstractAreaEffect.java
@Override
public void apply(Graphics2D g, Shape clipShape, int width, int height) {
    // opacity support added by lbalazscs
    Composite savedComposite = g.getComposite();
    if(opacity < 1.0f){
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
    }

    // create a rect to hold the bounds
    Rectangle2D clipShapeBounds = clipShape.getBounds2D();

    if(clipShapeBounds.isEmpty()) {
        // check added by lbalazscs
        return;
    }

    width = (int) (clipShapeBounds.getWidth() + clipShapeBounds.getX());
    height = (int) (clipShapeBounds.getHeight() + clipShapeBounds.getY());
    Rectangle effectBounds = new Rectangle(0, 0,
            (int) (width + getEffectWidth() * 2 + 1),
            (int) (height + getEffectWidth() * 2 + 1));

    if (effectBounds.isEmpty()) {
        // check added by lbalazscs
        // this can be empty even if the clip shape bounds is not
        // when the clip shape starts at large negative coordinates
        return;
    }

    // Apply the border glow effect
    if (isShapeMasked()) {
        BufferedImage clipImage = getClipImage(effectBounds);
        Graphics2D g2 = clipImage.createGraphics();

        // lbalazscs: moved here from getClipImage
        // in order to avoid two createGraphics calls
        g2.clearRect(0, 0, clipImage.getWidth(), clipImage.getHeight());

        try {
            // clear the buffer
            g2.setPaint(Color.BLACK);
            g2.setComposite(AlphaComposite.Clear);
            g2.fillRect(0, 0, effectBounds.width, effectBounds.height);

            if (debug) {
                g2.setPaint(Color.WHITE);
                g2.setComposite(AlphaComposite.SrcOver);
                g2.drawRect(0, 0, effectBounds.width - 1,
                        effectBounds.height - 1);
            }

            // turn on smoothing
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g2.translate(getEffectWidth() - getOffset().getX(),
                    getEffectWidth() - getOffset().getY());
            paintBorderGlow(g2, clipShape, width, height);

            // clip out the parts we don't want
            g2.setComposite(AlphaComposite.Clear);
            g2.setColor(Color.WHITE);
            if (isRenderInsideShape()) {
                // clip the outside
                Area area = new Area(effectBounds);
                area.subtract(new Area(clipShape));
                g2.fill(area);
            } else {
                // clip the inside
                g2.fill(clipShape);
            }
        } finally {
            // draw the final image
            g2.dispose();
        }

        int drawX = (int) (-getEffectWidth() + getOffset().getX());
        int drawY = (int) (-getEffectWidth() + getOffset().getY());
        g.drawImage(clipImage, drawX, drawY, null);
    } else {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        paintBorderGlow(g, clipShape, width, height);
    }

    //g.setColor(Color.MAGENTA);
    //g.draw(clipShape.getBounds2D());
    //g.drawRect(0,0,width,height);

    g.setComposite(savedComposite);
}
 
源代码20 项目: TencentKona-8   文件: JLightweightFrame.java
/**
 * Constructs a new, initially invisible {@code JLightweightFrame}
 * instance.
 */
public JLightweightFrame() {
    super();
    copyBufferEnabled = "true".equals(AccessController.
        doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true")));

    add(rootPane, BorderLayout.CENTER);
    setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
    if (getGraphicsConfiguration().isTranslucencyCapable()) {
        setBackground(new Color(0, 0, 0, 0));
    }

    layoutSizeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            Dimension d = (Dimension)e.getNewValue();

            if ("preferredSize".equals(e.getPropertyName())) {
                content.preferredSizeChanged(d.width, d.height);

            } else if ("maximumSize".equals(e.getPropertyName())) {
                content.maximumSizeChanged(d.width, d.height);

            } else if ("minimumSize".equals(e.getPropertyName())) {
                content.minimumSizeChanged(d.width, d.height);
            }
        }
    };

    repaintListener = (JComponent c, int x, int y, int w, int h) -> {
        Window jlf = SwingUtilities.getWindowAncestor(c);
        if (jlf != JLightweightFrame.this) {
            return;
        }
        Point p = SwingUtilities.convertPoint(c, x, y, jlf);
        Rectangle r = new Rectangle(p.x, p.y, w, h).intersection(
                new Rectangle(0, 0, bbImage.getWidth() / scaleFactor,
                              bbImage.getHeight() / scaleFactor));

        if (!r.isEmpty()) {
            notifyImageUpdated(r.x, r.y, r.width, r.height);
        }
    };

    SwingAccessor.getRepaintManagerAccessor().addRepaintListener(
        RepaintManager.currentManager(this), repaintListener);
}