当前位置: 首页>>代码示例>>Java>>正文


Java Rectangle.clone方法代码示例

本文整理汇总了Java中java.awt.Rectangle.clone方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle.clone方法的具体用法?Java Rectangle.clone怎么用?Java Rectangle.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Rectangle的用法示例。


在下文中一共展示了Rectangle.clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeBounds

import java.awt.Rectangle; //导入方法依赖的package包/类
/** Variation of the method for computing the bounds
 * for the concrete view component. As the component can possibly
 * be placed in a scroll pane it's first necessary
 * to translate the cursor bounds and also translate
 * back the resulting popup bounds.
 * @param popup  popup panel to be displayed
 * @param view component over which the popup is displayed.
 * @param cursorBounds the bounds of the caret or mouse cursor
 *    relative to the upper-left corner of the visible view.
 * @param placement where to place the popup panel according to
 *    the cursor position.
 * @return bounds of popup panel relative to the upper-left corner
 *    of the underlying view component.
 *    <CODE>null</CODE> if there is no place to display popup.
 */
protected static Rectangle computeBounds(JComponent popup,
JComponent view, Rectangle cursorBounds, Placement placement, HorizontalBounds horizontalBounds) {
    
    if (horizontalBounds == null) horizontalBounds = ViewPortBounds;
    
    Rectangle ret;
    Component viewParent = view.getParent();
    
    if (viewParent instanceof JLayeredPane) {
        viewParent = viewParent.getParent();
    }
    
    if (viewParent instanceof JViewport) {
        Rectangle viewBounds = ((JViewport)viewParent).getViewRect();

        Rectangle translatedCursorBounds = (Rectangle)cursorBounds.clone();
        if (placement != FixedPoint) {
            translatedCursorBounds.translate(-viewBounds.x, -viewBounds.y);
        }

        ret = computeBounds(popup, viewBounds.width, viewBounds.height,
            translatedCursorBounds, placement, horizontalBounds);
        
        if (ret != null) { // valid bounds
            ret.translate(viewBounds.x, viewBounds.y);
        }
        
    } else { // not in scroll pane
        ret = computeBounds(popup, view.getWidth(), view.getHeight(),
            cursorBounds, placement);
    }
    
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:PopupManager.java

示例2: test

import java.awt.Rectangle; //导入方法依赖的package包/类
public void test(Rectangle srcRect, Rectangle dstRect) {
    int w = getWidth();
    int h = getHeight();
    Toolkit.getDefaultToolkit().sync();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    Point p = getLocationOnScreen();
    grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h));

    // calculate the destination rectangle
    Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS);
    int trX = dstRect.x - srcRect.x;
    int trY = dstRect.y - srcRect.y;
    Rectangle newDstRect = (Rectangle)dstRect.clone();
    newDstRect.translate(-trX, -trY);
    Rectangle.intersect(newDstRect, srcBounds, newDstRect);
    newDstRect.translate(trX, trY);
    Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect);

    System.out.println("calculated dest rect:" + newDstRect);

    // we do implicit clipping of the destination surface
    // by only checking pixels within its bounds
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int rgb = 0;
            if (newDstRect.contains(x, y)) {
                rgb = Color.red.getRGB();
            } else {
                rgb = Color.green.getRGB();
            }
            if (grabbedBI.getRGB(x, y) != rgb) {
                String msg1 = "Test failed at x="+x+" y="+y;
                System.out.println(msg1);
                System.out.println(" expected: "+Integer.toHexString(rgb)+
                        " got:"+Integer.toHexString(grabbedBI.getRGB(x, y)));
                throw new RuntimeException(msg1);
            }
        }
    }
    System.out.println("subtest passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:44,代码来源:SourceClippingBlitTest.java

示例3: setSourceRegion

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * Sets the source region of interest.  The region of interest is
 * described as a rectangle, with the upper-left corner of the
 * source image as pixel (0, 0) and increasing values down and to
 * the right.  The actual number of pixels used will depend on
 * the subsampling factors set by <code>setSourceSubsampling</code>.
 * If subsampling has been set such that this number is zero,
 * an <code>IllegalStateException</code> will be thrown.
 *
 * <p> The source region of interest specified by this method will
 * be clipped as needed to fit within the source bounds, as well
 * as the destination offsets, width, and height at the time of
 * actual I/O.
 *
 * <p> A value of <code>null</code> for <code>sourceRegion</code>
 * will remove any region specification, causing the entire image
 * to be used.
 *
 * @param sourceRegion a <code>Rectangle</code> specifying the
 * source region of interest, or <code>null</code>.
 *
 * @exception IllegalArgumentException if
 * <code>sourceRegion</code> is non-<code>null</code> and either
 * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is
 * negative.
 * @exception IllegalArgumentException if
 * <code>sourceRegion</code> is non-<code>null</code> and either
 * <code>sourceRegion.width</code> or
 * <code>sourceRegion.height</code> is negative or 0.
 * @exception IllegalStateException if subsampling is such that
 * this region will have a subsampled width or height of zero.
 *
 * @see #getSourceRegion
 * @see #setSourceSubsampling
 * @see ImageReadParam#setDestinationOffset
 * @see ImageReadParam#getDestinationOffset
 */
public void setSourceRegion(Rectangle sourceRegion) {
    if (sourceRegion == null) {
        this.sourceRegion = null;
        return;
    }

    if (sourceRegion.x < 0) {
        throw new IllegalArgumentException("sourceRegion.x < 0!");
    }
    if (sourceRegion.y < 0){
        throw new IllegalArgumentException("sourceRegion.y < 0!");
    }
    if (sourceRegion.width <= 0) {
        throw new IllegalArgumentException("sourceRegion.width <= 0!");
    }
    if (sourceRegion.height <= 0) {
        throw new IllegalArgumentException("sourceRegion.height <= 0!");
    }

    // Throw an IllegalStateException if region falls between subsamples
    if (sourceRegion.width <= subsamplingXOffset) {
        throw new IllegalStateException
            ("sourceRegion.width <= subsamplingXOffset!");
    }
    if (sourceRegion.height <= subsamplingYOffset) {
        throw new IllegalStateException
            ("sourceRegion.height <= subsamplingYOffset!");
    }

    this.sourceRegion = (Rectangle)sourceRegion.clone();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:69,代码来源:IIOParam.java

示例4: setSourceRegion

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * Sets the source region of interest.  The region of interest is
 * described as a rectangle, with the upper-left corner of the
 * source image as pixel (0, 0) and increasing values down and to
 * the right.  The actual number of pixels used will depend on
 * the subsampling factors set by {@code setSourceSubsampling}.
 * If subsampling has been set such that this number is zero,
 * an {@code IllegalStateException} will be thrown.
 *
 * <p> The source region of interest specified by this method will
 * be clipped as needed to fit within the source bounds, as well
 * as the destination offsets, width, and height at the time of
 * actual I/O.
 *
 * <p> A value of {@code null} for {@code sourceRegion}
 * will remove any region specification, causing the entire image
 * to be used.
 *
 * @param sourceRegion a {@code Rectangle} specifying the
 * source region of interest, or {@code null}.
 *
 * @exception IllegalArgumentException if
 * {@code sourceRegion} is non-{@code null} and either
 * {@code sourceRegion.x} or {@code sourceRegion.y} is
 * negative.
 * @exception IllegalArgumentException if
 * {@code sourceRegion} is non-{@code null} and either
 * {@code sourceRegion.width} or
 * {@code sourceRegion.height} is negative or 0.
 * @exception IllegalStateException if subsampling is such that
 * this region will have a subsampled width or height of zero.
 *
 * @see #getSourceRegion
 * @see #setSourceSubsampling
 * @see ImageReadParam#setDestinationOffset
 * @see ImageReadParam#getDestinationOffset
 */
public void setSourceRegion(Rectangle sourceRegion) {
    if (sourceRegion == null) {
        this.sourceRegion = null;
        return;
    }

    if (sourceRegion.x < 0) {
        throw new IllegalArgumentException("sourceRegion.x < 0!");
    }
    if (sourceRegion.y < 0){
        throw new IllegalArgumentException("sourceRegion.y < 0!");
    }
    if (sourceRegion.width <= 0) {
        throw new IllegalArgumentException("sourceRegion.width <= 0!");
    }
    if (sourceRegion.height <= 0) {
        throw new IllegalArgumentException("sourceRegion.height <= 0!");
    }

    // Throw an IllegalStateException if region falls between subsamples
    if (sourceRegion.width <= subsamplingXOffset) {
        throw new IllegalStateException
            ("sourceRegion.width <= subsamplingXOffset!");
    }
    if (sourceRegion.height <= subsamplingYOffset) {
        throw new IllegalStateException
            ("sourceRegion.height <= subsamplingYOffset!");
    }

    this.sourceRegion = (Rectangle)sourceRegion.clone();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:IIOParam.java


注:本文中的java.awt.Rectangle.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。