Search in sources :

Example 31 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class ProgressReporterWindow method openWindow.

/**
 * Set initial size and layout for the window then open it
 */
private void openWindow() {
    /*
		 * Using initialMaxNumberOfPanels as a lower limit we exclude all other panels from the layout,
		 * compute the window size, then finally we include all panels back into the layout
		 *
		 *  This ensures that the window will fit exactly the desired number of panels
		 */
    Control[] controls = scrollChild.getChildren();
    for (int i = (initialMaxNumberOfPanels); i < controls.length; i++) {
        ((GridData) controls[i].getLayoutData()).exclude = true;
    }
    Point p = shell.computeSize(defaultShellWidth, SWT.DEFAULT);
    for (int i = 0; i < controls.length; i++) {
        ((GridData) controls[i].getLayoutData()).exclude = false;
    }
    formatLastPanel(null);
    scrollChild.layout();
    /*
		 * Set the shell size if it's different that the computed size
		 */
    if (!shell.getSize().equals(p)) {
        shell.setSize(p);
        shell.layout(false);
    }
    /*
		 * Centers the window
		 */
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (null == uiFunctions) {
        /*
			 * Centers on the active monitor
			 */
        Utils.centreWindow(shell);
    } else {
        /*
			 * Centers on the main application window
			 */
        Utils.centerWindowRelativeTo(shell, uiFunctions.getMainShell());
    }
    shell.open();
}
Also used : Control(org.eclipse.swt.widgets.Control) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 32 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class UIUpdaterSWT method makeDebugToolTip.

private void makeDebugToolTip(Map<UIUpdatable, Long> timeMap) {
    final int IDX_AVG = 0;
    final int IDX_SIZE = 1;
    final int IDX_MAX = 2;
    final int IDX_LAST = 3;
    final int IDX_TIME = 4;
    long ttl = 0;
    for (Iterator<UIUpdatable> iter = timeMap.keySet().iterator(); iter.hasNext(); ) {
        UIUpdatable key = iter.next();
        if (!averageTimes.containsKey(key))
            averageTimes.put(key, new Long[] { 0L, 0L, 0L, 0L, System.currentTimeMillis() });
        Long[] average = averageTimes.get(key);
        long diff = timeMap.get(key).longValue();
        if (diff > 0) {
            long count = average[IDX_SIZE];
            // require storing all 20 values and averaging them each time
            if (count >= 20)
                count = 19;
            long lNewAverage = (average[IDX_AVG] * count + diff) / (count + 1);
            average[IDX_AVG] = lNewAverage;
            average[IDX_SIZE] = count + 1;
            if (diff > average[IDX_MAX])
                average[IDX_MAX] = diff;
            average[IDX_LAST] = diff;
            average[IDX_TIME] = System.currentTimeMillis();
        } else {
            average[IDX_LAST] = diff;
        }
        ttl += diff;
        averageTimes.put(key, average);
    }
    // System.out.println(SystemTime.getCurrentTime() + "] Refresh " + ttl + "ms");
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    IMainStatusBar mainStatusBar = uiFunctionsSWT == null ? null : uiFunctionsSWT.getMainStatusBar();
    if (mainStatusBar != null && mainStatusBar.isMouseOver()) {
        StringBuilder sb = new StringBuilder();
        for (Iterator iter = averageTimes.keySet().iterator(); iter.hasNext(); ) {
            Object key = iter.next();
            Object[] average = (Object[]) averageTimes.get(key);
            long lLastUpdated = ((Long) average[IDX_TIME]).longValue();
            if (System.currentTimeMillis() - lLastUpdated > 10000) {
                iter.remove();
                continue;
            }
            long lTime = ((Long) average[IDX_AVG]).longValue();
            if (lTime > 0) {
                if (sb.length() > 0)
                    sb.append("\n");
                sb.append(lTime * 100 / waitTimeMS);
                sb.append("% ");
                sb.append(lTime).append("ms avg: ");
                sb.append("[").append(((UIUpdatable) key).getUpdateUIName()).append("]");
                sb.append(average[IDX_SIZE]).append(" samples");
                sb.append("; max:").append(average[IDX_MAX]);
                sb.append("; last:").append(average[IDX_LAST]);
            }
        }
        mainStatusBar.setDebugInfo(sb.toString());
    }
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) IMainStatusBar(com.biglybt.ui.swt.mainwindow.IMainStatusBar) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT)

Example 33 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class StatsView method initialize.

private void initialize(Composite composite) {
    parent = composite;
    // Call plugin listeners
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        tabbedMDI = uiFunctions.createTabbedMDI(composite, VIEW_ID);
        CTabFolder folder = tabbedMDI.getTabFolder();
        Label lblClose = new Label(folder, SWT.WRAP);
        lblClose.setText("x");
        lblClose.addListener(SWT.MouseUp, new Listener() {

            @Override
            public void handleEvent(Event event) {
                delete();
            }
        });
        folder.setTopRight(lblClose);
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(pluginUI);
        if (pluginUI != null) {
            UISWTViewEventListenerWrapper[] pluginViews = pluginUI.getViewListeners(UISWTInstance.VIEW_STATISTICS);
            for (int i = 0; i < pluginViews.length; i++) {
                UISWTViewEventListenerWrapper l = pluginViews[i];
                String name = l.getViewID();
                try {
                    MdiEntrySWT entry = (MdiEntrySWT) tabbedMDI.createEntryFromEventListener(UISWTInstance.VIEW_STATISTICS, l, name, false, null, null);
                    entry.setDestroyOnDeactivate(false);
                    if ((dataSource == null && i == 0) || name.equals(dataSource)) {
                        tabbedMDI.showEntry(entry);
                    }
                } catch (Exception e) {
                // skip
                }
            }
        }
    }
    updateThread = new UpdateThread();
    updateThread.setDaemon(true);
    updateThread.start();
    dataSourceChanged(dataSource);
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) Listener(org.eclipse.swt.widgets.Listener) Label(org.eclipse.swt.widgets.Label) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) UISWTViewEventListenerWrapper(com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance)

Aggregations

UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)33 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)6 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DownloadManager (com.biglybt.core.download.DownloadManager)3 UIFunctions (com.biglybt.ui.UIFunctions)3 Composite (org.eclipse.swt.widgets.Composite)3 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)2 Core (com.biglybt.core.Core)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 PEPeer (com.biglybt.core.peer.PEPeer)2 AERunnable (com.biglybt.core.util.AERunnable)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)2 TabbedMdiMaximizeListener (com.biglybt.ui.swt.mdi.TabbedMdiMaximizeListener)2 UISWTViewEventListenerWrapper (com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper)2