Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.ScrollBar


    final Composite comp = tableComposite;
    tableComposite.addControlListener(new ControlAdapter() {
      public void controlResized(ControlEvent e) {
        Rectangle area = comp.getClientArea();
        Point size = tref.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        ScrollBar vBar = tref.getVerticalBar();
        int width = area.width - tref.computeTrim(0,0,0,0).width - 2;
        if (size.y > area.height + tref.getHeaderHeight()) {
          Point vBarSize = vBar.getSize();
          width -= vBarSize.x;
        }
        Point oldSize = tref.getSize();
        if (oldSize.x > area.width) {
          tc1.setWidth(width/2-1);
View Full Code Here


            //use a monospaced font for a better layout
            Font font = new Font(compositeHolder.getDisplay(), "Courier", 10, SWT.NORMAL);
            hexText.setFont(font);
            asciiText.setFont(font);

            final ScrollBar hexScrollBar = hexText.getVerticalBar();
            final ScrollBar asciiScrollBar = asciiText.getVerticalBar();

            //create a sub composite to contain all the buttons
            final Composite buttonComposite = toolkit.createComposite(localComposite, SWT.NONE);
            layout = new GridLayout(7, false);
            layout.marginWidth = 0;
            buttonComposite.setLayout(layout);
            buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));

            _firstButton = toolkit.createButton(buttonComposite, "<<", SWT.PUSH);
            GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _firstButton.setLayoutData(layoutData);
            _firstButton.setToolTipText("See the first n bytes");

            _previousButton = toolkit.createButton(buttonComposite, "<", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _previousButton.setLayoutData(layoutData);
            _previousButton.setToolTipText("See the previous n bytes");
            _previousButton.setEnabled(false);

            _hexNumTextToStart = toolkit.createText(buttonComposite, "0");
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _hexNumTextToStart.setLayoutData(layoutData);
            _hexNumTextToStart.setEditable(false);

            final Text hexNumText = toolkit.createText(buttonComposite, "" + startContentSize);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            hexNumText.setLayoutData(layoutData);

            _hexNumTextToEnd = toolkit.createText(buttonComposite, "" + (byteArray.length - startContentSize));
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _hexNumTextToEnd.setLayoutData(layoutData);
            _hexNumTextToEnd.setEditable(false);

            _nextButton = toolkit.createButton(buttonComposite, ">", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _nextButton.setLayoutData(layoutData);
            _nextButton.setToolTipText("See the next n bytes");
            _nextButton.setEnabled(true);

            _lastButton = toolkit.createButton(buttonComposite, ">>", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _lastButton.setToolTipText("See the last n bytes");
            _lastButton.setLayoutData(layoutData);

            SelectionListener listener = new SelectionAdapter()
            {
                public void widgetSelected(SelectionEvent e)
                {
                    if (e.widget instanceof Button)
                    {
                        String numOfBytes = hexNumText.getText();
                        try
                        {
                            int n = Integer.parseInt(numOfBytes);

                            //Reset range display if user requests a large value
                            if (n > byteArray.length)
                            {
                                n = (byteArray.length > DEFAULT_CONTENT_SIZE) ? DEFAULT_CONTENT_SIZE : byteArray.length;
                                hexNumText.setText("" + n);
                            }

                            //rest if the user requests 0
                            if (n < 1)
                            {
                                n = DEFAULT_CONTENT_SIZE;
                                hexNumText.setText("" + n);
                            }

                            Button button = (Button) e.widget;
                            hexText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
                                                              button.getText(), true));
                            asciiText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
                                                                button.getText(), false));
                        }
                        catch (NumberFormatException exp)
                        {
                            popupErrorMessage("Error", "Please input the number of bytes you wish to look at");
                        }
                    }
                    if (e.widget instanceof ScrollBar)
                    {
                        //synchronize the movements of the two scrollbars
                        ScrollBar sb = (ScrollBar) e.widget;
                        if (sb.getParent().equals(hexText))
                        {
                            asciiScrollBar.setIncrement(sb.getIncrement());
                            asciiScrollBar.setSelection(sb.getSelection());
                        }
                        else if (sb.getParent().equals(asciiText))
                        {
                            hexScrollBar.setSelection(sb.getSelection());
                            hexScrollBar.setIncrement(sb.getIncrement());
                        }
                    }
                }
            };
            localComposite.addControlListener(new ControlAdapter()
View Full Code Here

        }
        if (preferredSize.y > area.height) {
            // Subtract the scrollbar width from the total column width
            // if a vertical scrollbar will be required, but is not currently showing
          // (in which case it is already subtracted above)
            ScrollBar vBar= table.getVerticalBar();
            if (!vBar.isVisible()) {
              Point vBarSize= vBar.getSize();
              trim += vBarSize.x;
            }
        }
    return trim;
  }
View Full Code Here

    public WidgetInfos(StyledText textWidget, Canvas canvas) {
      maxLines= textWidget.getLineCount();
      bounds= canvas.getBounds();
      writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines);
     
      ScrollBar verticalBar= textWidget.getVerticalBar();
      thumbHeight= verticalBar != null ? Math.max(Math.min(bounds.height, verticalBar.getThumbBounds().height), 0) : 0;
     
          int partialTopIndex= JFaceTextUtil.getPartialTopIndex(textWidget);
          int topLineHeight= textWidget.getLineHeight(textWidget.getOffsetAtLine(partialTopIndex));
          int topLinePixel= textWidget.getLinePixel(partialTopIndex);
          double topIndex= partialTopIndex - (double) topLinePixel / topLineHeight;
View Full Code Here

    yorigin = Math.min(yorigin, contentSize.y - 1);
    scomp.setOrigin(xorigin, yorigin);
  }

  public static void updatePageIncrement(ScrolledComposite scomp) {
    ScrollBar vbar = scomp.getVerticalBar();
    if (vbar != null) {
      Rectangle clientArea = scomp.getClientArea();
      int increment = clientArea.height - 5;
      vbar.setPageIncrement(increment);
    }
    ScrollBar hbar = scomp.getHorizontalBar();
    if (hbar != null) {
      Rectangle clientArea = scomp.getClientArea();
      int increment = clientArea.width - 5;
      hbar.setPageIncrement(increment);
    }
  }
View Full Code Here

     * @return an array containing {topArrowHeight, bottomArrowHeight}
     *
     * @since 3.6
     */
    private int[] getVerticalScrollArrowHeights(StyledText textWidget, int bottomOffset) {
      ScrollBar verticalBar= textWidget.getVerticalBar();
      if (verticalBar == null)
        return new int[] { 0, 0 };
     
      int[] arrowHeights= computeScrollArrowHeights(textWidget, bottomOffset);
      if (arrowHeights[0] > 0 || arrowHeights[1] > 0) {
        fScrollArrowHeights= arrowHeights;
      } else if (fScrollArrowHeights != null) {
        return fScrollArrowHeights;
      } else {
        // No arrow heights available. Enlarge textWidget and tweak scroll bar to get reasonable values.
        Point originalSize= textWidget.getSize();
        try {
          int fakeHeight= 1000;
          bottomOffset= bottomOffset - originalSize.y + fakeHeight;
          textWidget.setSize(originalSize.x, fakeHeight);
          verticalBar.setValues(0, 0, 1 << 30, 1, 10, 10);
          arrowHeights= computeScrollArrowHeights(textWidget, bottomOffset);
          fScrollArrowHeights= arrowHeights;
        } finally {
          textWidget.setSize(originalSize); // also resets scroll bar values
        }
View Full Code Here

     * @return an array containing {topArrowHeight, bottomArrowHeight}
     *
     * @since 3.6
     */
    private int[] computeScrollArrowHeights(StyledText textWidget, int bottomOffset) {
      ScrollBar verticalBar= textWidget.getVerticalBar();
      Rectangle thumbTrackBounds= verticalBar.getThumbTrackBounds();
      if (thumbTrackBounds.height == 0) // SWT returns bogus values on Cocoa in this case, see https://bugs.eclipse.org/352990
        return new int[] { 0, 0 };
     
      int topArrowHeight= thumbTrackBounds.y;
      int bottomArrowHeight= bottomOffset - (thumbTrackBounds.y + thumbTrackBounds.height);
View Full Code Here

    Composite c = (Composite) getContent();
    Rectangle clientArea = getClientArea();
    if (c == null)
      return;
    if (clientArea.width == getSize().x) {
      ScrollBar bar = getVerticalBar();
      if (bar != null) {
          clientArea.width -= bar.getSize().x;
      }
    }
     
    contentCache.setControl(c);
    if (flushCache) {
      contentCache.flush();
    }
    Point newSize = contentCache.computeSize(FormUtil.getWidthHint(
        clientArea.width, c), FormUtil.getHeightHint(clientArea.height,
        c));

    if (!(expandHorizontal && expandVertical)) {
      c.setSize(newSize);
    }

    setMinSize(newSize);
    FormUtil.updatePageIncrement(this);
   
    // reduce vertical scroll increment if necessary
    ScrollBar vbar = getVerticalBar();
    if (vbar != null) {
      if (getClientArea().height - 5 < V_SCROLL_INCREMENT)
        getVerticalBar().setIncrement(getClientArea().height - 5);
      else
        getVerticalBar().setIncrement(V_SCROLL_INCREMENT);
View Full Code Here

    } else
      reflow(flushCache);
  }

  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);
    }
    FormUtil.updatePageIncrement(this);
  }
View Full Code Here

            //use a monospaced font for a better layout
            Font font = new Font(compositeHolder.getDisplay(), "Courier", 10, SWT.NORMAL);
            hexText.setFont(font);
            asciiText.setFont(font);

            final ScrollBar hexScrollBar = hexText.getVerticalBar();
            final ScrollBar asciiScrollBar = asciiText.getVerticalBar();

            //create a sub composite to contain all the buttons
            final Composite buttonComposite = toolkit.createComposite(localComposite, SWT.NONE);
            layout = new GridLayout(7, false);
            layout.marginWidth = 0;
            buttonComposite.setLayout(layout);
            buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));

            _firstButton = toolkit.createButton(buttonComposite, "<<", SWT.PUSH);
            GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _firstButton.setLayoutData(layoutData);
            _firstButton.setToolTipText("See the first n bytes");

            _previousButton = toolkit.createButton(buttonComposite, "<", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _previousButton.setLayoutData(layoutData);
            _previousButton.setToolTipText("See the previous n bytes");
            _previousButton.setEnabled(false);

            _hexNumTextToStart = toolkit.createText(buttonComposite, "0");
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _hexNumTextToStart.setLayoutData(layoutData);
            _hexNumTextToStart.setEditable(false);

            final Text hexNumText = toolkit.createText(buttonComposite, "" + startContentSize);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            hexNumText.setLayoutData(layoutData);

            _hexNumTextToEnd = toolkit.createText(buttonComposite, "" + (byteArray.length - startContentSize));
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _hexNumTextToEnd.setLayoutData(layoutData);
            _hexNumTextToEnd.setEditable(false);

            _nextButton = toolkit.createButton(buttonComposite, ">", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _nextButton.setLayoutData(layoutData);
            _nextButton.setToolTipText("See the next n bytes");
            _nextButton.setEnabled(true);

            _lastButton = toolkit.createButton(buttonComposite, ">>", SWT.PUSH);
            layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            layoutData.widthHint = 40;
            _lastButton.setToolTipText("See the last n bytes");
            _lastButton.setLayoutData(layoutData);

            SelectionListener listener = new SelectionAdapter()
            {
                public void widgetSelected(SelectionEvent e)
                {
                    if (e.widget instanceof Button)
                    {
                        String numOfBytes = hexNumText.getText();
                        try
                        {
                            int n = Integer.parseInt(numOfBytes);

                            //Reset range display if user requests a large value
                            if (n > byteArray.length)
                            {
                                n = (byteArray.length > DEFAULT_CONTENT_SIZE) ? DEFAULT_CONTENT_SIZE : byteArray.length;
                                hexNumText.setText("" + n);
                            }

                            //rest if the user requests 0
                            if (n < 1)
                            {
                                n = DEFAULT_CONTENT_SIZE;
                                hexNumText.setText("" + n);
                            }

                            Button button = (Button) e.widget;
                            hexText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
                                                              button.getText(), true));
                            asciiText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
                                                                button.getText(), false));
                        }
                        catch (NumberFormatException exp)
                        {
                            popupErrorMessage("Error", "Please input the number of bytes you wish to look at");
                        }
                    }
                    if (e.widget instanceof ScrollBar)
                    {
                        //synchronize the movements of the two scrollbars
                        ScrollBar sb = (ScrollBar) e.widget;
                        if (sb.getParent().equals(hexText))
                        {
                            asciiScrollBar.setIncrement(sb.getIncrement());
                            asciiScrollBar.setSelection(sb.getSelection());
                        }
                        else if (sb.getParent().equals(asciiText))
                        {
                            hexScrollBar.setSelection(sb.getSelection());
                            hexScrollBar.setIncrement(sb.getIncrement());
                        }
                    }
                }
            };
            localComposite.addControlListener(new ControlAdapter()
View Full Code Here

TOP

Related Classes of org.eclipse.swt.widgets.ScrollBar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.