Search in sources :

Example 6 with PaintListener

use of org.eclipse.swt.events.PaintListener in project cubrid-manager by CUBRID.

the class InformationWindow method createContents.

protected Control createContents(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    infoText = new StyledText(composite, SWT.None);
    infoText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    infoText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    infoText.setEditable(false);
    infoText.setEnabled(false);
    infoText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseHover(MouseEvent e) {
            increaseAlpha();
        }

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

        public void mouseEnter(MouseEvent e) {
            increaseAlpha();
        }
    });
    parentShell.addControlListener(new ControlListener() {

        public void controlResized(ControlEvent e) {
            updateLocation();
        }

        public void controlMoved(ControlEvent e) {
            updateLocation();
        }
    });
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        parentShell.addPaintListener(new PaintListener() {

            public void paintControl(PaintEvent e) {
                updateLocation();
            }
        });
    }
    this.getShell().setAlpha(minAlpha);
    updateLocation();
    return parent;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) FillLayout(org.eclipse.swt.layout.FillLayout) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 7 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.

the class ViewValuePanel method createContents.

@Override
public Control createContents(IResultSetPresentation presentation, Composite parent) {
    this.presentation = presentation;
    viewPlaceholder = new Composite(parent, SWT.NONE);
    viewPlaceholder.setLayout(new FillLayout());
    viewPlaceholder.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (viewPlaceholder.getChildren().length == 0) {
                String hidePanelCmd = ActionUtils.findCommandDescription(ResultSetCommandHandler.CMD_TOGGLE_PANELS, ViewValuePanel.this.presentation.getController().getSite(), true);
                UIUtils.drawMessageOverControl(viewPlaceholder, e, "Select a cell to view/edit value", 0);
                UIUtils.drawMessageOverControl(viewPlaceholder, e, "Press " + hidePanelCmd + " to hide this panel", 20);
            }
        }
    });
    if (this.presentation instanceof ISelectionProvider) {
        final ISelectionProvider selectionProvider = (ISelectionProvider) this.presentation;
        final ISelectionChangedListener selectionListener = new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (ViewValuePanel.this.presentation.getController().getVisiblePanel() == ViewValuePanel.this) {
                    refreshValue(false);
                }
            }
        };
        selectionProvider.addSelectionChangedListener(selectionListener);
        viewPlaceholder.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                selectionProvider.removeSelectionChangedListener(selectionListener);
            }
        });
    }
    return viewPlaceholder;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) PaintListener(org.eclipse.swt.events.PaintListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 8 with PaintListener

use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.

the class NatCombo method createTextControl.

private void createTextControl() {
    text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
    text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(gridData);
    text.forceFocus();
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = dropdownList.getSelectionIndex();
                selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
                if (selectionIndex < 0) {
                    selectionIndex = 0;
                }
                dropdownList.select(selectionIndex);
                text.setText(dropdownList.getSelection()[0]);
            }
        }
    });
    iconImage = GUIHelper.getImage("down_2");
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = 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() {

        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(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) {
            showDropdownControl();
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) GC(org.eclipse.swt.graphics.GC)

Example 9 with PaintListener

use of org.eclipse.swt.events.PaintListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addPaintListenerLorg_eclipse_swt_events_PaintListener.

@Test
public void test_addPaintListenerLorg_eclipse_swt_events_PaintListener() {
    PaintListener listener = e -> eventOccurred = true;
    control.addPaintListener(listener);
    eventOccurred = false;
    Event event = new Event();
    GC gc = event.gc = new GC(control);
    control.notifyListeners(SWT.Paint, event);
    gc.dispose();
    assertTrue(eventOccurred);
    control.removePaintListener(listener);
}
Also used : PaintListener(org.eclipse.swt.events.PaintListener) HelpListener(org.eclipse.swt.events.HelpListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Rectangle(org.eclipse.swt.graphics.Rectangle) ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) KeyEvent(org.eclipse.swt.events.KeyEvent) Assert.fail(org.junit.Assert.fail) Font(org.eclipse.swt.graphics.Font) Widget(org.eclipse.swt.widgets.Widget) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) Assert.assertNotNull(org.junit.Assert.assertNotNull) Monitor(org.eclipse.swt.widgets.Monitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TraverseListener(org.eclipse.swt.events.TraverseListener) Display(org.eclipse.swt.widgets.Display) Consumer(java.util.function.Consumer) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) MouseListener(org.eclipse.swt.events.MouseListener) Assert.assertNull(org.junit.Assert.assertNull) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) Color(org.eclipse.swt.graphics.Color) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) Accessible(org.eclipse.swt.accessibility.Accessible) Assume.assumeTrue(org.junit.Assume.assumeTrue) KeyListener(org.eclipse.swt.events.KeyListener) Menu(org.eclipse.swt.widgets.Menu) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Control(org.eclipse.swt.widgets.Control) PaintListener(org.eclipse.swt.events.PaintListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Example 10 with PaintListener

use of org.eclipse.swt.events.PaintListener in project archi by archimatetool.

the class AboutDialog method createAboutTab.

private void createAboutTab() {
    aboutTabItem = new TabItem(folder, SWT.NONE);
    aboutTabItem.setText(Messages.AboutDialog_1);
    Composite control = new Composite(folder, SWT.NONE);
    control.setLayout(new GridLayout());
    aboutTabItem.setControl(control);
    Composite imageControl = new Composite(control, SWT.NO_BACKGROUND);
    GridData gd = new GridData(GridData.CENTER, GridData.CENTER, true, true);
    imageControl.setLayoutData(gd);
    final int imageHeight;
    // $NON-NLS-1$
    final Image image = IArchiImages.ImageFactory.getImage("splash.bmp");
    if (image != null) {
        ImageData id = image.getImageData();
        gd.widthHint = id.width;
        gd.heightHint = id.height;
        imageHeight = id.height;
    } else {
        gd.widthHint = 500;
        gd.heightHint = 300;
        imageHeight = 300;
    }
    final String version = Messages.AboutDialog_2 + System.getProperty(Application.APPLICATION_VERSIONID);
    final String build = Messages.AboutDialog_3 + System.getProperty(Application.APPLICATION_BUILDID);
    // $NON-NLS-1$
    final String copyright = ArchiPlugin.INSTANCE.getResourceString("%aboutCopyright");
    imageControl.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            int fontHeight = e.gc.getFontMetrics().getHeight() + 2;
            e.gc.drawImage(image, 0, 0);
            e.gc.drawString(version, 19, 166, true);
            e.gc.drawString(build, 19, 166 + fontHeight, true);
            e.gc.drawString(copyright, 12, imageHeight - fontHeight - 5, true);
        }
    });
}
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) ImageData(org.eclipse.swt.graphics.ImageData) GridData(org.eclipse.swt.layout.GridData) Image(org.eclipse.swt.graphics.Image)

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