示例#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();
  }
示例#2
0
 /* Initalize the scrollbar and register listeners. */
 private void initScrollBars() {
   ScrollBar horizontal = getHorizontalBar();
   horizontal.setEnabled(false);
   horizontal.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           scrollHorizontally((ScrollBar) event.widget);
         }
       });
   ScrollBar vertical = getVerticalBar();
   vertical.setEnabled(false);
   vertical.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           scrollVertically((ScrollBar) event.widget);
         }
       });
 }
示例#3
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);
      }
    }
  }
示例#4
0
  /**
   * Initialize the scroll bars This include: a) setting the initial enabled state b) adding the
   * necessary listeners
   */
  private void initScrollBars() {

    ScrollBar horizontal = getHorizontalBar();
    horizontal.setEnabled(false);
    horizontal.addSelectionListener(
        new SelectionAdapter() {
          /** @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent) */
          @Override
          public void widgetSelected(SelectionEvent event) {
            // Updates the translation
            displayRectangle.x = ((ScrollBar) event.widget).getSelection();

            // Update the UI
            layout();
            redraw();
          }
        });

    ScrollBar vertical = getVerticalBar();
    vertical.setEnabled(false);
    vertical.addSelectionListener(
        new SelectionAdapter() {
          /** @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent) */
          @Override
          public void widgetSelected(SelectionEvent event) {
            // Updates the translation
            displayRectangle.y = ((ScrollBar) event.widget).getSelection();

            // Update the UI
            layout();
            redraw();
          }
        });

    debug("Initialized scroll bars");
  }