Exemplo n.º 1
0
  /**
   * Set the scroll position.
   *
   * @param x coordinate of upper left corner.
   * @param y coordinate of upper left corner.
   */
  public void setScrollPosition(int x, int y) {
    final DjVuImage image = getImage();
    if ((image != null) && ((x != scrollPosition.x) || (y != scrollPosition.y))) {
      final Dimension imageSize = image.getSize();
      final Dimension viewportSize = getViewportSize();
      x = Math.max(0, Math.min(imageSize.width - viewportSize.width, x));
      y = Math.max(0, Math.min(imageSize.height - viewportSize.height, y));

      if ((x != scrollPosition.x) || (y != scrollPosition.y)) {
        scrollPosition.setLocation(x, y);
        updateScrollbars();
        repaint(50L);
      }
    }
  }
Exemplo n.º 2
0
  // Called to update the scrollbar properties.
  private void updateScrollbars() {
    final DjVuImage image = getImage();
    if (image != null) {
      final Dimension viewportSize = getViewportSize();
      final Dimension imageSize = image.getSize();
      final Point scrollPosition = getScrollPosition();
      final Scrollbar hScroll = getScrollbar(Scrollbar.HORIZONTAL);
      final Scrollbar vScroll = getScrollbar(Scrollbar.VERTICAL);

      if (hScroll != null) {
        hScroll.setValues(scrollPosition.x, viewportSize.width, 0, imageSize.width);
      }

      if (vScroll != null) {
        vScroll.setValues(scrollPosition.y, viewportSize.height, 0, imageSize.height);
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Adjust the image scale.
   *
   * @param width to scale the image to.
   * @param height to scale the image to.
   */
  public void setImageSize(int width, int height) {
    DjVuImage image = getImageWait();
    final Dimension imageSize = image.getSize();
    final int owidth = imageSize.width;
    final int oheight = imageSize.height;

    if ((width != owidth) || (height != oheight)) {
      zoom = 0;
      image = image.getScaledInstance(width, height);

      if (image != null) {
        width = image.getBounds().width;
        height = image.getBounds().height;
        setImage(image);
      }

      scaleScrollPosition(owidth, oheight, width, height);
      recursiveRevalidate();
    }
  }