/**
   * Resize the scrolled composite enclosing the sections, which may result in the addition or
   * removal of scroll bars.
   *
   * @since 3.5
   */
  public void resizeScrolledComposite() {
    Point currentTabSize = new Point(0, 0);
    if (currentTab != null) {
      final Composite sizeReference = (Composite) tabToComposite.get(currentTab);
      if (sizeReference != null) {
        currentTabSize = sizeReference.computeSize(SWT.DEFAULT, SWT.DEFAULT);
      }
    }
    tabbedPropertyComposite.getScrolledComposite().setMinSize(currentTabSize);

    final ScrollBar verticalScrollBar =
        tabbedPropertyComposite.getScrolledComposite().getVerticalBar();
    if (verticalScrollBar != null) {
      final Rectangle clientArea = tabbedPropertyComposite.getScrolledComposite().getClientArea();
      final int increment = clientArea.height - 5;
      verticalScrollBar.setPageIncrement(increment);
    }

    final ScrollBar horizontalScrollBar =
        tabbedPropertyComposite.getScrolledComposite().getHorizontalBar();
    if (horizontalScrollBar != null) {
      final Rectangle clientArea = tabbedPropertyComposite.getScrolledComposite().getClientArea();
      final int increment = clientArea.width - 5;
      horizontalScrollBar.setPageIncrement(increment);
    }
  }
Esempio n. 2
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();
  }
Esempio n. 3
0
 /** Resizes the maximum and thumb of both scrollbars. */
 void resizeScrollBars() {
   Rectangle clientArea = canvas.getClientArea();
   ScrollBar bar = canvas.getHorizontalBar();
   if (bar != null) {
     bar.setMaximum(maxX);
     bar.setThumb(clientArea.width);
     bar.setPageIncrement(clientArea.width);
   }
   bar = canvas.getVerticalBar();
   if (bar != null) {
     bar.setMaximum(maxY);
     bar.setThumb(clientArea.height);
     bar.setPageIncrement(clientArea.height);
   }
 }
 private void updatePageIncrement() {
   ScrollBar vbar = getVerticalBar();
   if (vbar != null) {
     Rectangle clientArea = getClientArea();
     int increment = clientArea.height - 5;
     vbar.setPageIncrement(increment);
   }
 }
Esempio n. 5
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);
      }
    }
  }
Esempio n. 6
0
  private void updateScrollBars() {
    ScrollBar hBar = getHorizontalBar();
    ScrollBar vBar = getVerticalBar();

    if (image == null || image.isDisposed()) {
      hBar.setVisible(false);
      vBar.setVisible(false);
      return;
    }

    // 표시해야할 이미지의 크기
    Rectangle imageBounds = image != null ? image.getBounds() : new Rectangle(0, 0, 0, 0);

    // 표시에 사용할 수 있는 클라이언트 영역
    Rectangle clientArea = getClientArea();

    // 스크롤바 표시 여부 계산, 표시해야할 그림이 클라이언트 영역보다 넓으면 표시
    hBar.setVisible(imageBounds.width > clientArea.width);
    vBar.setVisible(imageBounds.height > clientArea.height);

    hBar.setMaximum(imageBounds.width);
    vBar.setMaximum(imageBounds.height);

    clientArea = getClientArea();

    // 현재 표시중인 영역이 표시해야할 전체 영역에 대한 비율을 계산
    double hRatio = clientArea.width / (double) imageBounds.width;
    double vRatio = clientArea.height / (double) imageBounds.height;

    // 스크롤바의 썸 크기 업데이트
    hBar.setThumb((int) (hRatio * imageBounds.width));
    vBar.setThumb((int) (vRatio * imageBounds.height));

    // 스크롤바 빈영역 클릭시 10% 정도씩 이동하도록 지정
    hBar.setPageIncrement((int) (imageBounds.width * 0.1));
    vBar.setPageIncrement((int) (imageBounds.height * 0.1));
  }
Esempio n. 7
0
  protected void doCalculations() {
    if (m_Model == null) {
      ScrollBar sb = getHorizontalBar();
      if (sb != null) {
        sb.setMinimum(0);
        sb.setMaximum(1);
        sb.setPageIncrement(1);
        sb.setThumb(1);
        sb.setSelection(1);
      }
      sb = getVerticalBar();
      if (sb != null) {
        sb.setMinimum(0);
        sb.setMaximum(1);
        sb.setPageIncrement(1);
        sb.setThumb(1);
        sb.setSelection(1);
      }
      return;
    }

    int m_HeaderHeight = m_Model.getFirstRowHeight();
    int m_RowHeight = m_Model.getRowHeight();

    Rectangle rect = getClientArea();
    if (m_LeftColumn < m_Model.getFixedColumnCount()) {
      m_LeftColumn = m_Model.getFixedColumnCount();
    }

    if (m_TopRow < m_Model.getFixedRowCount()) {
      m_TopRow = m_Model.getFixedRowCount();
    }

    int fixedWidth = getFixedWidth();
    int fixedHeight = m_HeaderHeight + (m_Model.getFixedRowCount() - 1) * m_Model.getRowHeight();
    m_ColumnsVisible = 0;
    m_ColumnsFullyVisible = 0;

    if (m_Model.getColumnCount() > m_Model.getFixedColumnCount()) {
      int runningWidth = getColumnLeft(m_LeftColumn);
      for (int col = m_LeftColumn; col < m_Model.getColumnCount(); col++) {
        if (runningWidth < rect.width + rect.x) m_ColumnsVisible++;
        runningWidth += m_Model.getColumnWidth(col);
        if (runningWidth < rect.width + rect.x) m_ColumnsFullyVisible++;
        else break;
      }
    }

    ScrollBar sb = getHorizontalBar();
    if (sb != null) {
      if (m_Model.getColumnCount() <= m_Model.getFixedColumnCount()) {
        sb.setMinimum(0);
        sb.setMaximum(1);
        sb.setPageIncrement(1);
        sb.setThumb(1);
        sb.setSelection(1);
      } else {
        sb.setMinimum(m_Model.getFixedColumnCount());
        sb.setMaximum(m_Model.getColumnCount());
        sb.setIncrement(1);
        sb.setPageIncrement(2);
        sb.setThumb(m_ColumnsFullyVisible);
        sb.setSelection(m_LeftColumn);
      }
    }

    m_RowsFullyVisible = Math.max(0, (rect.height - fixedHeight) / m_RowHeight);
    m_RowsFullyVisible =
        Math.min(m_RowsFullyVisible, m_Model.getRowCount() - m_Model.getFixedRowCount());
    m_RowsFullyVisible = Math.max(0, m_RowsFullyVisible);

    m_RowsVisible = m_RowsFullyVisible + 1;

    if (m_TopRow + m_RowsFullyVisible > m_Model.getRowCount()) {
      m_TopRow = Math.max(m_Model.getFixedRowCount(), m_Model.getRowCount() - m_RowsFullyVisible);
    }

    if (m_TopRow + m_RowsFullyVisible >= m_Model.getRowCount()) {
      m_RowsVisible--;
    }

    sb = getVerticalBar();
    if (sb != null) {
      if (m_Model.getRowCount() <= m_Model.getFixedRowCount()) {
        sb.setMinimum(0);
        sb.setMaximum(1);
        sb.setPageIncrement(1);
        sb.setThumb(1);
        sb.setSelection(1);
      } else {
        sb.setMinimum(m_Model.getFixedRowCount());
        sb.setMaximum(m_Model.getRowCount());
        sb.setPageIncrement(m_RowsVisible);
        sb.setIncrement(1);
        sb.setThumb(m_RowsFullyVisible);
        sb.setSelection(m_TopRow);
      }
    }
  }