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

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

源代码1 项目: netbeans   文件: TaskListTable.java
private void maybeExpandGroup( Point point ) {
    int row = rowAtPoint( point );
    int col = columnAtPoint( point );
    if( 0 != col )
        return;
    Rectangle rect = getCellRect( row, col, false );
    TableCellRenderer renderer = getCellRenderer(row, col);
    prepareRenderer(renderer, row, col);
    if( renderer instanceof FoldingTaskGroupRenderer ) {
        Icon icon = ((FoldingTaskGroupRenderer)renderer).getIcon();
        rect.grow( 0, -(rect.height-openedIcon.getIconHeight())/2 );
        rect.x = getColumnModel().getColumnMargin(); //rect.width - icon.getIconWidth();
        rect.width = openedIcon.getIconWidth();
        if( rect.contains( point ) ) {
            FoldingTaskListModel foldingModel = getFoldingModel();
            foldingModel.toggleGroupExpanded( row );
        }
    }
}
 
源代码2 项目: importer-exporter   文件: BBoxSelectionPainter.java
@Override
public void paint(Graphics2D gd, JXMapViewer t, int i, int i1) {
	if (selectedArea != null) {
		Rectangle drawArea = createDrawArea(selectedArea, map.getZoom());

		if (!drawArea.isEmpty()) {
			if (drawArea.contains(map.getBounds()))
				drawArea = map.getBounds();			

			gd.setColor(regionColor);
			gd.fillRect(drawArea.x, drawArea.y, drawArea.width, drawArea.height);

			gd.setColor(borderColor);
			gd.drawRect(drawArea.x, drawArea.y, drawArea.width, drawArea.height);
		}
	}
}
 
源代码3 项目: netbeans   文件: AbstractTabDisplayer.java
@Override
public void autoscroll( Point cursorLocn ) {
    Rectangle tabsArea = getTabsArea();
    if( !tabsArea.contains( cursorLocn ) ) {
        autoscroller.stop();
        return;
    }
    if( orientation == JTabbedPane.HORIZONTAL ) {
        if( cursorLocn.x < tabsArea.x+25 ) {
            autoscroller.start( true );
        } else if( cursorLocn.x > tabsArea.x+tabsArea.width-25 ) {
            autoscroller.start( false );
        } else {
            autoscroller.stop();
        }
    } else {
        if( cursorLocn.y < tabsArea.y+25 ) {
            autoscroller.start( true );
        } else if( cursorLocn.y > tabsArea.y+tabsArea.height-25 ) {
            autoscroller.start( false );
        } else {
            autoscroller.stop();
        }
    }
}
 
源代码4 项目: Bytecoder   文件: MetalToolBarUI.java
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
源代码5 项目: jdk8u_jdk   文件: MetalToolBarUI.java
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
源代码6 项目: mapleLemon   文件: MapleMap.java
/**
 * 获取矩形中的怪物信息
 * @param box
 * @param MapObject_types
 * @return
 */
public List<MapleMapObject> getMapObjectsInRect(Rectangle box, List<MapleMapObjectType> MapObject_types) {
    List ret = new ArrayList();
    for (MapleMapObjectType type : MapObject_types) {
        mapobjectlocks.get(type).readLock().lock();
        try {
            Iterator itr = ((LinkedHashMap) this.mapobjects.get(type)).values().iterator();
            while (itr.hasNext()) {
                MapleMapObject mmo = (MapleMapObject) itr.next();
                if (box.contains(mmo.getTruePosition())) {
                    ret.add(mmo);
                }
            }
        } finally {
            mapobjectlocks.get(type).readLock().unlock();
        }
    }
    return ret;
}
 
源代码7 项目: netbeans   文件: ToolTipSupport.java
public @Override void mouseExited(MouseEvent evt) {
    lastMouseEvent = evt;
    if (isToolTipShowing()) {
        Rectangle r = new Rectangle(toolTip.getLocationOnScreen(), toolTip.getSize());

        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "mouseExited: screen-x=" + evt.getXOnScreen() + "; screen-y=" + evt.getYOnScreen() //NOI18N
                + "; tooltip=" + r); //NOI18N
        }
        if (r.contains(evt.getLocationOnScreen())) {
            // inside the tooltip component -> do not hide
            return;
        }
    }

    if (!isToolTipShowing() || (flags & FLAG_HIDE_ON_MOUSE_MOVE) != 0) {
        setToolTipVisible(false);
    }
}
 
源代码8 项目: netbeans   文件: FileCompletionPopup.java
public void mouseDragged(MouseEvent e) {
    if (e.getSource() == list) {
        return;
    }
    if ( isVisible() ) {
        MouseEvent newEvent = convertMouseEvent( e );
        Rectangle r = new Rectangle();
        list.computeVisibleRect( r );
        Point location =  newEvent.getPoint();
        int index = list.locationToIndex(location);
        if ( r.contains( location ) ) {
            list.setSelectedIndex(index);
        }
    }
}
 
源代码9 项目: libreveris   文件: Sections.java
/**
 * Convenient method to look for sections contained by the provided
 * rectangle
 *
 * @param rect     provided rectangle
 * @param sections the collection of sections to browse
 * @return the set of contained sections
 */
public static Set<Section> lookupSections (Rectangle rect,
                                           Collection<? extends Section> sections)
{
    Set<Section> found = new LinkedHashSet<>();

    for (Section section : sections) {
        if (rect.contains(section.getBounds())) {
            found.add(section);
        }
    }

    return found;
}
 
源代码10 项目: netbeans   文件: AbstractListUI.java
private boolean showPopup(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return false;
    }
    int index = list.locationToIndex(e.getPoint());
    Rectangle rect = list.getCellBounds(index, index);
    if (!rect.contains(e.getPoint())) {
        return false;
    }
    return showPopupAt( index, e.getPoint() );
}
 
源代码11 项目: libreveris   文件: AbstractGhostDropListener.java
/**
 * Check whether the provided local point lies within the component
 * bounds
 *
 * @param localPoint the local point (component-based)
 * @return true if point is over the component, false otherwise
 */
protected boolean isInTarget (Point localPoint)
{
    Rectangle bounds = new Rectangle(
            0,
            0,
            component.getWidth(),
            component.getHeight());

    return bounds.contains(localPoint);
}
 
源代码12 项目: iBioSim   文件: CloseTabPaneUI.java
protected void updateMaxIcon(int x, int y) {
	if (overTabIndex != -1) {
		int newMaxIndexStatus = INACTIVE;

		Rectangle maxRect = newMaxRect(rects[overTabIndex]);

		if (maxRect.contains(x, y))
			newMaxIndexStatus = mousePressed ? PRESSED : OVER;

		if (maxIndexStatus != (maxIndexStatus = newMaxIndexStatus))
			tabScroller.tabPanel.repaint();
	}
}
 
源代码13 项目: SwingBox   文件: ElementBoxView.java
/**
 * Locates a box from its position
 */
private Box locateBox(Box root, int x, int y)
{
    if (root.isVisible())
    {
        Box found = null;
        Rectangle bounds = root.getAbsoluteContentBounds().intersection(root.getClipBlock().getClippedContentBounds());
        if (bounds.contains(x, y))
            found = root;
        
        //find if there is something smallest that fits among the child boxes
        if (root instanceof ElementBox)
        {
            ElementBox eb = (ElementBox) root;
            for (int i = eb.getStartChild(); i < eb.getEndChild(); i++)
            {
                Box inside = locateBox(((ElementBox) root).getSubBox(i), x, y);
                if (inside != null)
                {
                    if (found == null)
                        found = inside;
                    else
                    {
                        if (inside.getAbsoluteBounds().width * inside.getAbsoluteBounds().height < found.getAbsoluteBounds().width * found.getAbsoluteBounds().height)
                            found = inside;
                    }
                }
            }
        }
        return found;
    }
    else
        return null;
}
 
源代码14 项目: rapidminer-studio   文件: FileTable.java
private void evaluateClick(MouseEvent e) {
	if (e.isPopupTrigger()) {
		if (e.getComponent() instanceof JTableHeader) {
			this.headerPopup.show(e.getComponent(), e.getX(), e.getY());
		} else {

			this.row = ((JTable) e.getComponent()).rowAtPoint(e.getPoint());
			this.column = ((JTable) e.getComponent()).columnAtPoint(e.getPoint());

			if (this.row < 0) {
				this.panePopup.show(e.getComponent(), e.getX(), e.getY());
				return;
			}

			int x = (int) this.tableHeader.getHeaderRect(this.mainColumnIndex).getX();
			int y = (this.row - 1) * this.getRowHeight() + this.getHeaderHeight();

			Dimension d = ((FileTableLabel) this.getValueAt(this.row, this.mainColumnIndex)).getPreferredSize();
			Rectangle r = new Rectangle(x, y, Math.min((int) d.getWidth(),
					this.getColumnModel().getColumn(this.mainColumnIndex).getWidth()), this.getRowHeight(this.row));

			if (r.contains(e.getPoint())) {
				this.tempItem = this.fileList.visibleItemsList.elementAt(this.row);
				this.tempItem.getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
				this.fileList.lastSelected = this.tempItem;
			} else {
				this.panePopup.show(e.getComponent(), e.getX(), e.getY());
			}
		}
	}
}
 
源代码15 项目: netbeans   文件: HintsPanelLogic.java
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    TreePath path = errorTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    if ( path != null ) {
        Rectangle r = errorTree.getPathBounds(path);
        if (r != null) {
            r.width = r.height;
            if ( r.contains(p)) {
                toggle( path );
            }
        }
    }
}
 
源代码16 项目: netbeans   文件: HintsPanelLogic.java
@Override
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    TreePath path = errorTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    if ( path != null ) {
        Rectangle r = errorTree.getPathBounds(path);
        if (r != null) {
            r.width = r.height;
            if ( r.contains(p)) {
                toggle( path );
            }
        }
    }
}
 
源代码17 项目: libreveris   文件: Slur.java
/**
 * Retrieve the notes that are embraced on the left side and on the
 * right side of a slur glyph.
 *
 * @param system     the containing system
 * @param curve      the slur underlying curve
 * @param leftNodes  output: the ordered list of notes found on left side
 * @param rightNodes output: the ordered list of notes found on right side
 * @return true if the placement is 'below'
 */
private static boolean retrieveEmbracedNotes (Glyph glyph,
                                              ScoreSystem system,
                                              CubicCurve2D curve,
                                              List<MeasureNode> leftNodes,
                                              List<MeasureNode> rightNodes)
{
    boolean below = isBelow(curve);

    // Determine left and right search areas
    final Scale scale = system.getScale();
    final int dx = scale.toPixels(constants.areaDx);
    final int dy = scale.toPixels(constants.areaDy);
    final int xMg = scale.toPixels(constants.areaXMargin);
    final Rectangle leftRect = new Rectangle(
            (int) Math.rint(curve.getX1() - dx),
            (int) Math.rint(curve.getY1()),
            dx + xMg,
            dy);
    final Rectangle rightRect = new Rectangle(
            (int) Math.rint(curve.getX2() - xMg),
            (int) Math.rint(curve.getY2()),
            dx + xMg,
            dy);

    if (below) {
        leftRect.y -= dy;
        rightRect.y -= dy;
    }

    // Visualize these rectangles (for visual debug)
    glyph.addAttachment("|^", leftRect);
    glyph.addAttachment("^|", rightRect);

    // System > Part > Measure > Chord > Note
    for (TreeNode pNode : system.getParts()) {
        SystemPart part = (SystemPart) pNode;

        for (TreeNode mNode : part.getMeasures()) {
            Measure measure = (Measure) mNode;

            for (TreeNode cNode : measure.getChords()) {
                Chord chord = (Chord) cNode;

                if (!chord.getNotes().isEmpty()) {
                    if (leftRect.contains(chord.getTailLocation())) {
                        leftNodes.add(chord);
                    }

                    if (rightRect.contains(chord.getTailLocation())) {
                        rightNodes.add(chord);
                    }

                    for (TreeNode nNode : chord.getNotes()) {
                        Note note = (Note) nNode;

                        if (leftRect.contains(note.getCenter())) {
                            leftNodes.add(note);
                        }

                        if (rightRect.contains(note.getCenter())) {
                            rightNodes.add(note);
                        }
                    }
                }
            }
        }
    }

    // Sort the collections of nodes, and keep only the closest ones
    filterNodes(
            leftNodes,
            new Point((int) curve.getX1(), (int) curve.getY1()));
    filterNodes(
            rightNodes,
            new Point((int) curve.getX2(), (int) curve.getY2()));

    return below;
}
 
源代码18 项目: jdk8u-jdk   文件: SourceClippingBlitTest.java
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");
}
 
源代码19 项目: openjdk-8   文件: SourceClippingBlitTest.java
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");
}
 
源代码20 项目: 3Dscript   文件: ColorPicker.java
@Override
public void mousePressed(MouseEvent e) {
	//IJ.log("mousePressed "+e);
	ip.setLineWidth(1);
	Rectangle flipperRect = new Rectangle(86, 268, 18, 18);
	Rectangle resetRect = new Rectangle(86, 294, 18, 18);
	Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10);
	Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25);
	Rectangle background1Rect = new Rectangle(33, 302, 45, 10);
	Rectangle background2Rect = new Rectangle(56, 277, 23, 25);
	int x = e.getX();
	int y = e.getY();
	long difference = System.currentTimeMillis()-mouseDownTime;
	boolean doubleClick = (difference<=250);
	mouseDownTime = System.currentTimeMillis();
	if (flipperRect.contains(x, y)) {
		Color c = getBackgroundColor();
		setBackgroundColor(getForegroundColor());
		setForegroundColor(c);
	} else if(resetRect.contains(x,y)) {
		setForegroundColor(new Color(0x000000));
		setBackgroundColor(new Color(0xffffff));
	} else if ((background1Rect.contains(x,y)) || (background2Rect.contains(x,y))) {
		background = true;
		if (doubleClick) editColor();
		ip.refreshForeground(background);
		ip.refreshBackground(background);
	} else if ((foreground1Rect.contains(x,y)) || (foreground2Rect.contains(x,y))) {
		background = false;
		if (doubleClick) editColor();
		ip.refreshBackground(background);
		ip.refreshForeground(background);
	} else {
		//IJ.log(" " + difference + " " + doubleClick);
		if (doubleClick)
			editColor();
		else
			setDrawingColor(x, y, background);
	}
	if (background) {
		ip.refreshForeground(background);
		ip.refreshBackground(background);
	} else {
		ip.refreshBackground(background);
		ip.refreshForeground(background);
	}
	repaint();
}