Search in sources :

Example 6 with CoreRunningListener

use of com.biglybt.core.CoreRunningListener in project BiglyBT by BiglySoftware.

the class NatPanel method show.

@Override
public void show() {
    wizard.setTitle(MessageText.getString("configureWizard.nat.title"));
    // wizard.setCurrentInfo(MessageText.getString("configureWizard.nat.hint"));
    Composite rootPanel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    rootPanel.setLayout(layout);
    Composite panel = new Composite(rootPanel, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(panel, gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    panel.setLayout(layout);
    Label label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "configureWizard.nat.message");
    label = new Label(panel, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(label, gridData);
    // TCP
    label = new Label(panel, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "configureWizard.nat.server.tcp_listen_port");
    final Text textServerTCPListen = new Text(panel, SWT.BORDER);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 80;
    Utils.setLayoutData(textServerTCPListen, gridData);
    textServerTCPListen.setText("" + ((ConfigureWizard) wizard).serverTCPListenPort);
    textServerTCPListen.addListener(SWT.Verify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            String text = e.text;
            char[] chars = new char[text.length()];
            text.getChars(0, chars.length, chars, 0);
            for (int i = 0; i < chars.length; i++) {
                if (!('0' <= chars[i] && chars[i] <= '9')) {
                    e.doit = false;
                    return;
                }
            }
        }
    });
    textServerTCPListen.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            try {
                final int TCPListenPort = Integer.parseInt(textServerTCPListen.getText());
                ((ConfigureWizard) wizard).serverTCPListenPort = TCPListenPort;
            } catch (NumberFormatException ex) {
            // ignore
            }
        }
    });
    bTestTCP = new Button(panel, SWT.PUSH);
    Messages.setLanguageText(bTestTCP, "configureWizard.nat.test");
    gridData = new GridData();
    gridData.widthHint = 70;
    Utils.setLayoutData(bTestTCP, gridData);
    label = new Label(panel, SWT.NULL);
    // UDP
    label = new Label(panel, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "configureWizard.nat.server.udp_listen_port");
    final Text textServerUDPListen = new Text(panel, SWT.BORDER);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 80;
    Utils.setLayoutData(textServerUDPListen, gridData);
    textServerUDPListen.setText("" + ((ConfigureWizard) wizard).serverUDPListenPort);
    textServerUDPListen.addListener(SWT.Verify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            String text = e.text;
            char[] chars = new char[text.length()];
            text.getChars(0, chars.length, chars, 0);
            for (int i = 0; i < chars.length; i++) {
                if (!('0' <= chars[i] && chars[i] <= '9')) {
                    e.doit = false;
                    return;
                }
            }
        }
    });
    textServerUDPListen.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            try {
                final int UDPListenPort = Integer.parseInt(textServerUDPListen.getText());
                ((ConfigureWizard) wizard).serverUDPListenPort = UDPListenPort;
            } catch (NumberFormatException ex) {
            // ignore
            }
        }
    });
    bTestUDP = new Button(panel, SWT.PUSH);
    Messages.setLanguageText(bTestUDP, "configureWizard.nat.test");
    gridData = new GridData();
    gridData.widthHint = 70;
    Utils.setLayoutData(bTestUDP, gridData);
    label = new Label(panel, SWT.NULL);
    // blah
    textResults = new StyledText(panel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 70;
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(textResults, gridData);
    textResults.setBackground(Colors.getSystemColor(panel.getDisplay(), SWT.COLOR_WHITE));
    bTestTCP.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            wizard.setNextEnabled(false);
            bTestTCP.setEnabled(false);
            bTestUDP.setEnabled(false);
            textResults.setText("");
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    ConfigureWizard cw = (ConfigureWizard) wizard;
                    int TCPListenPort = cw.serverTCPListenPort;
                    CheckerTCP checker = new CheckerTCP(core, TCPListenPort);
                    checker.start();
                }
            });
        }
    });
    bTestUDP.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            wizard.setNextEnabled(false);
            bTestTCP.setEnabled(false);
            bTestUDP.setEnabled(false);
            textResults.setText("");
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    ConfigureWizard cw = (ConfigureWizard) wizard;
                    int UDPListenPort = cw.serverUDPListenPort;
                    CheckerUDP checker = new CheckerUDP(core, UDPListenPort);
                    checker.start();
                }
            });
        }
    });
}
Also used : NetworkAdminProgressListener(com.biglybt.core.networkmanager.admin.NetworkAdminProgressListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) StyledText(org.eclipse.swt.custom.StyledText) StyledText(org.eclipse.swt.custom.StyledText) MessageText(com.biglybt.core.internat.MessageText) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) CoreRunningListener(com.biglybt.core.CoreRunningListener) Core(com.biglybt.core.Core)

Example 7 with CoreRunningListener

use of com.biglybt.core.CoreRunningListener in project BiglyBT by BiglySoftware.

the class RemotePairingWindow method open.

public static void open() {
    if (DEBUG) {
        if (testPairingClass == null) {
            testPairingClass = new testPairingClass();
        } else {
            testPairingClass.inc();
        }
    }
    final RemotePairingWindow inst;
    synchronized (RemotePairingWindow.class) {
        if (instance == null) {
            instance = new RemotePairingWindow();
        }
        inst = instance;
    }
    CoreWaiterSWT.waitForCore(TriggerInThread.SWT_THREAD, new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            inst._open();
        }
    });
}
Also used : CoreRunningListener(com.biglybt.core.CoreRunningListener) Core(com.biglybt.core.Core)

Example 8 with CoreRunningListener

use of com.biglybt.core.CoreRunningListener in project BiglyBT by BiglySoftware.

the class DebugMenuHelper method createDebugMenuItem.

/**
 * Creates the Debug menu and its children
 * NOTE: This is a development only menu and so it's not modularized into separate menu items
 * because this menu is always rendered in its entirety
 * @param menu
 * @param mainWindow
 * @return
 */
public static MenuItem createDebugMenuItem(final Menu menuDebug) {
    MenuItem item;
    final UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (null == uiFunctions) {
        throw new IllegalStateException("UIFunctionsManagerSWT.getUIFunctionsSWT() is returning null");
    }
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("Run GC");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            System.gc();
        }
    });
    item = new MenuItem(menuDebug, SWT.PUSH);
    item.setText("&CoreReq");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    new MessageBoxShell(0, "Done", "Core Now Avail").open(null);
                }
            });
        }
    });
    /*
		item = new MenuItem(menuDebug, SWT.CASCADE);
		item.setText("Subscriptions");
		Menu menuSubscriptions = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
		item.setMenu(menuSubscriptions);

		item = new MenuItem(menuSubscriptions, SWT.NONE);
		item.setText("Create RSS Feed");
		item.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				final Shell shell = new Shell(uiFunctions.getMainShell());
				shell.setLayout(new FormLayout());

				Label label = new Label(shell,SWT.NONE);
				label.setText("RSS Feed URL :");
				final Text urlText = new Text(shell,SWT.BORDER);
				urlText.setText(Utils.getLinkFromClipboard(shell.getDisplay(),false));
				Label separator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
				Button cancel = new Button(shell,SWT.PUSH);
				cancel.setText("Cancel");
				Button ok = new Button(shell,SWT.PUSH);
				ok.setText("Ok");

				FormData data;

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(0,5);
				label.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(label);
				data.width = 400;
				urlText.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(urlText);
				separator.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(ok);
				data.width = 100;
				data.top = new FormAttachment(separator);
				cancel.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(100,-5);
				data.width = 100;
				data.top = new FormAttachment(separator);
				ok.setLayoutData(data);

				cancel.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						shell.dispose();
					}
				});

				ok.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						String url_str = urlText.getText();
						shell.dispose();

						try{
							URL	url = new URL( url_str );

							SubscriptionManagerFactory.getSingleton().createSingletonRSS( url_str, url, 120, true );

						}catch( Throwable e ){

							Debug.printStackTrace(e);
						}
					}
				});

				shell.pack();


				Utils.centerWindowRelativeTo(shell, uiFunctions.getMainShell());

				shell.open();
				shell.setFocus();
				urlText.setFocus();


			}
		});
		 */
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("DW");
    Menu menuBrowserTB = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuBrowserTB);
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("popup check");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.checkForDonationPopup();
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("show");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.open(true, "debug");
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Alerts");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = "This is a  long message with lots of information and " + "stuff you really should read.  Are you still reading? Good, because " + "reading <a href=\"http://moo.com\">stimulates</a> the mind.\n\nYeah Baby.";
            LogAlert logAlert = new LogAlert(true, LogAlert.AT_INFORMATION, "Simple");
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_WARNING, text);
            logAlert.details = "Details: \n\n" + text;
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_ERROR, "ShortText");
            logAlert.details = "Details";
            Logger.log(logAlert);
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("MsgBox");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            VuzeMessageBox box = new VuzeMessageBox("Title", "Text", new String[] { "Ok", "Cancel" }, 0);
            box.setListener(new VuzeMessageBoxListener() {

                @Override
                public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
                    SWTSkin skin = soExtra.getSkin();
                    skin.createSkinObject("dlg.generic.test", "dlg.generic.test", soExtra);
                    skin.layout(soExtra);
                    shell.layout(true, true);
                }
            });
            box.open(null);
        }
    });
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("Size");
    Menu menuSize = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuSize);
    int[] sizes = { 640, 430, 800, 550, 1024, 718, 1280, 700, 1440, 850, 1600, 1050, 1920, 1150 };
    for (int i = 0; i < sizes.length; i += 2) {
        final int x = sizes[i];
        final int y = sizes[i + 1];
        item = new MenuItem(menuSize, SWT.NONE);
        item.setText("" + x + "," + y);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell().setSize(x, y);
            }
        });
    }
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Obfuscated Shell Image");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            Display display = Display.getCurrent();
            java.util.List<Image> shell_images = UIDebugGenerator.getShellImages();
            Image biggest_image = null;
            long biggest_area = 0;
            for (Image image : shell_images) {
                Shell shell2 = new Shell(display);
                Rectangle bounds = image.getBounds();
                long area = bounds.width * bounds.height;
                if (area > biggest_area) {
                    biggest_image = image;
                }
                Point size = shell2.computeSize(bounds.width, bounds.height);
                shell2.setSize(size);
                shell2.setBackgroundImage(image);
                shell2.open();
            }
            if (biggest_image != null) {
                new Clipboard(display).setContents(new Object[] { biggest_image.getImageData() }, new Transfer[] { ImageTransfer.getInstance() });
            }
        }
    });
    return item;
}
Also used : VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) CoreRunningListener(com.biglybt.core.CoreRunningListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Core(com.biglybt.core.Core) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) Transfer(org.eclipse.swt.dnd.Transfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) Clipboard(org.eclipse.swt.dnd.Clipboard) VuzeMessageBox(com.biglybt.ui.swt.views.skin.VuzeMessageBox)

Example 9 with CoreRunningListener

use of com.biglybt.core.CoreRunningListener in project BiglyBT by BiglySoftware.

the class SpeedTestSelector method runMLABTest.

public static void runMLABTest(final Runnable runWhenClosed) {
    CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            UIFunctionsManager.getUIFunctions().installPlugin("mlab", "dlg.install.mlab", new UIFunctions.actionListener() {

                @Override
                public void actionComplete(Object result) {
                    if (result instanceof Boolean) {
                        _runMLABTest(runWhenClosed);
                    } else {
                        try {
                            Throwable error = (Throwable) result;
                            Debug.out(error);
                        } finally {
                            if (runWhenClosed != null) {
                                runWhenClosed.run();
                            }
                        }
                    }
                }
            });
        }
    });
}
Also used : CoreRunningListener(com.biglybt.core.CoreRunningListener) Core(com.biglybt.core.Core)

Example 10 with CoreRunningListener

use of com.biglybt.core.CoreRunningListener in project BiglyBT by BiglySoftware.

the class CoreWaiterSWT method waitForCore.

public static void waitForCore(final TriggerInThread triggerInThread, final CoreRunningListener l) {
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            if (triggerInThread == TriggerInThread.ANY_THREAD) {
                l.coreRunning(core);
            } else if (triggerInThread == TriggerInThread.NEW_THREAD) {
                new AEThread2("CoreWaiterInvoke", true) {

                    @Override
                    public void run() {
                        l.coreRunning(core);
                    }
                }.start();
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    // TODO: Need to detect cancel (can't rely on shell status since it may never open)
                    if (shell != null && !shell.isDisposed()) {
                        shell.dispose();
                        shell = null;
                    }
                    if (triggerInThread == TriggerInThread.SWT_THREAD) {
                        l.coreRunning(core);
                    }
                }
            });
        }
    });
    if (!CoreFactory.isCoreRunning()) {
        if (DEBUG) {
            System.out.println("NOT AVAIL FOR " + Debug.getCompressedStackTrace());
        }
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                showWaitWindow();
            }
        });
    } else if (DEBUG) {
        System.out.println("NO NEED TO WAIT.. CORE AVAIL! " + Debug.getCompressedStackTrace());
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) CoreRunningListener(com.biglybt.core.CoreRunningListener) AEThread2(com.biglybt.core.util.AEThread2) Core(com.biglybt.core.Core)

Aggregations

Core (com.biglybt.core.Core)35 CoreRunningListener (com.biglybt.core.CoreRunningListener)35 DownloadManager (com.biglybt.core.download.DownloadManager)8 GridLayout (org.eclipse.swt.layout.GridLayout)6 Composite (org.eclipse.swt.widgets.Composite)6 GlobalManager (com.biglybt.core.global.GlobalManager)5 AERunnable (com.biglybt.core.util.AERunnable)5 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)4 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 MessageText (com.biglybt.core.internat.MessageText)3 LogAlert (com.biglybt.core.logging.LogAlert)3 Tag (com.biglybt.core.tag.Tag)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)3 UIFunctions (com.biglybt.ui.UIFunctions)3 File (java.io.File)3 List (java.util.List)3 GridData (org.eclipse.swt.layout.GridData)3 ParameterListener (com.biglybt.core.config.ParameterListener)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2