Search in sources :

Example 21 with Canvas

use of org.eclipse.swt.widgets.Canvas in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Caret method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    canvas = new Canvas(shell, SWT.NULL);
    caret = new Caret(canvas, SWT.NULL);
    setWidget(caret);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) Caret(org.eclipse.swt.widgets.Caret) Before(org.junit.Before)

Example 22 with Canvas

use of org.eclipse.swt.widgets.Canvas in project eclipse.platform.swt by eclipse.

the class Bug170631_NestedCompositeFocus method main.

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    final Canvas canvas = new Canvas(shell, SWT.NONE);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    canvas.setLayoutData(gridData);
    canvas.addPaintListener(event -> {
        Rectangle rect = canvas.getClientArea();
        event.gc.drawOval(0, 0, rect.width - 1, rect.height - 1);
    });
    final Text text = new Text(shell, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    text.setText("I want focus");
    shell.setBounds(10, 10, 200, 200);
    shell.open();
    // With shell.setFocus(), the Canvas gets focus.  Without it, the Text does.
    shell.setFocus();
    System.out.println(shell.getDisplay().getFocusControl());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Display(org.eclipse.swt.widgets.Display)

Example 23 with Canvas

use of org.eclipse.swt.widgets.Canvas in project liferay-ide by liferay.

the class LiferayCustomXmlHoverControl method _createAnnotationInformation.

private void _createAnnotationInformation(Composite parent, Annotation annotation) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 2;
    layout.marginWidth = 2;
    layout.horizontalSpacing = 0;
    composite.setLayout(layout);
    // this paints the icon..
    Canvas canvas = new Canvas(composite, SWT.NO_FOCUS);
    GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gridData.widthHint = 17;
    gridData.heightHint = 16;
    canvas.setLayoutData(gridData);
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            e.gc.setFont(null);
            _markerAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
        }
    });
    // and now comes the text
    StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(data);
    String annotationText = annotation.getText();
    if (annotationText != null) {
        text.setText(annotationText);
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 24 with Canvas

use of org.eclipse.swt.widgets.Canvas in project netxms by netxms.

the class Sleak method open.

public void open() {
    display = Display.getCurrent();
    shell = new Shell(display);
    // $NON-NLS-1$
    shell.setText("S-Leak");
    list = new List(shell, SWT.BORDER | SWT.V_SCROLL);
    list.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            refreshObject();
        }
    });
    text = new Text(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    canvas = new Canvas(shell, SWT.BORDER);
    canvas.addListener(SWT.Paint, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            paintCanvas(event);
        }
    });
    check = new Button(shell, SWT.CHECK);
    // $NON-NLS-1$
    check.setText("Stack");
    check.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event e) {
            toggleStackTrace();
        }
    });
    start = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    start.setText("Snap");
    start.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            refreshAll();
        }
    });
    stop = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    stop.setText("Diff");
    stop.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            refreshDifference();
        }
    });
    label = new Label(shell, SWT.BORDER);
    // $NON-NLS-1$
    label.setText("0 object(s)");
    shell.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(final Event e) {
            layout();
        }
    });
    check.setSelection(false);
    text.setVisible(false);
    final Point size = shell.getSize();
    shell.setSize(size.x / 2, size.y / 2);
    shell.open();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Listener(org.eclipse.swt.widgets.Listener) Button(org.eclipse.swt.widgets.Button) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) List(org.eclipse.swt.widgets.List) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point)

Example 25 with Canvas

use of org.eclipse.swt.widgets.Canvas in project yamcs-studio by yamcs.

the class OverviewOutlinePage method createControl.

@Override
public void createControl(Composite parent) {
    overview = new Canvas(parent, SWT.NONE);
    var lws = new LightweightSystem(overview);
    thumbnail = new ScrollableThumbnail((Viewport) rootEP.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEP.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
    disposeListener = e -> {
        if (thumbnail != null) {
            thumbnail.deactivate();
            thumbnail = null;
        }
    };
    rootEP.getViewer().getControl().addDisposeListener(disposeListener);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Aggregations

Canvas (org.eclipse.swt.widgets.Canvas)108 GridData (org.eclipse.swt.layout.GridData)44 Composite (org.eclipse.swt.widgets.Composite)36 GridLayout (org.eclipse.swt.layout.GridLayout)35 PaintEvent (org.eclipse.swt.events.PaintEvent)34 PaintListener (org.eclipse.swt.events.PaintListener)33 Rectangle (org.eclipse.swt.graphics.Rectangle)32 Point (org.eclipse.swt.graphics.Point)31 Label (org.eclipse.swt.widgets.Label)29 Text (org.eclipse.swt.widgets.Text)23 Button (org.eclipse.swt.widgets.Button)21 Color (org.eclipse.swt.graphics.Color)20 Shell (org.eclipse.swt.widgets.Shell)20 MouseEvent (org.eclipse.swt.events.MouseEvent)17 FillLayout (org.eclipse.swt.layout.FillLayout)17 Event (org.eclipse.swt.widgets.Event)17 GC (org.eclipse.swt.graphics.GC)16 Group (org.eclipse.swt.widgets.Group)16 Listener (org.eclipse.swt.widgets.Listener)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15