Example #1
0
 public void mouseMoved(int x, int y, MouseEvent event) {
   if (myLastMotionReport != null && myLastMotionReport.equals(new Point(x, y))) {
     return;
   }
   if (shouldSendMouseData(MouseMode.MOUSE_REPORTING_ALL_MOTION)) {
     myTerminalOutput.sendBytes(mouseReport(MouseButtonCodes.RELEASE, x + 1, y + 1));
   }
   myLastMotionReport = new Point(x, y);
 }
  private void setSizeAndDimensions(
      @NotNull JTable table,
      @NotNull JBPopup popup,
      @NotNull RelativePoint popupPosition,
      @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1) myWidth = width;
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
      window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
      TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    // table.setPreferredSize(dimension);
    // table.setMaximumSize(dimension);
    // table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight =
        (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4 /* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
  }
Example #3
0
  @Override
  public void mouseDragged(int x, int y, MouseEvent event) {
    if (myLastMotionReport != null && myLastMotionReport.equals(new Point(x, y))) {
      return;
    }
    if (shouldSendMouseData(MouseMode.MOUSE_REPORTING_BUTTON_MOTION)) {
      // when dragging, button is not in "button", but in "modifier"
      int cb = createButtonCode(event);

      if (cb != MouseButtonCodes.NONE) {
        cb |= MouseButtonModifierFlags.MOUSE_BUTTON_MOTION_FLAG;
        cb = applyModifierKeys(event, cb);
        myTerminalOutput.sendBytes(mouseReport(cb, x + 1, y + 1));
      }
    }
    myLastMotionReport = new Point(x, y);
  }
Example #4
0
 @Override
 public List<Point> getFreeCells() {
   List<Point> result = new LinkedList<Point>();
   for (Point cell : getCells()) {
     boolean isSapper = cell.equals(getSapper());
     boolean isBoard =
         cell.getX() == 0
             || cell.getY() == 0
             || cell.getX() == size.getValue() - 1
             || cell.getY() == size.getValue() - 1; // TODO test me
     boolean isMine = isMine(cell);
     if (!isSapper && !isMine && !isBoard) {
       result.add(cell);
     }
   }
   return result;
 }
Example #5
0
  // Recursivly goes through the maze until it finds the finish line
  public boolean findTheWay(Point p) {
    boolean northBarrier = false;
    boolean southBarrier = false;
    boolean eastBarrier = false;
    boolean westBarrier = false;
    int data = myMaze.getMazeData(p.y, p.x);
    // Returns false if Y position is out of range
    if (p.y < 0 || p.y > height) return false;

    // Returns false if X position is out of range
    if (p.x < 0 || p.x > height) return false;
    // Finds which paths are blocked for point P
    if (data > 14) {
      northBarrier = true;
      southBarrier = true;
      eastBarrier = true;
      westBarrier = true;
    }
    if (data <= 14 && data - 8 >= 0) {
      eastBarrier = true;
      data -= 8;
    }
    if (data <= 7 && data - 4 >= 0) {
      southBarrier = true;
      data -= 4;
    }
    if (data <= 3 && data - 2 >= 0) {
      westBarrier = true;
    }
    if (data % 2 != 0) {
      northBarrier = true;
    }

    // Returns true if the goal is reached
    if (p.equals(goal)) return true;

    // Adds the point to the path of points
    path.add(p);
    placesGone.add(p);

    // Checks for North
    if (!northBarrier && !placesGone.contains(new Point(p.x, p.y - 1))) {
      if (p.y - 1 >= 0) {
        if (findTheWay(new Point(p.x, p.y - 1))) {
          return true;
        }
      }
    }
    // Checks for South
    if (!southBarrier && !placesGone.contains(new Point(p.x, p.y + 1))) {
      if (p.y + 1 < height) {
        if (findTheWay(new Point(p.x, p.y + 1))) {
          return true;
        }
      }
    }

    // Checks for East
    if (!eastBarrier && !placesGone.contains(new Point(p.x + 1, p.y))) {
      if (p.x + 1 < width) {
        if (findTheWay(new Point(p.x + 1, p.y))) {
          return true;
        }
      }
    }

    // Checks for West
    if (!westBarrier && !placesGone.contains(new Point(p.x - 1, p.y))) {
      if (p.x - 1 >= 0) {
        if (findTheWay(new Point(p.x - 1, p.y))) {
          return true;
        }
      }
    }
    // Removes the point if its not part of the final solution
    path.remove(path.size() - 1);
    return false;
  }
Example #6
0
 @Override
 public boolean isSapper(Point pt) {
   return pt.equals(getSapper());
 }