Search in sources :

Example 36 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class CursorTest method main.

public static void main(String[] args) {
    try {
        final Display display = Display.getDefault();
        final Shell shell = new Shell(display, SWT.SHELL_TRIM);
        shell.setLayout(new FillLayout());
        final List list = new List(shell, SWT.BORDER);
        final Composite composite = new Composite(shell, SWT.NONE);
        CURSOR[] CURSORS = CURSOR.values();
        String[] itemnames = new String[CURSORS.length];
        for (int i = 0; i < CURSORS.length; i++) {
            itemnames[i] = CURSORS[i].name();
        }
        list.setItems(itemnames);
        list.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                composite.setCursor(new Cursor(display, list.getSelectionIndex()));
            }
        });
        shell.setText("SWT Cursor");
        shell.setSize(500, 320);
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) Display(org.eclipse.swt.widgets.Display)

Example 37 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class HelloCanvasArrow method open.

public void open() {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    shell.setLayout(new FillLayout());
    final Canvas canvas = new Canvas(shell, SWT.NONE);
    canvas.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_ARROW));
    canvas.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent arg0) {
        }

        public void mouseDown(MouseEvent e) {
            p[0] = e.x;
            p[1] = e.y;
            b = true;
        }

        public void mouseUp(MouseEvent arg0) {
            if (b) {
                int[] tp = new int[4];
                tp[0] = p[0];
                tp[1] = p[0];
                tp[2] = p[0];
                tp[3] = p[3];
            }
            b = false;
        }
    });
    canvas.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            p[2] = e.x;
            p[3] = e.y;
            canvas.redraw();
        }
    });
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent paintevent) {
            if (b) {
                paintArrow(paintevent.gc, new Point(p[0], p[1]), new Point(p[2], p[3]));
            }
        }
    });
    shell.setText("test");
    shell.setSize(300, 300);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) if (!display.readAndDispatch())
        display.sleep();
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Example 38 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class MyFillLayout method open.

public void open() {
    final Display display = Display.getDefault();
    shell = new Shell();
    fillLayout = new FillLayout();
    //# fillLayout.type=SWT.VERTICAL; 
    //# fillLayout.type=SWT.HORIZONTAL; 
    shell.setLayout(fillLayout);
    btnHorizontal = new Button(shell, SWT.NONE);
    btnHorizontal.setText("HORIZONTAL");
    btnHorizontal.addMouseListener(this);
    btnVertical = new Button(shell, SWT.NONE);
    btnVertical.setText("VERTICAL");
    btnVertical.addMouseListener(this);
    shell.setText("FillLayout");
    shell.setSize(200, 200);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display)

Example 39 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class MyFormLayout method main.

public static void main(String[] args) {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 20;
    formLayout.marginHeight = 20;
    new Button(shell, SWT.NONE).setText("B1");
    Button b = new Button(shell, SWT.NONE);
    b.setText("B2");
    FormData formData = new FormData(100, 100);
    b.setLayoutData(formData);
    shell.setLayout(formLayout);
    shell.setText("FormLayout");
    shell.setSize(200, 200);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) Display(org.eclipse.swt.widgets.Display)

Example 40 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class MyRowLayout method main.

public static void main(String[] args) {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 10;
    rowLayout.marginLeft = 5;
    rowLayout.spacing = 2;
    // true or false 
    rowLayout.wrap = true;
    rowLayout.type = SWT.HORIZONTAL;
    //# rowLayout.type = SWT.VERTICAL;
    rowLayout.pack = true;
    rowLayout.justify = false;
    new Button(shell, SWT.NONE).setText("b1");
    new Button(shell, SWT.NONE).setText("button2");
    Button b = new Button(shell, SWT.NONE);
    b.setText("btn3");
    RowData rowData = new RowData(50, 50);
    b.setLayoutData(rowData);
    shell.setLayout(rowLayout);
    shell.setText("RowLayout");
    shell.setSize(200, 200);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23