Search in sources :

Example 6 with ButtonListenerAdapter

use of com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter 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 7 with ButtonListenerAdapter

use of com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter in project BiglyBT by BiglySoftware.

the class MainWindowImpl method attachSearchBox.

/**
 * @param skinObject
 */
private void attachSearchBox(SWTSkinObject skinObject) {
    Composite cArea = (Composite) skinObject.getControl();
    if (Utils.isGTK3) {
        // TextBox on GTK3/SWT will expand box to fit it's hugeness
        // Workaround by creating a composite in a fixed height composite
        // (Yes, both are needed..)
        FormData filledFormData;
        Composite c1 = new Composite(cArea, SWT.NONE);
        filledFormData = Utils.getFilledFormData();
        filledFormData.height = 24;
        filledFormData.bottom = null;
        c1.setLayoutData(filledFormData);
        c1.setLayout(new FormLayout());
        Composite c2 = new Composite(c1, SWT.NONE);
        c2.setLayout(new FormLayout());
        filledFormData = Utils.getFilledFormData();
        c2.setLayoutData(filledFormData);
        cArea = c2;
    }
    final Text text = new Text(cArea, SWT.NONE);
    text.setMessage(MessageText.getString("v3.MainWindow.search.defaultText"));
    FormData filledFormData = Utils.getFilledFormData();
    text.setLayoutData(filledFormData);
    text.setData("ObfuscateImage", new ObfuscateImage() {

        @Override
        public Image obfuscatedImage(Image image) {
            Point location = Utils.getLocationRelativeToShell(text);
            Point size = text.getSize();
            UIDebugGenerator.obfuscateArea(image, new Rectangle(location.x, location.y, size.x, size.y));
            return image;
        }
    });
    text.addListener(SWT.Resize, new Listener() {

        Font lastFont = null;

        int lastHeight = -1;

        @Override
        public void handleEvent(Event event) {
            Text text = (Text) event.widget;
            int h = text.getClientArea().height - 2;
            if (Utils.isGTK3) {
                // GTK3 has border included in clientArea
                h -= 5;
            } else if (Utils.isGTK && h > 18) {
                h = 18;
            }
            if (h == lastHeight) {
                return;
            }
            lastHeight = h;
            Font font = FontUtils.getFontWithHeight(text.getFont(), null, h);
            if (font != null) {
                text.setFont(font);
                if (lastFont == null) {
                    text.addDisposeListener(new DisposeListener() {

                        @Override
                        public void widgetDisposed(DisposeEvent e) {
                            Text text = (Text) e.widget;
                            text.setFont(null);
                            Utils.disposeSWTObjects(lastFont);
                        }
                    });
                } else {
                    Utils.disposeSWTObjects(lastFont);
                }
                lastFont = font;
            }
        }
    });
    // URIs can get pretty long...
    text.setTextLimit(2048);
    if (Constants.isWindows) {
        text.addListener(SWT.MouseDown, new Listener() {

            @Override
            public void handleEvent(Event event) {
                if (event.count == 3) {
                    text.selectAll();
                }
            }
        });
    }
    String tooltip = MessageText.getString("v3.MainWindow.search.tooltip");
    text.setToolTipText(tooltip);
    SWTSkinProperties properties = skinObject.getProperties();
    Color colorSearchTextBG = properties.getColor("color.search.text.bg");
    Color colorSearchTextFG = properties.getColor("color.search.text.fg");
    if (colorSearchTextBG != null) {
        text.setBackground(colorSearchTextBG);
    }
    final TextWithHistory twh = new TextWithHistory("mainwindow.search.history", text);
    text.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            int key = e.character;
            if (e.stateMask == SWT.MOD1) {
                if (key <= 26 && key > 0) {
                    key += 'a' - 1;
                }
                if (key == 'a') {
                    text.selectAll();
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub
        }
    });
    text.addListener(SWT.KeyDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Text text = (Text) event.widget;
            if (event.keyCode == SWT.ESC) {
                text.setText("");
                return;
            }
            if (event.character == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                if (event.doit) {
                    String expression = text.getText();
                    uiFunctions.doSearch(expression);
                    twh.addHistory(expression);
                }
            }
        }
    });
    SWTSkinObject searchGo = skin.getSkinObject("search-go");
    if (searchGo != null) {
        SWTSkinButtonUtility btnGo = new SWTSkinButtonUtility(searchGo);
        btnGo.addSelectionListener(new ButtonListenerAdapter() {

            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                String sSearchText = text.getText().trim();
                uiFunctions.doSearch(sSearchText);
                twh.addHistory(sSearchText);
            }
        });
    }
    SWTSkinObject so = skin.getSkinObject("search-dropdown");
    if (so != null) {
        SWTSkinButtonUtility btnSearchDD = new SWTSkinButtonUtility(so);
        btnSearchDD.setTooltipID("v3.MainWindow.search.tooltip");
        btnSearchDD.addSelectionListener(new ButtonListenerAdapter() {

            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int button, int stateMask) {
                if (button == 1) {
                    String sSearchText = text.getText().trim();
                    uiFunctions.doSearch(sSearchText);
                    twh.addHistory(sSearchText);
                }
            }
        });
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) FormLayout(org.eclipse.swt.layout.FormLayout) MdiEntryLogIdListener(com.biglybt.ui.mdi.MdiEntryLogIdListener) ParameterListener(com.biglybt.core.config.ParameterListener) MdiListener(com.biglybt.ui.mdi.MdiListener) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) MessageText(com.biglybt.core.internat.MessageText) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) ButtonListenerAdapter(com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter)

Example 8 with ButtonListenerAdapter

use of com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter in project BiglyBT by BiglySoftware.

the class SearchResultsTabArea method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(final SWTSkinObject skinObject, Object params) {
    skin = skinObject.getSkin();
    SWTSkinObjectContainer controlArea = (SWTSkinObjectContainer) skin.getSkinObject("searchresultstop", skinObject);
    if (controlArea != null) {
        if (isViewSwitchHidden) {
            controlArea.setVisible(false);
        } else {
            Composite control_area = controlArea.getComposite();
            soButtonWeb = skin.getSkinObject("searchresults-button-web", controlArea);
            soButtonMeta = skin.getSkinObject("searchresults-button-meta", controlArea);
            SWTSkinButtonUtility btnWeb = new SWTSkinButtonUtility(soButtonWeb);
            btnWeb.addSelectionListener(new ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    isBrowserView = true;
                    COConfigurationManager.setParameter("Search View Is Web View", isBrowserView);
                    selectView(skinObject);
                }
            });
            SWTSkinButtonUtility btnMeta = new SWTSkinButtonUtility(soButtonMeta);
            btnMeta.addSelectionListener(new ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    isBrowserView = false;
                    COConfigurationManager.setParameter("Search View Is Web View", isBrowserView);
                    selectView(skinObject);
                }
            });
        }
    }
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null) {
        mdi_entry = mdi.getEntryBySkinView(this);
        if (mdi_entry != null) {
            mdi_entry.setViewTitleInfo(this);
            vitalityImage = mdi_entry.addVitalityImage("image.sidebar.vitality.dots");
            if (vitalityImage != null) {
                vitalityImage.setVisible(false);
            }
        }
    }
    browserSkinObject = (SWTSkinObjectBrowser) skin.getSkinObject("web-search-results", skinObject);
    browserImpl.init(browserSkinObject);
    nativeSkinObject = (SWTSkinObjectContainer) skin.getSkinObject("meta-search-results", skinObject);
    nativeImpl.skinObjectInitialShow(skinObject, params);
    selectView(skinObject);
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    initCoreStuff(core);
                }
            });
        }
    });
    return null;
}
Also used : ButtonListenerAdapter(com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)

Aggregations

ButtonListenerAdapter (com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter)8 ParameterListener (com.biglybt.core.config.ParameterListener)2 SWTSkinButtonUtility (com.biglybt.ui.swt.skin.SWTSkinButtonUtility)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 SkinnedDialogClosedListener (com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 FormData (org.eclipse.swt.layout.FormData)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)1 MessageText (com.biglybt.core.internat.MessageText)1 PluginInterface (com.biglybt.pif.PluginInterface)1 PluginInitializer (com.biglybt.pifimpl.local.PluginInitializer)1 MdiEntryLogIdListener (com.biglybt.ui.mdi.MdiEntryLogIdListener)1 MdiListener (com.biglybt.ui.mdi.MdiListener)1 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)1 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)1 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)1 SWTSkinObjectButton (com.biglybt.ui.swt.skin.SWTSkinObjectButton)1 SWTRunnable (com.biglybt.ui.swt.utils.SWTRunnable)1