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();
    }
  }