Example usage for org.eclipse.swt.widgets Composite setLayout

List of usage examples for org.eclipse.swt.widgets Composite setLayout

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Composite setLayout.

Prototype

public void setLayout(Layout layout) 

Source Link

Document

Sets the layout which is associated with the receiver to be the argument which may be null.

Usage

From source file:DNDExample.java

public void open(Display display) {
    Shell shell = new Shell(display);
    shell.setText("Drag and Drop Example");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);/*  w  ww  . ja  va2  s .co m*/
    parent.setLayout(new FormLayout());

    Label dragLabel = new Label(parent, SWT.LEFT);
    dragLabel.setText("Drag Source:");

    Group dragWidgetGroup = new Group(parent, SWT.NONE);
    dragWidgetGroup.setText("Widget");
    createDragWidget(dragWidgetGroup);

    Composite cLeft = new Composite(parent, SWT.NONE);
    cLeft.setLayout(new GridLayout(2, false));

    Group dragOperationsGroup = new Group(cLeft, SWT.NONE);
    dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    dragOperationsGroup.setText("Allowed Operation(s):");
    createDragOperations(dragOperationsGroup);

    Group dragTypesGroup = new Group(cLeft, SWT.NONE);
    dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    dragTypesGroup.setText("Transfer Type(s):");
    createDragTypes(dragTypesGroup);

    dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dragConsole.setText("");
        }
    });
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MenuItem item = (MenuItem) e.widget;
            dragEventDetail = item.getSelection();
        }
    });
    dragConsole.setMenu(menu);

    Label dropLabel = new Label(parent, SWT.LEFT);
    dropLabel.setText("Drop Target:");

    Group dropWidgetGroup = new Group(parent, SWT.NONE);
    dropWidgetGroup.setText("Widget");
    createDropWidget(dropWidgetGroup);

    Composite cRight = new Composite(parent, SWT.NONE);
    cRight.setLayout(new GridLayout(2, false));

    Group dropOperationsGroup = new Group(cRight, SWT.NONE);
    dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2));
    dropOperationsGroup.setText("Allowed Operation(s):");
    createDropOperations(dropOperationsGroup);

    Group dropTypesGroup = new Group(cRight, SWT.NONE);
    dropTypesGroup.setText("Transfer Type(s):");
    createDropTypes(dropTypesGroup);

    Group feedbackTypesGroup = new Group(cRight, SWT.NONE);
    feedbackTypesGroup.setText("Feedback Type(s):");
    createFeedbackTypes(feedbackTypesGroup);

    dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    menu = new Menu(shell, SWT.POP_UP);
    item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dropConsole.setText("");
        }
    });
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MenuItem item = (MenuItem) e.widget;
            dropEventDetail = item.getSelection();
        }
    });
    dropConsole.setMenu(menu);

    int height = 200;
    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(0, 10);
    dragLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragLabel, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.height = height;
    dragWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragWidgetGroup, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.bottom = new FormAttachment(100, -10);
    cLeft.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(cLeft, 10);
    dropLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropLabel, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.height = height;
    dropWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropWidgetGroup, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.bottom = new FormAttachment(100, -10);
    cRight.setLayoutData(data);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

public void open(Display display) {
    Shell shell = new Shell(display);
    shell.setText("Drag and Drop Example");
    shell.setLayout(new FillLayout());

    itemImage = new Image(display, DNDExample.class.getResourceAsStream("openFolder.gif"));

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);/*from   w  w w  .j  a  va 2 s.  c  o  m*/
    parent.setLayout(new FormLayout());

    Label dragLabel = new Label(parent, SWT.LEFT);
    dragLabel.setText("Drag Source:");

    Group dragWidgetGroup = new Group(parent, SWT.NONE);
    dragWidgetGroup.setText("Widget");
    createDragWidget(dragWidgetGroup);

    Composite cLeft = new Composite(parent, SWT.NONE);
    cLeft.setLayout(new GridLayout(2, false));

    Group dragOperationsGroup = new Group(cLeft, SWT.NONE);
    dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    dragOperationsGroup.setText("Allowed Operation(s):");
    createDragOperations(dragOperationsGroup);

    Group dragTypesGroup = new Group(cLeft, SWT.NONE);
    dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    dragTypesGroup.setText("Transfer Type(s):");
    createDragTypes(dragTypesGroup);

    dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dragConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dragEventDetail = eItem.getSelection();
    }));
    dragConsole.setMenu(menu);

    Label dropLabel = new Label(parent, SWT.LEFT);
    dropLabel.setText("Drop Target:");

    Group dropWidgetGroup = new Group(parent, SWT.NONE);
    dropWidgetGroup.setText("Widget");
    createDropWidget(dropWidgetGroup);

    Composite cRight = new Composite(parent, SWT.NONE);
    cRight.setLayout(new GridLayout(2, false));

    Group dropOperationsGroup = new Group(cRight, SWT.NONE);
    dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2));
    dropOperationsGroup.setText("Allowed Operation(s):");
    createDropOperations(dropOperationsGroup);

    Group dropTypesGroup = new Group(cRight, SWT.NONE);
    dropTypesGroup.setText("Transfer Type(s):");
    createDropTypes(dropTypesGroup);

    Group feedbackTypesGroup = new Group(cRight, SWT.NONE);
    feedbackTypesGroup.setText("Feedback Type(s):");
    createFeedbackTypes(feedbackTypesGroup);

    dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    menu = new Menu(shell, SWT.POP_UP);
    item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dropConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dropEventDetail = eItem.getSelection();
    }));
    dropConsole.setMenu(menu);

    if (dragEnabled)
        createDragSource();
    if (dropEnabled)
        createDropTarget();

    int height = 200;
    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(0, 10);
    dragLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragLabel, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.height = height;
    dragWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragWidgetGroup, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.bottom = new FormAttachment(100, -10);
    cLeft.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(cLeft, 10);
    dropLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropLabel, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.height = height;
    dropWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropWidgetGroup, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.bottom = new FormAttachment(100, -10);
    cRight.setLayoutData(data);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    itemImage.dispose();
}

From source file:CalculatorMichaelSchmidt.java

@Override
protected Control createDialogArea(final Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    final GridLayout calculatorGridLayout = new GridLayout();
    calculatorGridLayout.marginRight = 5;
    calculatorGridLayout.marginLeft = 5;
    calculatorGridLayout.marginBottom = 5;
    calculatorGridLayout.marginTop = 5;//  w  ww  . j  ava2s.  co m
    calculatorGridLayout.marginWidth = 10;
    calculatorGridLayout.marginHeight = 2;
    calculatorGridLayout.numColumns = 4;
    calculatorGridLayout.verticalSpacing = 2;
    calculatorGridLayout.makeColumnsEqualWidth = true;
    calculatorGridLayout.horizontalSpacing = 2;
    container.setLayout(calculatorGridLayout);

    // The display.  Note that it has a limit of 30 characters, 
    // much greater than the length of a double-precision number. 
    displayText = new Text(container, SWT.RIGHT | SWT.BORDER);
    displayText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    displayText.setEditable(false);
    displayText.setDoubleClickEnabled(false);
    displayText.setTextLimit(30);
    displayText.setText(displayString);
    displayText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 4, 1));

    final Button msButton = new Button(container, SWT.NONE);
    msButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('S');
        }
    });
    msButton.setToolTipText("Save value to Memory");
    msButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    msButton.setText("MS");

    final Button mcButton = new Button(container, SWT.NONE);
    mcButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('D');
        }
    });
    mcButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    mcButton.setToolTipText("Clear Memory");
    mcButton.setText("MC");

    final Button clearButton = new Button(container, SWT.NONE);
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('C');
        }
    });
    clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    clearButton.setToolTipText("Clear all Calculator Registers");
    clearButton.setText("C");

    final Button ceButton = new Button(container, SWT.NONE);
    ceButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('E');
        }
    });
    ceButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    ceButton.setToolTipText("Clear Entry");
    ceButton.setText("CE");

    final Button memAddButton = new Button(container, SWT.NONE);
    memAddButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('+');
        }
    });
    memAddButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    memAddButton.setToolTipText("Add value to Memory");
    memAddButton.setText("M+");

    final Button mrButton = new Button(container, SWT.NONE);
    mrButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('R');
        }
    });
    mrButton.setToolTipText("Recall value in Memory");
    mrButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    mrButton.setText("MR");

    final Button backButton = new Button(container, SWT.NONE);
    backButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('B');
        }
    });
    backButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    backButton.setToolTipText("Backspace");
    backButton.setText("BACK");

    final Button divideButton = new Button(container, SWT.NONE);
    divideButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('/');
        }
    });
    divideButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    divideButton.setToolTipText("Divide");
    divideButton.setText("/");

    final Button memSubtractButton = new Button(container, SWT.NONE);
    memSubtractButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('-');
        }
    });
    memSubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    memSubtractButton.setToolTipText("Subtract value from Memory");
    memSubtractButton.setText("M-");

    final Button inverseButton = new Button(container, SWT.NONE);
    inverseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('I');
        }
    });
    inverseButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    inverseButton.setToolTipText("Inverse of value");
    inverseButton.setText("1/X");

    final Button sqrtButton = new Button(container, SWT.NONE);
    sqrtButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('Q');
        }
    });
    sqrtButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    sqrtButton.setToolTipText("Square Root of value");
    sqrtButton.setText("SQRT");

    final Button multiplyButton = new Button(container, SWT.NONE);
    multiplyButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('*');
        }
    });
    multiplyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    multiplyButton.setToolTipText("Multiply");
    multiplyButton.setText("*");

    final Button num7Button = new Button(container, SWT.NONE);
    num7Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('7');
        }
    });
    num7Button.setToolTipText("Numeric Pad");
    num7Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num7Button.setText("7");

    final Button num8Button = new Button(container, SWT.NONE);
    num8Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('8');
        }
    });
    num8Button.setToolTipText("Numeric Pad");
    num8Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num8Button.setText("8");

    final Button num9Button = new Button(container, SWT.NONE);
    num9Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('9');
        }
    });
    num9Button.setToolTipText("Numeric Pad");
    num9Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num9Button.setText("9");

    final Button SubtractButton = new Button(container, SWT.NONE);
    SubtractButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('-');
        }
    });
    SubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    SubtractButton.setToolTipText("Subtract");
    SubtractButton.setText("-");

    final Button num4Button = new Button(container, SWT.NONE);
    num4Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('4');
        }
    });
    num4Button.setToolTipText("Numeric Pad");
    num4Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num4Button.setText("4");

    final Button num5Button = new Button(container, SWT.NONE);
    num5Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('5');
        }
    });
    num5Button.setToolTipText("Numeric Pad");
    num5Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num5Button.setText("5");

    final Button num6Button = new Button(container, SWT.NONE);
    num6Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('6');
        }
    });
    num6Button.setToolTipText("Numeric Pad");
    num6Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num6Button.setText("6");

    final Button AdditionButton = new Button(container, SWT.NONE);
    AdditionButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('+');
        }
    });
    AdditionButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    AdditionButton.setToolTipText("Add");
    AdditionButton.setText("+");

    final Button num1Button = new Button(container, SWT.NONE);
    num1Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('1');
        }
    });
    num1Button.setCapture(true);
    num1Button.setToolTipText("Numeric Pad");
    num1Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num1Button.setText("1");

    final Button num2Button = new Button(container, SWT.NONE);
    num2Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('2');
        }
    });
    num2Button.setToolTipText("Numeric Pad");
    num2Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num2Button.setText("2");

    final Button num3Button = new Button(container, SWT.NONE);
    num3Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('3');
        }
    });
    num3Button.setToolTipText("Numeric Pad");
    num3Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num3Button.setText("3");

    final Button equalsButton = new Button(container, SWT.NONE);
    equalsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('=');
        }
    });
    equalsButton.setToolTipText("Equals (get result)");
    equalsButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2));
    equalsButton.setText("=");

    final Button num0Button = new Button(container, SWT.NONE);
    num0Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('0');
        }
    });
    num0Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num0Button.setToolTipText("Numeric Pad");
    num0Button.setText("0");

    final Button decimalButton = new Button(container, SWT.NONE);
    decimalButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('.');
        }
    });
    decimalButton.setToolTipText("Numeric Pad");
    decimalButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    decimalButton.setText(".");

    final Button signButton = new Button(container, SWT.NONE);
    signButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('-');
        }
    });
    signButton.setToolTipText("Change sign of value");
    signButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    signButton.setText("+/-");
    new Label(container, SWT.NONE);
    //
    return container;
}

From source file:tools.descartes.bungee.viewer.DemandView.java

@Override
public void createPartControl(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    Composite chartParent = new Composite(composite, SWT.NONE);
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    chartParent.setLayoutData(gridData);
    showIntensityButton = new Button(composite, SWT.CHECK);
    showIntensityButton.setText("Show Intensity");
    showIntensityButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                redrawChart();//from   w w  w. ja  v a  2 s.  c  om
                break;
            }
        }
    });
    doCalibrationButton = new Button(composite, SWT.CHECK);
    doCalibrationButton.setText("Do Calibration");
    doCalibrationButton.setSelection(true);
    doCalibrationButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                redrawChart();
                break;
            }
        }
    });
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
    composite.setLayout(new GridLayout());
    chartParent.setLayout(new FillLayout());
    this.parent = chartParent;
}

From source file:SWTAddressBook.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search./*from  ww w  .  j  a v  a  2s .  co m*/
 * 
 * @param parent
 *            Shell The shell that is the parent of the dialog.
 */
public SearchDialog(Shell parent) {
    shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setText("Search");
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            // don't dispose of the shell, just hide it for later use
            e.doit = false;
            shell.setVisible(false);
        }
    });

    Label label = new Label(shell, SWT.LEFT);
    label.setText("Dialog_find_what");
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            boolean enableFind = (searchText.getCharCount() != 0);
            findButton.setEnabled(enableFind);
        }
    });

    searchAreaLabel = new Label(shell, SWT.LEFT);
    searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchArea.setLayoutData(gridData);

    matchCase = new Button(shell, SWT.CHECK);
    matchCase.setText("Dialog_match_case");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText("Dialog_match_word");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchWord.setLayoutData(gridData);

    Group direction = new Group(shell, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    direction.setLayoutData(gridData);
    direction.setLayout(new FillLayout());
    direction.setText("Dialog_direction");

    Button up = new Button(direction, SWT.RADIO);
    up.setText("Dialog_dir_up");
    up.setSelection(false);

    down = new Button(direction, SWT.RADIO);
    down.setText("Dialog_dir_down");
    down.setSelection(true);

    Composite composite = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    composite.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    composite.setLayout(layout);

    findButton = new Button(composite, SWT.PUSH);
    findButton.setText("Dialog_find");
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!findHandler.find()) {
                MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
                box.setText(shell.getText());
                box.setMessage("Cannot_find" + "\"" + searchText.getText() + "\"");
                box.open();
            }
        }
    });

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText("Cancel");
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            shell.setVisible(false);
        }
    });

    shell.pack();
}

From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java

/**
 * Create the composite/*from   w ww.java2s.  c o m*/
 * 
 * @param parent
 * @param style
 */
public AnalysisComposite(Composite parent, int style) {
    super(parent, style);
    setLayout(new GridLayout());
    this.setSize(557, 224);

    // Create the types
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

    final Composite composite_2 = new Composite(this, SWT.NONE);
    composite_2.setLayout(new FillLayout());
    final GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_composite_2.heightHint = 263;
    gd_composite_2.widthHint = 540;
    composite_2.setLayoutData(gd_composite_2);

    final SashForm sashForm = new SashForm(composite_2, SWT.HORIZONTAL);
    sashForm.setOrientation(SWT.HORIZONTAL);
    {
        composite2 = new FramedComposite(sashForm, SWT.SHADOW_NONE);
        GridLayout composite2Layout = new GridLayout();
        composite2Layout.horizontalSpacing = 1;
        composite2.setLayout(composite2Layout);
        {
            composite3 = new FramedComposite(composite2, SWT.SHADOW_NONE);
            GridLayout composite3Layout = new GridLayout();
            composite3Layout.numColumns = 2;
            composite3Layout.marginHeight = 3;
            GridData composite3LData = new GridData();
            composite3LData.grabExcessHorizontalSpace = true;
            composite3LData.horizontalAlignment = GridData.FILL;
            composite3LData.heightHint = 25;
            composite3.setLayoutData(composite3LData);
            composite3.setLayout(composite3Layout);
            {
                label2 = new Label(composite3, SWT.NONE);
                label2.setText("Graphic Analyses");
                GridData label2LData = new GridData();
                label2LData.horizontalAlignment = GridData.FILL;
                label2LData.heightHint = 14;
                label2LData.grabExcessHorizontalSpace = true;
                label2.setLayoutData(label2LData);
                label2.setAlignment(SWT.CENTER);
            }
            {
                clearButton = new Button(composite3, SWT.PUSH | SWT.CENTER);
                GridData button1LData = new GridData();
                button1LData.horizontalAlignment = GridData.CENTER;
                button1LData.widthHint = 19;
                button1LData.verticalAlignment = GridData.BEGINNING;
                button1LData.heightHint = 18;
                clearButton.setLayoutData(button1LData);
                clearButton.setText("x");
                clearButton.setToolTipText("Remove all nodes in analysis tree panel below");
                clearButton.setFont(SWTResourceManager.getFont("Tahoma", 10, 1, false, false));
                clearButton.addSelectionListener(new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                        clearButtonWidgetSelected(evt);
                    }
                });
            }
        }
        {
            tree1 = new Tree(composite2, SWT.BORDER);
            tree1.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(final SelectionEvent e) {
                    final TreeItem item = tree1.getSelection()[0];
                    if (item.getText().equalsIgnoreCase("No results to display")) {
                        return;
                    }
                    getDisplay().syncExec(new Runnable() {
                        public void run() {
                            queryName = item.getParentItem().getText();
                            label1.setText(item.getParentItem().getText());
                        }
                    });
                    setSelection((QueryResultData) item.getData());
                }
            });
            GridData tree1LData = new GridData();
            tree1LData.verticalAlignment = GridData.FILL;
            tree1LData.horizontalAlignment = GridData.FILL;
            tree1LData.grabExcessHorizontalSpace = true;
            tree1LData.grabExcessVerticalSpace = true;
            tree1.setLayoutData(tree1LData);
            {
                /*
                 * analyses = new TreeItem(tree1, SWT.NONE);
                 * analyses.setText("Analyses"); analyses
                 * .setImage(SWTResourceManager
                 * .getImage("edu/harvard/i2b2/analysis/ui/openFolder.jpg"
                 * )); analyses.setExpanded(true);
                 */
            }
        }
    }
    {
        final FramedComposite right_composite = new FramedComposite(sashForm, SWT.SHADOW_NONE);
        GridLayout right_compositeLayout = new GridLayout();
        right_composite.setLayout(right_compositeLayout);
        {
            final FramedComposite top_composite = new FramedComposite(right_composite, SWT.SHADOW_NONE);
            GridLayout top_compositeLayout = new GridLayout();
            top_compositeLayout.makeColumnsEqualWidth = true;
            top_composite.setLayout(top_compositeLayout);
            GridData top_compositeLData = new GridData();
            top_compositeLData.horizontalAlignment = GridData.FILL;
            top_compositeLData.grabExcessHorizontalSpace = true;
            top_composite.setLayoutData(top_compositeLData);
            {
                label1 = new Label(top_composite, SWT.NO_TRIM);
                GridData gd_top_composite = new GridData();
                gd_top_composite.grabExcessHorizontalSpace = true;
                gd_top_composite.horizontalAlignment = GridData.FILL;
                label1.setLayoutData(gd_top_composite);
                queryName = "Query Name: ";
                label1.setText("Query Name: ");
                label1.addListener(SWT.Resize, new Listener() {
                    public void handleEvent(Event event) {
                        int width = label1.getBounds().width;
                        GC gc = new GC(Display.getCurrent().getActiveShell());

                        if (gc != null) {

                            gc.setFont(label1.getFont());
                            Point pt = gc.stringExtent(queryName);

                            if (pt.x <= width) {
                                label1.setText(queryName);
                                gc.dispose();
                                return;
                            }

                            int charWidth = pt.x / queryName.length();
                            int charNum = width / charWidth;
                            label1.setText(queryName.substring(0, charNum - 6) + "...");
                            // System.out.println("size: "+label1.getSize()
                            // + "; width"+width+
                            // " font width: "+pt.x+"char width: "+pt.x/
                            // queryName.length());

                            gc.dispose();
                        }
                    }
                });
                label1.addMouseTrackListener(new MouseTrackListener() {

                    public void mouseEnter(MouseEvent arg0) {
                        top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
                    }

                    public void mouseExit(MouseEvent arg0) {
                        top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
                    }

                    public void mouseHover(MouseEvent arg0) {
                        top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
                    }

                });
            }
            {
                DropTarget target1 = new DropTarget(top_composite, DND.DROP_COPY);
                // RowData target1LData = new RowData();
                // target1.setLayoutData(target1LData);
                target1.setTransfer(types);
                target1.addDropListener(new DropTargetAdapter() {
                    @SuppressWarnings("unchecked")
                    public void drop(DropTargetEvent event) {
                        if (event.data == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }

                        try {
                            SAXBuilder parser = new SAXBuilder();
                            String xmlContent = (String) event.data;
                            java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                            org.jdom.Document tableDoc = parser.build(xmlStringReader);
                            org.jdom.Element tableXml = tableDoc.getRootElement().getChild("query_master",
                                    Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));

                            if (tableXml == null) {
                                tableXml = tableDoc.getRootElement().getChild("query_instance",
                                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));
                                if (tableXml == null) {

                                    MessageBox mBox = new MessageBox(top_composite.getShell(),
                                            SWT.ICON_INFORMATION | SWT.OK);
                                    mBox.setText("Please Note ...");
                                    mBox.setMessage("You can not drop this item here.");
                                    mBox.open();
                                    event.detail = DND.DROP_NONE;
                                    return;
                                } else {
                                    try {
                                        QueryInstanceData ndata = new QueryInstanceData();
                                        // ndata.name(tableXml.getChildText(
                                        // "name"));
                                        // label1.setText("Query Name: " +
                                        // ndata.name());
                                        ndata.xmlContent(null);
                                        ndata.id(tableXml.getChildTextTrim("query_instance_id"));
                                        ndata.userId(tableXml.getChildTextTrim("user_id"));
                                        ndata.name(tableXml.getChildTextTrim("name"));

                                        insertNodes(ndata);
                                        setSelection(tree1.getItemCount() - 1);

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        return;
                                    }

                                    event.detail = DND.DROP_NONE;
                                    return;
                                }
                            }
                            try {
                                JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil();
                                QueryMasterData ndata = new QueryMasterData();
                                ndata.name(tableXml.getChildText("name"));
                                // label1.setText("Query Name: " +
                                // ndata.name());
                                ndata.xmlContent(null);
                                ndata.id(tableXml.getChildTextTrim("query_master_id"));
                                ndata.userId(tableXml.getChildTextTrim("user_id"));

                                // get query instance
                                String xmlRequest = ndata.writeContentQueryXML();
                                // lastRequestMessage(xmlRequest);
                                String xmlResponse = QueryClient.sendQueryRequestREST(xmlRequest);
                                // lastResponseMessage(xmlResponse);

                                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                                ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                                BodyType bt = messageType.getMessageBody();
                                InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                        .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                                QueryInstanceData instanceData = null;
                                XMLGregorianCalendar startDate = null;
                                for (QueryInstanceType queryInstanceType : instanceResponseType
                                        .getQueryInstance()) {
                                    QueryInstanceData runData = new QueryInstanceData();

                                    runData.visualAttribute("FA");
                                    runData.tooltip("The results of the query run");
                                    runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                                    XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                                    runData.name(ndata.name());

                                    if (instanceData == null) {
                                        startDate = cldr;
                                        instanceData = runData;
                                    } else {
                                        if (cldr.toGregorianCalendar()
                                                .compareTo(startDate.toGregorianCalendar()) > 0) {
                                            startDate = cldr;
                                            instanceData = runData;
                                        }
                                    }
                                }

                                insertNodes(instanceData);
                                if (treeItem.getItemCount() == 0) {
                                    getDisplay().syncExec(new Runnable() {
                                        public void run() {
                                            TreeItem treeItem1 = new TreeItem(treeItem, SWT.NONE);
                                            treeItem1.setText("No results to display");
                                            treeItem1.setForeground(getDisplay().getSystemColor(SWT.COLOR_RED));
                                            treeItem1.setExpanded(true);
                                            treeItem1.setImage(SWTResourceManager
                                                    .getImage("edu/harvard/i2b2/analysis/ui/leaf.jpg"));

                                            JFreeChart chart = createNoDataChart(createEmptyDataset());
                                            composite1.getChildren()[0].dispose();
                                            ChartComposite frame = new ChartComposite(composite1, SWT.NONE,
                                                    chart, true, true, false, true, true);
                                            frame.pack();
                                            composite1.layout();

                                            tree1.select(treeItem1);
                                            return;
                                        }
                                    });

                                } else {
                                    setSelection(tree1.getItemCount() - 1);
                                }

                            } catch (Exception e) {
                                e.printStackTrace();
                                return;
                            }

                            event.detail = DND.DROP_NONE;
                        } catch (Exception e) {
                            e.printStackTrace();
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                    }

                    @Override
                    public void dragLeave(DropTargetEvent event) {
                        super.dragLeave(event);
                        top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
                    }

                    public void dragEnter(DropTargetEvent event) {
                        event.detail = DND.DROP_COPY;
                        top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
                    }
                });
            }
            top_composite.addMouseTrackListener(new MouseTrackListener() {

                public void mouseEnter(MouseEvent arg0) {
                    top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
                }

                public void mouseExit(MouseEvent arg0) {
                    top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
                }

                public void mouseHover(MouseEvent arg0) {
                    top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
                }

            });
        }
        {
            composite1 = new Composite(right_composite, SWT.BORDER);
            FillLayout composite1Layout = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL);
            GridData composite1LData = new GridData();
            composite1LData.grabExcessHorizontalSpace = true;
            composite1LData.grabExcessVerticalSpace = true;
            composite1LData.horizontalAlignment = GridData.FILL;
            composite1LData.verticalAlignment = GridData.FILL;
            composite1.setLayoutData(composite1LData);
            composite1.setLayout(composite1Layout);
            // composite1.setBackground(SWTResourceManager.getColor(255,
            // 255,
            // 0));

            getDisplay().syncExec(new Runnable() {
                public void run() {
                    JFreeChart chart = createEmptyChart(createEmptyDataset());
                    /* final ChartComposite frame = */new ChartComposite(composite1, SWT.NONE, chart, true,
                            true, false, true, true);
                }
            });
        }

    }

    {
        // label2 = new Label(top_composite, SWT.NONE);
        // label2.setText("2512+3 patients");
        // label2.setBounds(254, 7, 108, 19);
    }
    {
        DropTarget target2 = new DropTarget(tree1, DND.DROP_COPY);
        target2.setTransfer(types);
        target2.addDropListener(new DropTargetAdapter() {
            public void dragEnter(DropTargetEvent event) {
                event.detail = DND.DROP_COPY;
            }

            @SuppressWarnings("unchecked")
            public void drop(DropTargetEvent event) {
                if (event.data == null) {
                    event.detail = DND.DROP_NONE;
                    return;
                }

                try {
                    SAXBuilder parser = new SAXBuilder();
                    String xmlContent = (String) event.data;
                    java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                    org.jdom.Document tableDoc = parser.build(xmlStringReader);
                    org.jdom.Element tableXml = tableDoc.getRootElement().getChild("query_master",
                            Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));

                    if (tableXml == null) {
                        tableXml = tableDoc.getRootElement().getChild("query_instance",
                                Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));
                        if (tableXml == null) {

                            MessageBox mBox = new MessageBox(tree1.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage("You can not drop this item here.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;
                            return;
                        } else {
                            try {
                                // JAXBUtil jaxbUtil =
                                // AnalysisJAXBUtil.getJAXBUtil();
                                QueryInstanceData ndata = new QueryInstanceData();
                                // ndata.name(tableXml.getChildText("name"));
                                // label1.setText("Query Name: " +
                                // ndata.name());
                                ndata.xmlContent(null);
                                ndata.id(tableXml.getChildTextTrim("query_instance_id"));
                                ndata.userId(tableXml.getChildTextTrim("user_id"));
                                ndata.name(tableXml.getChildTextTrim("name"));

                                // clearTree();
                                insertNodes(ndata);
                                setSelection(tree1.getItemCount() - 1);

                            } catch (Exception e) {
                                e.printStackTrace();
                                return;
                            }

                            event.detail = DND.DROP_NONE;
                            return;
                        }
                    }
                    try {
                        JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        // label1.setText("Query Name: " + ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        // lastRequestMessage(xmlRequest);
                        String xmlResponse = QueryClient.sendQueryRequestREST(xmlRequest);
                        // lastResponseMessage(xmlResponse);

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        BodyType bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name(ndata.name());

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // clearTree();
                        insertNodes(instanceData);
                        setSelection(tree1.getItemCount() - 1);

                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }

                    event.detail = DND.DROP_NONE;
                } catch (Exception e) {
                    e.printStackTrace();
                    event.detail = DND.DROP_NONE;
                    return;
                }
            }
        });
    }

    sashForm.setWeights(new int[] { 30, 70 });
    sashForm.setSashWidth(1);
}

From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java

private void initUI(final Composite parent) {
    parent.setLayout(new FillLayout());
    final SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
    sashForm.SASH_WIDTH = 15;//from w w w. j  a va 2  s . co m
    sashForm.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));

    main = new Composite(sashForm, SWT.NONE);
    GridLayout gridLayout = new GridLayout(1, true);
    gridLayout.verticalSpacing = 2;
    gridLayout.marginLeft = 5;
    gridLayout.marginRight = 5;
    main.setLayout(gridLayout);

    initPreferencesGroup(main);
    initVehicleGroup(main);
    initAnalystContributionsGroup(main);
    initAddContributionGroup(main);

    Composite lowerSection = new Composite(sashForm, SWT.NONE);
    lowerSection.setLayout(new FillLayout());

    // ok - the next section needs to be in a sash - so we can resize it
    initGraphTabs(lowerSection);

    // set the relative sizes in the sash
    sashForm.setWeights(new int[] { 3, 1 });

    // also sort out the header controls
    final IActionBars bars = getViewSite().getActionBars();
    IToolBarManager manager = bars.getToolBarManager();
    manager.add(SATC_Activator.createOpenHelpAction("org.mwc.debrief.help.SATC", null, this));

    _exportBtn = new Action("Export SATC dataset", Action.AS_PUSH_BUTTON) {
        public void runWithEvent(final Event event) {
            exportSATC();
        }
    };
    _exportBtn.setToolTipText("Export SATC scenario to clipboard");
    _exportBtn.setImageDescriptor(SATC_Activator.getImageDescriptor("icons/export.png"));
    manager.add(_exportBtn);

}

From source file:msi.gama.gui.swt.controls.SWTChartEditor.java

/**
 * Creates a new editor.//  www.java 2s . c o  m
 * 
 * @param display the display.
 * @param chart2edit the chart to edit.
 */
public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) {
    this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM);
    this.shell.setSize(400, 500);
    this.shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
    // this.shell.setAlpha(140);
    this.chart = chart2edit;
    this.shell.setText("Chart properties");
    this.shell.setLocation(position);
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5;
    this.shell.setLayout(layout);
    Composite main = new Composite(this.shell, SWT.NONE);
    main.setLayout(new FillLayout());
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TabFolder tab = new TabFolder(main, SWT.BORDER);
    // build first tab
    TabItem item1 = new TabItem(tab, SWT.NONE);
    item1.setText(" " + "Title" + " ");
    this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle());
    item1.setControl(this.titleEditor);
    // build second tab
    TabItem item2 = new TabItem(tab, SWT.NONE);
    item2.setText(" " + "Plot" + " ");
    this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot());
    item2.setControl(this.plotEditor);
    // build the third tab
    TabItem item3 = new TabItem(tab, SWT.NONE);
    item3.setText(" " + "Other" + " ");
    this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart);
    item3.setControl(this.otherEditor);

    // ok and cancel buttons
    Button cancel = new Button(this.shell, SWT.PUSH);
    cancel.setText(" Cancel ");
    cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
    cancel.pack();
    cancel.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            SWTChartEditor.this.shell.dispose();
        }
    });
    Button ok = new Button(this.shell, SWT.PUSH | SWT.OK);
    ok.setText(" Ok ");
    ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
    ok.pack();
    ok.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            updateChart(SWTChartEditor.this.chart);
            SWTChartEditor.this.shell.dispose();
        }
    });

}

From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java

private void initPreferencesGroup(Composite parent) {
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;

    Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
    GridLayout layout = new GridLayout(1, false);
    group.setLayoutData(gridData);//from www .  ja v a2s  . co  m
    group.setLayout(layout);
    group.setText("Preferences");

    final ScrolledComposite scrolled = new ScrolledComposite(group, SWT.H_SCROLL);
    scrolled.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Composite preferencesComposite = UIUtils.createScrolledBody(scrolled, SWT.NONE);
    preferencesComposite.setLayout(new GridLayout(6, false));

    scrolled.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }
    });
    scrolled.setAlwaysShowScrollBars(true);
    scrolled.setContent(preferencesComposite);
    scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);

    liveConstraints = new Button(preferencesComposite, SWT.TOGGLE);
    liveConstraints.setText("Auto-Recalc of Constraints");
    liveConstraints.setEnabled(false);
    liveConstraints
            .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER));

    recalculate = new Button(preferencesComposite, SWT.DEFAULT);
    recalculate.setText("Calculate Solution");
    recalculate.setEnabled(false);
    recalculate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activeSolver != null) {
                // ok - make sure the performance tab is open
                graphTabs.setSelection(performanceTab);

                activeSolver.run(true, true);
                main.setSize(0, 0);
                main.getParent().layout(true, true);
            }
        }
    });
    recalculate.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER));

    cancelGeneration = new Button(preferencesComposite, SWT.PUSH);
    cancelGeneration.setText("Cancel");
    cancelGeneration.setVisible(false);
    cancelGeneration.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activeSolver != null) {
                activeSolver.cancel();
            }
        }
    });

    suppressCuts = new Button(preferencesComposite, SWT.CHECK);
    suppressCuts.setText("Suppress Cuts");
    suppressCuts.setVisible(true);
    suppressCuts.setEnabled(false);
    suppressCuts.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activeSolver != null) {
                boolean doSuppress = suppressCuts.getSelection();
                activeSolver.setAutoSuppress(doSuppress);
            }
        }
    });

    showOSCourse = new Button(preferencesComposite, SWT.CHECK);
    showOSCourse.setText("Plot O/S Course");
    showOSCourse.setVisible(true);
    showOSCourse.setEnabled(false);
    showOSCourse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activeSolver != null) {
                redoOwnshipStates();
            }
        }
    });

    Composite precisionPanel = new Composite(preferencesComposite, SWT.NONE);
    precisionPanel.setLayoutData(new GridData(
            GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));

    GridLayout precisionLayout = new GridLayout(2, false);
    precisionLayout.horizontalSpacing = 5;
    precisionPanel.setLayout(precisionLayout);

    Label precisionLabel = new Label(precisionPanel, SWT.NONE);
    precisionLabel.setText("Precision:");
    precisionLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    precisionsCombo = new ComboViewer(precisionPanel);
    precisionsCombo.getCombo().setEnabled(false);
    precisionsCombo.setContentProvider(new ArrayContentProvider());
    precisionsCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Precision) element).getLabel();
        }
    });
    precisionsCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = precisionsCombo.getSelection();
            IStructuredSelection cSel = (IStructuredSelection) sel;
            Precision precision = (Precision) cSel.getFirstElement();
            if (activeSolver != null) {
                activeSolver.setPrecision(precision);
            }
        }
    });
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

@Override
public void createFramesocPartControl(Composite parent) {

    // parent layout
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 2;/*from   ww w .  java  2s. co  m*/
    gl_parent.marginWidth = 0;
    gl_parent.horizontalSpacing = 0;
    gl_parent.marginHeight = 0;
    parent.setLayout(gl_parent);

    // -------------------------------
    // Base GUI: pie + table
    // -------------------------------

    SashForm sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // Composite Left: composite combo + composite pie
    Composite compositeLeft = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeLeft = new GridLayout(1, false);
    gl_compositeLeft.marginBottom = 3;
    gl_compositeLeft.verticalSpacing = 0;
    gl_compositeLeft.marginHeight = 0;
    compositeLeft.setLayout(gl_compositeLeft);

    // Composite Combo
    Composite compositeCombo = new Composite(compositeLeft, SWT.NONE);
    compositeCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    GridLayout gl_compositeCombo = new GridLayout(1, false);
    gl_compositeCombo.marginWidth = 0;
    compositeCombo.setLayout(gl_compositeCombo);

    // combo
    combo = new Combo(compositeCombo, SWT.READ_ONLY);
    combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    combo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean firstTime = true;
            for (LoaderDescriptor d : loaderDescriptors) {
                firstTime = firstTime && !d.dataLoaded();
            }
            if (firstTime) {
                return;
            }
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            // use global load interval
            timeBar.setSelection(globalLoadInterval);
            loadPieChart();
        }
    });

    int position = 0;
    for (LoaderDescriptor descriptor : loaderDescriptors) {
        combo.add(descriptor.loader.getStatName(), position++);
    }
    combo.select(0);
    currentDescriptor = loaderDescriptors.get(0);
    combo.setEnabled(false);

    // Composite Pie
    compositePie = new Group(compositeLeft, SWT.NONE);
    // Fill layout with Grid Data (FILL) to allow correct resize
    compositePie.setLayout(new FillLayout());
    compositePie.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    txtDescription = new Text(compositePie, SWT.READ_ONLY | SWT.WRAP | SWT.CENTER | SWT.MULTI);
    txtDescription.setEnabled(false);
    txtDescription.setEditable(false);
    txtDescription.setText("Select one of the above metrics, then press the Load button.");
    txtDescription.setVisible(false);

    // Composite Table
    Composite compositeTable = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeTable = new GridLayout(1, false);
    compositeTable.setLayout(gl_compositeTable);

    // filter
    textFilter = new Text(compositeTable, SWT.BORDER);
    textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textFilter.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.isEmpty()) {
                cleanTableFilter();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.equals(FILTER_HINT)) {
                textFilter.setText("");
                textFilter.setData("");
                textFilter.setForeground(blackColor);
            }
        }
    });
    textFilter.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || textFilter.getText().trim().isEmpty()) {
                textFilter.setData(textFilter.getText());
                refreshTableFilter();
            }
        }
    });

    // table
    tableTreeViewer = new TreeViewer(compositeTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
    tableTreeViewer.setContentProvider(new TreeContentProvider());
    comparator = new StatisticsColumnComparator();
    tableTreeViewer.setComparator(comparator);
    Tree table = tableTreeViewer.getTree();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    createColumns();
    createContextMenu();

    // status bar
    Composite statusBar = new Composite(compositeTable, SWT.BORDER);
    GridLayout statusBarLayout = new GridLayout();
    GridData statusBarGridData = new GridData();
    statusBarGridData.horizontalAlignment = SWT.FILL;
    statusBarGridData.grabExcessHorizontalSpace = true;
    statusBar.setLayoutData(statusBarGridData);
    statusBarLayout.numColumns = 1;
    statusBar.setLayout(statusBarLayout);
    // text
    statusText = new Text(statusBar, SWT.NONE);
    statusText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    statusText.setText(getStatus(0, 0));

    // -------------------------------
    // TIME MANAGEMENT BAR
    // -------------------------------

    Composite timeComposite = new Composite(parent, SWT.BORDER);
    timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_timeComposite = new GridLayout(1, false);
    gl_timeComposite.horizontalSpacing = 0;
    timeComposite.setLayout(gl_timeComposite);
    // time manager
    timeBar = new TimeBar(timeComposite, SWT.NONE, true, true);
    timeBar.setEnabled(false);
    combo.setEnabled(false);
    IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
    timeBar.setStatusLineManager(statusLineManager);

    // button to synch the timebar with the gantt
    timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo != null && timeBar != null && currentDescriptor != null) {
                if (currentDescriptor.dataLoaded()) {
                    timeBar.setSelection(currentDescriptor.interval.startTimestamp,
                            currentDescriptor.interval.endTimestamp);
                } else {
                    timeBar.setSelection(currentShownTrace.getMinTimestamp(),
                            currentShownTrace.getMaxTimestamp());
                }
            }
        }
    });
    timeBar.getSynchButton().setToolTipText("Synch Selection With Pie Chart");

    // load button
    timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo.getSelectionIndex() == -1)
                return;
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            loadPieChart();
        }
    });

    // ----------
    // TOOL BAR
    // ----------

    // filters and actions
    createFilterDialogs();
    createActions();

    // create SWT resources
    createResources();
    // clean the filter, after creating the font
    cleanTableFilter();

}