Search in sources :

Example 46 with RowLayout

use of org.eclipse.swt.layout.RowLayout in project eclipse.platform.swt by eclipse.

the class Bug530969_ControlPrint method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display, SWT.NO_TRIM);
    Color gray = new Color(display, 222, 223, 224);
    Composite composite = new Composite(shell, SWT.NONE);
    RowLayout layout = new RowLayout();
    layout.marginTop = 0;
    layout.marginLeft = 0;
    layout.marginBottom = 0;
    layout.marginRight = 0;
    layout.spacing = 0;
    composite.setLayout(layout);
    createButton(composite, gray, true, true);
    createButton(composite, gray, false, true);
    createButton(composite, gray, true, false);
    createButton(composite, gray, false, false);
    Point cSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    composite.setSize(cSize);
    shell.setBackground(gray);
    shell.setLocation(0, 0);
    shell.setSize(cSize);
    shell.open();
    Image canvas = new Image(display, cSize.x, cSize.y);
    GC gc = new GC(canvas);
    composite.print(gc);
    int buttonX = cSize.x / 4;
    Image[] images = new Image[4];
    for (int i = 0; i < 4; i++) {
        Image image = new Image(display, buttonX, cSize.y);
        gc.copyArea(image, buttonX * i, 0);
        images[i] = image;
    }
    shell.close();
    Shell properShell = new Shell(display);
    properShell.setLayout(new FillLayout());
    Image firstImage = images[0];
    final Tree tree = new Tree(properShell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    TreeItem lastItem = new TreeItem(tree, SWT.NONE);
    lastItem.setImage(firstImage);
    lastItem.setText("root item with first image");
    for (int i = 0; i < 3; i++) {
        TreeItem newItem = new TreeItem(lastItem, SWT.NONE);
        newItem.setText("descendant item with image " + i);
        newItem.setImage(images[i + 1]);
    }
    lastItem.setExpanded(true);
    properShell.setSize(400, 400);
    properShell.open();
    while (!properShell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
    canvas.dispose();
    gc.dispose();
    firstImage.dispose();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) RowLayout(org.eclipse.swt.layout.RowLayout) Tree(org.eclipse.swt.widgets.Tree) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 47 with RowLayout

use of org.eclipse.swt.layout.RowLayout in project eclipse.platform.swt by eclipse.

the class MJ_Table method virtual_addManyItems_Snippet144.

/**
 * Snippet 144 modified to auto-populate items when shell is activated instead.
 */
@Test
public void virtual_addManyItems_Snippet144() {
    final Shell shell = mkShell("Shell Should show and items should be populated in lazy way");
    shell.setSize(SWIDTH, SHEIGHT);
    final int COUNT = 100000;
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
    final Label label1 = new Label(shell, SWT.NONE);
    table.addListener(SWT.SetData, event -> {
        TableItem item = (TableItem) event.item;
        int index = table.indexOf(item);
        item.setText("Item  " + index);
        label1.setText("Added " + item.getText());
    });
    table.setLayoutData(new RowData(shell.getBounds().width - 100, 400));
    final Label label2 = new Label(shell, SWT.NONE);
    shell.addShellListener(new ShellAdapter() {

        @Override
        public void shellActivated(ShellEvent e) {
            System.out.println("activated");
            long t1 = System.currentTimeMillis();
            table.setItemCount(COUNT);
            long t2 = System.currentTimeMillis();
            label2.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms)");
            shell.layout();
        }
    });
    shell.open();
    mainLoop(shell);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) RowData(org.eclipse.swt.layout.RowData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Table(org.eclipse.swt.widgets.Table) RowLayout(org.eclipse.swt.layout.RowLayout) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 48 with RowLayout

use of org.eclipse.swt.layout.RowLayout in project eclipse.platform.swt by eclipse.

the class Bug186038_DNDActivateEvent method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    // create the drop down widget.shell
    final Shell dropDownShell = new Shell(shell, SWT.ON_TOP | SWT.DROP_DOWN);
    dropDownShell.setLayout(new RowLayout());
    dropDownShell.setVisible(false);
    dropDownShell.addListener(SWT.Activate, event -> System.out.println("dropDownShell gets Activate event!"));
    dropDownShell.addListener(SWT.Deactivate, event -> {
        System.out.println("dropDownShell entering Deactivate event handler and will hide the dropdown widget.shell");
        hideDropDown(dropDownShell);
    });
    dropDownShell.addListener(SWT.Close, event -> hideDropDown(dropDownShell));
    // create the button1 and when it is hovered, display the dropdown
    final Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Drop target");
    button1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!dropDownShell.isVisible()) {
                showDropDown(button1, dropDownShell);
            }
        }
    });
    int operations = DND.DROP_COPY | DND.DROP_DEFAULT;
    DropTarget target = new DropTarget(button1, operations);
    // Provide data in Text format
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    target.setTransfer(types);
    target.addDropListener(new DropTargetListener() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                if ((event.operations & DND.DROP_COPY) != 0) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
            }
            for (int i = 0; i < event.dataTypes.length; i++) {
                if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
                    event.currentDataType = event.dataTypes[i];
                    if (event.detail != DND.DROP_COPY) {
                        event.detail = DND.DROP_NONE;
                    }
                    break;
                }
            }
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT;
            if (!dropDownShell.isVisible()) {
                showDropDown(button1, dropDownShell);
            }
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                String text = (String) event.data;
                System.out.println(text);
            }
        }
    });
    // create the button2 as the drag source
    final Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Drag source");
    operations = DND.DROP_COPY;
    DragSource source = new DragSource(button2, operations);
    // Provide data in Text format
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        @Override
        public void dragStart(DragSourceEvent event) {
            if (button2.getText().length() == 0) {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            // Provide the data of the requested type.
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = button2.getText();
            }
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
        }
    });
    shell.setSize(300, 300);
    shell.addDisposeListener(e -> {
        if (dropDownShell != null && !dropDownShell.isDisposed()) {
            dropDownShell.dispose();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Point(org.eclipse.swt.graphics.Point) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Example 49 with RowLayout

use of org.eclipse.swt.layout.RowLayout in project yamcs-studio by yamcs.

the class AddManualEventDialog method createDialogArea.

// private void validate() {
// String errorMessage = null;
// Calendar start = RCPUtils.toCalendar(startDate, startTime);
// Calendar stop = RCPUtils.toCalendar(stopDate, stopTime);
// if (start.after(stop))
// errorMessage = "Stop has to be greater than start";
// 
// setErrorMessage(errorMessage);
// getButton(IDialogConstants.OK_ID).setEnabled(errorMessage == null);
// }
@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 20;
    layout.marginWidth = 20;
    layout.verticalSpacing = 5;
    container.setLayout(layout);
    Label lbl = new Label(container, SWT.NONE);
    lbl.setText("Generation Time:");
    Composite startComposite = new Composite(container, SWT.NONE);
    RowLayout rl = new RowLayout();
    rl.marginLeft = 0;
    rl.marginTop = 0;
    rl.marginBottom = 0;
    rl.center = true;
    startComposite.setLayout(rl);
    generationDatePicker = new DateTime(startComposite, SWT.DATE | SWT.LONG | SWT.DROP_DOWN | SWT.BORDER);
    // generationDatePicker.addListener(SWT.Selection, e -> validate());
    // generationDatePicker.addListener(SWT.FocusOut, e -> validate());
    generationTimePicker = new DateTime(startComposite, SWT.TIME | SWT.LONG | SWT.BORDER);
    // generationTimePicker.addListener(SWT.FocusOut, e -> validate());
    if (generationTimeValue != null) {
        generationDatePicker.setDate(generationTimeValue.get(Calendar.YEAR), generationTimeValue.get(Calendar.MONTH), generationTimeValue.get(Calendar.DAY_OF_MONTH));
        generationTimePicker.setTime(generationTimeValue.get(Calendar.HOUR_OF_DAY), generationTimeValue.get(Calendar.MINUTE), generationTimeValue.get(Calendar.SECOND));
    }
    lbl = new Label(container, SWT.NONE);
    lbl.setText("Source:");
    lbl = new Label(container, SWT.NONE);
    lbl.setText("Manual");
    lbl = new Label(container, SWT.NONE);
    lbl.setText("User:");
    if (YamcsAuthorizations.getInstance().isAuthorizationEnabled()) {
        userLbl = new Label(container, SWT.NONE);
        userLbl.setText(YamcsAuthorizations.getInstance().getUsername());
    } else {
        userText = new Text(container, SWT.SINGLE);
        userText.setLayoutData(new GridData(GridData.FILL_BOTH));
        userText.setText("");
    }
    lbl = new Label(container, SWT.NONE);
    lbl.setText("Message:");
    messageText = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.verticalAlignment = SWT.CENTER;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    messageText.setLayoutData(data);
    GC gc = new GC(messageText);
    try {
        gc.setFont(messageText.getFont());
        FontMetrics fm = gc.getFontMetrics();
        /* Set the height to 5 rows of characters */
        data.heightHint = 5 * fm.getHeight();
    } finally {
        gc.dispose();
    }
    messageText.setText("");
    lbl = new Label(container, SWT.NONE);
    lbl.setText("Severity:");
    severityCombo = new Combo(container, SWT.DROP_DOWN);
    severityCombo.add(EventSeverity.INFO.name(), EventSeverity.INFO_VALUE);
    severityCombo.add(EventSeverity.WARNING.name(), EventSeverity.WARNING_VALUE);
    severityCombo.add(EventSeverity.ERROR.name(), EventSeverity.ERROR_VALUE);
    severityCombo.add(EventSeverity.WATCH.name(), EventSeverity.WATCH_VALUE);
    // TODO use index,
    severityCombo.add(EventSeverity.DISTRESS.name(), EventSeverity.DISTRESS_VALUE - 1);
    // the value skips 4
    severityCombo.add(EventSeverity.CRITICAL.name(), EventSeverity.CRITICAL_VALUE - 1);
    severityCombo.add(EventSeverity.SEVERE.name(), EventSeverity.SEVERE_VALUE - 1);
    severityCombo.select(EventSeverity.INFO_VALUE);
    return container;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) FontMetrics(org.eclipse.swt.graphics.FontMetrics) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) GC(org.eclipse.swt.graphics.GC) DateTime(org.eclipse.swt.widgets.DateTime)

Example 50 with RowLayout

use of org.eclipse.swt.layout.RowLayout in project yamcs-studio by yamcs.

the class CommandFateDialog method open.

public int open(int type, String message) {
    Shell parent = getParent();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    shell.setLayout(new GridLayout(1, false));
    // title
    if (type == 1)
        shell.setText("Command older than " + CommandQueueView.oldCommandWarningTime + " seconds");
    else
        shell.setText("Command(s) older than " + CommandQueueView.oldCommandWarningTime + " seconds");
    // shell.pack();
    // message
    messageLabel = new Label(shell, SWT.NONE);
    messageLabel.setText(message);
    // radio buttons
    if (type == 1) {
        radios = new Button[3];
        radios[0] = new Button(shell, SWT.RADIO);
        radios[0].setSelection(true);
        radios[0].setText("Send the command with updated generation time");
        radios[1] = new Button(shell, SWT.RADIO);
        radios[1].setText("Send the command with the current (old) generation time");
        radios[2] = new Button(shell, SWT.RADIO);
        radios[2].setText("Reject the command");
    } else {
        radios = new Button[2];
        radios[0] = new Button(shell, SWT.RADIO);
        radios[0].setSelection(true);
        radios[0].setText("Send all the commands with updated generation time");
        radios[1] = new Button(shell, SWT.RADIO);
        radios[1].setText("Send all the commands with the current (old) generation time");
    }
    // add buttons OK Cancel
    Composite buttonCompo = new Composite(shell, SWT.NONE);
    buttonCompo.setLayout(new RowLayout());
    Button ok = new Button(buttonCompo, SWT.PUSH);
    ok.setText("Ok");
    Button cancel = new Button(buttonCompo, SWT.PUSH);
    cancel.setText("Cancel");
    shell.setDefaultButton(ok);
    // Add events to buttons
    ok.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            widgetSelected(arg0);
        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            result = -1;
            for (int i = 0; i < radios.length; i++) {
                if (radios[i].getSelection()) {
                    result = i;
                    break;
                }
            }
            shell.dispose();
        }
    });
    cancel.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            widgetSelected(arg0);
        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            result = -1;
            shell.dispose();
        }
    });
    shell.open();
    shell.pack();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return result;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Aggregations

RowLayout (org.eclipse.swt.layout.RowLayout)86 Composite (org.eclipse.swt.widgets.Composite)73 GridData (org.eclipse.swt.layout.GridData)55 Button (org.eclipse.swt.widgets.Button)54 GridLayout (org.eclipse.swt.layout.GridLayout)52 Label (org.eclipse.swt.widgets.Label)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)34 Group (org.eclipse.swt.widgets.Group)27 Text (org.eclipse.swt.widgets.Text)23 Combo (org.eclipse.swt.widgets.Combo)19 Shell (org.eclipse.swt.widgets.Shell)17 Display (org.eclipse.swt.widgets.Display)16 Point (org.eclipse.swt.graphics.Point)12 ArrayList (java.util.ArrayList)10 StyledText (org.eclipse.swt.custom.StyledText)10 Table (org.eclipse.swt.widgets.Table)10 List (java.util.List)9 SelectionListener (org.eclipse.swt.events.SelectionListener)9 FillLayout (org.eclipse.swt.layout.FillLayout)9