本文整理匯總了Java中java.awt.Rectangle.intersects方法的典型用法代碼示例。如果您正苦於以下問題:Java Rectangle.intersects方法的具體用法?Java Rectangle.intersects怎麽用?Java Rectangle.intersects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Rectangle
的用法示例。
在下文中一共展示了Rectangle.intersects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: intersectsRect
import java.awt.Rectangle; //導入方法依賴的package包/類
/**
* Returns whether or not the rectangle passed in hits any part of this
* curve.
* @param rect the rectangle to detect for a hit
* @return whether or not the rectangle hits this curve
*/
public boolean intersectsRect(Rectangle rect)
{
// To save CPU, we can test if the rectangle intersects the entire
// bounds of this label
if ( (labelBounds != null
&& (!labelBounds.getRectangle().intersects(rect)) )
|| labelGlyphs == null )
{
return false;
}
for (int i = 0; i < labelGlyphs.length; i++)
{
if (labelGlyphs[i].visible
&& rect.intersects(labelGlyphs[i].drawingBounds
.getRectangle()))
{
return true;
}
}
return false;
}
示例2: focusGained
import java.awt.Rectangle; //導入方法依賴的package包/類
@Override
public void focusGained(FocusEvent e) {
if (e.isTemporary()) {
return;
}
Component cmp = e.getComponent();
if(cmp instanceof JComponent) {
JViewport vp = getViewport(container);
if(vp == null) {
return;
}
Rectangle vr = vp.getViewRect();
Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
final Rectangle r = new Rectangle(p, cmp.getSize());
if(vr.intersects(r)) {
return;
}
container.scrollRectToVisible(r);
}
}
示例3: checkPolygonBounds
import java.awt.Rectangle; //導入方法依賴的package包/類
private boolean checkPolygonBounds(UnknownData d, Rectangle2D viewBounds, double wrap) {
if (d.polyline == null) return false;
Rectangle polyBounds = d.polyline.getBounds();
polyBounds.x += d.x;
polyBounds.y += d.y;
while (true) {
if (polyBounds.intersects(viewBounds))
return true;
if (wrap <= 0) break;
if (polyBounds.x >= wrap) break;
polyBounds.x += wrap;
}
return false;
}
示例4: paint
import java.awt.Rectangle; //導入方法依賴的package包/類
@Override
public void paint(Graphics g, JComponent c) {
recalculateIfInsetsChanged();
recalculateIfOrientationChanged();
Rectangle clip = g.getClipBounds();
if (!clip.intersects(trackRect) && slider.getPaintTrack()) {
calculateGeometry();
}
if (slider.getPaintTrack() && clip.intersects(trackRect)) {
paintTrack(g);
}
if (slider.hasFocus() && clip.intersects(focusRect)) {
paintFocus(g);
}
// the ticks are now inside the track so they have to be painted each thumb movement
paintTicks(g);
// thumb is always painted due to value below thumb
paintThumb(g);
}
示例5: displayStats
import java.awt.Rectangle; //導入方法依賴的package包/類
public void displayStats(GLAutoDrawable drawable) {
if ((drawable == null) || (chip.getCanvas() == null)) {
return;
}
canvas = chip.getCanvas();
glCanvas = (GLCanvas) canvas.getCanvas();
int sx = chip.getSizeX(), sy = chip.getSizeY();
Rectangle chipRect = new Rectangle(sx, sy);
GL2 gl = drawable.getGL().getGL2();
if (selection != null && chipRect.intersects(selection)) {
drawSelection(gl, selection, SELECT_COLOR);
}
stats.drawStats(drawable);
stats.play();
}
示例6: displayStats
import java.awt.Rectangle; //導入方法依賴的package包/類
public void displayStats(GLAutoDrawable drawable) {
if ((drawable == null) || (selection == null) || (chip.getCanvas() == null)) {
return;
}
canvas = chip.getCanvas();
glCanvas = (GLCanvas) canvas.getCanvas();
int sx = chip.getSizeX(), sy = chip.getSizeY();
Rectangle chipRect = new Rectangle(sx, sy);
GL2 gl = drawable.getGL().getGL2();
if (!chipRect.intersects(selection)) {
return;
}
drawSelection(gl, selection, SELECT_COLOR);
stats.drawStats(drawable);
stats.play();
}
示例7: findAt
import java.awt.Rectangle; //導入方法依賴的package包/類
@Override
public ComponentInfo findAt(int x, int y) {
Rectangle bounds = getWindowBounds();
if (!bounds.contains(x, y)) {
return null;
}
ComponentInfo[] subComponents = getSubComponents();
if (subComponents != null) {
Rectangle tempRect = null;
ComponentInfo tempRslt = null;
for (int i = 0; i < subComponents.length; i++) {
Rectangle sb = subComponents[i].getWindowBounds();
if (sb.contains(x, y)) {
tempRect = sb;
tempRslt = subComponents[i];
ComponentInfo tci = subComponents[i].findAt(x, y);
if (tci != null) {
Rectangle tbounds = tci.getWindowBounds();
if (tempRect.intersects(tbounds)) {
tempRect = tbounds;
tempRslt = tci;
}
}
}
}
return tempRslt;
}
return this;
}
示例8: drawOccupant
import java.awt.Rectangle; //導入方法依賴的package包/類
/**
* Draw one occupant object. First verify that the object is actually
* visible before any drawing, set up the clip appropriately and use the
* DisplayMap to determine which object to call upon to render this
* particular Locatable. Note that we save and restore the graphics
* transform to restore back to normalcy no matter what the renderer did to
* to the coordinate system.
*
* @param g2 the Graphics2D object to use to render
* @param xleft the leftmost pixel of the rectangle
* @param ytop the topmost pixel of the rectangle
* @param obj the Locatable object to draw
*/
private void drawOccupant(Graphics2D g2, int xleft, int ytop, Object obj) {
Rectangle cellToDraw = new Rectangle(xleft, ytop, cellSize, cellSize);
// Only draw if the object is visible within the current clipping
// region.
if (cellToDraw.intersects(g2.getClip().getBounds())) {
Graphics2D g2copy = (Graphics2D) g2.create();
g2copy.clip(cellToDraw);
// Get the drawing object to display this occupant.
Display displayObj = displayMap.findDisplayFor(obj.getClass());
displayObj.draw(obj, this, g2copy, cellToDraw);
g2copy.dispose();
}
}
示例9: paintCol
import java.awt.Rectangle; //導入方法依賴的package包/類
/**
* narysowanie kolumny
*
* @param col - indeks kolumny
* @param g - kontekst graficzny
*/
private void paintCol(int col, Graphics g) {
Rectangle rect = g.getClipBounds();
SpanTable spanTable = (SpanTable) table;
for (int row = 0; row < table.getRowCount(); row++) {
Rectangle cellRect = table.getCellRect(row, col, true);
if (cellRect.intersects(rect)) // czy jest widoczny
{
int rowIndex = spanTable.visibleRow(row, col);
paintCell(rowIndex, col, g, cellRect);
row += spanTable.rowSpan(rowIndex, col) - 1;
}
}
}
示例10: PixelPointCollision
import java.awt.Rectangle; //導入方法依賴的package包/類
public static final Rectangle PixelPointCollision(int PointX, int PointY,
BufferedImage Img1, int X, int Y, int width, int height, int SrcX,
int SrcY)
{
Rectangle rct = new Rectangle();
rct.x = PointX;
rct.y = PointY;
rct.width = 1;
rct.height = 1;
Rectangle rct2 = new Rectangle();
rct2.x = X;
rct2.y = Y;
rct2.width = width;
rct2.height = height;
if (rct.intersects(rct2) == true)
{
Rectangle intersection = rct.intersection(rct2);
int Image1StartX = SrcX + (intersection.x - X);
int Image1StartY = SrcY + (intersection.y - Y);
int pixel1 = Img1.getRGB(Image1StartX, Image1StartY);
int alpha1 = (pixel1 >> 24) & 0xff;
if (alpha1 > 0)
{
return intersection;
}
}
return null;
}
示例11: PixelPointWeaponCollision
import java.awt.Rectangle; //導入方法依賴的package包/類
public static final Rectangle PixelPointWeaponCollision(int PointX, int PointY,
BufferedImage Img1, int X, int Y, int width, int height, int SrcX,
int SrcY, int Tolerance)
{
Rectangle rct = new Rectangle();
rct.x = PointX;
rct.y = PointY;
rct.width = 1;
rct.height = 1;
Rectangle rct2 = new Rectangle();
rct2.x = X + Tolerance;
rct2.y = Y + Tolerance;
rct2.width = width - Tolerance;
rct2.height = height - Tolerance;
if (rct.intersects(rct2) == true)
{
Rectangle intersection = rct.intersection(rct2);
int Image1StartX = SrcX + (intersection.x - rct2.x);
int Image1StartY = SrcY + (intersection.y - rct2.y);
int pixel1 = Img1.getRGB(Image1StartX, Image1StartY);
int alpha = (pixel1 >> 24) & 0xff;
int red = (pixel1 >> 16) & 0xff;
int green = (pixel1 >> 8) & 0xff;
int blue = (pixel1) & 0xff;
if (alpha > 0 && !(red == 255 && green == 0 && blue == 0))
{
return intersection;
}
}
return null;
}
示例12: avoid
import java.awt.Rectangle; //導入方法依賴的package包/類
/**
*
*/
protected void avoid(mxCellState edge, mxCellState vertex) {
mxIGraphModel model = graph.getModel();
Rectangle labRect = edge.getLabelBounds().getRectangle();
Rectangle vRect = vertex.getRectangle();
if (labRect.intersects(vRect)) {
int dy1 = -labRect.y - labRect.height + vRect.y;
int dy2 = -labRect.y + vRect.y + vRect.height;
int dy = (Math.abs(dy1) < Math.abs(dy2)) ? dy1 : dy2;
int dx1 = -labRect.x - labRect.width + vRect.x;
int dx2 = -labRect.x + vRect.x + vRect.width;
int dx = (Math.abs(dx1) < Math.abs(dx2)) ? dx1 : dx2;
if (Math.abs(dx) < Math.abs(dy)) {
dy = 0;
} else {
dx = 0;
}
mxGeometry g = model.getGeometry(edge.getCell());
if (g != null) {
g = (mxGeometry) g.clone();
if (g.getOffset() != null) {
g.getOffset().setX(g.getOffset().getX() + dx);
g.getOffset().setY(g.getOffset().getY() + dy);
} else {
g.setOffset(new mxPoint(dx, dy));
}
model.setGeometry(edge.getCell(), g);
}
}
}
示例13: IntersectPath
import java.awt.Rectangle; //導入方法依賴的package包/類
public boolean IntersectPath(Rectangle recsel) {
return recsel.intersects(getBounds());
}
示例14: paint
import java.awt.Rectangle; //導入方法依賴的package包/類
/** Paint a representation of the <code>table</code> instance
* that was set in installUI().
*
* (copy & paste from BasicTableUI)
*/
public void paint(Graphics g, JComponent c) {
Rectangle clip = g.getClipBounds();
Rectangle bounds = table.getBounds();
// account for the fact that the graphics has already been translated
// into the table's bounds
bounds.x = bounds.y = 0;
if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
// this check prevents us from painting the entire table
// when the clip doesn't intersect our bounds at all
!bounds.intersects(clip)) {
return;
}
Point upperLeft = clip.getLocation();
Point lowerRight = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1);
int rMin = table.rowAtPoint(upperLeft);
int rMax = table.rowAtPoint(lowerRight);
// This should never happen (as long as our bounds intersect the clip,
// which is why we bail above if that is the case).
if (rMin == -1) {
rMin = 0;
}
// If the table does not have enough rows to fill the view we'll get -1.
// (We could also get -1 if our bounds don't intersect the clip,
// which is why we bail above if that is the case).
// Replace this with the index of the last row.
if (rMax == -1) {
rMax = table.getRowCount()-1;
}
boolean ltr = table.getComponentOrientation().isLeftToRight();
int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
// This should never happen.
if (cMin == -1) {
cMin = 0;
}
// If the table does not have enough columns to fill the view we'll get -1.
// Replace this with the index of the last column.
if (cMax == -1) {
cMax = table.getColumnCount()-1;
}
// Paint the grid.
paintGrid(g, rMin, rMax, cMin, cMax);
// Paint the cells.
paintCells(g, rMin, rMax, cMin, cMax);
}
示例15: paint
import java.awt.Rectangle; //導入方法依賴的package包/類
public void paint(Graphics g, JComponent c) {
Rectangle clip = g.getClipBounds();
thumbRect = zeroRect;
super.paint(g, c);
int thumbNum = additonalUi.getThumbNum();
Rectangle[] thumbRects = additonalUi.getThumbRects();
for (int i = thumbNum - 1; 0 <= i; i--) {
if (clip.intersects(thumbRects[i])) {
thumbRect = thumbRects[i];
paintThumb(g);
}
}
}