Search in sources :

Example 51 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class MyTrackerView method defaultSelected.

// @see TableSelectionListener#defaultSelected(TableRowCore[])
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
    final TRHostTorrent torrent = (TRHostTorrent) tv.getFirstSelectedDataSource();
    if (torrent == null)
        return;
    CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            DownloadManager dm = core.getGlobalManager().getDownloadManager(torrent.getTorrent());
            if (dm != null) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                }
            }
        }
    });
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) CoreRunningListener(com.biglybt.core.CoreRunningListener) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) DownloadManager(com.biglybt.core.download.DownloadManager) Core(com.biglybt.core.Core)

Example 52 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class PeersGraphicView method initialize.

protected void initialize(Composite composite) {
    display = composite.getDisplay();
    panel = new Canvas(composite, SWT.NO_BACKGROUND);
    panel.addListener(SWT.MouseHover, new Listener() {

        @Override
        public void handleEvent(Event event) {
            int x = event.x;
            int y = event.y;
            String tt = "";
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        if (dm_data.length > 1) {
                            tt = manager.getDisplayName() + "\r\n";
                        }
                        tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
                        break;
                    } else {
                        PEPeer target = null;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                break;
                            }
                        }
                        if (target != null) {
                            PEPeerStats stats = target.getStats();
                            String[] details = PeerUtils.getCountryDetails(target);
                            String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
                            /*
							if ( dm_map.size() > 1 ){

								tt = manager.getDisplayName() + "\r\n";
							}
							*/
                            tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
                            break;
                        }
                    }
                }
            }
            panel.setToolTipText(tt);
        }
    });
    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent event) {
            if (event.button == 3) {
                int x = event.x;
                int y = event.y;
                PEPeer target = null;
                DownloadManager target_manager = null;
                synchronized (dm_data_lock) {
                    for (ManagerData data : dm_data) {
                        DownloadManager manager = data.manager;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                target_manager = manager;
                                break;
                            }
                        }
                        if (target != null) {
                            break;
                        }
                    }
                }
                if (target == null) {
                    return;
                }
                Menu menu = panel.getMenu();
                if (menu != null && !menu.isDisposed()) {
                    menu.dispose();
                }
                menu = new Menu(panel);
                PeersViewBase.fillMenu(menu, target, target_manager);
                final Point cursorLocation = Display.getCurrent().getCursorLocation();
                menu.setLocation(cursorLocation.x, cursorLocation.y);
                menu.setVisible(true);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            int x = event.x;
            int y = event.y;
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                        if (uiFunctions != null) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
                        }
                    } else {
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                PEPeer target = entry.getKey();
                                try {
                                    String dm_id = "DMDetails_" + Base32.encode(manager.getTorrent().getHash());
                                    MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(dm_id);
                                    if (mdi_entry != null) {
                                        mdi_entry.setDatasource(new Object[] { manager, target });
                                    }
                                    Composite comp = panel.getParent();
                                    while (comp != null) {
                                        if (comp instanceof CTabFolder) {
                                            CTabFolder tf = (CTabFolder) comp;
                                            CTabItem[] items = tf.getItems();
                                            for (CTabItem item : items) {
                                                UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
                                                UISWTViewEventListener listener = view.getEventListener();
                                                if (listener instanceof UISWTViewEventListenerHolder) {
                                                    listener = ((UISWTViewEventListenerHolder) listener).getDelegatedEventListener(view);
                                                }
                                                if (listener instanceof PeersView) {
                                                    tf.setSelection(item);
                                                    Event ev = new Event();
                                                    ev.item = item;
                                                    // manual setSelection doesn't file selection event - derp
                                                    tf.notifyListeners(SWT.Selection, ev);
                                                    ((PeersView) listener).selectPeer(target);
                                                    return;
                                                }
                                            }
                                        }
                                        comp = comp.getParent();
                                    }
                                } catch (Throwable e) {
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    });
    // without this we get a transient blank when mousing in and out of the tab folder on OSX :(
    panel.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            doRefresh();
        }
    });
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) Listener(org.eclipse.swt.widgets.Listener) DownloadManagerPeerListener(com.biglybt.core.download.DownloadManagerPeerListener) CTabFolder(org.eclipse.swt.custom.CTabFolder) PEPeerStats(com.biglybt.core.peer.PEPeerStats) DownloadManager(com.biglybt.core.download.DownloadManager) CTabItem(org.eclipse.swt.custom.CTabItem) MdiEntry(com.biglybt.ui.mdi.MdiEntry) UIFunctions(com.biglybt.ui.UIFunctions) MdiEntry(com.biglybt.ui.mdi.MdiEntry) Menu(org.eclipse.swt.widgets.Menu) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Example 53 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class FilesView method defaultSelected.

// @see TableSelectionListener#defaultSelected(TableRowCore[])
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
    DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) tv.getFirstSelectedDataSource();
    if (fileInfo == null) {
        return;
    }
    boolean webInBrowser = COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowser");
    if (webInBrowser) {
        if (ManagerUtils.browseWebsite(fileInfo)) {
            return;
        }
    }
    String mode = COConfigurationManager.getStringParameter("list.dm.dblclick");
    if (origin == 1) {
        String enter_mode = COConfigurationManager.getStringParameter("list.dm.enteraction");
        if (!enter_mode.equals("-1")) {
            mode = enter_mode;
        }
    }
    switch(mode) {
        case "1":
            {
                DownloadManager dm = fileInfo.getDownloadManager();
                if (dm != null) {
                    UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                }
                break;
            }
        case "2":
            boolean openMode = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
            ManagerUtils.open(fileInfo, openMode);
            break;
        case "3":
        case "4":
            if (fileInfo.getAccessMode() == DiskManagerFileInfo.READ) {
                if (mode.equals("4") && fileInfo.getDownloaded() == fileInfo.getLength() && Utils.isQuickViewSupported(fileInfo)) {
                    Utils.setQuickViewActive(fileInfo, true);
                } else {
                    Utils.launch(fileInfo);
                }
            }
            break;
        case "5":
            ManagerUtils.browse(fileInfo);
            break;
        default:
            int file_index = fileInfo.getIndex();
            DownloadManager dm = fileInfo.getDownloadManager();
            boolean canPlay = PlayUtils.canPlayDS(dm, file_index, true) || PlayUtils.canStreamDS(dm, file_index, true);
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (uif != null) {
                uif.playOrStreamDataSource(fileInfo, DLReferals.DL_REFERAL_PLAYDM, false, false);
                return;
            }
            if (fileInfo.getAccessMode() == DiskManagerFileInfo.READ) {
                Utils.launch(fileInfo);
            }
            break;
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) UIFunctions(com.biglybt.ui.UIFunctions) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 54 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class ConfigSectionInterfaceLanguage method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    Label label;
    GridLayout layout;
    GridData gridData;
    Composite cMain = new Composite(parent, SWT.NULL);
    cMain.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cMain.setLayout(layout);
    label = new Label(cMain, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    label.setLayoutData(gridData);
    // old name path, but already translated
    Messages.setLanguageText(label, "MainWindow.menu.language");
    Locale[] locales = MessageText.getLocales(true);
    String[] drop_labels = new String[locales.length];
    String[] drop_values = new String[locales.length];
    int iUsingLocale = -1;
    for (int i = 0; i < locales.length; i++) {
        Locale locale = locales[i];
        String sName = locale.getDisplayName(locale);
        String sName2 = locale.getDisplayName();
        if (!sName.equals(sName2)) {
            sName += " - " + sName2;
        }
        drop_labels[i] = sName + " - " + locale;
        drop_values[i] = locale.toString();
        if (MessageText.isCurrentLocale(locale))
            iUsingLocale = i;
    }
    StringListParameter locale_param = new StringListParameter(cMain, "locale", drop_labels, drop_values, false);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.minimumHeight = 50;
    locale_param.setLayoutData(gridData);
    // in the future that matches closer to their locale)
    if (iUsingLocale >= 0)
        ((List) locale_param.getControl()).select(iUsingLocale);
    locale_param.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            MessageText.loadBundle();
            DisplayFormatters.setUnits();
            DisplayFormatters.loadMessages();
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshLanguage();
            }
        }
    });
    BooleanParameter uc = new BooleanParameter(cMain, "label.lang.upper.case", false, "label.lang.upper.case");
    uc.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            MessageText.loadBundle(true);
            DisplayFormatters.setUnits();
            DisplayFormatters.loadMessages();
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshLanguage();
            }
        }
    });
    return cMain;
}
Also used : Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) GridData(org.eclipse.swt.layout.GridData)

Example 55 with UIFunctions

use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.

the class LanguagePanel method show.

@Override
public void show() {
    GridData gridData;
    wizard.setTitleAsResourceID("configureWizard.welcome.title");
    Composite rootPanel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    rootPanel.setLayout(layout);
    final Label lblChoose = new Label(rootPanel, SWT.WRAP);
    setChooseLabel(lblChoose);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(lblChoose, gridData);
    final List lstLanguage = new List(rootPanel, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 350;
    Utils.setLayoutData(lstLanguage, gridData);
    final Locale[] locales = MessageText.getLocales(true);
    int iUsingLocale = -1;
    for (int i = 0; i < locales.length; i++) {
        Locale locale = locales[i];
        lstLanguage.add(buildName(locale));
        if (MessageText.isCurrentLocale(locale))
            iUsingLocale = i;
    }
    lstLanguage.select(iUsingLocale);
    lstLanguage.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            int index = lstLanguage.getSelectionIndex();
            if (index >= 0 && index < locales.length) {
                COConfigurationManager.setParameter("locale", locales[index].toString());
                MessageText.loadBundle();
                DisplayFormatters.setUnits();
                DisplayFormatters.loadMessages();
                Shell shell = wizard.getWizardWindow();
                Messages.updateLanguageForControl(shell);
                setChooseLabel(lblChoose);
                shell.layout(true, true);
                lstLanguage.setRedraw(false);
                for (int i = 0; i < locales.length; i++) {
                    lstLanguage.setItem(i, buildName(locales[i]));
                }
                lstLanguage.setRedraw(true);
                try {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    if (uiFunctions != null) {
                        uiFunctions.refreshLanguage();
                    }
                } catch (Exception ex) {
                }
            }
        }
    });
    FontData[] fontData = lstLanguage.getFont().getFontData();
    for (int i = 0; i < fontData.length; i++) {
        if (fontData[i].getHeight() < 10)
            fontData[i].setHeight(10);
    }
    final Font font = new Font(rootPanel.getDisplay(), fontData);
    lstLanguage.setFont(font);
    lstLanguage.getShell().addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event event) {
            lstLanguage.showSelection();
        }
    });
    lstLanguage.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (font != null && !font.isDisposed())
                font.dispose();
        }
    });
}
Also used : Locale(java.util.Locale) DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) FontData(org.eclipse.swt.graphics.FontData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

UIFunctions (com.biglybt.ui.UIFunctions)68 DownloadManager (com.biglybt.core.download.DownloadManager)16 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 File (java.io.File)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 GridData (org.eclipse.swt.layout.GridData)8 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Menu (org.eclipse.swt.widgets.Menu)7 Core (com.biglybt.core.Core)6 LogEvent (com.biglybt.core.logging.LogEvent)6 UIFunctionsUserPrompter (com.biglybt.ui.UIFunctionsUserPrompter)6 Composite (org.eclipse.swt.widgets.Composite)6 MenuItem (org.eclipse.swt.widgets.MenuItem)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 GlobalManager (com.biglybt.core.global.GlobalManager)5 LogAlert (com.biglybt.core.logging.LogAlert)5