Search in sources :

Example 21 with PaintListener

use of org.eclipse.swt.events.PaintListener in project tdq-studio-se by Talend.

the class Grid method initListeners.

/**
 * Initialize all listeners.
 */
private void initListeners() {
    disposeListener = new Listener() {

        public void handleEvent(Event e) {
            onDispose(e);
        }
    };
    addListener(SWT.Dispose, disposeListener);
    addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            onPaint(e);
        }
    });
    addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event e) {
            onResize();
        }
    });
    if (getVerticalBar() != null) {
        getVerticalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    if (getHorizontalBar() != null) {
        getHorizontalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event e) {
            onKeyDown(e);
        }
    });
    addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            e.doit = true;
        }
    });
    addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            onMouseDoubleClick(e);
        }

        public void mouseDown(MouseEvent e) {
            onMouseDown(e);
        }

        public void mouseUp(MouseEvent e) {
            onMouseUp(e);
        }
    });
    addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            onMouseMove(e);
        }
    });
    addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent e) {
        }

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

        public void mouseHover(MouseEvent e) {
        }
    });
    addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            onFocusIn();
            redraw();
        }

        public void focusLost(FocusEvent e) {
            redraw();
        }
    });
    // Special code to reflect mouse wheel events if using an external
    // scroller
    addListener(SWT.MouseWheel, new Listener() {

        public void handleEvent(Event e) {
            onMouseWheel(e);
        }
    });
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) TypedListener(org.eclipse.swt.widgets.TypedListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeListener(org.eclipse.swt.events.TreeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 22 with PaintListener

use of org.eclipse.swt.events.PaintListener in project titan.EclipsePlug-ins by eclipse.

the class Overview method overviewAppear.

/**
 * Process overview appear
 */
private void overviewAppear(final int mx, final int my) {
    if (this.overview == null) {
        this.overview = new Shell(this.sv.getShell(), SWT.ON_TOP | SWT.NO_BACKGROUND);
        this.overview.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(final PaintEvent e) {
                Overview.this.sv.drawOverview(e.gc, Overview.this.overview.getClientArea());
            }
        });
    }
    // Always the same..
    this.overview.setForeground(this.sv.viewcontrol.getForeground());
    // Get location of shell (in screen coordinates)
    Point p = toGlobalCoordinates(this.sv.cornerControl, 0, 0);
    int x = p.x;
    int y = p.y;
    int w = this.overviewSize;
    int h = this.overviewSize;
    Rectangle scr = this.sv.getDisplay().getBounds();
    Point ccs = this.sv.cornerControl.getSize();
    try {
        if (this.sv.contentsWidth > this.sv.contentsHeight) {
            float ratio = this.sv.contentsHeight / (float) this.sv.contentsWidth;
            h = (int) (w * ratio);
            if (h < ccs.y) {
                h = ccs.y;
            } else if (h >= scr.height / 2) {
                h = scr.height / 2;
            }
        } else {
            float ratio = this.sv.contentsWidth / (float) this.sv.contentsHeight;
            w = (int) (h * ratio);
            if (w < ccs.x) {
                w = ccs.x;
            } else if (w >= scr.width / 2) {
                w = scr.width / 2;
            }
        }
        this.overviewFactorX = this.sv.contentsWidth / (float) w / 2;
        this.overviewFactorY = this.sv.contentsHeight / (float) h / 2;
    } catch (java.lang.ArithmeticException e) {
    // Do nothing
    }
    if (x <= 0) {
        x = 1;
    }
    if (y <= 0) {
        y = 1;
    }
    x = x - w + ccs.x;
    y = y - h + ccs.y;
    this.overview.setBounds(x, y, w, h);
    this.overview.setVisible(true);
    this.overview.redraw(x, y, w, h, false);
    if (overviewCursor == null) {
        RGB[] rgb = { new RGB(0, 0, 0), new RGB(255, 0, 0) };
        PaletteData pal = new PaletteData(rgb);
        int s = 1;
        byte[] src = new byte[s * s];
        byte[] msk = new byte[s * s];
        for (int i = 0; i < s * s; ++i) {
            src[i] = (byte) 0xFF;
        }
        ImageData iSrc = new ImageData(s, s, 1, pal, 1, src);
        ImageData iMsk = new ImageData(s, s, 1, pal, 1, msk);
        overviewCursor = new Cursor(null, iSrc, iMsk, 0, 0);
    }
    this.sv.cornerControl.setCursor(overviewCursor);
    // convert to global coordinates
    p = toGlobalCoordinates(this.sv.cornerControl, mx, my);
    this.saveCursorX = p.x;
    this.saveCursorY = p.y;
    Rectangle r = this.overview.getClientArea();
    int cx = (int) (r.width * this.sv.contentsX / (float) this.sv.contentsWidth);
    int cy = (int) (r.height * this.sv.contentsY / (float) this.sv.contentsHeight);
    // cx,cy to display's global coordinates
    p = toGlobalCoordinates(this.overview.getParent(), cx, cy);
    cx = p.x;
    cy = p.y;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) Cursor(org.eclipse.swt.graphics.Cursor) Point(org.eclipse.swt.graphics.Point) PaletteData(org.eclipse.swt.graphics.PaletteData) Shell(org.eclipse.swt.widgets.Shell) ImageData(org.eclipse.swt.graphics.ImageData)

Example 23 with PaintListener

use of org.eclipse.swt.events.PaintListener in project titan.EclipsePlug-ins by eclipse.

the class ScrollView method initListerners.

/**
 * Initialize all listeners
 */
private void initListerners() {
    PaintListener localPaintListener = new PaintListener() {

        @Override
        public void paintControl(final PaintEvent event) {
            // use clipping, to reduce cost of paint.
            Rectangle r = event.gc.getClipping();
            int cx = viewToContentsX(r.x);
            int cy = viewToContentsY(r.y);
            drawContents(event.gc, cx, cy, r.width, r.height);
        }
    };
    this.viewcontrol.addPaintListener(localPaintListener);
    MouseMoveListener localMouseMoveListener = new MouseMoveListener() {

        @Override
        public void mouseMove(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseMoveEvent(e);
            e.x = ox;
            e.y = oy;
        }
    };
    this.viewcontrol.addMouseMoveListener(localMouseMoveListener);
    this.viewcontrol.getVerticalBar().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            verticalScrollBarEvent(e);
        }
    });
    MouseTrackListener localMouseTrackListener = new MouseTrackListener() {

        @Override
        public void mouseEnter(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseEnter(e);
            e.x = ox;
            e.y = oy;
        }

        @Override
        public void mouseHover(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseHover(e);
            e.x = ox;
            e.y = oy;
        }

        @Override
        public void mouseExit(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseExit(e);
            e.x = ox;
            e.y = oy;
        }
    };
    this.viewcontrol.addMouseTrackListener(localMouseTrackListener);
    MouseListener localMouseListener = new MouseListener() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseDoubleClickEvent(e);
            e.x = ox;
            e.y = oy;
            // Notify listeners
            Event event = new Event();
            notifyListeners(SWT.MouseDoubleClick, event);
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            ScrollView.this.mouseDownX = viewToContentsX(e.x);
            e.x = ScrollView.this.mouseDownX;
            ScrollView.this.mouseDownY = viewToContentsY(e.y);
            e.y = ScrollView.this.mouseDownY;
            contentsMouseDownEvent(e);
            e.x = ox;
            e.y = oy;
        }

        @Override
        public void mouseUp(final MouseEvent e) {
            int ox = e.x, oy = e.y;
            e.x = viewToContentsX(e.x);
            e.y = viewToContentsY(e.y);
            contentsMouseUpEvent(e);
            e.x = ox;
            e.y = oy;
            ScrollView.this.mouseDownY = -1;
            ScrollView.this.mouseDownX = -1;
        }
    };
    this.viewcontrol.addMouseListener(localMouseListener);
    KeyListener localKeyListener = new KeyListener() {

        @Override
        public void keyPressed(final KeyEvent e) {
            keyPressedEvent(e);
        }

        @Override
        public void keyReleased(final KeyEvent e) {
            keyReleasedEvent(e);
        }
    };
    this.viewcontrol.addKeyListener(localKeyListener);
    getVerticalBar().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            setContentsPos(ScrollView.this.contentsX, getVerticalBar().getSelection());
            // force focus on viewcontrol_ so we got future mouse wheel's scroll events
            if (!ScrollView.this.viewcontrol.isFocusControl()) {
                ScrollView.this.viewcontrol.setFocus();
            }
        }
    });
    if (this.viewcontrol.getVerticalBar() != null) {
        // add view control hidden scrollbar listener to get mouse wheel ...
        this.viewcontrol.getVerticalBar().addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                ScrollBar b = ScrollView.this.viewcontrol.getVerticalBar();
                setContentsPos(ScrollView.this.contentsX, b.getSelection());
                // change "real" vertical bar selection too
                getVerticalBar().setSelection(b.getSelection());
            }
        });
    }
    getHorizontalBar().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            setContentsPos(getHorizontalBar().getSelection(), ScrollView.this.contentsY);
            // force focus on viewcontrol_ so we got future mouse wheel's scroll events
            if (!ScrollView.this.viewcontrol.isFocusControl()) {
                ScrollView.this.viewcontrol.setFocus();
            }
        }
    });
    if (this.viewcontrol.getHorizontalBar() != null) {
        this.viewcontrol.getHorizontalBar().addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                ScrollBar b = ScrollView.this.viewcontrol.getHorizontalBar();
                setContentsPos(b.getSelection(), ScrollView.this.contentsY);
                // change "real" vertical bar selection too
                getHorizontalBar().setSelection(b.getSelection());
            }
        });
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseListener(org.eclipse.swt.events.MouseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 24 with PaintListener

use of org.eclipse.swt.events.PaintListener in project BiglyBT by BiglySoftware.

the class MultiPlotGraphic method initialize.

public void initialize(Canvas canvas, boolean is_active) {
    super.initialize(canvas);
    drawCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (bufferImage != null && !bufferImage.isDisposed()) {
                Rectangle bounds = bufferImage.getBounds();
                if (bounds.width >= e.width && bounds.height >= e.height) {
                    e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
                }
            }
        }
    });
    drawCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            drawChart(true);
        }
    });
    setActive(is_active);
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ParameterListener(com.biglybt.core.config.ParameterListener) Listener(org.eclipse.swt.widgets.Listener) PaintListener(org.eclipse.swt.events.PaintListener) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) TimerEvent(com.biglybt.core.util.TimerEvent)

Example 25 with PaintListener

use of org.eclipse.swt.events.PaintListener in project BiglyBT by BiglySoftware.

the class UIFunctionsImpl method showCoreWaitDlg.

// @see UIFunctionsSWT#showCoreWaitDlg()
@Override
public Shell showCoreWaitDlg() {
    final SkinnedDialog closeDialog = new SkinnedDialog("skin3_dlg_coreloading", "coreloading.body", SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
    closeDialog.setTitle(MessageText.getString("dlg.corewait.title"));
    SWTSkin skin = closeDialog.getSkin();
    SWTSkinObjectButton soButton = (SWTSkinObjectButton) skin.getSkinObject("close");
    final SWTSkinObjectText soWaitTask = (SWTSkinObjectText) skin.getSkinObject("task");
    final SWTSkinObject soWaitProgress = skin.getSkinObject("progress");
    if (soWaitProgress != null) {
        soWaitProgress.getControl().addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                Control c = (Control) e.widget;
                Point size = c.getSize();
                e.gc.setBackground(ColorCache.getColor(e.display, "#23a7df"));
                Object data = soWaitProgress.getData("progress");
                if (data instanceof Long) {
                    int waitProgress = ((Long) data).intValue();
                    int breakX = size.x * waitProgress / 100;
                    e.gc.fillRectangle(0, 0, breakX, size.y);
                    e.gc.setBackground(ColorCache.getColor(e.display, "#cccccc"));
                    e.gc.fillRectangle(breakX, 0, size.x - breakX, size.y);
                }
            }
        });
    }
    if (!CoreFactory.isCoreRunning()) {
        final Initializer initializer = Initializer.getLastInitializer();
        if (initializer != null) {
            initializer.addListener(new InitializerListener() {

                @Override
                public void reportPercent(final int percent) {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (soWaitProgress != null && !soWaitProgress.isDisposed()) {
                                soWaitProgress.setData("progress", new Long(percent));
                                soWaitProgress.getControl().redraw();
                                soWaitProgress.getControl().update();
                            }
                        }
                    });
                    if (percent > 100) {
                        initializer.removeListener(this);
                    }
                }

                @Override
                public void reportCurrentTask(String currentTask) {
                    if (soWaitTask != null && !soWaitTask.isDisposed()) {
                        soWaitTask.setText(currentTask);
                    }
                }
            });
        }
    }
    if (soButton != null) {
        soButton.addSelectionListener(new ButtonListenerAdapter() {

            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                closeDialog.close();
            }
        });
    }
    closeDialog.addCloseListener(new SkinnedDialogClosedListener() {

        @Override
        public void skinDialogClosed(SkinnedDialog dialog) {
        }
    });
    closeDialog.open();
    return closeDialog.getShell();
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) PaintListener(org.eclipse.swt.events.PaintListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) PluginInitializer(com.biglybt.pifimpl.local.PluginInitializer) ButtonListenerAdapter(com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)

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