public static void centreOnScreen(Window window) { Window owner = window.getOwner(); // If the window has an owner, use the same graphics configuration so it // will // open on the same screen. Otherwise, grab the mouse pointer and work // from there. GraphicsConfiguration gc = owner != null ? owner.getGraphicsConfiguration() : MouseInfo.getPointerInfo() .getDevice().getDefaultConfiguration(); if( gc != null ) { window.setBounds(centre(getUsableScreenBounds(gc), window.getBounds())); } else { // Fall-back to letting Java do the work window.setLocationRelativeTo(null); } }
@FXML private void handleAddButton() { popup.setAutoHide( true ); popup.setHideOnEscape( true ); popup.setAutoFix( true ); try { sl = SearchList.createSearchList(relationType, this); } catch (IOException e1) { e1.printStackTrace(); } popup.getContent().addAll(sl.getOurRoot()); Point p = MouseInfo.getPointerInfo().getLocation(); popup.show( getOurRoot(), p.getX(), p.getY()); sl.setMaxImageSize(16); sl.getSearchField().requestFocus(); }
public void update() { synchronized (lock) { for (int i = 0; i < MAX_BUTTONS; i++) { if (down[i]) { buttons[i]++; } else { buttons[i] = 0; } } Point p = MouseInfo.getPointerInfo().getLocation(); int curX = p.x - display.getX(); int curY = p.y - display.getY(); dx = curX - x; dy = curY - y; x = curX; y = curY; dir = curDir; curDir = ScrollDirection.NONE; } }
@Override public void setPosition(float newX, float newY) { synchronized (lock) { Point p = MouseInfo.getPointerInfo().getLocation(); int curX = p.x - display.getX(); int curY = p.y - display.getY(); int oldX = x; int oldY = x; this.x = (int)newX; this.y = (int)(display.getHeight() - (int)newY - 1); if (display.getCanvas().hasFocus()) robot.mouseMove(display.getX() + this.x, display.getY() + this.y); // resetPosition(); this.dx = curX - oldX; this.dy = curY - oldY; // lastX += -(curX - oldX); // lastY += -(curY - oldY); } }
@Override public void mouseClicked(MouseEvent arg0) { Point p = MouseInfo.getPointerInfo().getLocation(); if(num==1) { pt1 = p; win2 = new ScreenRegionGrab(2); } else { pt2 = p; int x = Math.min(pt1.x,pt2.x); int y = Math.min(pt1.y, pt2.y); int w = Math.max(pt1.x,pt2.x)-x; int h = Math.max(pt1.y,pt2.y)-y; BufferedImage a = rob.createScreenCapture(new Rectangle(x,y,w,h)); RecogApp.doRecog(a); win1.dispose(); win1=win2=null; pt1=pt2=null; dispose(); } }
@Override public void paint(Graphics g, JComponent c) { LAFUtilities.setProperties(g, c); if (c.isOpaque()) { ImageLibrary.drawTiledImage("image.background.FreeColButton", g, c, null); } super.paint(g, c); AbstractButton a = (AbstractButton) c; if (a.isRolloverEnabled()) { Point p = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(p, c); boolean rollover = c.contains(p); if (rollover) { paintButtonPressed(g, (AbstractButton) c); } } }
@Override public void onSuccess(final Object o) { /** * naprawione odświeżanie się tooltipów po załadowaniu */ final Point locationOnScreen = MouseInfo.getPointerInfo().getLocation(); final Point locationOnComponent = new Point(locationOnScreen); SwingUtilities.convertPointFromScreen(locationOnComponent, component); if (component.contains(locationOnComponent)) { SwingUtilities.invokeLater(() -> { ToolTipManager.sharedInstance().mouseMoved( new MouseEvent(component, -1, System.currentTimeMillis(), 0, locationOnComponent.x, locationOnComponent.y, locationOnScreen.x, locationOnScreen.y, 0, false, 0)); }); } }
@Override public void mouseHover(MouseEvent e) { final java.awt.Point mouseLocation1 = MouseInfo.getPointerInfo().getLocation(); EditPart paletteInternalController = viewer.findObjectAt(new Point( e.x, e.y)); if(paletteInternalController.getModel() instanceof CombinedTemplateCreationEntry){ setGenericComponent(paletteInternalController); // Hide tooltip if already showing hidePaletteToolTip(); showToolTipWithDelay(mouseLocation1); } }
public void keyPressed(KeyEvent e) { if ( e.getKeyCode() == KeyEvent.VK_SPACE) { setSpaceBarPress(true); } if(getSpaceBarPress()) { // Set locations screenPressedX = MouseInfo.getPointerInfo().getLocation().x; screenPressedY = MouseInfo.getPointerInfo().getLocation().y; pressedX = scrollPane.getHorizontalScrollBar().getValue(); pressedY = scrollPane.getVerticalScrollBar().getValue(); // Set cursor to closed hand Toolkit toolkit = Toolkit.getDefaultToolkit(); ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader(); String path = "org/geomapapp/resources/icons/close_hand.png"; java.net.URL url = loader.getResource(path); try { BufferedImage im = ImageIO.read(url); Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand"); setCursor(closeHandCursor); } catch (IOException e1) { e1.printStackTrace(); } } }
protected void openPopupMenu(NodeType[] availableTypes, final AvroNode targetNode, final AvroContext context) { Shell shell = Display.getCurrent().getActiveShell(); final Menu menu = new Menu(shell, SWT.POP_UP); for (NodeType availableType : availableTypes) { final NodeType type = availableType; MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText(type.getDisplayLabel()); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { menu.dispose(); IEditCommand cmd = context.getService(IEditCommandFactory.class) .createAddElementCommand(targetNode, type, getNotifications()); context.getService(ICommandExecutor.class).execute(cmd); } }); } Point location = MouseInfo.getPointerInfo().getLocation(); int x = location.x; int y = location.y; menu.setLocation(x, y); menu.setVisible(true); }
/** * Draws the cursor on the frame, if required. * * @param frame the frame to update * @return the (potentially) updated frame */ protected BufferedImage drawCursor(BufferedImage frame) { PointerInfo pointer; if (m_CaptureMouse && (m_Cursor != null)) { pointer = MouseInfo.getPointerInfo(); frame.getGraphics().drawImage( m_Cursor, (int) pointer.getLocation().getX() - m_X, (int) pointer.getLocation().getY() - m_Y, m_Cursor.getWidth(null), m_Cursor.getHeight(null), m_BackgroundColor, null); } return frame; }
/** * Use reflection to access the JDK 1.5 pointer location, if possible and * only if the given component is on the same screen as the cursor. Return * null otherwise. */ private static Point getPointerLocation(final Component component) { try { final GraphicsConfiguration config = component.getGraphicsConfiguration(); if (config != null) { PointerInfo pointer_info = AccessController.doPrivileged(new PrivilegedExceptionAction<PointerInfo>() { public PointerInfo run() throws Exception { return MouseInfo.getPointerInfo(); } }); GraphicsDevice device = pointer_info.getDevice(); if (device == config.getDevice()) { return pointer_info.getLocation(); } return null; } } catch (Exception e) { LWJGLUtil.log("Failed to query pointer location: " + e.getCause()); } return null; }
public AnalyzerGroupPane(final Session parent, final NodePresentationHelper presentationHelper) { super(false); this.parent = parent; listeners = new ArrayList<AnalyzerPaneListener>(); addChangeListener(this); analyzerService = new AnalyzerService(); this.presentationHelper = presentationHelper; final AnalyzerGroupPane me = this; setAddTabAction(new Runnable() { @Override public void run() { Point p1 = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(p1, me); AddTabPopUp popup = new AddTabPopUp(me); popup.show(me, p1.x, p1.y); } }); }
private void canvasMouseDown(MouseEvent e) { if (rootDiagramObject == null) return; // SetFocus; // don't remember for what purpose?? Point cursorPos = MouseInfo.getPointerInfo().getLocation(); if (panningMode) { // set mouse cursor to 'closed hand' // Screen.Cursor = crClHand; startPoint.x = round(hsb.getValue() / SCROLL_FACTOR + cursorPos.x / scale); startPoint.y = round(vsb.getValue() / SCROLL_FACTOR + cursorPos.y / scale); } else { SwingUtilities.convertPointFromScreen(cursorPos, canvas); startPoint.setLocation(cursorPos); currentPoint.setLocation(startPoint); selection.mouseDown(rootDiagramObject.testHit(currentPoint.x, currentPoint.y), (e.getModifiersEx() & (InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) > 0); mouseDown = true; } }
private void canvasMouseDragged(MouseEvent e) { if (rootDiagramObject == null) return; Point cursorPos = MouseInfo.getPointerInfo().getLocation(); if (panningMode) { // передвижение картинки как единого целого hsb.setValue(round((startPoint.x - cursorPos.x / scale) * SCROLL_FACTOR)); vsb.setValue(round((startPoint.y - cursorPos.y / scale) * SCROLL_FACTOR)); } else { if (!mouseDown) return; // передвижение одного объекта на картинке selection.mouseMove(currentPoint.x - startPoint.x, currentPoint.y - startPoint.y); SwingUtilities.convertPointFromScreen(cursorPos, canvas); currentPoint.setLocation(cursorPos); selection.mouseMove(currentPoint.x - startPoint.x, currentPoint.y - startPoint.y); } }
private void mainLoop() throws InterruptedException { long start = System.currentTimeMillis(); int captureCount = 0; Point previous = new Point(-1, -1); while (true) { final Point current = MouseInfo.getPointerInfo().getLocation(); ++captureCount; if (!current.equals(previous)) { if (fireOnLocationUpdated(current)) { previous = current; } } final int delayedCaptureCount = syncOnTick(start, captureCount, 50); captureCount += delayedCaptureCount; } }
/** * Returns a scroll bar adjustment listener bound to the given <code>scrollPane</code> view * that updates view tool tip when its vertical scroll bar is adjusted. */ public static AdjustmentListener createAdjustmentListenerUpdatingScrollPaneViewToolTip(final JScrollPane scrollPane) { return new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent ev) { Point screenLocation = MouseInfo.getPointerInfo().getLocation(); Point point = new Point(screenLocation); Component view = scrollPane.getViewport().getView(); SwingUtilities.convertPointFromScreen(point, view); if (scrollPane.isShowing() && scrollPane.getViewport().getViewRect().contains(point)) { MouseEvent mouseEvent = new MouseEvent(view, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, point.x, point.y, 0, false, MouseEvent.NOBUTTON); if (isToolTipShowing()) { ToolTipManager.sharedInstance().mouseMoved(mouseEvent); } } } }; }
private void update(){ jFrame.setTitle("DDS Viewer - "+item.getFile().getName()); jImageLabel.setIcon(new ImageIcon(item.getImage())); //jNameLabel.setText(" Name: "+item.getFile().getName()); jDimensionLabel.setText(" Size: "+item.getImage().getWidth()+"x"+item.getImage().getHeight()); jMipMapLabel.setText(" MipMap: "+(mipMap+1)+"/"+mipMapMax); jFormatLabel.setText(" Format: "+format); //Force mouse movment... Point b = MouseInfo.getPointerInfo().getLocation(); int x = (int) b.getX(); int y = (int) b.getY(); try { Robot r = new Robot(); r.mouseMove(x, y-1); r.mouseMove(x, y); } catch (AWTException ex) { } }
@Override public void mousePressed() { Point globalMousePoint = MouseInfo.getPointerInfo().getLocation(); Point globalWindowPoint = getLocationOnScreen().getLocation(); float localMouseX = globalMousePoint.x - globalWindowPoint.x; float localMouseY = globalMousePoint.y - globalWindowPoint.y; if(mouseTarget == null) { mouseTarget = new Breadcrumb(new PVector(localMouseX, localMouseY)); this.gameObjects.add(mouseTarget); } else{ mouseTarget.getRigidbody2D().setPosition(new PVector(localMouseX, localMouseY)); } mouseTarget.setVisible(true); }
public void mouseMoved(MouseEvent e) { //check if there is an open menu boolean hasSelectedMenu = false; for (int i = 0; i < menu.getMenuCount() && !hasSelectedMenu; ++i) { if (menu.getMenu(i).isSelected()) { hasSelectedMenu = true; } } Point pos = MouseInfo.getPointerInfo().getLocation(); if (!hasSelectedMenu) { if (menu.isVisible()) { menu.setVisible(pos.y < menu.getHeight()); } else { menu.setVisible(pos.y < 5); } } if (pos.y > screenSize.height - 15) { sp.setDividerLocation(screenSize.height - 100); sp.setDividerSize(5); } else if (pos.y < screenSize.height - 100) { sp.setDividerLocation(screenSize.height - 5); sp.setDividerSize(0); } }
/** * Create a mouse movement event as if the mouse just * moved to its current position. * @param c the base swing component to relativize the mouse location * @return the mouse event */ public static UIMouse createCurrent(Component c) { UIMouse m = new UIMouse(); m.type = UIMouse.Type.MOVE; PointerInfo pointerInfo = MouseInfo.getPointerInfo(); if (pointerInfo != null) { Point pm = pointerInfo.getLocation(); Point pc = new Point(0, 0); try { pc = c.getLocationOnScreen(); } catch (IllegalStateException ex) { // ignored } m.x = pm.x - pc.x; m.y = pm.y - pc.y; } return m; }
public void drawMouseData(Graphics g, Visual v, List<Point> mousepath) { if (mousepath.isEmpty()) { return; } g.setColor(Color.GREEN); Point last; Point current; for (int i = 1; i < mousepath.size(); i++) { last = mousepath.get(i - 1); current = mousepath.get(i); g.drawLine(last.x, last.y, current.x, current.y); } last = mousepath.get(mousepath.size() - 1); Point ml = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(ml, v); g.drawLine(last.x, last.y, ml.x, ml.y); }
/** * Check if mouse location has changed from previous check. */ private static void checkMouseLocation() { PointerInfo info = MouseInfo.getPointerInfo(); // This can sometimes be null, so check for it (e.g. when Windows' UAC // screen is active) if (info == null) { return; } Point currentLocation = info.getLocation(); if (lastLocation != null && !lastLocation.equals(currentLocation)) { lastMoved = System.currentTimeMillis(); triggerActivity(); } lastLocation = currentLocation; }
/** * Creates update progress bar. * * @param max max file size * @param urlBase base url for the browser * @param fromVersion the version the update is based on, may be <code>null</code> * @param toVersion the version the download leads to */ UpdateProgressBar(final int max, final String urlBase, final String fromVersion, final String toVersion) { super("Downloading...", MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration()); setLocationByPlatform(true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new UpdateProgressBarWindowListener()); this.max = max; this.urlBase = urlBase; this.fromVersion = fromVersion; this.toVersion = toVersion; try { final URL url = this.getClass().getClassLoader().getResource( ClientGameConfiguration.get("GAME_ICON")); setIconImage(new ImageIcon(url).getImage()); } catch (final RuntimeException e) { // in case that resource is not available } initializeComponents(); this.pack(); }
/** * Prepare a frame for use as the main window, or create a new one if * needed. * * @param frame frame to be used as the main game window. If * <code>null</code>, then a new frame will be created * @return frame suitable for use as the main game window */ static JFrame prepare(JFrame frame) { if (frame == null) { // Open on the screen where the mouse cursor is GraphicsConfiguration gc = MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration(); frame = new JFrame(gc); frame.setLocationByPlatform(true); } setTitle(frame); setIcon(frame); // Splash screen uses the same identifier on purpose. It is the same // window. WindowUtils.trackLocation(frame, "main", true); /* * When the user tries to close the window, don't close immediately, * but let it show a confirmation dialog. */ frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); WindowUtils.closeOnEscape(frame); return frame; }
/** * */ protected void showTooltip() { ToolTipController.this.hideTooltip(); final JComponent aC = ToolTipController.this.activeComponent; if (aC != null && (!aC.isFocusable() || aC.hasFocus() || ((ToolTipHandler) aC).isTooltipWithoutFocusEnabled()) && !ToolTipController.this.isTooltipVisible() && ToolTipController.this.mouseOverComponent(MouseInfo.getPointerInfo().getLocation())) { if (aC instanceof JTable && ((JTable) aC).getDropLocation() != null) { System.out.println("drop is going on"); return; } final Window ownerWindow = SwingUtilities.getWindowAncestor(aC); // if the components window is not the active any more, for exmaple // because we opened a dialog, don't show tooltip if (ownerWindow.isActive()) { final Point p = new Point(ToolTipController.this.mousePosition); SwingUtilities.convertPointFromScreen(p, aC); this.show(((ToolTipHandler) aC).createExtTooltip(p)); } } }
public void sendCursorStatus() { try { Point mouseP = MouseInfo.getPointerInfo().getLocation(); float scaleFactor = (1.0f * dim.getResizeX()) / dim.getSpinnerWidth(); // Real size: Real mouse position = Resize : X int x = (int)((mouseP.getX() - dim.getSpinnerX()) * scaleFactor); int y = (int)((mouseP.getY() - dim.getSpinnerY()) * scaleFactor); if (instance.getConnection() != null) { if (Red5.getConnectionLocal() == null) { Red5.setConnectionLocal(instance.getConnection()); } instance.invoke("setNewCursorPosition", new Object[] { x, y }, this); } } catch (NullPointerException npe) { //noop } catch (Exception err) { frame.setStatus("Exception: " + err); log.error("[sendCursorStatus]", err); } }
@Override protected void doLeftClick(final Point point) throws InterruptedException { // TODO non funziona final PointerInfo a = MouseInfo.getPointerInfo(); final java.awt.Point b = a.getLocation(); final int xOrig = (int) b.getX(); final int yOrig = (int) b.getY(); try { final Point p = clientToScreen(point); robot.mouseMove(p.x(), p.y()); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); } finally { robot.mouseMove(xOrig, yOrig); } }
private JPopupMenu buildPopup(Map<Class, StepDescription> stepMap) { JPopupMenu pop = new JPopupMenu(); JMenu add = new JMenu("Add Transformer"); JMenuItem labelMenuItem = new JMenuItem("Add Label"); //figure out where the user clicked PointerInfo pi = MouseInfo.getPointerInfo(); Point startLocation = pi.getLocation(); SwingUtilities.convertPointFromScreen(startLocation,this); labelMenuItem.addActionListener(new AddLabelAction(this, startLocation)); pop.add(add); pop.add(labelMenuItem); StepDescription[] sds = stepMap.values().toArray(new StepDescription[0]); Arrays.sort(sds); for (StepDescription sd : sds) { JMenuItem item = new JMenuItem(sd.getName(), sd.getIcon()); item.addActionListener(new AddStepActon(sd.getLogicClass())); add.add(item); } return pop; }
/** * Scrolls the {@link ScrollPane} along the given {@code edge}. * * @param edge The scrolling side. */ private void scroll ( Edge edge ) { if ( edge == null ) { return; } Point screenLocation = MouseInfo.getPointerInfo().getLocation(); Point2D localLocation = scrollPane.screenToLocal(screenLocation.getX(), screenLocation.getY()); switch ( edge ) { case LEFT: scrollPane.setHvalue(scrollPane.getHvalue() + Math.min(1.0, localLocation.getX() / 2.0) / scrollPane.getWidth()); break; case RIGHT: scrollPane.setHvalue(scrollPane.getHvalue() + Math.max(1.0, ( localLocation.getX() - scrollPane.getWidth() ) / 2.0) / scrollPane.getWidth()); break; case TOP: scrollPane.setVvalue(scrollPane.getVvalue() + Math.min(1.0, localLocation.getY() / 2.0) / scrollPane.getHeight()); break; case BOTTOM: scrollPane.setVvalue(scrollPane.getVvalue() + Math.max(1.0, ( localLocation.getY() - scrollPane.getHeight() ) / 2.0) / scrollPane.getHeight()); break; } }
public void handlePressedMouseButtons(WorldView view) { double deltaX = MouseInfo.getPointerInfo().getLocation().x - lastPosition.x; double deltaY = MouseInfo.getPointerInfo().getLocation().y - lastPosition.y; if (rightButtonPressed || leftButtonPressed) { if (Math.abs(deltaX) > 0) { controller.changeOffsetX(((int) deltaX) * view.getZoomFactor()); } if (Math.abs(deltaY) > 0) { controller.changeOffsetY(((int) deltaY) * view.getZoomFactor()); } } lastPosition = MouseInfo.getPointerInfo().getLocation(); }
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Point panelPoint = panel.getLocationOnScreen(); Point mousePoint = MouseInfo.getPointerInfo().getLocation(); int x = (int)(mousePoint.getX() - panelPoint.getX()); int y = (int)(mousePoint.getY() - panelPoint.getY()); Role role = panel.getRoleAt(x, y); popupMenu.removeAll(); if (role == null) { makeUnhideMenu(); } else { Host host = role.getHostAt(x, y); if (host == null) { makeHideMenu(role.getRoleName()); } else { curHost = host; makeHostMenu(host.toString()); } } }
@Override public void setEnabled(boolean b) {//On gèle la détection de la souris en cas de désactivation super.setEnabled(b); //On envoie un event pour simuler l'entrée ou la sortie de la souris lors de la réactivation ou la désactivation de l'espace dessin java.awt.Point P = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(P, this); MouseEvent e = new MouseEvent(this, 0, System.currentTimeMillis(), 0, P.x, P.y, 0, false); if(b) { addMouseEventListener(); mouseListener.mouseEntered(e); } else { mouseListener.mouseExited(e); removeMouseEventListener(); } for(Component c : getComponents()) {c.setEnabled(b);} }
public void mouseDragged () { Point mouse, winloc; mouse = MouseInfo.getPointerInfo ().getLocation (); winloc =frame.getLocation (); if (!frame.isUndecorated()) { winloc.x += 3; winloc.y += 29; } mouseX = mouse.x-winloc.x; mouseY = mouse.y-winloc.y; if (isMoveWindow) { frame.setLocation( frame.getLocationOnScreen().x+mouseX-cx, frame.getLocationOnScreen().y+mouseY-cy); oldx = mouseX; oldy = mouseY; } }
/** * Determines how far the mouse moved from the center and resets the mouse to the center. * The information can be retrieved with {@code getMouseX()} and {@code getMouseY()}. * @see #getMouseX * @see #getMouseY */ public void readMouse() { GLWindow win = c.getWindow(); if (win.hasFocus() && focused) { Point mousePos = MouseInfo.getPointerInfo().getLocation(); int centerX = win.getX() + win.getWidth()/2; int centerY = win.getY() + win.getHeight()/2; mouseX = (mousePos.getX()-centerX)*mouseSensitivity; mouseY = (mousePos.getY()-centerY)*mouseSensitivity; robot.mouseMove(centerX, centerY); } else { setFocused(false); mouseX = 0; mouseY = 0; } }