List of usage examples for java.awt Rectangle contains
public boolean contains(Rectangle r)
From source file:Main.java
public static void scrollVertically(JComponent c, int from, int to, int bias) { Rectangle visible = c.getVisibleRect(), dest = new Rectangle(visible); dest.y = from;/*www . ja v a 2 s. c o m*/ dest.height = to - from; if (dest.height > visible.height) { if (bias == VIEWPORT) { // leave as is } else if (bias == UNCHANGED) { if (dest.y <= visible.y && dest.y + dest.height >= visible.y + visible.height) { dest.y = visible.y; dest.height = visible.height; } } else { if (bias == CENTER) dest.y += (dest.height - visible.height) / 2; else if (bias == LAST) dest.y += dest.height - visible.height; dest.height = visible.height; } } if (!visible.contains(dest)) c.scrollRectToVisible(dest); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(10, 10, 50, 40); System.out.println(r.contains(new Rectangle(40, 40, 20, 20))); g2.fill(r);/*from ww w. j av a 2 s . co m*/ }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(10, 10, 50, 40); System.out.println(r.contains(new Point(40, 40))); g2.fill(r);//from ww w . j av a2s . c om }
From source file:Main.java
@Override protected void processMouseEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) { if (e.getID() != MouseEvent.MOUSE_CLICKED) { return;/*from w ww . j a va 2 s .co m*/ } pt.setLocation(e.getPoint()); JTabbedPane tabbedPane = (JTabbedPane) l.getView(); int index = tabbedPane.indexAtLocation(pt.x, pt.y); if (index >= 0) { Rectangle rect = tabbedPane.getBoundsAt(index); Dimension d = button.getPreferredSize(); int x = rect.x + rect.width - d.width - 2; int y = rect.y + (rect.height - d.height) / 2; Rectangle r = new Rectangle(x, y, d.width, d.height); if (r.contains(pt)) { tabbedPane.removeTabAt(index); } } l.getView().repaint(); }
From source file:Main.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); if (c instanceof JLayer == false) { return;/* w w w .java2 s . com*/ } JLayer jlayer = (JLayer) c; JTabbedPane tabPane = (JTabbedPane) jlayer.getView(); for (int i = 0; i < tabPane.getTabCount(); i++) { Rectangle rect = tabPane.getBoundsAt(i); Dimension d = button.getPreferredSize(); int x = rect.x + rect.width - d.width - 2; int y = rect.y + (rect.height - d.height) / 2; Rectangle r = new Rectangle(x, y, d.width, d.height); button.setForeground(r.contains(pt) ? Color.RED : Color.BLACK); SwingUtilities.paintComponent(g, button, p, r); } }
From source file:tech.flatstone.appliedlogistics.client.gui.machines.GuiPulverizer.java
@Override public void drawScreen(int mouse_x, int mouse_y, float btn) { super.drawScreen(mouse_x, mouse_y, btn); Point currentMouse = new Point(mouse_x - guiLeft, mouse_y - guiTop); for (Rectangle rectangle : tooltips.keySet()) { if (rectangle.contains(currentMouse)) { ArrayList<String> messages = new ArrayList<String>(tooltips.get(rectangle)); renderToolTip(messages, mouse_x, mouse_y); }/*www .jav a 2s . co m*/ } }
From source file:de.hstsoft.sdeep.NoteManager.java
public Note getNoteAt(Point2D mapPosition, int size) { int x = (int) mapPosition.getX() - size / 2; int y = (int) mapPosition.getY() - size / 2; Rectangle rectangle = new Rectangle(x, y, size, size); for (Note n : notes) { if (rectangle.contains(n.getPosition())) { return n; }//from w w w . j a v a2 s . c om } return null; }
From source file:com.original.widget.OPicture.java
public void mouseMoved(MouseEvent e) { Point pt = e.getPoint();//from w w w .j ava 2 s. c om Rectangle btnRect = getUI().getBtnRect(); if (btnRect.contains(pt)) this.model.setMouseOverBtn(true); //_mouseOverBtn = true; else //_mouseOverBtn = false; this.model.setMouseOverBtn(false); this.repaint(); }
From source file:com.original.widget.OPicture.java
/** mouse event processing **/ public void mouseClicked(MouseEvent e) { Point pt = e.getPoint();/*w w w. j av a 2 s . c om*/ Rectangle btnRect = getUI().getBtnRect(); if (btnRect.contains(pt)) { //here, you can make a dialog to select a image file. File fil = chooseImgFile(); if (fil != null) { try { int ind = fil.getAbsolutePath().lastIndexOf("."); if (ind != -1) { this.model.setDataformat(fil.getAbsolutePath().substring(ind + 1)); this.model.setDatablock(IOUtils.toByteArray(new FileInputStream(fil))); //_hasImg = true; this.model.setHasdata(true); this.model.setBrwbtntext("?"); repaint(); } } catch (IOException ex) { } } } }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private void init() { this.srcPoint = new Point(); this.selectionColor = createSelectionColor(); this.rubberBandMouseListener = new MouseAdapter() { @Override/*from w w w .java 2 s .co m*/ public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); Rectangle rect = getCellBounds(index, index); if (!rect.contains(e.getPoint())) { clearSelection(); getSelectionModel().setAnchorSelectionIndex(-1); getSelectionModel().setLeadSelectionIndex(-1); setFocusable(false); } else { setFocusable(true); } } @Override public void mouseReleased(MouseEvent e) { setFocusable(true); rubberBand = null; repaint(); } }; this.rubberBandMouseMotionListener = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { setFocusable(true); if (rubberBand == null) { srcPoint.setLocation(e.getPoint()); } Point destPoint = e.getPoint(); rubberBand = new Path2D.Double(); rubberBand.moveTo(srcPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, destPoint.y); rubberBand.lineTo(srcPoint.x, destPoint.y); rubberBand.closePath(); setSelectedIndices(getIntersectsIdices(rubberBand)); repaint(); } }; addMouseListener(rubberBandMouseListener); addMouseMotionListener(rubberBandMouseMotionListener); }