Java Code Examples for java.awt.Rectangle#contains()
The following examples show how to use
java.awt.Rectangle#contains() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskListTable.java From netbeans with Apache License 2.0 | 6 votes |
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 ); } } }
Example 2
Source File: BBoxSelectionPainter.java From importer-exporter with Apache License 2.0 | 6 votes |
@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); } } }
Example 3
Source File: ToolTipSupport.java From netbeans with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: AbstractTabDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
@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(); } } }
Example 5
Source File: MetalToolBarUI.java From Bytecoder with Apache License 2.0 | 6 votes |
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); } }
Example 6
Source File: MapleMap.java From mapleLemon with GNU General Public License v2.0 | 6 votes |
/** * 获取矩形中的怪物信息 * @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; }
Example 7
Source File: MetalToolBarUI.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example 8
Source File: CloseTabPaneUI.java From iBioSim with Apache License 2.0 | 5 votes |
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(); } }
Example 9
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
@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 ); } } } }
Example 10
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
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 ); } } } }
Example 11
Source File: FileTable.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
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()); } } } }
Example 12
Source File: ElementBoxView.java From SwingBox with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example 13
Source File: AbstractGhostDropListener.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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); }
Example 14
Source File: AbstractListUI.java From netbeans with Apache License 2.0 | 5 votes |
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() ); }
Example 15
Source File: Sections.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example 16
Source File: FileCompletionPopup.java From netbeans with Apache License 2.0 | 5 votes |
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); } } }
Example 17
Source File: SourceClippingBlitTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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"); }
Example 18
Source File: Slur.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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; }
Example 19
Source File: ColorPicker.java From 3Dscript with BSD 2-Clause "Simplified" License | 4 votes |
@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(); }
Example 20
Source File: SourceClippingBlitTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); }