Пример #1
0
  protected void layout() {
    Rectangle parentArea = this.composite.getClientArea();
    int width = parentArea.width;
    int height = parentArea.height;

    Rectangle sashBounds = sash.getBounds();

    resultText.setBounds(0, 0, width, sashBounds.y);
    userText.setBounds(0, sashBounds.y + 3, width, height - sashBounds.y - 3);
    sash.setBounds(0, sashBounds.y, width, 3);
  }
 /**
  * Create the sash with right control on the right. Note that this method assumes GridData for the
  * layout data of the rightControl.
  *
  * @param composite
  * @param rightControl
  * @return Sash
  * @since 3.1
  */
 protected Sash createSash(final Composite composite, final Control rightControl) {
   final Sash sash = new Sash(composite, SWT.VERTICAL);
   sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
   sash.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
   // the following listener resizes the tree control based on sash deltas.
   // If necessary, it will also grow/shrink the dialog.
   sash.addListener(
       SWT.Selection,
       event -> {
         if (event.detail == SWT.DRAG) {
           return;
         }
         int shift = event.x - sash.getBounds().x;
         GridData data = (GridData) rightControl.getLayoutData();
         int newWidthHint = data.widthHint + shift;
         if (newWidthHint < 20) {
           return;
         }
         Point computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
         Point currentSize = getShell().getSize();
         // if the dialog wasn't of a custom size we know we can shrink
         // it if necessary based on sash movement.
         boolean customSize = !computedSize.equals(currentSize);
         data.widthHint = newWidthHint;
         setLastTreeWidth(newWidthHint);
         composite.layout(true);
         // recompute based on new widget size
         computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
         // if the dialog was of a custom size then increase it only if
         // necessary.
         if (customSize) {
           computedSize.x = Math.max(computedSize.x, currentSize.x);
         }
         computedSize.y = Math.max(computedSize.y, currentSize.y);
         if (computedSize.equals(currentSize)) {
           return;
         }
         setShellSize(computedSize.x, computedSize.y);
         lastShellSize = getShell().getSize();
       });
   return sash;
 }