private void initializeScrollBars() {
   ScrollBar hbar = getHorizontalBar();
   if (hbar != null) {
     hbar.setIncrement(H_SCROLL_INCREMENT);
   }
   ScrollBar vbar = getVerticalBar();
   if (vbar != null) {
     vbar.setIncrement(V_SCROLL_INCREMENT);
   }
   updatePageIncrement();
 }
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
  /**
   * 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. 4
0
  private void init() {
    this.composite = new Composite(this, SWT.BORDER | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED);
    this.composite.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    this.composite.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            TGPainter painter = new TGPainter(e.gc);
            paintChords(painter);
          }
        });
    this.composite.addMouseListener(
        new MouseAdapter() {
          public void mouseUp(MouseEvent e) {
            getComposite().setFocus();
            getDialog().getEditor().setChord(getChord(e.x, e.y, true));
            redraw();
          }
        });

    final Point origin = new Point(0, 0);
    final ScrollBar vBar = this.composite.getVerticalBar();
    vBar.setIncrement(SCROLL_INCREMENT);
    vBar.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            int vSelection = vBar.getSelection();
            int destY = -vSelection - origin.y;
            Rectangle rect = getComposite().getBounds();
            getShell().scroll(0, destY, 0, 0, rect.width, rect.height, false);
            origin.y = -vSelection;
            redraw();
          }
        });

    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.minimumHeight = MIN_HEIGHT;
    this.composite.setLayoutData(data);
    this.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent arg0) {
            disposeChords();
            disposeFont();
          }
        });
  }
Esempio n. 5
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);
      }
    }
  }