Ejemplo n.º 1
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (horizontalButton.getSelection()) style |= SWT.H_SCROLL;
    if (verticalButton.getSelection()) style |= SWT.V_SCROLL;
    if (borderButton.getSelection()) style |= SWT.BORDER;
    if (noBackgroundButton.getSelection()) style |= SWT.NO_BACKGROUND;
    if (noFocusButton.getSelection()) style |= SWT.NO_FOCUS;
    if (noMergePaintsButton.getSelection()) style |= SWT.NO_MERGE_PAINTS;
    if (noRedrawResizeButton.getSelection()) style |= SWT.NO_REDRAW_RESIZE;

    /* Create the example widgets */
    paintCount = 0;
    cx = 0;
    cy = 0;
    canvas = new Canvas(canvasGroup, style);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            paintCount++;
            GC gc = e.gc;
            if (fillDamageButton.getSelection()) {
              Color color = e.display.getSystemColor(colors[paintCount % colors.length]);
              gc.setBackground(color);
              gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
            Point size = canvas.getSize();
            gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
            gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
          }
        });
    canvas.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent event) {
            Point size = canvas.getSize();
            maxX = size.x * 3 / 2;
            maxY = size.y * 3 / 2;
            resizeScrollBars();
          }
        });
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollHorizontal((ScrollBar) event.widget);
            }
          });
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollVertical((ScrollBar) event.widget);
            }
          });
    }
  }
 @Override
 public void controlResized(final ControlEvent e) {
   final Rectangle area = this.parent.getClientArea();
   final Point size = this.table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   final ScrollBar vBar = this.table.getVerticalBar();
   int width =
       area.width - this.table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x - this.usedWidth;
   if (size.y > area.height + this.table.getHeaderHeight()) {
     // Subtract the scrollbar width from the total column width
     // if a vertical scrollbar will be required
     final Point vBarSize = vBar.getSize();
     width -= vBarSize.x;
   }
   final Point oldSize = this.table.getSize();
   if (oldSize.x > area.width) {
     // table is getting smaller so make the columns
     // smaller first and then resize the table to
     // match the client area width
     this.column.setWidth(width);
     this.table.setSize(area.width, area.height);
   } else {
     // table is getting bigger so make the table
     // bigger first and then make the columns wider
     // to match the client area width
     this.table.setSize(area.width, area.height);
     this.column.setWidth(width);
   }
 }
 private static void renderChanges(ScrollBar scrollBar) {
   if (scrollBar != null) {
     renderProperty(scrollBar, PROP_VISIBILITY, scrollBar.getVisible(), false);
     renderListener(
         scrollBar, PROP_SELECTION_LISTENER, scrollBar.isListening(SWT.Selection), false);
   }
 }
Ejemplo n.º 4
0
 public void updateScroll() {
   Rectangle rect = this.composite.getBounds();
   Rectangle client = this.composite.getClientArea();
   ScrollBar vBar = this.composite.getVerticalBar();
   vBar.setMaximum(this.height);
   vBar.setThumb(Math.min(rect.height, client.height));
 }
  /**
   * 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);
    }
  }
 private void updatePageIncrement() {
   ScrollBar vbar = getVerticalBar();
   if (vbar != null) {
     Rectangle clientArea = getClientArea();
     int increment = clientArea.height - 5;
     vbar.setPageIncrement(increment);
   }
 }
Ejemplo n.º 7
0
 private void appendLog(String text) {
   synchronized (console) {
     console.setText(console.getText() + text);
     ScrollBar verticalBar = console.getVerticalBar();
     if (verticalBar != null) {
       verticalBar.setSelection(verticalBar.getMaximum());
     }
   }
 }
Ejemplo n.º 8
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();
 }
 private void initScrollBarListener() {
   ScrollBar scroll = getTable().getVerticalBar();
   fScrollSelectionListener =
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           handleScrollBarSelection();
         }
       };
   scroll.addSelectionListener(fScrollSelectionListener);
 }
Ejemplo n.º 10
0
  /** Saves the state of the filter actions */
  public void saveState(IMemento memento) {
    fMemberFilterActionGroup.saveState(memento);

    memento.putString(TAG_SHOWINHERITED, String.valueOf(isShowInheritedMethods()));
    memento.putString(TAG_SORTBYDEFININGTYPE, String.valueOf(isShowDefiningTypes()));

    ScrollBar bar = getTable().getVerticalBar();
    int position = bar != null ? bar.getSelection() : 0;
    memento.putString(TAG_VERTICAL_SCROLL, String.valueOf(position));
  }
Ejemplo n.º 11
0
  /**
   * Installs this highlighter into the specified StyledText object. Client can manually call
   * detach() method, then wants to destroy this object.
   */
  public void attach(StyledText parent) {
    detach();

    text = parent;
    text.addDisposeListener(ml);
    text.addLineStyleListener(ml);
    text.addLineBackgroundListener(ml);
    text.addPaintListener(ml);
    text.addVerifyListener(ml);
    text.addExtendedModifyListener(ml);
    text.addControlListener(ml);
    text.addKeyListener(ml);
    text.addTraverseListener(ml);
    text.addMouseListener(ml);
    text.addSelectionListener(ml);
    text.getContent().addTextChangeListener(ml);
    ScrollBar sb = text.getVerticalBar();
    if (sb != null) sb.addSelectionListener(ml);
    updateViewport();

    new Thread() {
      public void run() {
        // setPriority(Thread.NORM_PRIORITY-1);
        while (true) {
          try {
            sleep(300);
          } catch (InterruptedException e) {
          }
          if (baseEditor == null || text == null) break;
          if (backParserDelay) {
            backParserDelay = false;
            try {
              sleep(1500);
            } catch (InterruptedException e) {
            }
            continue;
          }
          ;
          Display.getDefault()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      if (baseEditor == null || text == null) return;
                      if (text.isDisposed()) return;
                      // System.out.println(System.currentTimeMillis());
                      baseEditor.idleJob(80);
                      // redrawFrom(text.getLineAtOffset(text.getCaretOffset()));
                    }
                  });
        }
        ;
      };
    }.start();
  }
 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();
 }
Ejemplo n.º 13
0
  protected Point getOffset(Point thumb, Point area) {
    Point p = new Point(0, 0);
    Point sel = new Point(hori.getSelection(), vert.getSelection());

    if (thumb.x == 0 || thumb.y == 0) return p;

    p.x = Math.round(-sel.x * area.x / thumb.x / magnification);
    p.y = Math.round(-sel.y * area.y / thumb.y / magnification);

    return p;
  }
Ejemplo n.º 14
0
  @Test
  public void testReadData_ScrollBarsSelectionEvent() {
    sc.setContent(new Composite(sc, SWT.NONE));
    SelectionListener selectionListener = mock(SelectionListener.class);
    hScroll.addSelectionListener(selectionListener);
    vScroll.addSelectionListener(selectionListener);

    Fixture.fakeNotifyOperation(getId(hScroll), "Selection", null);
    Fixture.fakeNotifyOperation(getId(vScroll), "Selection", null);
    Fixture.readDataAndProcessAction(sc);

    verify(selectionListener, times(2)).widgetSelected(any(SelectionEvent.class));
  }
Ejemplo n.º 15
0
  @Test
  public void testRenderOrigin_SetByScrollbar() throws IOException {
    Composite content = new Composite(sc, SWT.NONE);
    sc.setContent(content);

    hScroll.setSelection(1);
    vScroll.setSelection(2);
    lca.renderChanges(sc);

    TestMessage message = Fixture.getProtocolMessage();
    JsonArray expected = JsonArray.readFrom("[ 1, 2 ]");
    assertEquals(expected, message.findSetProperty(sc, "origin"));
  }
  @Override
  protected void updateLowerViewWidget(Object[] elements) {

    if (elements == null || elements.length < 1) {
      fTreeViewer.setInput(null);
      return;
    }

    fTreeViewer.setInput(elements[0]);

    ScrollBar bar = fTree.getVerticalBar();
    if (bar != null) {
      bar.setSelection(0);
    }
  }
Ejemplo n.º 17
0
  @Test
  public void testRenderRemoveScrollBarsSelectionListener_Vertical() throws Exception {
    SelectionListener listener = new SelectionAdapter() {};
    vScroll.addSelectionListener(listener);
    Fixture.markInitialized(display);
    Fixture.markInitialized(sc);
    Fixture.markInitialized(vScroll);
    Fixture.preserveWidgets();

    vScroll.removeSelectionListener(listener);
    lca.renderChanges(sc);

    TestMessage message = Fixture.getProtocolMessage();
    assertEquals(JsonValue.FALSE, message.findListenProperty(vScroll, "Selection"));
  }
Ejemplo n.º 18
0
 @Test
 public void testPreserveValues() {
   RemoteAdapter adapter = WidgetUtil.getAdapter(sc);
   assertEquals(null, adapter.getPreserved(PROP_SHOW_FOCUSED_CONTROL));
   hScroll.setSelection(23);
   vScroll.setSelection(42);
   sc.setShowFocusedControl(true);
   assertEquals(23, hScroll.getSelection());
   assertEquals(42, vScroll.getSelection());
   Rectangle rectangle = new Rectangle(12, 30, 20, 40);
   sc.setBounds(rectangle);
   Fixture.markInitialized(display);
   Fixture.preserveWidgets();
   assertEquals(Boolean.TRUE, adapter.getPreserved(PROP_SHOW_FOCUSED_CONTROL));
 }
Ejemplo n.º 19
0
  private void handleOptionSelection() {
    // Get the selection from the tree list
    if (fTree == null) return;
    IStructuredSelection selection = (IStructuredSelection) fTree.getSelection();
    ToolListElement element = (ToolListElement) selection.getFirstElement();
    if (element != null) {
      displayPageForElement(element);
    }

    ScrollBar sb = containerSC.getHorizontalBar();
    if (sb != null && sb.isVisible()) {
      settingsPageContainer.pack(true);
      containerSC.setMinSize(settingsPageContainer.getSize());
      ((AbstractPage) page).resize();
    }
  }
Ejemplo n.º 20
0
  /**
   * search next text
   *
   * @param widgetText text widget
   * @param widgetFind search text widget
   */
  private void findNext(StyledText widgetText, Text widgetFind) {
    if (!widgetText.isDisposed()) {
      String findText = widgetFind.getText().toLowerCase();
      if (!findText.isEmpty()) {
        // get cursor position
        int cursorIndex = widgetText.getCaretOffset();

        // search
        int offset = -1;
        if (cursorIndex >= 0) {
          String text = widgetText.getText();
          offset =
              (cursorIndex + 1 < text.length())
                  ? text.substring(cursorIndex + 1).toLowerCase().indexOf(findText)
                  : -1;
        }
        if (offset >= 0) {
          int index = cursorIndex + 1 + offset;

          widgetText.setCaretOffset(index);
          widgetText.setSelection(index);
          widgetText.redraw();

          int topIndex = widgetText.getTopIndex();

          widgetLineNumbers.setTopIndex(topIndex);
          widgetVerticalScrollBar.setSelection(topIndex);
        } else {
          Widgets.flash(widgetFind);
        }
      }
    }
  }
Ejemplo n.º 21
0
  @Test
  public void testRenderScrollBarsVisibleUnchanged() throws IOException {
    Fixture.markInitialized(display);
    Fixture.markInitialized(sc);
    Fixture.markInitialized(hScroll);
    Fixture.markInitialized(vScroll);

    hScroll.setVisible(false);
    vScroll.setVisible(false);
    Fixture.preserveWidgets();
    lca.renderChanges(sc);

    TestMessage message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(hScroll, "visibility"));
    assertNull(message.findSetOperation(vScroll, "visibility"));
  }
Ejemplo n.º 22
0
  void onDispose(Event event) {
    removeListener(SWT.Dispose, listener);
    notifyListeners(SWT.Dispose, event);
    event.type = SWT.None;

    table.removeListener(SWT.FocusIn, tableListener);
    table.removeListener(SWT.MouseDown, tableListener);
    unhookRowColumnListeners();
    ScrollBar hBar = table.getHorizontalBar();
    if (hBar != null) {
      hBar.removeListener(SWT.Selection, resizeListener);
    }
    ScrollBar vBar = table.getVerticalBar();
    if (vBar != null) {
      vBar.removeListener(SWT.Selection, resizeListener);
    }
  }
Ejemplo n.º 23
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();
          }
        });
  }
 private static String getOverflow(final ScrolledComposite composite) {
   String result;
   ScrollBar horizontalBar = composite.getHorizontalBar();
   boolean scrollX = horizontalBar != null && horizontalBar.getVisible();
   ScrollBar verticalBar = composite.getVerticalBar();
   boolean scrollY = verticalBar != null && verticalBar.getVisible();
   if (scrollX && scrollY) {
     result = "scroll";
   } else if (scrollX) {
     result = "scrollX";
   } else if (scrollY) {
     result = "scrollY";
   } else {
     result = "hidden";
   }
   return result;
 }
Ejemplo n.º 25
0
 /**
  * Removes this object from the corresponding StyledText widget. Object can't be used after this
  * call, until another attach. This method is called automatically, when StyledText widget is
  * disposed
  */
 public void detach() {
   if (text == null) return;
   text.removeDisposeListener(ml);
   text.removeLineStyleListener(ml);
   text.removeLineBackgroundListener(ml);
   text.removePaintListener(ml);
   text.removeVerifyListener(ml);
   text.removeExtendedModifyListener(ml);
   text.removeControlListener(ml);
   text.removeKeyListener(ml);
   text.removeTraverseListener(ml);
   text.removeMouseListener(ml);
   text.removeSelectionListener(ml);
   ScrollBar sb = text.getVerticalBar();
   if (sb != null) sb.removeSelectionListener(ml);
   baseEditor = null;
 }
 private static void renderCreate(ScrollBar scrollBar) {
   if (scrollBar != null) {
     IClientObject clientObject = ClientObjectFactory.getClientObject(scrollBar);
     clientObject.create(TYPE);
     clientObject.set("parent", getId(scrollBar.getParent()));
     clientObject.set("style", WidgetLCAUtil.getStyles(scrollBar, ALLOWED_STYLES));
   }
 }
 private static Integer getBarSelection(final ScrollBar scrollBar) {
   Integer result;
   if (scrollBar != null) {
     result = new Integer(scrollBar.getSelection());
   } else {
     result = null;
   }
   return result;
 }
Ejemplo n.º 28
0
  @Test
  public void testRenderScrollBarsVisible_Vertical() throws IOException {
    vScroll.setVisible(true);
    lca.renderChanges(sc);

    TestMessage message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(hScroll, "visibility"));
    assertEquals(JsonValue.TRUE, message.findSetProperty(vScroll, "visibility"));
  }
Ejemplo n.º 29
0
 /**
  * Scrolls the canvas horizontally.
  *
  * @param scrollBar
  */
 void scrollHorizontal(ScrollBar scrollBar) {
   Rectangle bounds = canvas.getClientArea();
   int x = -scrollBar.getSelection();
   if (x + maxX < bounds.width) {
     x = bounds.width - maxX;
   }
   canvas.scroll(x, cy, cx, cy, maxX, maxY, false);
   cx = x;
 }
Ejemplo n.º 30
0
 /**
  * Scrolls the canvas vertically.
  *
  * @param scrollBar
  */
 void scrollVertical(ScrollBar scrollBar) {
   Rectangle bounds = canvas.getClientArea();
   int y = -scrollBar.getSelection();
   if (y + maxY < bounds.height) {
     y = bounds.height - maxY;
   }
   canvas.scroll(cx, y, cx, cy, maxX, maxY, false);
   cy = y;
 }