org.eclipse.swt.widgets.Sash#addListener ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.Sash#addListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: depan   文件: Sasher.java
/**
 * 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);
      }
    }
  });
}
 
源代码2 项目: translationstudio8   文件: TermDbManagerDialog.java
/**
 * 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;
}
 
源代码3 项目: translationstudio8   文件: TmDbManagerDialog.java
/**
 * 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;
}
 
源代码4 项目: tmxeditor8   文件: TmDbManagerDialog.java
/**
 * 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;
}
 
源代码5 项目: tmxeditor8   文件: TermDbManagerDialog.java
/**
 * 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;
}
 
源代码6 项目: tmxeditor8   文件: TmDbManagerDialog.java
/**
 * 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;
}