Search in sources :

Example 16 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project core by jcryptool.

the class NewKeyComposite method initGUI.

private void initGUI() {
    try {
        GridLayout thisLayout = new GridLayout();
        thisLayout.numColumns = 3;
        this.setLayout(thisLayout);
        // this.setSize(396, 100);
        {
            GridData canvas1LData = new GridData();
            canvas1LData.widthHint = 48;
            canvas1LData.heightHint = 48;
            canvas1 = new Canvas(this, SWT.NONE);
            canvas1.setLayoutData(canvas1LData);
            canvas1.addPaintListener(new PaintListener() {

                ImageDescriptor imgDescriptor = getKeyImageDescriptor();

                public void paintControl(PaintEvent e) {
                    // $NON-NLS-1$
                    e.gc.drawImage(imgDescriptor.createImage(), 0, 0);
                }
            });
        }
        {
            infoComposite = new Composite(this, SWT.NONE);
            GridLayout infoCompositeLayout = new GridLayout();
            infoCompositeLayout.makeColumnsEqualWidth = true;
            infoCompositeLayout.verticalSpacing = 1;
            infoCompositeLayout.marginHeight = 0;
            GridData infoCompositeLData = new GridData();
            infoCompositeLData.grabExcessHorizontalSpace = true;
            infoCompositeLData.grabExcessVerticalSpace = true;
            infoCompositeLData.horizontalAlignment = GridData.FILL;
            infoCompositeLData.verticalAlignment = GridData.CENTER;
            infoComposite.setLayoutData(infoCompositeLData);
            infoComposite.setLayout(infoCompositeLayout);
            {
                labelInfo1 = new Label(infoComposite, SWT.NONE);
                GridData labelInfo1LData = new GridData();
                labelInfo1LData.grabExcessHorizontalSpace = true;
                labelInfo1LData.horizontalAlignment = GridData.FILL;
                labelInfo1.setLayoutData(labelInfo1LData);
                // $NON-NLS-1$
                setInfoLabelText();
                // $NON-NLS-1$
                labelInfo1.setFont(SWTResourceManager.getFont("Segoe UI", 9, 1, false, false));
            }
            {
                labelOwner = new Label(infoComposite, SWT.NONE);
                GridData labelOwnerLData = new GridData();
                labelOwner.setLayoutData(labelOwnerLData);
                // $NON-NLS-1$
                labelOwner.setText(Messages.getString("NewKeyComposite.owner") + publicKeyAlias.getContactName());
            }
            {
                labelType = new Label(infoComposite, SWT.NONE);
                GridData labelTypeLData = new GridData();
                labelType.setLayoutData(labelTypeLData);
                labelType.setText(publicKeyAlias.getOperation());
            }
        }
        {
            GridData buttonDeleteLData = new GridData();
            buttonDeleteLData.widthHint = 24;
            buttonDeleteLData.heightHint = 24;
            buttonDeleteLData.grabExcessVerticalSpace = true;
            buttonDeleteLData.verticalAlignment = SWT.FILL;
            buttonDelete = new Button(this, SWT.PUSH | SWT.CENTER);
            buttonDelete.setLayoutData(buttonDeleteLData);
            // $NON-NLS-1$
            buttonDelete.setImage(KeyStorePlugin.getImageDescriptor("icons/16x16/cancel.png").createImage());
            // $NON-NLS-1$
            buttonDelete.setToolTipText(Messages.getString("NewKeyComposite.removeKeypairBtn"));
            buttonDelete.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    removeKeyFromKeystore();
                }
            });
        }
        this.layout();
    } catch (Exception ex) {
        LogUtil.logError(IntegratorPlugin.PLUGIN_ID, ex);
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Button(org.eclipse.swt.widgets.Button) Canvas(org.eclipse.swt.widgets.Canvas) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 17 with PaintEvent

use of org.eclipse.swt.events.PaintEvent 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 18 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project nebula.widgets.nattable by eclipse.

the class NatCombo method createTextControl.

/**
 * Creates the Text control of this NatCombo, adding styles, look&feel
 * and needed listeners for the control only.
 *
 * @param style
 *            The style for the Text Control to construct. Uses this style
 *            adding internal styles via ConfigRegistry.
 */
protected void createTextControl(int style) {
    int widgetStyle = style | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
    this.text = new Text(this, widgetStyle);
    this.text.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    this.text.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    this.text.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    this.text.setLayoutData(gridData);
    this.text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = getDropdownTable().getSelectionIndex();
                if (selectionIndex < 0) {
                    select(0);
                } else {
                    // only visualize the selection in the dropdown, do not
                    // perform a selection
                    getDropdownTable().select(selectionIndex);
                }
                // ensure the arrow key events do not have any further
                // effect
                event.doit = false;
            } else if (!LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character)) {
                if (NatCombo.this.freeEdit) {
                    // free value in text control will be used
                    if (!getDropdownTable().isDisposed()) {
                        getDropdownTable().deselectAll();
                        for (Map.Entry<String, Boolean> entry : NatCombo.this.selectionStateMap.entrySet()) {
                            entry.setValue(Boolean.FALSE);
                        }
                    }
                } else {
                    showDropdownControl();
                }
            }
        }
    });
    this.text.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            if (!NatCombo.this.freeEdit) {
                if (getDropdownTable().isDisposed() || !getDropdownTable().isVisible()) {
                    showDropdownControl();
                } else {
                    // if there is no free edit enabled, set the focus back
                    // to the dropdownlist so it handles key strokes itself
                    getDropdownTable().forceFocus();
                }
            }
        }
    });
    this.text.addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            calculateBounds();
        }

        @Override
        public void controlMoved(ControlEvent e) {
            calculateBounds();
        }
    });
    this.text.addFocusListener(new FocusListenerWrapper());
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = NatCombo.this.iconImage.getBounds();
            return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
        }
    };
    gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
    iconCanvas.setLayoutData(gridData);
    iconCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = NatCombo.this.iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(NatCombo.this.iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
            Color originalFg = gc.getForeground();
            gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
            gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
            gc.setForeground(originalFg);
        }
    });
    iconCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            if (NatCombo.this.dropdownShell != null && !NatCombo.this.dropdownShell.isDisposed()) {
                if (NatCombo.this.dropdownShell.isVisible()) {
                    NatCombo.this.text.forceFocus();
                    hideDropdownControl();
                } else {
                    showDropdownControl();
                }
            } else {
                showDropdownControl();
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project selenium_java by sergueik.

the class PreferencesDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    folder = new TabFolder(parent, SWT.NONE);
    folder.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).indent(0, 0).align(SWT.FILL, SWT.FILL).create());
    // Build tabs
    for (final String category : categories) {
        // Create the tab folder
        final TabItem tab = new TabItem(folder, SWT.NONE);
        tab.setText(category);
        if (images.get(category) != null) {
            tab.setImage(images.get(category));
        }
        final Composite tabC = createCategory(folder, category, preferences.get(category));
        tab.setControl(tabC);
    }
    // Ugly hack that seems to be needed to achieve a correct layout on
    // Linux/GTK
    folder.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent arg0) {
            folder.layout(true, true);
            folder.removePaintListener(this);
        }
    });
    return parent;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) TabFolder(org.eclipse.swt.widgets.TabFolder)

Example 20 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project tdq-studio-se by Talend.

the class Grid method initListeners.

/**
 * Initialize all listeners.
 */
private void initListeners() {
    disposeListener = new Listener() {

        public void handleEvent(Event e) {
            onDispose(e);
        }
    };
    addListener(SWT.Dispose, disposeListener);
    addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            onPaint(e);
        }
    });
    addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event e) {
            onResize();
        }
    });
    if (getVerticalBar() != null) {
        getVerticalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    if (getHorizontalBar() != null) {
        getHorizontalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event e) {
            onKeyDown(e);
        }
    });
    addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            e.doit = true;
        }
    });
    addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            onMouseDoubleClick(e);
        }

        public void mouseDown(MouseEvent e) {
            onMouseDown(e);
        }

        public void mouseUp(MouseEvent e) {
            onMouseUp(e);
        }
    });
    addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            onMouseMove(e);
        }
    });
    addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent e) {
        }

        public void mouseExit(MouseEvent e) {
            onMouseExit(e);
        }

        public void mouseHover(MouseEvent e) {
        }
    });
    addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            onFocusIn();
            redraw();
        }

        public void focusLost(FocusEvent e) {
            redraw();
        }
    });
    // Special code to reflect mouse wheel events if using an external
    // scroller
    addListener(SWT.MouseWheel, new Listener() {

        public void handleEvent(Event e) {
            onMouseWheel(e);
        }
    });
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) TypedListener(org.eclipse.swt.widgets.TypedListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeListener(org.eclipse.swt.events.TreeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)92 PaintListener (org.eclipse.swt.events.PaintListener)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)30 MouseEvent (org.eclipse.swt.events.MouseEvent)28 GridData (org.eclipse.swt.layout.GridData)26 Rectangle (org.eclipse.swt.graphics.Rectangle)25 Point (org.eclipse.swt.graphics.Point)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 DisposeEvent (org.eclipse.swt.events.DisposeEvent)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 GC (org.eclipse.swt.graphics.GC)11 Label (org.eclipse.swt.widgets.Label)10