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

The following examples show how to use org.eclipse.swt.widgets.Sash#addListener() . 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: 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 2
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 3
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 4
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 5
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 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;
}