Java Code Examples for org.eclipse.swt.widgets.Sash#setLayoutData()

The following examples show how to use org.eclipse.swt.widgets.Sash#setLayoutData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static Sash createSplitter(Composite parent, FormAttachment left) {
  final Sash sash = new Sash(parent, SWT.VERTICAL);
  FormData formData = new FormData();
  formData.top = new FormAttachment(0, 0); // Attach to top
  formData.bottom = new FormAttachment(100, 0); // Attach to bottom
  formData.left = left;
  sash.setLayoutData(formData);
  sash.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
      // We reattach to the left edge, and we use the x value of the event to
      // determine the offset from the left
      ((FormData) sash.getLayoutData()).left = new FormAttachment(0, event.x);

      // Until the parent window does a layout, the sash will not be redrawn
      // in
      // its new location.
      sash.getParent().layout();
    }
  });
  return sash;
}
 
Example 2
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static Sash createSplitter(Composite parent, FormAttachment left) {
	final Sash sash = new Sash(parent, SWT.VERTICAL);
	FormData formData = new FormData();
	formData.top = new FormAttachment(0, 0); // Attach to top
	formData.bottom = new FormAttachment(100, 0); // Attach to bottom
	formData.left = left;
	sash.setLayoutData(formData);
	sash.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent event) {
			// We reattach to the left edge, and we use the x value of the
			// event to
			// determine the offset from the left
			((FormData) sash.getLayoutData()).left = new FormAttachment(0,
					event.x);

			// Until the parent window does a layout, the sash will not be
			// redrawn
			// in
			// its new location.
			sash.getParent().layout();
		}
	});
	return sash;
}
 
Example 3
Source File: Sasher.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the sasher, with the two given contained controls, the style,
 * {@link SWT#VERTICAL} or {@link SWT#HORIZONTAL}, and the percentage of
 * space initially used by the first Control.
 *
 * @param first first control (top or left)
 * @param second second control (down or right)
 * @param sasherStyle {@link SWT#VERTICAL} or {@link SWT#HORIZONTAL}.
 * @param percent percentage of space initially used by the first Control
 */
public void init(Control first, Control second,
    int sasherStyle, int percent) {
  this.sashStyle = sasherStyle;

  sash = new Sash(this, sashStyle);

  // create position instructions
  FormData firstData = new FormData();
  final FormData sashData = new FormData();
  FormData secondData = new FormData();

  // setup constant positions
  firstData.left = new FormAttachment(0);
  firstData.top = new FormAttachment(0);
  sashData.left = new FormAttachment(0);
  sashData.top = new FormAttachment(percent);
  secondData.right = new FormAttachment(100);
  secondData.bottom = new FormAttachment(100);

  // setup direction dependent positions
  if (isVertical()) { // horizontal == top/down
    firstData.right = new FormAttachment(sash);
    firstData.bottom = new FormAttachment(100);
    sashData.bottom = new FormAttachment(100);
    secondData.left = new FormAttachment(sash);
    secondData.top = new FormAttachment(0);
  } else {
    firstData.right = new FormAttachment(100);
    firstData.bottom = new FormAttachment(sash);
    sashData.right = new FormAttachment(100);
    secondData.left = new FormAttachment(0);
    secondData.top = new FormAttachment(sash);
  }

  // set the layouts
  first.setLayoutData(firstData);
  sash.setLayoutData(sashData);
  second.setLayoutData(secondData);

  // move event / constraints:
  sash.addListener(SWT.Selection, new Listener() {

    @Override
    public void handleEvent(Event e) {
      if (isVertical()) {
        resizeVertical(e, sashData);
      } else {
        resizeHorizontal(e, sashData);
      }
    }
  });
}
 
Example 4
Source File: TermDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 */
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, new Listener() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
		 */
		public void handleEvent(Event 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;
}
 
Example 5
Source File: TmDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 */
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, new Listener() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
		 */
		public void handleEvent(Event 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;
}
 
Example 6
Source File: TmDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 */
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, new Listener() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
		 */
		public void handleEvent(Event 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;
}
 
Example 7
Source File: TermDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 */
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, new Listener() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
		 */
		public void handleEvent(Event 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;
}
 
Example 8
Source File: TmDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 */
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, new Listener() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
		 */
		public void handleEvent(Event 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;
}
 
Example 9
Source File: AbstractPropertyDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private Sash createSash( final Composite composite )
{
	final Sash sash = new Sash( composite, SWT.VERTICAL );
	sash.setLayoutData( new GridData( GridData.FILL_VERTICAL ) );
	return sash;
}