Search in sources :

Example 21 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project portfolio by buchen.

the class ReturnsVolatilityChartView method createBody.

@Override
protected Composite createBody(Composite parent) {
    cache = make(DataSeriesCache.class);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    resources = new LocalResourceManager(JFaceResources.getResources(), composite);
    chart = new ScatterChart(composite);
    chart.getTitle().setVisible(false);
    IAxis xAxis = chart.getAxisSet().getXAxis(0);
    xAxis.getTitle().setText(Messages.LabelVolatility);
    // $NON-NLS-1$
    xAxis.getTick().setFormat(new DecimalFormat("0.##%"));
    IAxis yAxis = chart.getAxisSet().getYAxis(0);
    yAxis.getTitle().setText(Messages.LabelPeformanceTTWROR);
    // $NON-NLS-1$
    yAxis.getTick().setFormat(new DecimalFormat("0.##%"));
    ((IPlotArea) chart.getPlotArea()).addCustomPaintListener(new ICustomPaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            int y = xAxis.getPixelCoordinate(0);
            e.gc.drawLine(y, 0, y, e.height);
            int x = yAxis.getPixelCoordinate(0);
            e.gc.drawLine(0, x, e.width, x);
        }

        @Override
        public boolean drawBehindSeries() {
            return true;
        }
    });
    configurator = new DataSeriesConfigurator(this, DataSeries.UseCase.RETURN_VOLATILITY);
    configurator.addListener(() -> updateChart());
    DataSeriesChartLegend legend = new DataSeriesChartLegend(composite, configurator);
    // $NON-NLS-1$ //$NON-NLS-2$
    updateTitle(Messages.LabelHistoricalReturnsAndVolatiltity + " (" + configurator.getConfigurationName() + ")");
    chart.getTitle().setText(getTitle());
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 0).applyTo(composite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(chart);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.FILL).applyTo(legend);
    setChartSeries();
    return composite;
}
Also used : ICustomPaintListener(org.swtchart.ICustomPaintListener) PaintEvent(org.eclipse.swt.events.PaintEvent) DataSeriesCache(name.abuchen.portfolio.ui.views.dataseries.DataSeriesCache) Composite(org.eclipse.swt.widgets.Composite) DataSeriesConfigurator(name.abuchen.portfolio.ui.views.dataseries.DataSeriesConfigurator) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ScatterChart(name.abuchen.portfolio.ui.util.chart.ScatterChart) DecimalFormat(java.text.DecimalFormat) IPlotArea(org.swtchart.IPlotArea) DataSeriesChartLegend(name.abuchen.portfolio.ui.views.dataseries.DataSeriesChartLegend) IAxis(org.swtchart.IAxis)

Example 22 with PaintEvent

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

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

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

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

PaintEvent (org.eclipse.swt.events.PaintEvent)92 PaintListener (org.eclipse.swt.events.PaintListener)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)30 MouseEvent (org.eclipse.swt.events.MouseEvent)28 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 DisposeEvent (org.eclipse.swt.events.DisposeEvent)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 GC (org.eclipse.swt.graphics.GC)11 Label (org.eclipse.swt.widgets.Label)10