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:macro.pkg2.MouseCollection.java

/**
 * Method that is called when a mouse button has been pressed. Used to
 * add a mouse click action to the list of events. -1 for leftmouse and
 * -3 for right mouse//w  w w.  java  2s.c om
 *
 * @param button The mouse button that was pressed.
 */
public void mouseDown(int button) {//-1 for leftmouseDown, -3 for right mouse down
    if (record) {
        unpause();//ensures that the collection is not paused
        //Adds the appropriate action to the action list
        if (button == 1) {
            mouseEvents.add(new SimpleMouseEvent(MouseInfo.getPointerInfo().getLocation().x,
                    MouseInfo.getPointerInfo().getLocation().y, -1));
        } else if (button == 2) {
            mouseEvents.add(new SimpleMouseEvent(MouseInfo.getPointerInfo().getLocation().x,
                    MouseInfo.getPointerInfo().getLocation().y, -3));
        }
        //System.out.println("Added: " + mouseEvents.getLast().toString());
    }
}

From source file:com.db2eshop.gui.menu.RightClickPopupMenu.java

/**
 * <p>relocate.</p>/*from   w  w  w. j  a v  a 2  s  .c  o  m*/
 *
 * @param point a {@link java.awt.Point} object.
 */
public void relocate(Point point) {
    //      Point mainFrameLocation = mainFrame.getLocation();
    setLocation(MouseInfo.getPointerInfo().getLocation());
    //      this.setLocation((int)(mainFrameLocation.getX() + point.getX()) + 40, (int)(mainFrameLocation.getY() + point.getY()) + 70);
}

From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java

/**
 * @return mouse absolute location on the screen. This works for Mac and Windows, as
 * opposed to AWT MouseInfo.getPointerInfo() which will not work in Mac (due to HeadlessException)
 *//*from   w ww  . j a  v a  2s  .  c  om*/
public static Point getAbsMouseLocation() {
    return PlatformUtil.isMac() ? getMacMouseLocation() : MouseInfo.getPointerInfo().getLocation();
}

From source file:macro.pkg2.MouseCollection.java

/**
 * Method that is called when a mouse button has been release. Used to
 * add a mouse click action to the list of events. -2 for left mouse up
 * and -4 for right mouse up./* w w w. j  ava2 s.  c  o  m*/
 *
 * @param button The mouse Button that was pressed.
 */
public void mouseUp(int button) {//-2 for left mouse up, -4 for right mouse up
    if (record) {
        unpause(); //Ensures that the collection is not paused.
        if (button == 1) {
            mouseEvents.add(new SimpleMouseEvent(MouseInfo.getPointerInfo().getLocation().x,
                    MouseInfo.getPointerInfo().getLocation().y, -2));
        } else if (button == 2) {
            mouseEvents.add(new SimpleMouseEvent(MouseInfo.getPointerInfo().getLocation().x,
                    MouseInfo.getPointerInfo().getLocation().y, -4));
        }
        //System.out.println("Added: " + mouseEvents.getLast().toString());
    }
}

From source file:com.o2d.pkayjava.editor.Main.java

private void toggleVisible() {
    mainFrame.setVisible(!mainFrame.isVisible());
    if (mainFrame.isVisible()) {
        mainFrame.toFront();/*from   ww  w. j av  a  2s .  c  o  m*/
        mainFrame.requestFocus();
        mainFrame.setAlwaysOnTop(true);
        try {
            //remember the last location of mouse
            final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

            //simulate a mouse click on title bar of window
            Robot robot = new Robot();
            robot.mouseMove(mainFrame.getX() + 100, mainFrame.getY() + 5);
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

            //move mouse to old location
            robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
        } catch (Exception ex) {
            //just ignore exception, or you can handle it as you want
        } finally {
            mainFrame.setAlwaysOnTop(false);
        }
    }
}

From source file:macro.pkg2.MouseCollection.java

/**
 * Unpauses the collection of mouse points
 */// ww w .jav a  2  s. c o m
public void unpause() {
    if (pause) {
        System.out.println("unpause");
        stopWatch.stop();
        //Adds a mouse event that includes the new mouse locaiton and also the number of miliseconds
        //that the collection has been paused.
        mouseEvents.add(new SimpleMouseEvent(MouseInfo.getPointerInfo().getLocation().x,
                MouseInfo.getPointerInfo().getLocation().y, (int) stopWatch.getTime()));
        System.out.println(mouseEvents.getLast().toString());
        stopWatch.reset();
        pause = false;
    }
}

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

protected void showTooltip(JComponent field, String text) {
    if (!field.isShowing())
        return;//from  ww  w. j  ava2  s. c om

    if (StringUtils.isEmpty(text)) {
        return;
    }

    PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    if (pointerInfo == null) {
        return;
    }

    if (toolTipWindow != null) {
        hideTooltip();
    }

    component = field;

    final JToolTip toolTip = new CubaToolTip();
    toolTip.setTipText(text);

    // Location to display tooltip
    Point location = getToolTipLocation(pointerInfo, toolTip.getTipText());

    final Popup tooltipContainer = PopupFactory.getSharedInstance().getPopup(field, toolTip, location.x,
            location.y);
    tooltipContainer.show();

    window = tooltipContainer;
    toolTipWindow = toolTip;

    tooltipShowing = true;
    if (!(field instanceof ToolTipButton)) {
        toolTip.addMouseListener(this);
        field.addMouseListener(this);
    }
}

From source file:robots.ScrapBot.java

public void scrapWeapons(boolean verbose, boolean pretend) throws Exception {
    // TODO: Pretty sure I'll need to ensure that it's scrapping scrappable weapons.  eg. pull out genuines, etc.
    getSchema();/*from  w w w  .j a va2 s .  c  om*/
    getBackpack();

    final Point smeltWeapons = pointProvider.getPoint(PointPlace.smeltWeapons);

    outputter.output("Scrapping Weapons...");
    leftClick(smeltWeapons.x, smeltWeapons.y);

    // Populate the array with all items and the information we care about.
    int bitmask = 0xFFFF;
    for (int i = 0; i < backpackItems.length(); i++) {
        JSONObject item = backpackItems.getJSONObject(i);
        int inventoryValue = backpackItems.getJSONObject(i).getInt("inventory");
        Weapon currentItem = new Weapon();
        currentItem.setDefindex(item.getInt("defindex"));
        currentItem.setInventorySlot(inventoryValue & bitmask);
        items.add(currentItem);
    }

    // Fill in remaining information and remove non-weapons
    ArrayList<Weapon> newList = new ArrayList<Weapon>();
    for (Weapon item : items) {
        for (int i = 0; i < schemaItems.length(); i++) {
            JSONObject schemaItem = schemaItems.getJSONObject(i);
            if (item.getDefindex().equals(schemaItem.getInt("defindex")) && item.getInventorySlot() > 0) {
                if (schemaItem.has("craft_material_type")) {
                    if (schemaItem.getString("craft_material_type").equals("weapon")) {
                        item.setName(schemaItem.getString("item_name"));
                        JSONArray classesJson = schemaItem.getJSONObject("used_by_classes")
                                .getJSONArray("class");
                        ArrayList<TF2Class> classes = new ArrayList<TF2Class>();
                        for (int j = 0; j < classesJson.length(); j++) {
                            String tf2Class = classesJson.getString(j);
                            TF2Class currentClass = TF2Class.SCOUT;
                            if (tf2Class.equals("Scout"))
                                currentClass = TF2Class.SCOUT;
                            else if (tf2Class.equals("Soldier"))
                                currentClass = TF2Class.SOLIDER;
                            else if (tf2Class.equals("Pyro"))
                                currentClass = TF2Class.PYRO;
                            else if (tf2Class.equals("Demoman"))
                                currentClass = TF2Class.DEMOMAN;
                            else if (tf2Class.equals("Heavy"))
                                currentClass = TF2Class.HEAVY;
                            else if (tf2Class.equals("Engineer"))
                                currentClass = TF2Class.ENGINEER;
                            else if (tf2Class.equals("Medic"))
                                currentClass = TF2Class.MEDIC;
                            else if (tf2Class.equals("Sniper"))
                                currentClass = TF2Class.SNIPER;
                            else if (tf2Class.equals("Spy"))
                                currentClass = TF2Class.SPY;
                            classes.add(currentClass);
                        }
                        item.setClasses(classes);
                        newList.add(item);
                    }
                }
            }
        }
    }
    items = newList;

    // Now, compare and determine two items to scrap
    ArrayList<Weapon> itemsToIgnore = new ArrayList<Weapon>();
    for (Weapon item : items) {
        // If the item is still there, it hasn't been used in crafting OR it hasn't been iterated to yet.
        if (!itemsToIgnore.contains(item)) {
            Weapon match = null;
            for (Weapon hopefulMatch : items) {
                if (!hopefulMatch.equals(item) && !itemsToIgnore.contains(hopefulMatch)) {
                    for (TF2Class tf2Class : item.getClasses()) {
                        for (TF2Class hopefulClass : hopefulMatch.getClasses()) {
                            if (tf2Class.equals(hopefulClass)) {
                                // These two weapons are compatible.  Scrap 'em!
                                match = hopefulMatch;
                                break;
                            }
                        }
                        if (match != null)
                            break;
                    }
                }
                if (match != null)
                    break;
            }
            // Come out here
            if (match != null) {
                // Scrap
                if (verbose)
                    outputter.output("Scrapping a " + item.getName() + " and a " + match.getName() + ".");
                if (!pretend) {
                    scrapWeapons(item, match);
                    Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
                    Point ok2 = pointProvider.getPoint(PointPlace.ok2);
                    if (mouseLoc.getX() != ok2.x || mouseLoc.getY() != ok2.getY())
                        break;
                }
                itemsToIgnore.add(match);
            }
            itemsToIgnore.add(item);
        }
    }
    outputter.output("Weapons Scrapped.");
}

From source file:jdroidremote.ServerFrame.java

private void startMonitoring() {
    thStartMonitoring = new Thread(new Runnable() {
        @Override/* www.j  a  va  2s  .  co m*/
        public void run() {
            try {

                System.out.println("START MONITORING..........");

                //                    while (1 == 1) {
                BufferedImage screenCapture = robot
                        .createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

                Image cursor = ImageIO.read(new File("cursor.png"));
                int x = MouseInfo.getPointerInfo().getLocation().x;
                int y = MouseInfo.getPointerInfo().getLocation().y;
                Graphics2D graphics2D = screenCapture.createGraphics();
                graphics2D.drawImage(cursor, x, y, 13, 25, null); // cursor.gif is 16x16 size.
                ImageIO.write(screenCapture, "JPG", new File("2.jpg"));

                Thread.sleep(200);

                File file = new File("2.jpg");

                // Reading a Image file from file system
                FileInputStream imageInFile = new FileInputStream(file);
                byte imageData[] = new byte[(int) file.length()];
                imageInFile.read(imageData);

                // Converting Image byte array into Base64 String
                String imageDataString = ImageManipulation.encodeImage(imageData);

                System.out.println(imageDataString.length());

                //                        System.out.println(imageDataString);
                //                        // Converting a Base64 String into Image byte array
                //                        byte[] imageByteArray = ImageManipulation.decodeImage(imageDataString);
                //
                //                        // Write a image byte array into file system
                //                        FileOutputStream imageOutFile = new FileOutputStream(
                //                                "_avatar_.jpg");
                //
                //                        imageOutFile.write(imageByteArray);
                imageInFile.close();
                //                        imageOutFile.close();

                System.out.println("Image Successfully Manipulated!");

                // Split the five sandwiches.!
                StringBuilder sbImageDataString = new StringBuilder(imageDataString);

                for (int i = 0; i < sbImageDataString.toString().length(); i += 30000) {
                    if (i + 30000 <= sbImageDataString.toString().length()) {
                        dos.writeUTF(sbImageDataString.substring(i, i + 30000));
                        dos.flush();
                    } else {
                        dos.writeUTF(sbImageDataString.substring(i, sbImageDataString.toString().length()));
                        dos.flush();
                    }

                }
                dos.writeUTF("...");
                dos.flush();

                //                    }
            } catch (IOException ex) {
                Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 *
 *///from w w  w.  j  av  a  2 s . c om
protected void updateMouseMarker() {
    if (markerAnnotation.isVisible()) {
        Point screenPoint = MouseInfo.getPointerInfo().getLocation();
        SwingUtilities.convertPointFromScreen(screenPoint, chartPanel);
        updateMouseMarker(screenPoint);
    }
}