List of usage examples for java.awt Rectangle contains
public boolean contains(Rectangle r)
From source file:Main.java
public static boolean isInside(Component c, Rectangle r) { return r.contains(c.getBounds()); }
From source file:Main.java
public static void swingDispatch(MouseEvent e, Point point, final Component component) { synchronized (component.getTreeLock()) { if (component instanceof Container) { Container container = (Container) component; for (int i = container.getComponentCount(); i-- != 0;) { Component child = container.getComponent(i); Rectangle r = child.getBounds(); if (r.contains(point)) { swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child); return; }/* w w w. java 2s . c o m*/ } } } final MouseEvent adapted = convertMouseEvent(e, component, point); SwingUtilities.invokeLater(new Runnable() { public void run() { component.dispatchEvent(adapted); } }); }
From source file:Main.java
public static void showOnSameScreenAsMouseCenter(Container frame) { Point mouseLocation = MouseInfo.getPointerInfo().getLocation(); GraphicsDevice device;//from w ww . ja v a 2s .co m GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice lstGDs[] = ge.getScreenDevices(); ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length); for (GraphicsDevice gd : lstGDs) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screenBounds = gc.getBounds(); if (screenBounds.contains(mouseLocation)) { lstDevices.add(gd); } } if (lstDevices.size() > 0) { device = lstDevices.get(0); } else { device = ge.getDefaultScreenDevice(); } Rectangle bounds = device.getDefaultConfiguration().getBounds(); frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2, bounds.y + bounds.height / 2 - frame.getHeight() / 2); }
From source file:Main.java
public static GraphicsDevice getScreenByLocation(Point p) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] screens = ge.getScreenDevices(); for (final GraphicsDevice screen : screens) { final Rectangle bounds = screen.getDefaultConfiguration().getBounds(); if (bounds.contains(p)) { return screen; }//w w w .ja v a 2 s . c o m } return null; }
From source file:org.pentaho.reporting.libraries.designtime.swing.LibSwingUtil.java
public static boolean safeRestoreWindow(final Window frame, final Rectangle bounds) { final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices(); for (int i = 0; i < devices.length; i++) { final GraphicsDevice device = devices[i]; final Rectangle rectangle = device.getDefaultConfiguration().getBounds(); if (rectangle.contains(bounds) || rectangle.equals(bounds)) { logger.info("Found a usable screen-configuration: Restoring frame to " + bounds); frame.setBounds(bounds);/*from www.j a va2 s . c om*/ return true; } } return false; }
From source file:Main.java
/** * Returns true if the given point is within the actual bounds of the * JList item at index (not just inside the cell). *//*from w w w.java2s . c o m*/ private static boolean pointIsInActualBounds(JList list, int index, Point point) { ListCellRenderer renderer = list.getCellRenderer(); ListModel dataModel = list.getModel(); Object value = dataModel.getElementAt(index); Component item = renderer.getListCellRendererComponent(list, value, index, false, false); Dimension itemSize = item.getPreferredSize(); Rectangle cellBounds = list.getCellBounds(index, index); if (!item.getComponentOrientation().isLeftToRight()) { cellBounds.x += (cellBounds.width - itemSize.width); } cellBounds.width = itemSize.width; return cellBounds.contains(point); }
From source file:Main.java
/** * * @param list//ww w . ja va 2 s . c o m * @param index * @param point * @return */ public static boolean pointIsInActualBounds(JList list, int index, Point point) { ListCellRenderer renderer = list.getCellRenderer(); ListModel dataModel = list.getModel(); Object value = dataModel.getElementAt(index); Component item = renderer.getListCellRendererComponent(list, value, index, false, false); Dimension itemSize = item.getPreferredSize(); Rectangle cellBounds = list.getCellBounds(index, index); if (!item.getComponentOrientation().isLeftToRight()) { cellBounds.x += (cellBounds.width - itemSize.width); } cellBounds.width = itemSize.width; return cellBounds.contains(point); }
From source file:JTreeUtil.java
private static void autoscroll(JTree tree, Point cursorLocation) { Insets insets = DEFAULT_INSETS; Rectangle outer = tree.getVisibleRect(); Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top, outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom)); if (!inner.contains(cursorLocation)) { Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top, insets.left + insets.right, insets.top + insets.bottom); tree.scrollRectToVisible(scrollRect); }//from w w w . ja v a2 s.c o m }
From source file:org.eclipse.jubula.rc.common.util.PointUtil.java
/** * @param constraints//w w w . j a v a 2 s .c o m * The rectangle to move to * @param xPos * xPos in component * @param yPos * yPos in component * @param xAbsolute * true if x-position should be absolute * @param yAbsolute * true if y-position should be absolute * @return the point to go for the robot */ public static Point calculateAwtPointToGo(final int xPos, final boolean xAbsolute, final int yPos, final boolean yAbsolute, final Rectangle constraints) { Point pointToGo = new Point(constraints.x, constraints.y); if (xAbsolute) { pointToGo.x += xPos; } else { int x = (int) ((constraints.width / 100.0) * xPos); pointToGo.x += x; } if (yAbsolute) { pointToGo.y += yPos; } else { int y = (int) ((constraints.height / 100.0) * yPos); pointToGo.y += y; } pointToGo = adjustPointToGo(pointToGo, constraints); if (!constraints.contains(pointToGo)) { throw new StepExecutionException(TestErrorEvent.CLICKPOINT_INVALID, EventFactory.createActionError(TestErrorEvent.CLICKPOINT_INVALID)); } return pointToGo; }
From source file:Main.java
public static void scrollHorizontally(JComponent c, int from, int to, int bias) { Rectangle visible = c.getVisibleRect(), dest = new Rectangle(visible); dest.x = from;/* w ww . j av a2 s . c o m*/ dest.width = to - from; if (dest.width > visible.width) { if (bias == VIEWPORT) { // leave as is } else if (bias == UNCHANGED) { if (dest.x <= visible.x && dest.x + dest.width >= visible.x + visible.width) { dest.x = visible.x; dest.width = visible.width; } } else { if (bias == CENTER) dest.x += (dest.width - visible.width) / 2; else if (bias == LAST) dest.x += dest.width - visible.width; dest.width = visible.width; } } if (!visible.contains(dest)) c.scrollRectToVisible(dest); }