Search in sources :

Example 56 with PaintListener

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

the class VerticalRuler method createControl.

@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
    fTextViewer = textViewer;
    fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
    fCanvas.addPaintListener(new PaintListener() {

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

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fTextViewer = null;
        }
    });
    fCanvas.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent event) {
        }

        @Override
        public void mouseDown(MouseEvent event) {
            fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
        }
    });
    if (fTextViewer != null) {
        fTextViewer.addViewportListener(fInternalListener);
        fTextViewer.addTextListener(fInternalListener);
    }
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 57 with PaintListener

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

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

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

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

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