Search in sources :

Example 46 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 + e.x) && bounds.height >= (e.height + e.y)) {
                    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) Listener(org.eclipse.swt.widgets.Listener) ParameterListener(com.biglybt.core.config.ParameterListener) 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 47 with PaintEvent

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

the class ProgressWindow method showDialog.

protected void showDialog(Shell _shell, CoreOperation _core_op) {
    shell = _shell;
    if (shell == null || shell.isDisposed()) {
        return;
    }
    boolean closeable = (shell.getStyle() & SWT.CLOSE) != 0;
    shell.setText(MessageText.getString("progress.window.title"));
    CoreOperationTask task = _core_op == null ? null : _core_op.getTask();
    ProgressCallback progress = task == null ? null : task.getProgressCallback();
    boolean alreadyPositioned = Utils.linkShellMetricsToConfig(shell, "com.biglybt.ui.swt.progress.ProgressWindow" + "." + _core_op.getOperationType());
    Utils.setShellIcon(shell);
    if (!closeable) {
        shell.addListener(SWT.Close, (ev) -> {
            ev.doit = false;
        });
    }
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    Color bg = (Utils.isDarkAppearanceNative() || Utils.isDarkAppearancePartial()) ? null : Colors.white;
    shell.setBackground(bg);
    if (task != null) {
        String name = task.getName();
        if (name != null) {
            Label lName = new Label(shell, SWT.NONE);
            FontData fontData = lName.getFont().getFontData()[0];
            Font bold_font = new Font(shell.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
            lName.setText(name);
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            lName.setLayoutData(gridData);
            lName.setBackground(bg);
            lName.setFont(bold_font);
            lName.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent arg0) {
                    bold_font.dispose();
                }
            });
            if (progress != null && (progress.getSupportedTaskStates() & ProgressCallback.ST_SUBTASKS) != 0) {
                subtask_label = new Label(shell, SWT.NONE);
                gridData = new GridData(GridData.FILL_HORIZONTAL);
                gridData.horizontalSpan = 2;
                gridData.horizontalIndent = 25;
                subtask_label.setLayoutData(gridData);
                subtask_label.setBackground(bg);
            }
        }
    }
    spinImages = ImageLoader.getInstance().getImages("working");
    if (spinImages == null || spinImages.length == 0) {
        new Label(shell, SWT.NULL);
    } else {
        final Rectangle spinBounds = spinImages[0].getBounds();
        final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED) {

            @Override
            public Point computeSize(int wHint, int hHint, boolean changed) {
                return (new Point(spinBounds.width, spinBounds.height));
            }
        };
        canvas.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                e.gc.drawImage(spinImages[curSpinIndex], 0, 0);
            }
        });
        Utils.execSWTThreadLater(100, new AERunnable() {

            @Override
            public void runSupport() {
                if (canvas == null || canvas.isDisposed()) {
                    return;
                }
                canvas.redraw();
                if (curSpinIndex == spinImages.length - 1) {
                    curSpinIndex = 0;
                } else {
                    curSpinIndex++;
                }
                if (progress != null && progress_bar != null) {
                    if (progress_bar.isDisposed()) {
                        return;
                    }
                    int p = progress.getProgress();
                    progress_bar.setSelection(p);
                    if (subtask_label != null) {
                        String st = progress.getSubTaskName();
                        if (st == null) {
                            st = "";
                        }
                        subtask_label.setText(st);
                    }
                }
                Utils.execSWTThreadLater(100, this);
            }
        });
        canvas.setBackground(bg);
    }
    Label label = new Label(shell, SWT.NONE);
    label.setText(MessageText.getString(resource));
    GridData gridData = new GridData();
    label.setLayoutData(gridData);
    label.setBackground(bg);
    if (progress != null) {
        Composite compProg = new Composite(shell, SWT.BORDER);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 2;
        compProg.setLayoutData(gridData);
        GridLayout layoutProgress = new GridLayout();
        layoutProgress.numColumns = 1;
        layoutProgress.marginWidth = layoutProgress.marginHeight = 0;
        compProg.setLayout(layoutProgress);
        compProg.setBackground(bg);
        progress_bar = new ProgressBar(compProg, SWT.HORIZONTAL);
        progress_bar.setMinimum(0);
        progress_bar.setMaximum(1000);
        progress_bar.setBackground(bg);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.widthHint = 400;
        progress_bar.setLayoutData(gridData);
        int states = progress.getSupportedTaskStates();
        if ((states & ProgressCallback.ST_BUTTONS) != 0) {
            Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
            gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            labelSeparator.setLayoutData(gridData);
            // buttons
            boolean has_pause_resume = (states & (ProgressCallback.ST_PAUSE | ProgressCallback.ST_RESUME)) != 0;
            boolean has_cancel = (states & ProgressCallback.ST_CANCEL) != 0;
            if (!has_pause_resume) {
                has_cancel = true;
            }
            int num_buttons = 0;
            if (has_pause_resume)
                num_buttons += 2;
            if (has_cancel)
                num_buttons++;
            Composite comp = new Composite(shell, SWT.NULL);
            gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
            gridData.grabExcessHorizontalSpace = true;
            gridData.horizontalSpan = 2;
            comp.setLayoutData(gridData);
            GridLayout layoutButtons = new GridLayout();
            layoutButtons.numColumns = num_buttons;
            comp.setLayout(layoutButtons);
            comp.setBackground(bg);
            List<Button> buttons = new ArrayList<>();
            Button bPause;
            Button bResume;
            Button bCancel;
            if (has_pause_resume) {
                bPause = new Button(comp, SWT.PUSH);
                bPause.setText(MessageText.getString("v3.MainWindow.button.pause"));
                gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
                gridData.grabExcessHorizontalSpace = true;
                // gridData.widthHint = 70;
                bPause.setLayoutData(gridData);
                buttons.add(bPause);
                bResume = new Button(comp, SWT.PUSH);
                bResume.setText(MessageText.getString("v3.MainWindow.button.resume"));
                gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
                gridData.grabExcessHorizontalSpace = false;
                // gridData.widthHint = 70;
                bResume.setLayoutData(gridData);
                buttons.add(bResume);
            } else {
                bPause = null;
                bResume = null;
            }
            if (has_cancel) {
                bCancel = new Button(comp, SWT.PUSH);
                bCancel.setText(MessageText.getString("UpdateWindow.cancel"));
                gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
                gridData.grabExcessHorizontalSpace = false;
                // gridData.widthHint = 70;
                bCancel.setLayoutData(gridData);
                buttons.add(bCancel);
            } else {
                bCancel = null;
            }
            Utils.makeButtonsEqualWidth(buttons);
            if (has_pause_resume) {
                // if we have resume then we have pause
                bResume.setEnabled(false);
                bPause.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        task_paused = true;
                        bPause.setEnabled(false);
                        bResume.setEnabled(true);
                        shell.setDefaultButton(bResume);
                        progress.setTaskState(ProgressCallback.ST_PAUSE);
                    }
                });
                bResume.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        task_paused = false;
                        bPause.setEnabled(true);
                        bResume.setEnabled(false);
                        shell.setDefaultButton(bPause);
                        progress.setTaskState(ProgressCallback.ST_RESUME);
                    }
                });
            }
            if (bCancel != null) {
                bCancel.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        if (has_pause_resume) {
                            bPause.setEnabled(false);
                            bResume.setEnabled(false);
                        }
                        bCancel.setEnabled(false);
                        progress.setTaskState(ProgressCallback.ST_CANCEL);
                    }
                });
            }
            Utils.execSWTThreadLater(250, new Runnable() {

                @Override
                public void run() {
                    if (comp.isDisposed()) {
                        return;
                    }
                    int state = progress.getTaskState();
                    if (state == ProgressCallback.ST_CANCEL) {
                        shell.dispose();
                    } else {
                        if (has_pause_resume) {
                            if (state == ProgressCallback.ST_PAUSE) {
                                bPause.setEnabled(false);
                                bResume.setEnabled(true);
                            } else {
                                bPause.setEnabled(true);
                                bResume.setEnabled(false);
                            }
                        }
                        Utils.execSWTThreadLater(250, this);
                    }
                }
            });
            shell.setDefaultButton(has_pause_resume ? bPause : bCancel);
            shell.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent arg0) {
                    if (task_paused) {
                        progress.setTaskState(ProgressCallback.ST_RESUME);
                    }
                }
            });
        }
    }
    shell.pack();
    if (!alreadyPositioned) {
        Composite parent = shell.getParent();
        if (parent != null) {
            Utils.centerWindowRelativeTo(shell, parent);
        } else {
            Utils.centreWindow(shell);
        }
    }
    shell.open();
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DisposeListener(org.eclipse.swt.events.DisposeListener) PaintListener(org.eclipse.swt.events.PaintListener) DisposeListener(org.eclipse.swt.events.DisposeListener) UIExitUtilsSWT.canCloseListener(com.biglybt.ui.swt.UIExitUtilsSWT.canCloseListener) CoreOperationListener(com.biglybt.core.CoreOperationListener) ArrayList(java.util.ArrayList) CoreOperationTask(com.biglybt.core.CoreOperationTask) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DelayedEvent(com.biglybt.core.util.DelayedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent)

Example 48 with PaintEvent

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

the class ViewQuickNotifications method initialize.

private void initialize(Composite parent) {
    parent.setLayout(new GridLayout());
    composite = new Composite(parent, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(gridData);
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginRight = layout.marginTop = layout.marginBottom = 0;
    composite.setLayout(layout);
    // icon
    notification_icon = new Label(composite, SWT.NONE);
    gridData = new GridData();
    gridData.widthHint = 20;
    notification_icon.setLayoutData(gridData);
    // text
    notification_text = new Label(composite, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    notification_text.setLayoutData(gridData);
    MouseAdapter listener = new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (uif != null) {
                uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES);
            }
        }
    };
    // text
    more_text = new BufferedLabel(composite, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    more_text.setLayoutData(gridData);
    notification_text.setData("");
    Control[] controls = { composite, notification_icon, notification_text, more_text.getControl() };
    for (Control c : controls) {
        c.addMouseListener(listener);
        Messages.setLanguageTooltip(c, "label.click.to.view.tooltip");
    }
    notification_text.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            String text = (String) notification_text.getData();
            int style = SWT.LEFT;
            Rectangle bounds = notification_text.getBounds();
            bounds.x = 4;
            bounds.y = 0;
            bounds.width -= 8;
            GCStringPrinter sp = new GCStringPrinter(e.gc, text, bounds, true, true, style);
            sp.calculateMetrics();
            sp.printString();
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) PaintEvent(org.eclipse.swt.events.PaintEvent) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) PaintListener(org.eclipse.swt.events.PaintListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) GridData(org.eclipse.swt.layout.GridData)

Example 49 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project translationstudio8 by heartsome.

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 50 with PaintEvent

use of org.eclipse.swt.events.PaintEvent in project translationstudio8 by heartsome.

the class InnerTag method init.

// 初始化组件。
private void init() {
    addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            tagRender.draw(e.gc, innerTagBean, 0, 0);
        }
    });
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            Control parent = getParent();
            if (parent instanceof StyledText) {
                StyledText text = (StyledText) parent;
                Point size = getSize();
                Point p = getLocation();
                int offset = text.getOffsetAtLocation(p);
                int mouseX = e.x;
                if (mouseX > size.x / 2) {
                    text.setCaretOffset(offset + 1);
                } else {
                    text.setCaretOffset(offset);
                }
            }
        }
    });
}
Also used : Control(org.eclipse.swt.widgets.Control) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) PaintListener(org.eclipse.swt.events.PaintListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point)

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