Search in sources :

Example 1 with SkinnedDialogClosedListener

use of com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener in project BiglyBT by BiglySoftware.

the class DeviceTemplateChooser method open.

public void open(DeviceTemplateClosedListener l) {
    this.listener = l;
    skinnedDialog = new SkinnedDialog("skin3_dlg_deviceadd_mfchooser", "shell", SWT.TITLE | SWT.BORDER);
    skinnedDialog.addCloseListener(new SkinnedDialogClosedListener() {

        @Override
        public void skinDialogClosed(SkinnedDialog dialog) {
            if (listener != null) {
                listener.deviceTemplateChooserClosed(selectedDeviceTemplate);
            }
        }
    });
    SWTSkin skin = skinnedDialog.getSkin();
    SWTSkinObject so = skin.getSkinObject("list");
    if (so instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer soList = (SWTSkinObjectContainer) so;
        createDeviceTemplateList2(soList);
    }
    skinnedDialog.open();
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin)

Example 2 with SkinnedDialogClosedListener

use of com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener 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)

Example 3 with SkinnedDialogClosedListener

use of com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener 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 4 with SkinnedDialogClosedListener

use of com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener in project BiglyBT by BiglySoftware.

the class ManufacturerChooser method open.

public void open(ClosedListener l) {
    this.listener = l;
    skinnedDialog = new SkinnedDialog("skin3_dlg_deviceadd_mfchooser", "shell", SWT.TITLE | SWT.BORDER);
    skinnedDialog.addCloseListener(new SkinnedDialogClosedListener() {

        @Override
        public void skinDialogClosed(SkinnedDialog dialog) {
            if (listener != null) {
                listener.MfChooserClosed(chosenMF);
            }
        }
    });
    SWTSkin skin = skinnedDialog.getSkin();
    SWTSkinObject so = skin.getSkinObject("list");
    if (so instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer soList = (SWTSkinObjectContainer) so;
        Composite parent = soList.getComposite();
        Canvas centerCanvas = new Canvas(parent, SWT.NONE);
        FormData fd = Utils.getFilledFormData();
        fd.bottom = null;
        fd.height = 0;
        centerCanvas.setLayoutData(fd);
        Composite area = new Composite(parent, SWT.NONE);
        RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
        rowLayout.fill = true;
        Utils.setLayout(area, rowLayout);
        fd = Utils.getFilledFormData();
        fd.left = new FormAttachment(centerCanvas, 50, SWT.CENTER);
        fd.right = null;
        area.setLayoutData(fd);
        Listener btnListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                chosenMF = (DeviceManufacturer) event.widget.getData("mf");
                skinnedDialog.close();
            }
        };
        DeviceManager deviceManager = DeviceManagerFactory.getSingleton();
        DeviceManufacturer[] mfs = deviceManager.getDeviceManufacturers(Device.DT_MEDIA_RENDERER);
        for (DeviceManufacturer mf : mfs) {
            DeviceTemplate[] deviceTemplates = mf.getDeviceTemplates();
            boolean hasNonAuto = false;
            for (DeviceTemplate deviceTemplate : deviceTemplates) {
                if (!deviceTemplate.isAuto()) {
                    hasNonAuto = true;
                    break;
                }
            }
            if (!hasNonAuto) {
                continue;
            }
            Button button = new Button(area, SWT.PUSH);
            button.setText(mf.getName());
            button.setData("mf", mf);
            button.addListener(SWT.MouseUp, btnListener);
        }
    }
    skinnedDialog.getShell().pack();
    skinnedDialog.open();
}
Also used : FormData(org.eclipse.swt.layout.FormData) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) RowLayout(org.eclipse.swt.layout.RowLayout) DeviceManufacturer(com.biglybt.core.devices.DeviceManager.DeviceManufacturer) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

SkinnedDialogClosedListener (com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)4 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)3 SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)2 ButtonListenerAdapter (com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 DeviceManufacturer (com.biglybt.core.devices.DeviceManager.DeviceManufacturer)1 PluginInterface (com.biglybt.pif.PluginInterface)1 PluginInitializer (com.biglybt.pifimpl.local.PluginInitializer)1 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)1 TableCellSWTPaintListener (com.biglybt.ui.swt.views.table.TableCellSWTPaintListener)1 Point (org.eclipse.swt.graphics.Point)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1