Search in sources :

Example 16 with PaintListener

use of org.eclipse.swt.events.PaintListener in project erlide_eclipse by erlang.

the class SplashHandler method init.

@Override
public void init(final Shell splash) {
    super.init(splash);
    String progressRectString = null;
    String messageRectString = null;
    String foregroundColorString = null;
    final IProduct product = Platform.getProduct();
    if (product != null) {
        progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
        messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
        foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
    }
    final Rectangle progressRect = StringConverter.asRectangle(progressRectString, new Rectangle(10, 10, 300, 15));
    setProgressRect(progressRect);
    final Rectangle messageRect = StringConverter.asRectangle(messageRectString, new Rectangle(10, 35, 300, 15));
    setMessageRect(messageRect);
    int foregroundColorInteger;
    try {
        foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
    } catch (final Exception ex) {
        // off white
        foregroundColorInteger = 0xD2D7FF;
    }
    setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
    final String buildId = ErlangPlugin.getDefault().getCore().getFeatureVersion();
    final Point buildIdPoint;
    // hardcoded to be sensible with our current splash Graphic
    if (product != null) {
        // $NON-NLS-1$
        final String buildIdLocString = product.getProperty("buildIdLocation");
        buildIdPoint = StringConverter.asPoint(buildIdLocString, new Point(30, splash.getSize().y - 60));
    } else {
        buildIdPoint = new Point(30, splash.getSize().y - 60);
    }
    getContent().addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent e) {
            e.gc.setForeground(getForeground());
            e.gc.drawText(buildId, buildIdPoint.x, buildIdPoint.y, true);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) IProduct(org.eclipse.core.runtime.IProduct) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point)

Example 17 with PaintListener

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

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

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

use of org.eclipse.swt.events.PaintListener 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)

Aggregations

PaintListener (org.eclipse.swt.events.PaintListener)89 PaintEvent (org.eclipse.swt.events.PaintEvent)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)29 MouseEvent (org.eclipse.swt.events.MouseEvent)26 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 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 DisposeEvent (org.eclipse.swt.events.DisposeEvent)14 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Control (org.eclipse.swt.widgets.Control)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Event (org.eclipse.swt.widgets.Event)11 GC (org.eclipse.swt.graphics.GC)10 Button (org.eclipse.swt.widgets.Button)10