private void recenterMouse(final Component component) { if (robot != null) { eventsSinceRecenter = 0; isRecentering = true; centerLocation.setLocation(component.getWidth() / 2, component.getHeight() / 2); centerLocationOnScreen.setLocation(centerLocation); SwingUtilities.convertPointToScreen(centerLocationOnScreen, component); robot.mouseMove(centerLocationOnScreen.x, centerLocationOnScreen.y); } }
@Override public void mousePressed(MouseEvent e) { lastPoint = e.getPoint(); SwingUtilities.convertPointToScreen(lastPoint, panel); } };
@Override public void mousePressed(MouseEvent e) { origPos = e.getPoint(); SwingUtilities.convertPointToScreen(origPos, SizeGrip.this); }
@Override public void mouseExited(MouseEvent e) { // Since we registered this listener on the child components of // the JWindow, not the JWindow iteself, we have to be careful. Component source = (Component)e.getSource(); Point p = e.getPoint(); SwingUtilities.convertPointToScreen(p, source); if (!TipWindow.this.getBounds().contains(p)) { ft.possiblyDisposeOfTipWindow(); } }
@Override public void mousePressed(MouseEvent e, TransferData data) { data.component.requestFocusInWindow(); // for some reason sometime mouseRelease happens before numerous Mouse_Dragged events // that results in not finished dragging clearDragging(this.prevCardPanel); isDragging = false; startedDragging = false; prevCardPanel = null; cardPanels.clear(); Point mouse = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(mouse, data.component); initialMousePos = new Point((int) mouse.getX(), (int) mouse.getY()); initialCardPos = data.component.getLocation(); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); }
/** * Positions this popup to be in the top right-hand corner of the parent * editor. */ private void setLocation() { Point topLeft = textArea.getVisibleRect().getLocation(); SwingUtilities.convertPointToScreen(topLeft, textArea); topLeft.y = Math.max(topLeft.y - 24, 0); setLocation(topLeft.x - LEFT_EMPTY_BORDER, topLeft.y); }
@Override public void mouseDragged(MouseEvent e) { Point p = e.getPoint(); SwingUtilities.convertPointToScreen(p, panel); if (lastPoint==null) { lastPoint = p; } else { int dx = p.x - lastPoint.x; int dy = p.y - lastPoint.y; setLocation(getX()+dx, getY()+dy); lastPoint = p; } } @Override
@Override public void mouseReleased(MouseEvent e, TransferData transferData) { CardPanel card = ((CardPanel) transferData.component); if (e.isPopupTrigger() /*&& card.getPopupMenu() != null*/) { hideTooltipPopup(); } else if (card.getZone() != null && card.getZone().equalsIgnoreCase("hand")) { int maxXOffset = 0; if (isDragging) { Point mouse = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(mouse, transferData.component); maxXOffset = Math.abs((int) (mouse.getX() - initialMousePos.x)); } clearDragging(card); this.startedDragging = false; if (maxXOffset < MIN_X_OFFSET_REQUIRED) { // we need this for protection from small card movements transferData.component.requestFocusInWindow(); DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); } e.consume(); } else { transferData.component.requestFocusInWindow(); DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); e.consume(); } }
@Override public void mouseDragged(MouseEvent e, TransferData transferData) { CardPanel cardPanel = ((CardPanel) transferData.component); if (cardPanel.getZone() == null || !cardPanel.getZone().equalsIgnoreCase("hand")) { // drag'n'drop is allowed for HAND zone only return; } if (!SwingUtilities.isLeftMouseButton(e)) { // only allow draging with the left mouse button return; } isDragging = true; prevCardPanel = cardPanel; Point cardPanelLocationOld = cardPanel.getLocation(); Point mouse = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(mouse, transferData.component); int xOffset = cardPanel.getXOffset(cardPanel.getCardWidth()); int newX = Math.max(initialCardPos.x + (int) (mouse.getX() - initialMousePos.x) - xOffset, 0); cardPanel.setCardBounds( newX, cardPanelLocationOld.y + cardPanel.getCardYOffset(), cardPanel.getCardWidth(), cardPanel.getCardHeight()); cardPanel.getCardArea().setComponentZOrder(cardPanel, 0); sort(cardPanel, cardPanel.getCardArea(), false); if (!this.startedDragging) { this.startedDragging = true; } }
window.pack(); Point pt = p.draggingLabel.getLocation(); SwingUtilities.convertPointToScreen(pt, p); window.setLocation(pt); window.setVisible(true);
@Override public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
/** * Creates a new ScreenPoint object, using a local component-based point. * * @param component the component to use as the base * @param localPoint the component-based point */ public ScreenPoint (Component component, Point localPoint) { this(localPoint.x, localPoint.y); SwingUtilities.convertPointToScreen(this, component); }
@Override public final int getScreenLocationY() { Point p = new Point(); SwingUtilities.convertPointToScreen(p, c); return p.y; }
SwingUtilities.convertPointToScreen(p, textArea); r.x = p.x; r.y = p.y;
SwingUtilities.convertPointToScreen(p, textArea);
private Point toScreen(MouseEvent e) { Point p = e.getPoint(); SwingUtilities.convertPointToScreen(p, e.getComponent()); return p; }
public void mouseReleased(MouseEvent e) { if (isDragging) { Point pnt = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(pnt,pTree); tearOff(null,pnt); } isDragging = false; } });
@Override public void mouseDragged(MouseEvent evt) { Point pt = evt.getPoint(); SwingUtilities.convertPointToScreen(pt,evt.getComponent()); ((MagnifyingPanel)magPanel).setMagPoint(pt); } @Override
public static void setDialogLocationUnder(final JDialog dialog, final NodeModel node) { final Controller controller = Controller.getCurrentController(); final IMapViewManager viewController = controller.getMapViewManager(); final JComponent c = (JComponent) viewController.getComponent(node); final int x = 0; final int y = c.getHeight(); final Point location = new Point(x, y); SwingUtilities.convertPointToScreen(location, c); UITools.setBounds(dialog, location.x, location.y, dialog.getWidth(), dialog.getHeight()); }
private static void resizePopup() { popupWindow.pack(); Point point = new Point(0,0); SwingUtilities.convertPointToScreen(point, getMainWindow()); popupWindow.setLocation( point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2, point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3); }