private static Point fixPopupLocation(final Component contents, final int x, final int y) {
      if (!(contents instanceof JToolTip)) return new Point(x, y);

      final PointerInfo info;
      try {
        info = MouseInfo.getPointerInfo();
      } catch (InternalError e) {
        // http://www.jetbrains.net/jira/browse/IDEADEV-21390
        // may happen under Mac OSX 10.5
        return new Point(x, y);
      }
      int deltaY = 0;

      if (info != null) {
        final Point mouse = info.getLocation();
        deltaY = mouse.y - y;
      }

      final Dimension size = contents.getPreferredSize();
      final Rectangle rec = new Rectangle(new Point(x, y), size);
      ScreenUtil.moveRectangleToFitTheScreen(rec);

      if (rec.y < y) {
        rec.y += deltaY;
      }

      return rec.getLocation();
    }
Beispiel #2
0
  @Override
  public void mouseClicked(MouseEvent e) {

    indexOfLabelPressed = -1;

    for (int i = 0; i < orderLabel.length; i++) {
      if (e.getSource() == orderLabel[i]) {
        indexOfLabelPressed = i;
        PointerInfo a = MouseInfo.getPointerInfo();
        Point b = a.getLocation();
        int x = (int) b.getX();
        int y = (int) b.getY();
        popup.setLocation(x, y);
        popup.setInvoker(popup);
        popup.setVisible(true);
        revalidate();
        repaint();
      }
    }

    if (e.getSource() == topPanelLabel) {
      indexOfLabelPressed = -2;
    }

    if (indexOfLabelPressed == -1) {
      okDiscountButton.setText("Deduct");
      discountPopup.setLocation(700, 220);
      discountPopup.setInvoker(discountPopup);
      discountPopup.setVisible(true);
      itemDiscountPopupLabel.setText(
          "$"
              + finalModifier
              + " off with "
              + menuPanel.df.format((1 - finalPercentModifier) * 100)
              + "%"
              + " discount");
    } else if (indexOfLabelPressed == -2) {
      // TODO
      resetAll();
    }
  }
 private void checkMousePosition(Location p) {
   PointerInfo mp = MouseInfo.getPointerInfo();
   Point pc;
   if (mp == null) {
     Debug.error(
         "RobotDesktop: checkMousePosition: MouseInfo.getPointerInfo invalid\nafter move to %s",
         p);
   } else {
     pc = mp.getLocation();
     if (pc.x != p.x || pc.y != p.y) {
       Debug.error(
           "RobotDesktop: checkMousePosition: should be %s\nbut after move is %s"
               + "\nPossible cause: Mouse actions are blocked generally or by the frontmost application."
               + (Settings.isWindows()
                   ? "\nYou might try to run the SikuliX stuff as admin."
                   : ""),
           p,
           new Location(pc));
     }
   }
 }
  public static GraphicsDevice getMouseInfo(Point point) {
    GraphicsDevice rval = null;

    if (!hasMouseInfoPeer) {
      hasMouseInfoPeer = true;
      mouseInfoPeer = null;
      ArrayList<Exception> exceptions = new ArrayList<Exception>();
      try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Method method = toolkit.getClass().getDeclaredMethod("getMouseInfoPeer", new Class<?>[0]);
        boolean accessibleChanged = false;
        try {
          if (!method.isAccessible()) {
            method.setAccessible(true);
            accessibleChanged = true;
          }
          mouseInfoPeer = (MouseInfoPeer) method.invoke(toolkit, new Object[0]);
        } catch (IllegalArgumentException e) {
          exceptions.add(e);
        } catch (IllegalAccessException e) {
          exceptions.add(e);
        } catch (InvocationTargetException e) {
          exceptions.add(e);
        } finally {
          if (accessibleChanged) {
            method.setAccessible(false);
          }
        }
      } catch (SecurityException e) {
        exceptions.add(e);
      } catch (NoSuchMethodException e) {
        exceptions.add(e);
      }

      if (DEBUG) {
        for (Exception e : exceptions) {
          e.printStackTrace();
        }
      }
      exceptions.clear();
      exceptions = null;
    }
    if (mouseInfoPeer == null) {
      PointerInfo info = MouseInfo.getPointerInfo();
      // on windows info could be null if the lock screen activates

      if (info != null) {
        if (point != null) {
          Point tmpPoint = info.getLocation();
          point.x = tmpPoint.x;
          point.y = tmpPoint.y;
        }

        rval = info.getDevice();
      }
    } else {
      int device = mouseInfoPeer.fillPointWithCoords(point != null ? point : new Point());
      GraphicsDevice[] devices = getScreenDevices();

      rval = devices[device];
    }

    if (rval != null) {
      // found an instance where garbage ridiculously large values were
      // returned when coming back from lock screen on windows7
      int[] initialScale = new int[2];
      Rectangle bounds = getScreenBoundsVerbose(rval, initialScale);

      point.x -= bounds.x;
      point.y -= bounds.y;

      if (initialScale[0] != bounds.width || initialScale[1] != bounds.height) {
        point.x =
            Math.round(((float) bounds.width) / ((float) initialScale[0]) * ((float) point.x));
        point.y =
            Math.round(((float) bounds.height) / ((float) initialScale[1]) * ((float) point.y));
      }

      if (point.x < 0) {
        point.x = 0;
      } else if (point.x > bounds.width) {
        point.x = bounds.width;
      }

      if (point.y < 0) {
        point.y = 0;
      } else if (point.y > bounds.height) {
        point.y = bounds.height;
      }
    }

    return rval;
  }
Beispiel #5
0
 public Point getMousePosition() {
   PointerInfo a = MouseInfo.getPointerInfo();
   Point b = a.getLocation();
   b.setLocation(b.getX() - frmDrawPum.getX() - 8, b.getY() - frmDrawPum.getY() - 42);
   return b;
 }