示例#1
0
  /**
   * Synchronize the scrollbar with the image. If the transform is out of range, it will correct it.
   * This function considers only following factors :<b> transform, image size, client area</b>.
   */
  public void syncScrollBars() {
    if (sourceImage == null) {
      redraw();
      return;
    }

    AffineTransform af = transform;
    double sx = af.getScaleX(), sy = af.getScaleY();
    double tx = af.getTranslateX(), ty = af.getTranslateY();
    if (tx > 0) tx = 0;
    if (ty > 0) ty = 0;

    ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement((int) (getClientArea().width / 20));
    horizontal.setPageIncrement(getClientArea().width);
    Rectangle imageBound = sourceImage.getBounds();
    int cw = getClientArea().width, ch = getClientArea().height;
    if (imageBound.width * sx > cw) {
        /* image is wider than client area */
      horizontal.setMaximum((int) (imageBound.width * sx));
      horizontal.setEnabled(true);
      if (((int) -tx) > horizontal.getMaximum() - cw) tx = -horizontal.getMaximum() + cw;
    } else {
        /* image is narrower than client area */
      horizontal.setEnabled(false);
      tx = (cw - imageBound.width * sx) / 2; // center if too small.
    }
    horizontal.setSelection((int) (-tx));
    horizontal.setThumb((int) (getClientArea().width));

    ScrollBar vertical = getVerticalBar();
    vertical.setIncrement((int) (getClientArea().height / 20));
    vertical.setPageIncrement((int) (getClientArea().height));
    if (imageBound.height * sy > ch) {
        /* image is higher than client area */
      vertical.setMaximum((int) (imageBound.height * sy));
      vertical.setEnabled(true);
      if (((int) -ty) > vertical.getMaximum() - ch) ty = -vertical.getMaximum() + ch;
    } else {
        /* image is less higher than client area */
      vertical.setEnabled(false);
      ty = (ch - imageBound.height * sy) / 2; // center if too small.
    }
    vertical.setSelection((int) (-ty));
    vertical.setThumb((int) (getClientArea().height));

    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    transform = af;

    redraw();
  }
 private void appendLog(String text) {
   synchronized (console) {
     console.setText(console.getText() + text);
     ScrollBar verticalBar = console.getVerticalBar();
     if (verticalBar != null) {
       verticalBar.setSelection(verticalBar.getMaximum());
     }
   }
 }
示例#3
0
 public void scrolled(final ScrollBar scrollBar, final int widthToSubtract) {
   _thumb = scrollBar.getThumb();
   _minimum = scrollBar.getMinimum();
   _maximum = scrollBar.getMaximum();
   _selection = scrollBar.getSelection();
   _widthToSubtract = widthToSubtract;
   redraw();
   update();
 }
示例#4
0
  /**
   * This method is responsible to set the scroll bar attributes so that they reflect the size of
   * the current image at the current zoom factor
   */
  private void synchronizeScrollBars() {
    // Syncronizing only makes sense if there is a skin being drawn
    if (currentSkinImage != null) {

      // Retrieves the current image and client area sizes
      Rectangle imageBound = currentSkinImage.getBounds();
      int cw = getClientArea().width;
      int ch = getClientArea().height;

      // Updates horizontal scroll bar attributes
      ScrollBar horizontal = getHorizontalBar();
      horizontal.setIncrement((cw / 100));
      horizontal.setPageIncrement((cw / 2));
      horizontal.setMaximum(imageBound.width);
      horizontal.setThumb(cw);
      horizontal.setSelection(displayRectangle.x);

      // Updates vertical scroll bar attributes
      ScrollBar vertical = getVerticalBar();
      vertical.setIncrement((ch / 100));
      vertical.setPageIncrement((ch / 2));
      vertical.setMaximum(imageBound.height);
      vertical.setThumb(ch);
      vertical.setSelection(displayRectangle.y);

      if (horizontal.getMaximum() > cw) // Image is wider than client area
      {
        horizontal.setEnabled(true);
      } else {
        horizontal.setEnabled(false);
      }

      if (vertical.getMaximum() > ch) // Image is wider than client area
      {
        vertical.setEnabled(true);
      } else {
        vertical.setEnabled(false);
      }
    }
  }