use of org.eclipse.swt.layout.FormLayout in project eclipse.platform.swt by eclipse.
the class GraphicsExample method createControls.
void createControls(final Composite parent) {
tabs = createTabs();
createToolBar(parent);
createTabList(parent);
hSash = new Sash(parent, SWT.HORIZONTAL);
createTabDesc(parent);
vSash = new Sash(parent, SWT.VERTICAL);
createCanvas(parent);
createControlPanel(parent);
FormData data;
FormLayout layout = new FormLayout();
parent.setLayout(layout);
data = new FormData();
data.left = new FormAttachment(0, MARGIN);
data.top = new FormAttachment(0, MARGIN);
data.right = new FormAttachment(100, -MARGIN);
toolBar.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, MARGIN);
data.top = new FormAttachment(toolBar, MARGIN);
data.right = new FormAttachment(vSash, -SASH_SPACING);
data.bottom = new FormAttachment(hSash, -SASH_SPACING);
tabList.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, MARGIN);
int offset = parent.getBounds().height - tabDesc.computeSize(SWT.DEFAULT, tabDesc.getLineHeight() * 10).y;
data.top = new FormAttachment(null, offset);
data.right = new FormAttachment(vSash, -SASH_SPACING);
hSash.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, MARGIN);
data.top = new FormAttachment(hSash, SASH_SPACING);
data.right = new FormAttachment(vSash, -SASH_SPACING);
data.bottom = new FormAttachment(100, -MARGIN);
tabDesc.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(null, tabList.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + 50);
data.top = new FormAttachment(toolBar, MARGIN);
data.bottom = new FormAttachment(100, -MARGIN);
vSash.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(vSash, SASH_SPACING);
data.top = new FormAttachment(toolBar, MARGIN);
data.right = new FormAttachment(100, -MARGIN);
data.bottom = new FormAttachment(tabControlPanel);
canvas.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(vSash, SASH_SPACING);
data.right = new FormAttachment(100, -MARGIN);
data.bottom = new FormAttachment(100, -MARGIN);
tabControlPanel.setLayoutData(data);
vSash.addListener(SWT.Selection, event -> {
Rectangle rect = hSash.getParent().getClientArea();
event.x = Math.min(Math.max(event.x, 60), rect.width - 60);
if (event.detail != SWT.DRAG) {
FormData data1 = (FormData) vSash.getLayoutData();
data1.left.offset = event.x;
vSash.requestLayout();
animate = true;
} else {
animate = false;
}
});
hSash.addListener(SWT.Selection, event -> {
Rectangle rect = vSash.getParent().getClientArea();
event.y = Math.min(Math.max(event.y, tabList.getLocation().y + 60), rect.height - 60);
if (event.detail != SWT.DRAG) {
FormData data1 = (FormData) hSash.getLayoutData();
data1.top.offset = event.y;
hSash.requestLayout();
}
});
}
use of org.eclipse.swt.layout.FormLayout in project eclipse.platform.swt by eclipse.
the class BrowserExample method show.
void show(boolean owned, Point location, Point size, boolean addressBar, boolean menuBar, boolean statusBar, boolean toolBar) {
final Shell shell = browser.getShell();
if (owned) {
if (location != null)
shell.setLocation(location);
if (size != null)
shell.setSize(shell.computeSize(size.x, size.y));
}
FormData data = null;
if (toolBar) {
toolbar = new ToolBar(parent, SWT.NONE);
data = new FormData();
data.top = new FormAttachment(0, 5);
toolbar.setLayoutData(data);
itemBack = new ToolItem(toolbar, SWT.PUSH);
itemBack.setText(getResourceString("Back"));
itemForward = new ToolItem(toolbar, SWT.PUSH);
itemForward.setText(getResourceString("Forward"));
final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
itemStop.setText(getResourceString("Stop"));
final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
itemRefresh.setText(getResourceString("Refresh"));
final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
itemGo.setText(getResourceString("Go"));
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
Listener listener = event -> {
ToolItem item = (ToolItem) event.widget;
if (item == itemBack)
browser.back();
else if (item == itemForward)
browser.forward();
else if (item == itemStop)
browser.stop();
else if (item == itemRefresh)
browser.refresh();
else if (item == itemGo)
browser.setUrl(locationBar.getText());
};
itemBack.addListener(SWT.Selection, listener);
itemForward.addListener(SWT.Selection, listener);
itemStop.addListener(SWT.Selection, listener);
itemRefresh.addListener(SWT.Selection, listener);
itemGo.addListener(SWT.Selection, listener);
canvas = new Canvas(parent, SWT.NO_BACKGROUND);
data = new FormData();
data.width = 24;
data.height = 24;
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(100, -5);
canvas.setLayoutData(data);
final Rectangle rect = images[0].getBounds();
canvas.addListener(SWT.Paint, e -> {
Point pt = ((Canvas) e.widget).getSize();
e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
});
canvas.addListener(SWT.MouseDown, e -> browser.setUrl(getResourceString("Startup")));
final Display display = parent.getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
if (canvas.isDisposed())
return;
if (busy) {
index++;
if (index == images.length)
index = 0;
canvas.redraw();
}
display.timerExec(150, this);
}
});
}
if (addressBar) {
locationBar = new Text(parent, SWT.BORDER);
data = new FormData();
if (toolbar != null) {
data.top = new FormAttachment(toolbar, 0, SWT.TOP);
data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
} else {
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
}
locationBar.setLayoutData(data);
locationBar.addListener(SWT.DefaultSelection, e -> browser.setUrl(locationBar.getText()));
}
if (statusBar) {
status = new Label(parent, SWT.NONE);
progressBar = new ProgressBar(parent, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 5);
data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
data.bottom = new FormAttachment(100, -5);
status.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -5);
data.bottom = new FormAttachment(100, -5);
progressBar.setLayoutData(data);
browser.addStatusTextListener(event -> status.setText(event.text));
}
parent.setLayout(new FormLayout());
Control aboveBrowser = toolBar ? (Control) canvas : (addressBar ? (Control) locationBar : null);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.top = aboveBrowser != null ? new FormAttachment(aboveBrowser, 5, SWT.DEFAULT) : new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = status != null ? new FormAttachment(status, -5, SWT.DEFAULT) : new FormAttachment(100, 0);
browser.setLayoutData(data);
if (statusBar || toolBar) {
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
if (event.total == 0)
return;
int ratio = event.current * 100 / event.total;
if (progressBar != null)
progressBar.setSelection(ratio);
busy = event.current != event.total;
if (!busy) {
index = 0;
if (canvas != null)
canvas.redraw();
}
}
@Override
public void completed(ProgressEvent event) {
if (progressBar != null)
progressBar.setSelection(0);
busy = false;
index = 0;
if (canvas != null) {
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
canvas.redraw();
}
}
});
}
if (addressBar || statusBar || toolBar) {
browser.addLocationListener(LocationListener.changedAdapter(event -> {
busy = true;
if (event.top && locationBar != null)
locationBar.setText(event.location);
}));
}
if (title) {
browser.addTitleListener(event -> shell.setText(event.title + " - " + getResourceString("window.title")));
}
parent.layout(true);
if (owned)
shell.open();
}
use of org.eclipse.swt.layout.FormLayout in project cogtool by cogtool.
the class DefaultSEUIModel method setDevicesFooter.
public void setDevicesFooter(Composite footer) {
devicesFooter = footer;
FormLayout footerLayout = new FormLayout();
footerLayout.marginHeight = 0;
footerLayout.spacing = DEVICE_MARGIN;
devicesFooter.setLayout(footerLayout);
}
use of org.eclipse.swt.layout.FormLayout in project cogtool by cogtool.
the class SashUtility method createVerticalSash.
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;
}
use of org.eclipse.swt.layout.FormLayout in project cogtool by cogtool.
the class ActionSet method createMouseComposite.
protected Composite createMouseComposite() {
Composite mouseComp = new Composite(actionSettings, SWT.NONE);
mouseComp.setLayout(new FormLayout());
mouseButtonLabel = new DisplayLabel(mouseComp, SWT.NONE);
mouseButtonLabel.setText(L10N.get("DE.MouseButtonCaption", "Mouse Button") + ":");
// TODO Why is this here rather than in its natural home in the
// overridden method in ActionPropertySet?
transitionSourceLabelMouse = createTransitionSourceLabel(mouseComp);
transitionSourceNameMouse = createTransitionSourceName(mouseComp);
transitionDestinationLabelMouse = createTransitionDestinationLabel(mouseComp);
transitionDestinationNameMouse = createTransitionDestinationName(mouseComp);
mouseButtonCombo = new ComboWithEnableFix(mouseComp, SWT.DROP_DOWN | SWT.READ_ONLY);
for (MouseButtonState element : MouseButtonState.DISPLAY) {
mouseButtonCombo.add(element.toString());
}
mouseButtonCombo.select(0);
mouseButtonCombo.addSelectionListener(widgetActionChange);
mouseActionLabel = new DisplayLabel(mouseComp, SWT.NONE);
mouseActionLabel.setText(L10N.get("DE.ButtonActionCaption", "Action") + ":");
mouseActionCombo = new ComboWithEnableFix(mouseComp, SWT.DROP_DOWN | SWT.READ_ONLY);
for (MousePressType element : MousePressType.DISPLAY) {
mouseActionCombo.add(element.toString());
}
mouseActionCombo.select(0);
mouseActionCombo.addSelectionListener(widgetActionChange);
// then add modifier set for the mouse clicks.
if (DeviceType.Keyboard.isMember(deviceTypes)) {
buttonModifierSet = new ActionModifierSet(mouseActionCombo, widgetActionChange, vertical);
}
return mouseComp;
}
Aggregations