예제 #1
0
  /**
   * Shows a tool tip over the upper left corner of the viewport with the contents of the pannable
   * view's pannable tip text (typically a string identifiying the corner point). Tip is removed
   * after a short delay.
   */
  public void showPanTip() {
    String tipText = null;
    Point upperLeft = new Point(0, 0);
    JViewport vp = getEnclosingViewport();
    if (!isPannableUnbounded() && vp != null) upperLeft = vp.getViewPosition();
    Location loc = locationForPoint(upperLeft);
    if (loc != null) tipText = getToolTipText(loc);

    showTip(tipText, getLocation());
  }
예제 #2
0
  /**
   * Moves the current location by a given amount.
   *
   * @param dr the number of rows by which to move the location
   * @param dc the number of columns by which to move the location
   */
  public void moveLocation(int dr, int dc) {
    Location newLocation =
        new Location(currentLocation.getRow() + dr, currentLocation.getCol() + dc);
    if (!grid.isValid(newLocation)) return;

    currentLocation = newLocation;

    JViewport viewPort = getEnclosingViewport();
    if (isPannableUnbounded()) {
      if (originRow > currentLocation.getRow()) originRow = currentLocation.getRow();
      if (originCol > currentLocation.getCol()) originCol = currentLocation.getCol();
      Dimension dim = viewPort.getSize();
      int rows = dim.height / (cellSize + 1);
      int cols = dim.width / (cellSize + 1);
      if (originRow + rows - 1 < currentLocation.getRow())
        originRow = currentLocation.getRow() - rows + 1;
      if (originCol + rows - 1 < currentLocation.getCol())
        originCol = currentLocation.getCol() - cols + 1;
    } else if (viewPort != null) {
      int dx = 0;
      int dy = 0;
      Point p = pointForLocation(currentLocation);
      Rectangle locRect =
          new Rectangle(p.x - cellSize / 2, p.y - cellSize / 2, cellSize + 1, cellSize + 1);

      Rectangle viewRect = viewPort.getViewRect();
      if (!viewRect.contains(locRect)) {
        while (locRect.x < viewRect.x + dx) dx -= cellSize + 1;
        while (locRect.y < viewRect.y + dy) dy -= cellSize + 1;
        while (locRect.getMaxX() > viewRect.getMaxX() + dx) dx += cellSize + 1;
        while (locRect.getMaxY() > viewRect.getMaxY() + dy) dy += cellSize + 1;

        Point pt = viewPort.getViewPosition();
        pt.x += dx;
        pt.y += dy;
        viewPort.setViewPosition(pt);
      }
    }
    repaint();
    showTip(getToolTipText(currentLocation), pointForLocation(currentLocation));
  }