本文整理汇总了Java中org.eclipse.swt.widgets.Sash.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java Sash.addListener方法的具体用法?Java Sash.addListener怎么用?Java Sash.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.widgets.Sash
的用法示例。
在下文中一共展示了Sash.addListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JoSashForm
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
public JoSashForm(final Composite parent, final ISplitCompositeSetupSpi setup) {
super(parent, getSashFormStyle(setup));
resizePolicy = setup.getResizePolicy();
sashUtil = getSashUtil(setup);
layout = new JoSashFormLayout(this, sashUtil);
setLayout(layout);
sash = new Sash(this, getSashStyle(setup));
sash.setToolTipText(getToolTipText());
sash.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(final Event event) {
if (event.detail == SWT.DRAG) {
return;
}
onDragSash(event);
}
});
firstMinSize = new Point(SPLIT_MINIMUM, SPLIT_MINIMUM);
secondMinSize = new Point(SPLIT_MINIMUM, SPLIT_MINIMUM);
}
示例2: createSash
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
/**
* Create the <code>Sash</code>with left control on the left. Note that
* this method assumes <code>GridData</code> for the layout data of the
* leftControl.
*
* @param composite the <code>Composite</code> to embed the
* <code>Sash</code> into
* @param leftControl the <code>Control</code> at the left side of the
* <code>Sash</code>
* @return Sash the created <code>Sash</code>
*/
protected Sash createSash(final Composite composite,
final Control leftControl)
{
final Sash sash = new Sash(composite, SWT.VERTICAL);
sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
sash.setBackground(composite.getDisplay().getSystemColor(
SWT.COLOR_LIST_BACKGROUND));
sash.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event event)
{
if (event.detail == SWT.DRAG)
return;
int shift = event.x - sash.getBounds().x;
GridData data = (GridData) leftControl.getLayoutData();
int newWidthHint = data.widthHint + shift;
int maxSize = getPageContainer().getSize().x / 2;
if (newWidthHint > maxSize || newWidthHint < 70)
{
event.doit = false;
return;
}
data.widthHint = newWidthHint;
composite.layout(true);
}
});
return (sash);
}
示例3: init
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
/**
* 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);
}
}
});
}
示例4: createSash
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
/**
* 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: createSash
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
/**
* 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, 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: construct
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public Control construct(Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
.grab(true, true).applyTo(composite);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite);
GridLayout layout = new GridLayout();
Button button1 = new Button(composite, SWT.PUSH);
button1.setText("Button 1");
final Sash sash = new Sash(composite, SWT.VERTICAL);
Button button2 = new Button(composite, SWT.PUSH);
button2.setText("Button 2");
final FormLayout form = new FormLayout();
composite.setLayout(form);
FormData button1Data = new FormData();
button1Data.left = new FormAttachment(0, 0);
button1Data.right = new FormAttachment(sash, 0);
button1Data.top = new FormAttachment(0, 0);
button1Data.bottom = new FormAttachment(100, 0);
button1.setLayoutData(button1Data);
final int limit = 20, percent = 50;
final FormData sashData = new FormData();
sashData.left = new FormAttachment(percent, 0);
sashData.top = new FormAttachment(0, 0);
sashData.bottom = new FormAttachment(100, 0);
sash.setLayoutData(sashData);
sash.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle shellRect = composite.getClientArea();
int right = shellRect.width - sashRect.width - limit;
e.x = Math.max(Math.min(e.x, right), limit);
if (e.x != sashRect.x) {
sashData.left = new FormAttachment(0, e.x);
composite.layout();
}
}
});
FormData button2Data = new FormData();
button2Data.left = new FormAttachment(sash, 0);
button2Data.right = new FormAttachment(100, 0);
button2Data.top = new FormAttachment(0, 0);
button2Data.bottom = new FormAttachment(100, 0);
button2.setLayoutData(button2Data);
return null;
}
示例7: createVerticalSash
import org.eclipse.swt.widgets.Sash; //导入方法依赖的package包/类
public static Sash createVerticalSash(Composite parent,
int leftMinSize,
int rightMinSize,
int loc,
Composite left,
FormData leftData,
Composite right,
FormData rightData)
{
parent.setLayout(new FormLayout());
FormData sashData = new FormData();
final Sash sash = new Sash(parent, SWT.VERTICAL | SWT.SMOOTH);
SashAdjustment listener =
new SashAdjustment(parent, leftMinSize, rightMinSize, sash, sashData, -1);
// If the sash is "dragged" update the layout to demonstrate the change.
sash.addListener(SWT.Selection, listener);
// Add a listener on the shell to listen for resize events.
// Need to update the sash so that it maintains the min size
// property
parent.addControlListener(listener);
// For now, the initial sash percentage is unset:
int sashPercentage = -1;
// Use the static SashPrecentage if it is set.
if (loc == SWT.RIGHT) {
if (sashPercentage == -1) {
sashData.left = new FormAttachment(100, -rightMinSize);
}
else {
sashData.left = new FormAttachment(sashPercentage, 0);
}
}
else {
if (sashPercentage == -1) {
sashData.left = new FormAttachment(0, leftMinSize);
}
else {
sashData.left = new FormAttachment(100 - sashPercentage, 0);
}
}
sashData.top = new FormAttachment(0, 0);
sashData.bottom = new FormAttachment(100, 0);
sash.setLayoutData(sashData);
leftData.right = new FormAttachment(sash, 0, SWT.LEFT);
left.setLayoutData(leftData);
rightData.left = new FormAttachment(sash, 0, SWT.RIGHT);
right.setLayoutData(rightData);
return sash;
}