Search in sources :

Example 61 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.text by eclipse.

the class AbstractInformationControl method addResizeSupportIfNecessary.

private void addResizeSupportIfNecessary(final Composite bars) {
    // XXX: workarounds for
    // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=219139 : API to add resize grip / grow box in lower right corner of shell
    // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=23980 : platform specific shell resize behavior
    String platform = SWT.getPlatform();
    // $NON-NLS-1$
    final boolean isWin = platform.equals("win32");
    if (// $NON-NLS-1$
    !isWin && !platform.equals("gtk"))
        return;
    final Canvas resizer = new Canvas(bars, SWT.NONE);
    int size = getResizeHandleSize(bars);
    GridData data = new GridData(SWT.END, SWT.END, false, true);
    data.widthHint = size;
    data.heightHint = size;
    resizer.setLayoutData(data);
    resizer.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            Point s = resizer.getSize();
            int x = s.x - 2;
            int y = s.y - 2;
            int min = Math.min(x, y);
            if (isWin) {
                // draw dots
                e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                int end = min - 1;
                for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
                end--;
                e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
                for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
            } else {
                // draw diagonal lines
                e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
                for (int i = 1; i < min; i += 4) {
                    e.gc.drawLine(i, y, x, i);
                }
                e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                for (int i = 2; i < min; i += 4) {
                    e.gc.drawLine(i, y, x, i);
                }
            }
        }
    });
    final boolean isRTL = (resizer.getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
    resizer.setCursor(resizer.getDisplay().getSystemCursor(isRTL ? SWT.CURSOR_SIZESW : SWT.CURSOR_SIZESE));
    MouseAdapter resizeSupport = new MouseAdapter() {

        private MouseMoveListener fResizeListener;

        @Override
        public void mouseDown(MouseEvent e) {
            Rectangle shellBounds = fShell.getBounds();
            final int shellX = shellBounds.x;
            final int shellY = shellBounds.y;
            final int shellWidth = shellBounds.width;
            final int shellHeight = shellBounds.height;
            Point mouseLoc = resizer.toDisplay(e.x, e.y);
            final int mouseX = mouseLoc.x;
            final int mouseY = mouseLoc.y;
            fResizeListener = new MouseMoveListener() {

                @Override
                public void mouseMove(MouseEvent e2) {
                    Point mouseLoc2 = resizer.toDisplay(e2.x, e2.y);
                    int dx = mouseLoc2.x - mouseX;
                    int dy = mouseLoc2.y - mouseY;
                    if (isRTL) {
                        setLocation(new Point(shellX + dx, shellY));
                        setSize(shellWidth - dx, shellHeight + dy);
                    } else {
                        setSize(shellWidth + dx, shellHeight + dy);
                    }
                }
            };
            resizer.addMouseMoveListener(fResizeListener);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            resizer.removeMouseMoveListener(fResizeListener);
            fResizeListener = null;
        }
    };
    resizer.addMouseListener(resizeSupport);
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) GridData(org.eclipse.swt.layout.GridData)

Example 62 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.text by eclipse.

the class ChangeRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    fParentRuler = parentRuler;
    fCachedTextViewer = parentRuler.getTextViewer();
    fCachedTextWidget = fCachedTextViewer.getTextWidget();
    fCanvas = new Canvas(parentControl, SWT.NONE);
    fCanvas.setBackground(getBackground());
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            if (fCachedTextViewer != null)
                doubleBufferPaint(event.gc);
        }
    });
    fCanvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fCachedTextViewer = null;
            fCachedTextWidget = null;
        }
    });
    fCanvas.addMouseListener(fMouseHandler);
    fCanvas.addMouseMoveListener(fMouseHandler);
    if (fCachedTextViewer != null) {
        fCachedTextViewer.addViewportListener(fInternalListener);
        fCachedTextViewer.addTextListener(fInternalListener);
    }
    fRevisionPainter.setParentRuler(parentRuler);
    fDiffPainter.setParentRuler(parentRuler);
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 63 with PaintEvent

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

the class ConfigureMetaNodePortsPage method createPreviewPanel.

private void createPreviewPanel(final Composite parent) {
    m_previewPanel = new Composite(parent, SWT.FILL | SWT.BORDER);
    m_previewPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER));
    m_previewPanel.setLayout(new FillLayout());
    m_previewPanel.addPaintListener(new PaintListener() {

        private static final int IMAGE_HEIGHT = 30;

        private static final int IMAGE_WIDTH = 30;

        private static final int PORT_BAR_HEIGHT = 40;

        private final int PORT_SIZE = AbstractPortFigure.getPortSizeNode();

        private int m_top;

        @Override
        public void paintControl(final PaintEvent e) {
            GC gc = e.gc;
            Rectangle bounds = m_previewPanel.getBounds();
            m_top = (bounds.height / 2) - (IMAGE_HEIGHT / 2) - (PORT_SIZE / 2);
            drawInPorts(gc);
            drawOutPorts(gc);
            gc.drawImage(ImageRepository.getImage(KNIMEEditorPlugin.PLUGIN_ID, "/icons/meta/meta_custom_preview.png"), (bounds.width / 2) - (IMAGE_WIDTH / 2), (bounds.height / 2) - (IMAGE_HEIGHT / 2));
        }

        private void drawInPorts(final GC gc) {
            Rectangle b = m_previewPanel.getBounds();
            int offset = (PORT_BAR_HEIGHT + PORT_SIZE) / (m_inPortList.size() + 1);
            int left = (b.width / 2) - (IMAGE_WIDTH / 2);
            int i = 0;
            for (MetaPortInfo inPort : m_inPortList) {
                int y = m_top + (((i + 1) * offset) - (PORT_SIZE));
                if (inPort.getType().equals(BufferedDataTable.TYPE)) {
                    gc.drawPolygon(new int[] { left - PORT_SIZE, y, left, y + (PORT_SIZE / 2), left - PORT_SIZE, y + PORT_SIZE });
                } else if (PMMLPortObject.TYPE.isSuperTypeOf(inPort.getType())) {
                    gc.setBackground(ColorConstants.blue);
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(DatabasePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(FlowVariablePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
                    gc.fillOval(left - PORT_SIZE - 1, y - 1, PORT_SIZE + 1, PORT_SIZE + 1);
                } else {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
                    gc.fillRectangle(left - PORT_SIZE, y, PORT_SIZE, PORT_SIZE);
                }
                i++;
            }
        }

        private void drawOutPorts(final GC gc) {
            Rectangle b = m_previewPanel.getBounds();
            int right = (b.width / 2) + (IMAGE_WIDTH / 2) + 2;
            int offset = (PORT_BAR_HEIGHT + PORT_SIZE) / (m_outPortList.size() + 1);
            int i = 0;
            for (MetaPortInfo inPort : m_outPortList) {
                int y = m_top + (((i + 1) * offset) - (PORT_SIZE));
                if (inPort.getType().equals(BufferedDataTable.TYPE)) {
                    gc.drawPolygon(new int[] { right, y, right + PORT_SIZE, y + (PORT_SIZE / 2), right, y + PORT_SIZE });
                } else if (PMMLPortObject.TYPE.isSuperTypeOf(inPort.getType())) {
                    gc.setBackground(ColorConstants.blue);
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(DatabasePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else if (inPort.getType().equals(FlowVariablePortObject.TYPE)) {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                } else {
                    gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
                    gc.fillRectangle(right, y, PORT_SIZE, PORT_SIZE);
                }
                i++;
            }
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) FillLayout(org.eclipse.swt.layout.FillLayout) GC(org.eclipse.swt.graphics.GC)

Example 64 with PaintEvent

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

the class IconSection method createControls.

@Override
protected void createControls(Composite parent) {
    createLabel(parent, Messages.IconSection_9, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    final int canvasSize = IIconic.MAX_IMAGE_SIZE;
    fCanvas = new Canvas(parent, SWT.BORDER);
    getWidgetFactory().adapt(fCanvas);
    GridData gd = new GridData(SWT.NONE, SWT.NONE, false, false);
    gd.widthHint = canvasSize;
    gd.heightHint = canvasSize;
    fCanvas.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fCanvas.setLayout(layout);
    fCanvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            disposeImage();
        }
    });
    fCanvas.addListener(SWT.MouseDoubleClick, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (!isLocked(getFirstSelectedObject())) {
                chooseImage();
            }
        }
    });
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (fImage != null) {
                Rectangle bounds = fImage.getBounds();
                int x = (canvasSize - bounds.width) / 2;
                int y = (canvasSize - bounds.height) / 2;
                e.gc.drawImage(fImage, x, y);
            }
        }
    });
    String tooltip = Messages.IconSection_10;
    fCanvas.setToolTipText(tooltip);
    DropTarget target = new DropTarget(fCanvas, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    target.setTransfer(new Transfer[] { FileTransfer.getInstance() });
    target.addDropListener(new DropTargetAdapter() {

        @Override
        public void drop(DropTargetEvent event) {
            if (event.data instanceof String[]) {
                if (!isLocked(getFirstSelectedObject())) {
                    File file = new File(((String[]) event.data)[0]);
                    setImage(file);
                }
            }
        }
    });
    // Image Button
    createImageButton(parent);
    // Position
    createLabel(parent, Messages.IconSection_11, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    fComboPosition = new Combo(parent, SWT.READ_ONLY);
    fComboPosition.setItems(fComboPositionItems);
    gd = new GridData(SWT.NONE, SWT.NONE, false, false);
    fComboPosition.setLayoutData(gd);
    fComboPosition.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CompoundCommand result = new CompoundCommand();
            for (EObject iconic : getEObjects()) {
                if (isAlive(iconic)) {
                    Command cmd = new EObjectFeatureCommand(Messages.IconSection_12, iconic, ICanvasPackage.Literals.ICONIC__IMAGE_POSITION, fComboPosition.getSelectionIndex());
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    });
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintListener(org.eclipse.swt.events.PaintListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) Rectangle(org.eclipse.swt.graphics.Rectangle) Combo(org.eclipse.swt.widgets.Combo) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) GridLayout(org.eclipse.swt.layout.GridLayout) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) File(java.io.File)

Example 65 with PaintEvent

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

the class Tab method log.

/**
 * Logs an untyped event to the event console.
 */
void log(Event event) {
    int i = 0;
    while (i < EVENT_INFO.length) {
        if (EVENT_INFO[i].type == event.type)
            break;
        i++;
    }
    String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
    if (!untypedEvents) {
        switch(event.type) {
            case SWT.KeyDown:
            case SWT.KeyUp:
                toString += new KeyEvent(event).toString();
                break;
            case SWT.MouseDown:
            case SWT.MouseUp:
            case SWT.MouseMove:
            case SWT.MouseEnter:
            case SWT.MouseExit:
            case SWT.MouseDoubleClick:
            case SWT.MouseWheel:
            case SWT.MouseHover:
                toString += new MouseEvent(event).toString();
                break;
            case SWT.Paint:
                toString += new PaintEvent(event).toString();
                break;
            case SWT.Move:
            case SWT.Resize:
                toString += new ControlEvent(event).toString();
                break;
            case SWT.Dispose:
                toString += new DisposeEvent(event).toString();
                break;
            case SWT.Selection:
            case SWT.DefaultSelection:
                toString += new SelectionEvent(event).toString();
                break;
            case SWT.FocusIn:
            case SWT.FocusOut:
                toString += new FocusEvent(event).toString();
                break;
            case SWT.Expand:
            case SWT.Collapse:
                toString += new TreeEvent(event).toString();
                break;
            case SWT.Iconify:
            case SWT.Deiconify:
            case SWT.Close:
            case SWT.Activate:
            case SWT.Deactivate:
                toString += new ShellEvent(event).toString();
                break;
            case SWT.Show:
            case SWT.Hide:
                toString += (event.widget instanceof Menu) ? new MenuEvent(event).toString() : event.toString();
                break;
            case SWT.Modify:
                toString += new ModifyEvent(event).toString();
                break;
            case SWT.Verify:
                toString += new VerifyEvent(event).toString();
                break;
            case SWT.Help:
                toString += new HelpEvent(event).toString();
                break;
            case SWT.Arm:
                toString += new ArmEvent(event).toString();
                break;
            case SWT.Traverse:
                toString += new TraverseEvent(event).toString();
                break;
            case SWT.HardKeyDown:
            case SWT.HardKeyUp:
            case SWT.DragDetect:
            case SWT.MenuDetect:
            case SWT.SetData:
            default:
                toString += event.toString();
        }
    } else {
        toString += event.toString();
    }
    log(toString);
    /* Return values for event fields. */
    int mask = EVENT_INFO[i].setFields;
    if (!ignore && mask != 0) {
        Event setFieldsEvent = EVENT_INFO[i].event;
        if ((mask & DOIT) != 0)
            event.doit = setFieldsEvent.doit;
        if ((mask & DETAIL) != 0)
            event.detail = setFieldsEvent.detail;
        if ((mask & TEXT) != 0)
            event.text = setFieldsEvent.text;
        if ((mask & X) != 0)
            event.x = setFieldsEvent.x;
        if ((mask & Y) != 0)
            event.y = setFieldsEvent.y;
        if ((mask & WIDTH) != 0)
            event.width = setFieldsEvent.width;
        if ((mask & HEIGHT) != 0)
            event.height = setFieldsEvent.height;
        eventConsole.append(ControlExample.getResourceString("Returning"));
        ignore = true;
        log(event);
        ignore = false;
    }
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TypedEvent(org.eclipse.swt.events.TypedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)96 PaintListener (org.eclipse.swt.events.PaintListener)92 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 MouseEvent (org.eclipse.swt.events.MouseEvent)27 GridData (org.eclipse.swt.layout.GridData)26 Point (org.eclipse.swt.graphics.Point)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 DisposeEvent (org.eclipse.swt.events.DisposeEvent)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DisposeListener (org.eclipse.swt.events.DisposeListener)15 FillLayout (org.eclipse.swt.layout.FillLayout)15 Event (org.eclipse.swt.widgets.Event)15 MouseAdapter (org.eclipse.swt.events.MouseAdapter)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 ControlEvent (org.eclipse.swt.events.ControlEvent)12 Control (org.eclipse.swt.widgets.Control)12 GC (org.eclipse.swt.graphics.GC)11 Listener (org.eclipse.swt.widgets.Listener)11