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


Java Rectangle.intersection方法代码示例

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


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

示例1: scrollAtEdge

import java.awt.Rectangle; //导入方法依赖的package包/类
public void scrollAtEdge(Point evtPt, int dist) {
  JScrollPane scroll = myStack.stackConfigurer.getScroll();

  Point p = new Point(evtPt.x - scroll.getViewport().getViewPosition().x,
      evtPt.y - scroll.getViewport().getViewPosition().y);
  int dx = 0, dy = 0;
  if (p.x < dist && p.x >= 0)
    dx = -1;
  if (p.x >= scroll.getViewport().getSize().width - dist
      && p.x < scroll.getViewport().getSize().width)
    dx = 1;
  if (p.y < dist && p.y >= 0)
    dy = -1;
  if (p.y >= scroll.getViewport().getSize().height - dist
      && p.y < scroll.getViewport().getSize().height)
    dy = 1;

  if (dx != 0 || dy != 0) {
    Rectangle r = new Rectangle(scroll.getViewport().getViewRect());
    r.translate(2 * dist * dx, 2 * dist * dy);
    r = r.intersection(new Rectangle(new Point(0, 0), getPreferredSize()));
    scrollRectToVisible(r);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:SetupStack.java

示例2: paintComponent

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 
 */
public void paintComponent(Graphics g) {
  if (gradientColor == null) {
    super.paintComponent(g);
  } else {
    Rectangle rect = getVisibleRect();

    if (g.getClipBounds() != null) {
      rect = rect.intersection(g.getClipBounds());
    }

    Graphics2D g2 = (Graphics2D) g;

    g2.setPaint(new GradientPaint(0, 0, getBackground(), getWidth(), 0, gradientColor));
    g2.fill(rect);
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:20,代码来源:EditorPalette.java

示例3: getSourceRegion

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * A utility method that may be used by readers to compute the
 * region of the source image that should be read, taking into
 * account any source region and subsampling offset settings in
 * the supplied {@code ImageReadParam}.  The actual
 * subsampling factors, destination size, and destination offset
 * are <em>not</em> taken into consideration, thus further
 * clipping must take place.  The {@link #computeRegions computeRegions}
 * method performs all necessary clipping.
 *
 * @param param the {@code ImageReadParam} being used, or
 * {@code null}.
 * @param srcWidth the width of the source image.
 * @param srcHeight the height of the source image.
 *
 * @return the source region as a {@code Rectangle}.
 */
protected static Rectangle getSourceRegion(ImageReadParam param,
                                           int srcWidth,
                                           int srcHeight) {
    Rectangle sourceRegion = new Rectangle(0, 0, srcWidth, srcHeight);
    if (param != null) {
        Rectangle region = param.getSourceRegion();
        if (region != null) {
            sourceRegion = sourceRegion.intersection(region);
        }

        int subsampleXOffset = param.getSubsamplingXOffset();
        int subsampleYOffset = param.getSubsamplingYOffset();
        sourceRegion.x += subsampleXOffset;
        sourceRegion.y += subsampleYOffset;
        sourceRegion.width -= subsampleXOffset;
        sourceRegion.height -= subsampleYOffset;
    }

    return sourceRegion;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:ImageReader.java

示例4: read

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 
 * @param x
 * @param y
 * @param width
 * @param height
 * @param band
 * @return
 */
public synchronized int[] read(int x, int y,int w,int h, int band) {
    Rectangle rect = new Rectangle(x, y, w, h);
    rect = rect.intersection(getImage(band).getBounds());
    int data[]=null;

    GeoToolsGDALReader tiff=(GeoToolsGDALReader)getImage(band);
     try {
 		int[] b=tiff.readPixValues(x, y, w,h);
 		data=new int[b.length];
     	for(int i=0;i<b.length;i++)
     		data[i]=b[i];
 		
     } catch (Exception ex) {
         logger.warn(ex.getMessage());
     }finally{
     }
    
    return data;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:29,代码来源:GDALSentinel1.java

示例5: getImageableRect

import java.awt.Rectangle; //导入方法依赖的package包/类
public Rectangle getImageableRect(Rectangle rect, int xAvg, int yAvg,
		int xRep, int yRep) {
	Rectangle r = rect.intersection(new Rectangle(0,0,width*xRep/xAvg,height*yRep/yAvg));
	if(flip==hFlip && xA==xAvg && yA== yAvg && xRep==xR && yRep==yR 
			&& tmpRect != null && tmpRect.contains(r))return tmpRect;
	if(r.width<=0 || r.height <=0) return r;
	int x = r.x + r.width;
	int dx = x % (xRep*4);
	if( dx != 0 ) x += xRep*4-dx;
	r.x -= r.x % (xRep*4);
	r.width = x - r.x;
	int y = r.y + r.height;
	int dy = y % yRep;
	if( dy != 0 ) y += yRep-dy;
	r.y -= r.y % yRep;
	r.height = y - r.y;
	return r;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:19,代码来源:JPEGimage.java

示例6: read

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
*
* @param x
* @param y
* @param width
* @param height
* @param band
* @return
*/
public int[] read(int x, int y,int w,int h, int band) {
    Rectangle rect = new Rectangle(x, y, w, h);
    rect = rect.intersection(getImage(band).getBounds());
    int data[]=null;

     TIFF tiff=getImage(band);
     try {
     	BufferedImage bi=null;
 		bi=tiff.read(0, rect);
 		DataBufferUShort raster=(DataBufferUShort)bi.getRaster().getDataBuffer();
 		short[] b=raster.getData();
 		data=new int[b.length];
     	for(int i=0;i<b.length;i++)
     		data[i]=b[i];

     } catch (Exception ex) {
         logger.warn(ex.getMessage());
     }finally{
     }

    return data;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:32,代码来源:AlosGeoTiff.java

示例7: setData

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 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) {
    bitmap2Raster();
    this.currentBuffer = BUFFER_RASTER;
    
    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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:BufferedImage.java

示例8: computePopups

import java.awt.Rectangle; //导入方法依赖的package包/类
private Rectangle[] computePopups(int row, int column, Point point, Component renderer) {
    Rectangle rendererRect = getRendererRect(column, renderer);
    if (rendererRect == null) return null;
    
    Rectangle cellRect = table.getCellRect(row, column, true);
    rendererRect.translate(cellRect.x, cellRect.y);
    cellRect.width -= 1;
    if (cellRect.contains(rendererRect)) return null; // Value fully visible
    
    Rectangle visibleRect = cellRect.intersection(rendererRect);
    if (!visibleRect.contains(point)) return null; // Value fully invisible
    
    // Mouse over partially visible value
    Rectangle[] ret = new Rectangle[2];
    
    if (rendererRect.x < visibleRect.x) {
        Rectangle left = new Rectangle(rendererRect);
        left.width = visibleRect.x - left.x;
        ret[POPUP_LEFT] = left;
    }

    // rendererRect.x + rendererRect.width *- 1*: workaround for extra space for correctly right-aligned values
    if (rendererRect.x + rendererRect.width - 1 > visibleRect.x + visibleRect.width) {
        Rectangle right = new Rectangle(rendererRect);
        right.x = visibleRect.x + visibleRect.width;
        right.width = rendererRect.x + rendererRect.width - right.x;
        ret[POPUP_RIGHT] = right;
    }
    
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ProfilerTableHovers.java

示例9: readTile

import java.awt.Rectangle; //导入方法依赖的package包/类
@Override
public int[] readTile(int x, int y, int width, int height,int band) {

    Rectangle rect = new Rectangle(x, y, width, height);
    rect = rect.intersection(bounds);
    int[] tile = new int[height * width];
    if (rect.isEmpty()) {
        return tile;
    }
    if (rect.y != preloadedInterval[0] | rect.y + rect.height != preloadedInterval[1]) {
        preloadLineTile(rect.y, rect.height,band);
    }
    int yOffset =  getImage(band).getxSize();
    int xinit = rect.x - x;
    int yinit = rect.y - y;
    int temp =0;
    try{
     for (int i = 0; i < rect.height; i++) {
         for (int j = 0; j < rect.width; j++) {
             temp = (i * yOffset + j + rect.x);
             long real=preloadedDataReal[temp];
             long img=preloadedDataImg[temp];
             tile[(i + yinit) * width + j + xinit] = (int)Math.sqrt(real*real+img*img);
         }
     }
    }catch(Exception e ){
    	e.printStackTrace();
    }    
    return tile;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:31,代码来源:Radarsat2Image_SLC.java

示例10: readTile

import java.awt.Rectangle; //导入方法依赖的package包/类
@Override
public int[] readTile(int x, int y, int width, int height,int band) {
    Rectangle rect = new Rectangle(x, y, width, height);
    rect = rect.intersection(bounds);
    int[] tile= new int[height*width];
    if (rect.isEmpty()) {
        return tile;
    }
    if (rect.y != preloadedInterval[0] | rect.y + rect.height != preloadedInterval[1]) {
        preloadLineTile(rect.y, rect.height,band);
    }
    int yOffset = getImage(band).getxSize();
    int xinit = rect.x - x;
    int yinit = rect.y - y;
    for (int i = 0; i < rect.height; i++) {
        for (int j = 0; j < rect.width; j++) {
            int temp = i * yOffset + j + rect.x;
            	if(preloadedData.length>=temp){
            		tile[(i + yinit) * width + j + xinit] = preloadedData[temp];
            	}else{
            		
                	//logger.debug("");
            	}	
        }
    }
    return tile;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:28,代码来源:Radarsat2Image.java

示例11: readTile

import java.awt.Rectangle; //导入方法依赖的package包/类
@Override
public int[] readTile(int x, int y, int width, int height, int band) {
	TIFF tiff=(TIFF)getImage(band);

	Rectangle rect = new Rectangle(x, y, width, height);
       rect = rect.intersection(tiff.getBounds());

       int[] tile = new int[height * width];
       if (rect.isEmpty()) {
           return tile;
       }

       if (rect.y != preloadedInterval[0] || rect.y + rect.height != preloadedInterval[1]||preloadedData.length<(rect.width*rect.height-1)) {
           preloadLineTile(rect.y, rect.height,band);
       }else{
       	logger.debug("using preloaded data");
       }

       int yOffset = tiff.xSize;
       int xinit = rect.x - x;
       int yinit = rect.y - y;
       for (int i = 0; i < rect.height; i++) {
           for (int j = 0; j < rect.width; j++) {
               int temp = i * yOffset + j + rect.x;
               try{
               	tile[(i + yinit) * width + j + xinit] =(int) preloadedData[temp];
               }catch(ArrayIndexOutOfBoundsException e ){
               	logger.warn("readTile function:"+e.getMessage());
               }
           }
           }
       return tile;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:34,代码来源:Alos.java

示例12: readPixel

import java.awt.Rectangle; //导入方法依赖的package包/类
@Override
public long readPixel(int x, int y, int band) {
	Rectangle rect = new Rectangle(x, y, 1, 1);
	rect = rect.intersection(getImage(band).getBounds());
	int data[] = null;

	GeoToolsGDALReader img = (GeoToolsGDALReader)getImage(band);
	try {
		data=img.readPixValues(x, y,1,1);
	} finally {
	}

	return data[0];

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:16,代码来源:GDALAlosCeos.java

示例13: paintComponent

import java.awt.Rectangle; //导入方法依赖的package包/类
protected final void paintComponent(Graphics g, Rectangle invalidArea) {
    int shiftX = 0;
    int shiftY = 0;

    contentsWillBeUpdated(offsetX, offsetY, scaleX, scaleY,
                          lastOffsetX, lastOffsetY, lastScaleX, lastScaleY);

    if (!translationPending()) {
        // No translation
        paintContents(g, invalidArea);
    } else {
        // Translation
        int width = getWidth();
        int height = getHeight();

        if (Math.abs(dx) >= width || Math.abs(dy) >= height) {
            // Translation outside of visible area
            paintContents(g, new Rectangle(0, 0, width, height));
        } else {
            // Translation in visible area
            int idx = rightBased ? -(int)dx : (int)dx;
            int idy = bottomBased ? -(int)dy : (int)dy;

            // Total component area
            int total = width * height;
            // Area of the contents saved by shift
            int shiftedSaved = (width - Math.abs(idx)) * (height - Math.abs(idy));

            if (idx != 0 && idy != 0 && shiftedSaved < total * DIAGONAL_SHIFT_ACCEL_LIMIT) {
                // DIAGONAL_SHIFT_ACCEL_LIMIT not met for diagonal shift
                paintContents(g, new Rectangle(0, 0, width, height));
            } else {
                // Saved rectangle
                Rectangle viewport = new Rectangle(idx, idy, width, height);
                Rectangle savedRect = viewport.intersection(
                        new Rectangle(0, 0, width, height));

                // InvalidArea to repaint
                Rectangle invalidRect = invalidArea.intersection(savedRect);

                // Area of invalidRect
                int invalidAfterShift = invalidRect.isEmpty() ? 0 :
                                     invalidRect.width * invalidRect.height;

                // Total saved area
                int savedTotal = shiftedSaved - invalidAfterShift;

                if (savedTotal < total * SHIFT_ACCEL_LIMIT) {
                    // SHIFT_ACCEL_LIMIT not met for shift
                    paintContents(g, new Rectangle(0, 0, width, height));
                } else {
                    // Shift
                    shift(g, idx, idy, width, height);

                    // Repaint original invalidArea if needed
                    if (invalidAfterShift != 0) paintContents(g, invalidRect);

                    shiftX = idx;
                    shiftY = idy;
                }
            }
        }
    }

    contentsUpdated(offsetX, offsetY, scaleX, scaleY, lastOffsetX, lastOffsetY,
                    lastScaleX, lastScaleY, shiftX, shiftY);

    dx = 0;
    dy = 0;
    lastOffsetX = offsetX;
    lastOffsetY = offsetY;
    lastScaleX = scaleX;
    lastScaleY = scaleY;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:75,代码来源:TransformableCanvasComponent.java

示例14: copyData

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:SimpleRenderedImage.java

示例15: draw

import java.awt.Rectangle; //导入方法依赖的package包/类
public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed, int xOffset, int yOffset) {
  if (!bounds.intersects(visibleRect)) {
    return;
  }

  final int labelOffset = 7;

  int size = (int) (scale * myGrid.getFontSize() + 0.5);
  Font f = new Font("Dialog", Font.PLAIN, size); //$NON-NLS-1$

  Color fg = selected ? Color.white : Color.black;
  Color bg = selected ? Color.black : Color.white;

  Rectangle region = bounds.intersection(visibleRect);

  Shape oldClip = g.getClip();
  if (oldClip != null) {
    Area clipArea = new Area(oldClip);
    clipArea.intersect(new Area(region));
    g.setClip(clipArea);
  }

  int posX = (int) (scale * origin.x + 0.5) + bounds.x - 1 + xOffset;
  int posY = (int) (scale * origin.y + 0.5) + bounds.y - 1 + yOffset;

  Color saveColor = g.getColor();

  g.setColor(bg);
  g.fillRect(posX, posY, 3, 3);
  g.setColor(fg);
  g.drawRect(posX, posY, 3, 3);

  g.setColor(saveColor);

  Labeler.drawLabel(g, getLocalizedConfigureName(), posX, posY + labelOffset, f, Labeler.CENTER,
                    Labeler.TOP, fg, bg, fg);
  g.setClip(oldClip);

  // Calculate and store the selection rectangle
  int width = g.getFontMetrics().stringWidth(getConfigureName() + "  ")+1; //$NON-NLS-1$
  int height = g.getFontMetrics().getHeight()+1;

  selectionRect.setLocation(posX - (width / 2), posY - 1);
  selectionRect.setSize(width, height + labelOffset + 1);

}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:47,代码来源:Region.java


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