use of org.eclipse.swt.widgets.Layout in project BiglyBT by BiglySoftware.
the class PeersViewBase method initComposite.
@Override
public Composite initComposite(Composite composite) {
if (swarm_view_enable) {
Composite parent = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 0;
parent.setLayout(layout);
Layout compositeLayout = composite.getLayout();
if (compositeLayout instanceof GridLayout) {
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
} else if (compositeLayout instanceof FormLayout) {
parent.setLayoutData(Utils.getFilledFormData());
}
final CTabFolder tab_folder = new CTabFolder(parent, SWT.NONE);
tab_folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final CTabItem tab1 = new CTabItem(tab_folder, SWT.NONE);
Messages.setLanguageText(tab1, "label.table");
Composite tableParent = new Composite(tab_folder, SWT.NONE);
tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = gridLayout.marginWidth = 0;
tableParent.setLayout(gridLayout);
tab1.setControl(tableParent);
final CTabItem tab2 = new CTabItem(tab_folder, SWT.NONE);
Messages.setLanguageText(tab2, "label.swarms");
final Composite swarmParent = new Composite(tab_folder, SWT.NONE);
swarmParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
gridLayout = new GridLayout();
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = gridLayout.marginWidth = 0;
swarmParent.setLayout(gridLayout);
tab2.setControl(swarmParent);
tab_folder.setSelection(tab1);
tab_folder.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (tab_folder.getSelection() == tab2) {
Utils.disposeComposite(swarmParent, false);
createSwarmsView(swarmParent);
} else {
if (swarm_view != null) {
swarm_view.delete();
}
Utils.disposeComposite(swarmParent, false);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
});
return tableParent;
} else {
return (super.initComposite(composite));
}
}
use of org.eclipse.swt.widgets.Layout in project n4js by eclipse.
the class SuffixText method configureListeners.
/**
* Configures the listeners of the suffix text control.
*/
private void configureListeners() {
// Redirect focus to internal editable text widget
MouseListener focusCatcher = new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
mousePressed = false;
}
@Override
public void mouseDown(MouseEvent e) {
editableText.forceFocus();
editableText.setSelection(editableText.getText().length());
mousePressed = true;
}
@Override
public void mouseDoubleClick(MouseEvent e) {
editableText.setSelection(0, editableText.getText().length());
}
};
this.addMouseListener(focusCatcher);
suffixText.addMouseListener(focusCatcher);
this.addMouseListener(focusCatcher);
// Workaround theme dependent background color issues:
// Reset the background color for every paint event
addPaintListener(paintEvent -> setBackground(editableText.getBackground()));
// Copy over the text from the internal editable text whenever it changes
editableText.addModifyListener(modifyEvent -> {
layout();
setText(editableText.getText());
});
// Relayout when the suffix text changes
this.addPropertyChangeListener(propertyChange -> {
if (propertyChange.getPropertyName() == SUFFIX_PROPERTY) {
layout(true);
}
});
// Connect the internal suffix visibility state to the SWT label visibility
this.addPropertyChangeListener(propertyChange -> {
if (propertyChange.getPropertyName() == SUFFIX_VISIBILITY_PROPERTY) {
suffixText.setVisible(suffixVisible);
}
});
// Bind content proposal decoration to editable text focus state
this.editableText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
setDecorationVisibility(false);
}
@Override
public void focusGained(FocusEvent e) {
setDecorationVisibility(true);
}
});
// Make the graphic context use the font settings of the input
gc.setFont(editableText.getFont());
// Tracks dragging mouse movement in this widget and applies it to the text field userInput to
// fake proper text selection behavior
MouseMoveListener mouseMoveSelectionListener = mouseMoveEvent -> {
if (mousePressed) {
int userInputRightEdgeOffset = editableText.getBounds().x + editableText.getBounds().width;
if (mouseMoveEvent.x < userInputRightEdgeOffset) {
String inputString = editableText.getText();
int selectedPixels = (userInputRightEdgeOffset - mouseMoveEvent.x);
int i = 1;
// adapt the text selection.
while (inputString.length() - i >= 0 && gc.textExtent(editableText.getText().substring(inputString.length() - i, inputString.length() - 1)).x < selectedPixels) {
i++;
}
int startIndex = Ints.max(0, inputString.length() - i + 1);
editableText.setSelection(startIndex, inputString.length());
}
}
};
this.addMouseMoveListener(mouseMoveSelectionListener);
}
use of org.eclipse.swt.widgets.Layout in project liferay-ide by liferay.
the class FormEntry method _fillIntoGrid.
private void _fillIntoGrid(Composite parent, int indent, int tcolspan) {
Layout layout = parent.getLayout();
int tspan;
if (layout instanceof GridLayout) {
int span = ((GridLayout) layout).numColumns;
if (tcolspan > 0) {
tspan = tcolspan;
} else {
tspan = _fBrowse != null ? span - 2 : span - 1;
}
GridData gd;
if (_fLabel != null) {
gd = new GridData(GridData.VERTICAL_ALIGN_CENTER);
gd.horizontalIndent = indent;
_fLabel.setLayoutData(gd);
}
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = tspan;
if (_fLabel != null) {
gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
}
gd.grabExcessHorizontalSpace = tspan == 1;
gd.widthHint = 10;
_fText.setLayoutData(gd);
if (_fBrowse != null) {
gd = new GridData(GridData.VERTICAL_ALIGN_CENTER);
_fBrowse.setLayoutData(gd);
}
} else if (layout instanceof TableWrapLayout) {
int span = ((TableWrapLayout) layout).numColumns;
if (tcolspan > 0) {
tspan = tcolspan;
} else {
tspan = _fBrowse != null ? span - 2 : span - 1;
}
TableWrapData td;
if (_fLabel != null) {
td = new TableWrapData();
td.valign = TableWrapData.MIDDLE;
td.indent = indent;
_fLabel.setLayoutData(td);
}
td = new TableWrapData(TableWrapData.FILL);
td.colspan = tspan;
if (_fLabel != null) {
td.indent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
}
td.grabHorizontal = tspan == 1;
td.valign = TableWrapData.MIDDLE;
_fText.setLayoutData(td);
if (_fBrowse != null) {
td = new TableWrapData(TableWrapData.FILL);
td.valign = TableWrapData.MIDDLE;
_fBrowse.setLayoutData(td);
}
}
}
Aggregations