Search in sources :

Example 16 with Layout

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));
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Layout(org.eclipse.swt.widgets.Layout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CTabItem(org.eclipse.swt.custom.CTabItem) SelectionListener(org.eclipse.swt.events.SelectionListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener)

Example 17 with Layout

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);
}
Also used : Text(org.eclipse.swt.widgets.Text) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Layout(org.eclipse.swt.widgets.Layout) StyledText(org.eclipse.swt.custom.StyledText) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) FocusEvent(org.eclipse.swt.events.FocusEvent) Display(org.eclipse.swt.widgets.Display) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Ints(com.google.common.primitives.Ints) FocusListener(org.eclipse.swt.events.FocusListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) PropertyChangeListener(java.beans.PropertyChangeListener) Color(org.eclipse.swt.graphics.Color) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) PropertyChangeSupport(java.beans.PropertyChangeSupport) Platform(org.eclipse.core.runtime.Platform) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 18 with Layout

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);
        }
    }
}
Also used : TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) GridLayout(org.eclipse.swt.layout.GridLayout) Layout(org.eclipse.swt.widgets.Layout) TableWrapLayout(org.eclipse.ui.forms.widgets.TableWrapLayout) GridLayout(org.eclipse.swt.layout.GridLayout) TableWrapLayout(org.eclipse.ui.forms.widgets.TableWrapLayout) GridData(org.eclipse.swt.layout.GridData)

Aggregations

Layout (org.eclipse.swt.widgets.Layout)18 GridLayout (org.eclipse.swt.layout.GridLayout)10 Composite (org.eclipse.swt.widgets.Composite)10 GridData (org.eclipse.swt.layout.GridData)8 Point (org.eclipse.swt.graphics.Point)7 FillLayout (org.eclipse.swt.layout.FillLayout)4 Control (org.eclipse.swt.widgets.Control)4 CTabFolder (org.eclipse.swt.custom.CTabFolder)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 FormLayout (org.eclipse.swt.layout.FormLayout)3 Button (org.eclipse.swt.widgets.Button)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 ArrayList (java.util.ArrayList)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 StyledText (org.eclipse.swt.custom.StyledText)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Color (org.eclipse.swt.graphics.Color)2 Display (org.eclipse.swt.widgets.Display)2