Example usage for java.awt MouseInfo getPointerInfo

List of usage examples for java.awt MouseInfo getPointerInfo

Introduction

In this page you can find the example usage for java.awt MouseInfo getPointerInfo.

Prototype

public static PointerInfo getPointerInfo() throws HeadlessException 

Source Link

Document

Returns a PointerInfo instance that represents the current location of the mouse pointer.

Usage

From source file:com.willwinder.universalgcodesender.model.GUIBackend.java

private void keepAwake() {
    logger.log(Level.INFO, "Moving the mouse location slightly to keep the computer awake.");
    try {/*from  www.  j a  v a  2 s .  com*/
        Robot hal = new Robot();
        Point pObj = MouseInfo.getPointerInfo().getLocation();
        hal.mouseMove(pObj.x + 1, pObj.y + 1);
        hal.mouseMove(pObj.x - 1, pObj.y - 1);
        pObj = MouseInfo.getPointerInfo().getLocation();
        logger.log(Level.INFO, pObj.toString() + "x>>" + pObj.x + "  y>>" + pObj.y);
    } catch (AWTException | NullPointerException ex) {
        Logger.getLogger(GUIBackend.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:analisisnumerico.Main.java

private void jPanel2MouseDragged(java.awt.event.MouseEvent evt) {
    Point point = MouseInfo.getPointerInfo().getLocation();
    setLocation(point.x - x, point.y - y);
}

From source file:org.squidy.nodes.MouseIO.java

protected void processDirectInputMouseEvent(CDirectInputMouse.EventID iEventID, int iData) {
    IData data = null;/*from   w  ww  .j  ava 2 s .  com*/

    // move mouse (relative coordinates in iData)
    if (iEventID.equals(CDirectInputMouse.EventID.DIMEID_X)
            || iEventID.equals(CDirectInputMouse.EventID.DIMEID_Y)
            || iEventID.equals(CDirectInputMouse.EventID.DIMEID_XY)) {
        Point ptMouse = MouseInfo.getPointerInfo().getLocation();
        double x = (double) ptMouse.x / (maxX - minX);
        double y = (double) ptMouse.y / (maxY - minY);
        data = new DataPosition2D(MouseIO.class, x, y);
    }

    /*
    // for debugging only
    if (iEventID.equals(CDirectInputMouse.EventID.DIMEID_XY)) {
       short x = (short)(iData & 0xffff);
       short y = (short)(iData >> 16);
       LOG.debug(iEventID.toString() + " " + x + " " + y);
    }
    */

    // scroll wheel (offset in iData)
    //if (iEventID.equals(DirectInputMouseEventID.DIMEID_Z)
    //   data = new DataMouseWheel(MouseIO, iData);

    // click button (flag 0x80 is set in iData when pressed)  
    if (iEventID.equals(CDirectInputMouse.EventID.DIMEID_BUTTON0))
        data = new DataButton(MouseIO.class, DataButton.BUTTON_0, iData == 0x80);
    if (iEventID.equals(CDirectInputMouse.EventID.DIMEID_BUTTON1))
        data = new DataButton(MouseIO.class, DataButton.BUTTON_1, iData == 0x80);
    if (iEventID.equals(CDirectInputMouse.EventID.DIMEID_BUTTON2))
        data = new DataButton(MouseIO.class, DataButton.BUTTON_2, iData == 0x80);

    if (data != null)
        publish(data);
}

From source file:org.revager.tools.GUITools.java

/**
 * Sets the location of the given window to cursor position.
 * //from w w  w.  j  a  v  a2 s  . c o m
 * @param win
 *            the window for which the location is to be set
 */
public static void setLocationToCursorPos(Window win) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    double cursorPosX = MouseInfo.getPointerInfo().getLocation().getX();
    double cursorPosY = MouseInfo.getPointerInfo().getLocation().getY();

    double screenWidth = screenSize.getWidth();
    double screenHeight = screenSize.getHeight() - 40;

    double winWidth = win.getSize().getWidth();
    double winHeight = win.getSize().getHeight();

    int winPosX = (int) cursorPosX;
    int winPosY = (int) cursorPosY;
    // If the window would break the screen size
    if (cursorPosX + winWidth > screenWidth) {
        winPosX = (int) (screenWidth - winWidth);
    }
    if (cursorPosY + winHeight > screenHeight) {
        winPosY = (int) (screenHeight - winHeight);
    }
    win.setLocation(new Point(winPosX, winPosY));
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

/**
 * Switch the fullscreen mode of TV-Browser
 *///from   w  w  w  . jav a2s .  c o m
public void switchFullscreenMode() {
    dispose();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

            if (isFullScreenMode()) {
                // switch back from fullscreen
                device.setFullScreenWindow(null);
                setUndecorated(false);
                setBounds(mXPos, mYPos, mWidth, mHeight);

                if (mMenuBar != null) {
                    mMenuBar.setFullscreenItemChecked(false);
                    mMenuBar.setVisible(true);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(Settings.propIsToolbarVisible.getBoolean());
                }

                if (mStatusBar != null) {
                    mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(Settings.propShowChannels.getBoolean());
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(Settings.propShowDatelist.getBoolean());
                }

                setVisible(true);

                setShowPluginOverview(Settings.propShowPluginView.getBoolean(), false);
                setShowTimeButtons(Settings.propShowTimeButtons.getBoolean(), false);
                setShowDatelist(Settings.propShowDatelist.getBoolean(), false);
                setShowChannellist(Settings.propShowChannels.getBoolean(), false);
            } else {
                // switch into fullscreen
                mXPos = getX();
                mYPos = getY();
                mWidth = getWidth();
                mHeight = getHeight();

                setShowPluginOverview(false, false);
                setShowTimeButtons(false, false);
                setShowDatelist(false, false);
                setShowChannellist(false, false);

                if (mStatusBar != null) {
                    mMenuBar.setFullscreenItemChecked(true);
                    mStatusBar.setVisible(false);
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(false);
                }

                if (mMenuBar != null) {
                    mMenuBar.setVisible(false);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(false);
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(false);
                }

                setUndecorated(true);
                final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

                if (device.isFullScreenSupported() && OperatingSystem.isMacOs()) {
                    device.setFullScreenWindow(MainFrame.getInstance());
                } else {
                    setLocation(0, 0);
                    setSize(screen);
                }

                setVisible(true);
                mProgramTableScrollPane.requestFocusInWindow();

                new Thread("Fullscreen border detection") {
                    public void run() {
                        setPriority(Thread.MIN_PRIORITY);

                        while (isFullScreenMode()) {
                            final Point p = MouseInfo.getPointerInfo().getLocation();
                            SwingUtilities.convertPointFromScreen(p, MainFrame.this);

                            if (isActive()) {

                                // mouse pointer is at top
                                if (p.y <= 10) {
                                    if (mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.NORTH) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (p.y <= 0) {
                                        mMenuBar.setVisible(true);
                                    }
                                } else if (p.y > (mMenuBar != null && mMenuBar.isVisible()
                                        ? mMenuBar.getHeight()
                                        : 0)
                                        + (Settings.propIsToolbarVisible.getBoolean()
                                                ? mToolBarPanel.getHeight()
                                                : 0)) {
                                    if (mMenuBar.isVisible()) {
                                        mMenuBar.setVisible(!isFullScreenMode());
                                    }

                                    if (mToolBarPanel != null && mToolBarPanel.isVisible() && mToolBar
                                            .getToolbarLocation().compareTo(BorderLayout.NORTH) == 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }
                                }

                                // mouse pointer is at the bottom
                                if (p.y >= screen.height - 1) {
                                    if (mStatusBar != null && !mStatusBar.isVisible()) {
                                        mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                                    }
                                } else if (mStatusBar != null && mStatusBar.isVisible()
                                        && p.y < screen.height - mStatusBar.getHeight()) {
                                    mStatusBar.setVisible(!isFullScreenMode());
                                }

                                // mouse pointer is on the left side
                                if (p.x <= 5) {
                                    if (p.x == 0 && mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.WEST) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    int toolBarWidth = (mToolBarPanel != null && mToolBarPanel.isVisible()
                                            && mToolBar.getToolbarLocation().compareTo(BorderLayout.WEST) == 0)
                                                    ? mToolBarPanel.getWidth()
                                                    : 0;

                                    if (p.x > toolBarWidth && toolBarWidth != 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x > mPluginView.getWidth() + toolBarWidth + 25) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x > mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x > mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x > mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }

                                // mouse pointer is on the right side
                                if (p.x >= screen.width - 1) {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x < screen.width - mPluginView.getWidth()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x < screen.width - mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x < screen.width
                                                                - mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x < screen.width - mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                            try {
                                Thread.sleep(200);
                            } catch (Exception e) {
                            }
                        }
                    }
                }.start();
            }
        }
    });
}

From source file:openqcm.mainGUI.java

private void chartDataMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartDataMouseMoved
    // TODO add your handling code here:
    //this will be some mouse-moved stuff
    PointerInfo a = MouseInfo.getPointerInfo();
    Point b = a.getLocation();//from w  w  w. ja  v a2 s  . com
    int x = (int) b.getX();
    int y = (int) b.getY();
    String xycoords = "x: " + Integer.toString(x) + " y:" + Integer.toString(y);
    System.out.println(xycoords);
    jTextField2.setText(xycoords);
}

From source file:hydrograph.ui.graph.figure.ComponentFigure.java

private void attachMouseListener() {
    addMouseMotionListener(new MouseMotionListener() {

        @Override//from  www.jav a 2  s .  c o m
        public void mouseMoved(org.eclipse.draw2d.MouseEvent arg0) {
            // Do nothing
        }

        @Override
        public void mouseHover(org.eclipse.draw2d.MouseEvent arg0) {
            arg0.consume();
            final org.eclipse.swt.graphics.Point location1 = new org.eclipse.swt.graphics.Point(arg0.x, arg0.y);
            java.awt.Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
            final org.eclipse.swt.graphics.Point location = new org.eclipse.swt.graphics.Point(mouseLocation.x,
                    mouseLocation.y);
            componentCanvas = getComponentCanvas();
            display = componentCanvas.getCanvasControl().getShell().getDisplay();
            timer = new Runnable() {
                public void run() {
                    // if(componentCanvas.isToolTipTimerRunning())
                    java.awt.Point mouseLocation2 = MouseInfo.getPointerInfo().getLocation();
                    org.eclipse.swt.graphics.Point location2 = new org.eclipse.swt.graphics.Point(
                            mouseLocation2.x, mouseLocation2.y);

                    org.eclipse.swt.graphics.Point perfectToolTipLocation = getToolTipLocation(location1,
                            location2, getBounds());

                    if (location2.equals(location)) {
                        showStatusToolTip(perfectToolTipLocation);
                        // showStatusToolTip(location);
                    }

                }
            };
            display.timerExec(TOOLTIP_SHOW_DELAY, timer);

        }

        @Override
        public void mouseExited(org.eclipse.draw2d.MouseEvent arg0) {
            // Do nothing
        }

        @Override
        public void mouseEntered(org.eclipse.draw2d.MouseEvent arg0) {
            // Do nothing
        }

        @Override
        public void mouseDragged(org.eclipse.draw2d.MouseEvent arg0) {
            // Do nothing
        }
    });

    addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(org.eclipse.draw2d.MouseEvent arg0) {

        }

        @Override
        public void mousePressed(org.eclipse.draw2d.MouseEvent arg0) {
            hideToolTip();
        }

        @Override
        public void mouseDoubleClicked(org.eclipse.draw2d.MouseEvent arg0) {
            hideToolTip();
        }
    });
}

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * @return The current mouse position as a Point {@inheritDoc}
 */
public Point getCurrentMousePosition() {
    return MouseInfo.getPointerInfo().getLocation();
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected void showNotificationPopup(String popupText, NotificationType type) {
    JPanel panel = new JPanel(new MigLayout("flowy"));
    panel.setBorder(BorderFactory.createLineBorder(Color.gray));

    switch (type) {
    case WARNING:
    case WARNING_HTML:
        panel.setBackground(Color.yellow);
        break;/*  w  w  w . jav  a2  s  .  c o  m*/
    case ERROR:
    case ERROR_HTML:
        panel.setBackground(Color.orange);
        break;
    default:
        panel.setBackground(Color.cyan);
    }

    JLabel label = new JLabel(popupText);
    panel.add(label);

    Dimension labelSize = DesktopComponentsHelper.measureHtmlText(popupText);

    int x = frame.getX() + frame.getWidth() - (50 + labelSize.getSize().width);
    int y = frame.getY() + frame.getHeight() - (50 + labelSize.getSize().height);

    PopupFactory factory = PopupFactory.getSharedInstance();
    final Popup popup = factory.getPopup(frame, panel, x, y);
    popup.show();

    panel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            popup.hide();
        }
    });

    PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    if (pointerInfo != null) {
        final Point location = pointerInfo.getLocation();
        final Timer timer = new Timer(3000, null);
        timer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                PointerInfo currentPointer = MouseInfo.getPointerInfo();
                if (currentPointer == null) {
                    timer.stop();
                } else if (!currentPointer.getLocation().equals(location)) {
                    popup.hide();
                    timer.stop();
                }
            }
        });
        timer.start();
    }
}

From source file:com.sikulix.core.SX.java

public static Location at() {
    PointerInfo mp = MouseInfo.getPointerInfo();
    if (mp != null) {
        return new Location(MouseInfo.getPointerInfo().getLocation());
    } else {/*from   w w  w. ja v a  2 s  .  c o  m*/
        error("not possible to get mouse position (PointerInfo == null)");
        return null;
    }
}