Search in sources :

Example 26 with PaintEvent

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

the class RemotePairingWindow method _open.

private void _open() {
    alreadyTested = false;
    pairingManager = PairingManagerFactory.getSingleton();
    PluginInterface piWebUI = getWebUI();
    boolean showFTUX = piWebUI == null || !pairingManager.isEnabled();
    if (skinnedDialog == null || skinnedDialog.isDisposed()) {
        skinnedDialog = new SkinnedDialog("skin3_dlg_remotepairing", "shell", SWT.DIALOG_TRIM);
        skin = skinnedDialog.getSkin();
        soCodeArea = skin.getSkinObject("code-area");
        control = soCodeArea.getControl();
        soEnablePairing = (SWTSkinObjectButton) skin.getSkinObject("enable-pairing");
        soEnablePairing.addSelectionListener(new ButtonListenerAdapter() {

            // @see SWTSkinButtonUtility.ButtonListenerAdapter#pressed(SWTSkinButtonUtility, SWTSkinObject, int)
            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                skinObject.getControl().setEnabled(false);
                if (!pairingManager.isEnabled()) {
                    // enabling will automatically get access code and trigger
                    // somethingChanged
                    pairingManager.setEnabled(true);
                    if (SHOW_SPEW) {
                        System.out.println("PAIR] SetEnabled");
                    }
                } else {
                    // picked up
                    if (SHOW_SPEW) {
                        System.out.println("PAIR] AlreadyEnabled");
                    }
                    somethingChanged(pairingManager);
                }
                if (getWebUI() == null) {
                    installWebUI();
                } else {
                    switchToCode();
                }
            }
        });
        soFTUX = skin.getSkinObject("pairing-ftux");
        soCode = skin.getSkinObject("pairing-code");
        soQR = (SWTSkinObjectImage) skin.getSkinObject("pairing-qr");
        if (accessCode != null) {
            setupQR(accessCode);
        }
        soStatusText = (SWTSkinObjectText) skin.getSkinObject("status-text");
        soStatusText.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {

            @Override
            public boolean urlClicked(URLInfo urlInfo) {
                if (urlInfo.url.equals("retry")) {
                    if (DEBUG) {
                        testPairingClass.inc();
                    }
                    alreadyTested = false;
                    testPairing(false);
                    return true;
                }
                return false;
            }
        });
        pairingManager.addListener(this);
        Font font = control.getFont();
        GC gc = new GC(control);
        fontCode = FontUtils.getFontWithHeight(font, gc, Constants.isWindows ? 20 : 18, SWT.BOLD);
        gc.dispose();
        control.setFont(fontCode);
        control.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                Color oldColor = e.gc.getForeground();
                Rectangle printArea = ((Composite) e.widget).getClientArea();
                printArea.y += 10;
                printArea.height -= 20;
                int fullWidth = printArea.width;
                int fullHeight = printArea.height;
                GCStringPrinter sp = new GCStringPrinter(e.gc, MessageText.getString("remote.pairing.accesscode"), printArea, false, false, SWT.NONE);
                sp.calculateMetrics();
                Point sizeAccess = sp.getCalculatedSize();
                String drawAccessCode = accessCode == null ? "      " : accessCode;
                int numBoxes = drawAccessCode.length();
                int boxSize = 25;
                int boxSizeAndPadding = 30;
                int allBoxesWidth = numBoxes * boxSizeAndPadding;
                int textPadding = 15;
                printArea.y = (fullHeight - boxSizeAndPadding - sizeAccess.y + textPadding) / 2;
                sp.printString(e.gc, printArea, SWT.CENTER | SWT.TOP);
                e.gc.setBackground(Colors.white);
                e.gc.setForeground(Colors.blue);
                int xStart = (fullWidth - allBoxesWidth) / 2;
                int yStart = printArea.y + sizeAccess.y + textPadding;
                for (int i = 0; i < numBoxes; i++) {
                    Rectangle r = new Rectangle(xStart + (i * boxSizeAndPadding), yStart, boxSize, boxSize);
                    e.gc.fillRectangle(r);
                    e.gc.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
                    e.gc.drawRectangle(r);
                    if (isCodeVisible()) {
                        e.gc.setForeground(oldColor);
                        GCStringPrinter.printString(e.gc, "" + drawAccessCode.charAt(i), r, false, false, SWT.CENTER);
                    }
                }
            }
        });
        soToClipboard = (SWTSkinObjectText) skin.getSkinObject("pair-clipboard");
        soToClipboard.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {

            @Override
            public boolean urlClicked(URLInfo urlInfo) {
                if (urlInfo.url.equals("new")) {
                    try {
                        accessCode = pairingManager.getReplacementAccessCode();
                    } catch (PairingException e) {
                    // ignore.. if error, lastErrorUpdates will trigger
                    }
                    control.redraw();
                    setupQR(accessCode);
                    String s = soToClipboard.getText();
                    int i = s.indexOf("|");
                    if (i > 0) {
                        soToClipboard.setText(s.substring(0, i - 1));
                    }
                } else if (urlInfo.url.equals("clip")) {
                    ClipboardCopy.copyToClipBoard(accessCode);
                }
                return true;
            }
        });
        SWTSkinButtonUtility btnToClipboard = new SWTSkinButtonUtility(soToClipboard);
        btnToClipboard.addSelectionListener(new ButtonListenerAdapter() {

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

            @Override
            public void skinDialogClosed(SkinnedDialog dialog) {
                skinnedDialog = null;
                pairingManager.removeListener(RemotePairingWindow.this);
                Utils.disposeSWTObjects(new Object[] { fontCode });
                if (pairingTest != null) {
                    pairingTest.cancel();
                }
            }
        });
        if (showFTUX) {
            soFTUX.getControl().moveAbove(null);
        }
    }
    setCodeVisible(false);
    skinnedDialog.open();
    if (showFTUX) {
        switchToFTUX();
    } else {
        switchToCode();
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) PluginInterface(com.biglybt.pif.PluginInterface) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) ButtonListenerAdapter(com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)

Example 27 with PaintEvent

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

the class SWTBGImagePainter2 method main.

public static void main(String[] args) {
    Display display = Display.getDefault();
    Shell shell = new Shell(display, SWT.DIALOG_TRIM);
    shell.setLayout(new FillLayout());
    Composite c = new Composite(shell, SWT.BORDER);
    c.setLayout(new FillLayout());
    c.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.drawLine(0, 0, 100, 50);
        }
    });
    Label lbl = new Label(c, SWT.NONE);
    lbl.setText("text");
    shell.open();
    while (!shell.isDisposed()) {
        if (display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 28 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;
    shell.setText(MessageText.getString("progress.window.title"));
    final CoreOperationTask.ProgressCallback progress = _core_op == null ? null : _core_op.getTask().getProgressCallback();
    Utils.setShellIcon(shell);
    /*
		shell.addListener(
				SWT.Close,
				new Listener()
				{
					public void
					handleEvent(
						org.eclipse.swt.widgets.Event event)
					{
						event.doit = false;
					}
				});
		*/
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setBackground(Colors.white);
    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);
                if (progress != null && progress_bar != null) {
                    int p = progress.getProgress();
                    progress_bar.setSelection(p);
                }
            }
        });
        Utils.execSWTThreadLater(100, new AERunnable() {

            @Override
            public void runSupport() {
                if (canvas == null || canvas.isDisposed()) {
                    return;
                }
                canvas.redraw();
                // canvas.update();
                if (curSpinIndex == spinImages.length - 1) {
                    curSpinIndex = 0;
                } else {
                    curSpinIndex++;
                }
                Utils.execSWTThreadLater(100, this);
            }
        });
        canvas.setBackground(Colors.white);
    }
    Label label = new Label(shell, SWT.NONE);
    label.setText(MessageText.getString(resource));
    GridData gridData = new GridData();
    label.setLayoutData(gridData);
    label.setBackground(Colors.white);
    if (progress != null) {
        progress_bar = new ProgressBar(shell, SWT.HORIZONTAL);
        progress_bar.setMinimum(0);
        progress_bar.setMaximum(1000);
        progress_bar.setBackground(Colors.white);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        progress_bar.setLayoutData(gridData);
    }
    shell.pack();
    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) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) CoreOperationTask(com.biglybt.core.CoreOperationTask) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ProgressBar(org.eclipse.swt.widgets.ProgressBar)

Example 29 with PaintEvent

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

the class PieceGraphView method initialize.

// @see com.biglybt.ui.swt.views.AbstractIView#initialize(org.eclipse.swt.widgets.Composite)
private void initialize(Composite parent) {
    blockColors = new Color[] { properties.getColor("color.pieceview.alldone"), properties.getColor("color.pieceview.notdone"), properties.getColor("color.pieceview.uploading"), properties.getColor("color.pieceview.downloading"), properties.getColor("color.pieceview.noavail"), properties.getColor("color.pieceview.havesome") };
    compFindPEPiece = new Comparator() {

        @Override
        public int compare(Object arg0, Object arg1) {
            int arg0no = (arg0 instanceof PEPiece) ? ((PEPiece) arg0).getPieceNumber() : ((Long) arg0).intValue();
            int arg1no = (arg1 instanceof PEPiece) ? ((PEPiece) arg1).getPieceNumber() : ((Long) arg1).intValue();
            return arg0no - arg1no;
        }
    };
    canvas = new Canvas(parent, SWT.NO_BACKGROUND);
    canvas.setLayout(new FillLayout());
    canvas.addPaintListener(new PaintListener() {

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

        @Override
        public void handleEvent(Event event) {
            calcBlockSize();
        }
    });
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PaintEvent(org.eclipse.swt.events.PaintEvent) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) PaintListener(org.eclipse.swt.events.PaintListener) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 30 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);
    Utils.setLayoutData(composite, 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;
    Utils.setLayoutData(notification_icon, gridData);
    // text
    notification_text = new Label(composite, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(notification_text, 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;
    Utils.setLayoutData(more_text, 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)

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