Search in sources :

Example 31 with PaintListener

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

the class ConfigurationBlock method highlight.

protected void highlight(final Composite parent, final Label labelControl, final Combo comboBox, final int color) {
    class HighlightPainter implements PaintListener {

        private int fColor = color;

        @Override
        public void paintControl(PaintEvent e) {
            if (((GridData) labelControl.getLayoutData()).exclude) {
                parent.removePaintListener(this);
                labelControl.setData(null);
                return;
            }
            int GAP = 7;
            int ARROW = 3;
            Rectangle l = labelControl.getBounds();
            Point c = comboBox.getLocation();
            e.gc.setForeground(e.display.getSystemColor(fColor));
            int x2 = c.x - GAP;
            int y = l.y + l.height / 2 + 1;
            e.gc.drawLine(l.x + l.width + GAP, y, x2, y);
            e.gc.drawLine(x2 - ARROW, y - ARROW, x2, y);
            e.gc.drawLine(x2 - ARROW, y + ARROW, x2, y);
        }
    }
    Object data = labelControl.getData();
    if (data == null) {
        if (color != HIGHLIGHT_NONE) {
            PaintListener painter = new HighlightPainter();
            parent.addPaintListener(painter);
            labelControl.setData(painter);
        } else {
            return;
        }
    } else {
        if (color == HIGHLIGHT_NONE) {
            parent.removePaintListener((PaintListener) data);
            labelControl.setData(null);
        } else if (color != ((HighlightPainter) data).fColor) {
            ((HighlightPainter) data).fColor = color;
        } else {
            return;
        }
    }
    parent.redraw();
    parent.update();
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 32 with PaintListener

use of org.eclipse.swt.events.PaintListener in project polymap4-core by Polymap4.

the class ColorChooser method drawColorBoxMarker.

private void drawColorBoxMarker(Composite panelBody, int x, int y) {
    int adjustedX = x - 10;
    if (adjustedX < 0) {
        adjustedX = 0;
    }
    int adjustedY = y - 10;
    if (adjustedY < 0) {
        adjustedY = 0;
    }
    colorBoxMarker.setBounds(adjustedX, adjustedY, 20, 20);
    colorBoxMarker.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    colorBoxMarker.setBackground(null);
    colorBoxMarker.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_BLACK));
            e.gc.drawOval(1, 1, 18, 18);
            e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_WHITE));
            e.gc.drawOval(2, 2, 16, 16);
            e.gc.drawOval(3, 3, 14, 14);
            e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_BLACK));
            e.gc.drawOval(4, 4, 12, 12);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener)

Example 33 with PaintListener

use of org.eclipse.swt.events.PaintListener in project polymap4-core by Polymap4.

the class ColorChooser method setColorBoxColor.

private void setColorBoxColor(Composite panelBody, RGB rgb) {
    Integer[][] colorBoxColors = new Integer[COLORBOX_WIDTH][COLORBOX_HEIGHT];
    if (rgb == null) {
        rgb = getDefaultRGB();
    }
    Color color = new Color(panelBody.getDisplay(), rgb);
    float[] hsb = new float[3];
    java.awt.Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
    int rgbValue;
    float saturationFilter = hsb[1] == 0.0 ? 0.0f : 1.0f;
    float newS, newB;
    BufferedImage bi = new BufferedImage(COLORBOX_WIDTH, COLORBOX_HEIGHT, BufferedImage.TYPE_INT_RGB);
    boolean markerSet = false;
    int markerPosX = 0, markerPosY = 0;
    for (int w = 0; w < COLORBOX_WIDTH; w += 1) {
        for (int h = COLORBOX_HEIGHT - 1; h >= 0; h -= 1) {
            newS = saturationFilter * Double.valueOf((double) w / COLORBOX_WIDTH).floatValue();
            newB = Double.valueOf((double) h / COLORBOX_HEIGHT).floatValue();
            rgbValue = java.awt.Color.HSBtoRGB(hsb[0], newS, newB);
            colorBoxColors[w][h] = rgbValue;
            if (!markerSet && Math.abs(newS - hsb[1]) <= 0.01 && Math.abs(newB - hsb[2]) <= 0.01) {
                if (colorBox.getBounds().contains(w, h)) {
                    markerPosX = w;
                    markerPosY = h;
                    markerSet = true;
                }
            }
            bi.setRGB(w, h, rgbValue);
        }
    }
    final PaletteData palette = new PaletteData(0xff0000, 0xff00, 0xff);
    DataBuffer dataBuffer = bi.getData().getDataBuffer();
    int[] data = ((DataBufferInt) dataBuffer).getData();
    ImageData imageData = new ImageData(bi.getWidth(), bi.getHeight(), 24, palette);
    imageData.setPixels(0, 0, data.length, data, 0);
    if (colorBoxImage != null) {
        colorBoxImage.dispose();
    }
    colorBoxImage = new Image(Display.getDefault(), imageData);
    GC gc = new GC(colorBox);
    gc.drawImage(colorBoxImage, 0, 0);
    gc.dispose();
    int finalMarkerPosX = markerPosX, finalMarkerPosY = markerPosY;
    colorBoxMarker.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            drawColorBoxMarker(panelBody, finalMarkerPosX, finalMarkerPosY);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Color(org.eclipse.swt.graphics.Color) DataBufferInt(java.awt.image.DataBufferInt) Image(org.eclipse.swt.graphics.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) PaletteData(org.eclipse.swt.graphics.PaletteData) ImageData(org.eclipse.swt.graphics.ImageData) GC(org.eclipse.swt.graphics.GC) DataBuffer(java.awt.image.DataBuffer)

Example 34 with PaintListener

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

the class ServiceAvailability method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    final Composite clientArea = new Composite(parent, SWT.NONE);
    colors = new ColorCache(clientArea);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    clientArea.setLayout(layout);
    dayChart = createChart(clientArea, Messages.get().ServiceAvailability_Today);
    weekChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisWeek);
    monthChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisMonth);
    Canvas legend = new Canvas(clientArea, SWT.NONE);
    legend.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            paintLegend(e.gc);
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    legend.setLayoutData(gd);
    listener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (!clientArea.isDisposed() && (n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getSubCode() == object.getObjectId())) {
                clientArea.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        object = (ServiceContainer) n.getObject();
                        refresh();
                    }
                });
            }
        }
    };
    ConsoleSharedData.getSession().addListener(listener);
}
Also used : ColorCache(org.netxms.ui.eclipse.tools.ColorCache) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 35 with PaintListener

use of org.eclipse.swt.events.PaintListener in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTWidget method setupCanvas.

private void setupCanvas() {
    resizeCanvas();
    canvas.setBackground(WHITE);
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent e) {
            if (lastControl != null) {
                adjustView(lastControl);
            }
            if (root != null) {
                root.visit(node -> {
                    if (node.data().getFirst().isVisible()) {
                        if (node.parent() != null) {
                            drawArrowFromParent(e.gc, node);
                        }
                        return NodeVisitor.AfterVisitBehaviour.Continue;
                    }
                    return NodeVisitor.AfterVisitBehaviour.Abort;
                });
            }
        }
    });
}
Also used : IASTPreprocessorIncludeStatement(org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement) NodeVisitor(ch.hsr.ifs.pasta.tree.NodeVisitor) PaintListener(org.eclipse.swt.events.PaintListener) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) LinkedList(java.util.LinkedList) PreferenceConstants(ch.hsr.ifs.pasta.plugin.preferences.PreferenceConstants) Cursor(org.eclipse.swt.graphics.Cursor) Button(org.eclipse.swt.widgets.Button) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) IASTFileLocation(org.eclipse.cdt.core.dom.ast.IASTFileLocation) Display(org.eclipse.swt.widgets.Display) CUIPlugin(org.eclipse.cdt.ui.CUIPlugin) Node(ch.hsr.ifs.pasta.tree.Node) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) Color(org.eclipse.swt.graphics.Color) TextSelection(org.eclipse.jface.text.TextSelection) SWT(org.eclipse.swt.SWT) ICPPASTTranslationUnit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Control(org.eclipse.swt.widgets.Control) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener)

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