Search in sources :

Example 6 with UIUpdatable

use of com.biglybt.ui.common.updater.UIUpdatable in project BiglyBT by BiglySoftware.

the class TopBarView method buildTopBarViews.

/**
 * @param skinObject
 *
 * @since 3.0.1.1
 */
public void buildTopBarViews() {
    // TODO actually use plugins..
    SWTSkinObject skinObject = skin.getSkinObject("topbar-plugins");
    if (skinObject == null) {
        return;
    }
    try {
        cPluginArea = (Composite) skinObject.getControl();
        final UIUpdatable updatable = new UIUpdatable() {

            @Override
            public void updateUI() {
                Object[] views = topbarViews.toArray();
                for (int i = 0; i < views.length; i++) {
                    try {
                        UISWTViewCore view = (UISWTViewCore) views[i];
                        if (view.getComposite().isVisible()) {
                            view.triggerEvent(UISWTViewEvent.TYPE_REFRESH, null);
                        }
                    } catch (Exception e) {
                        Debug.out(e);
                    }
                }
            }

            @Override
            public String getUpdateUIName() {
                return "TopBar";
            }
        };
        try {
            UIUpdater updater = UIUpdaterSWT.getInstance();
            if (updater != null) {
                updater.addUpdater(updatable);
            }
        } catch (Exception e) {
            Debug.out(e);
        }
        skinObject.getControl().addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                try {
                    UIUpdater updater = UIUpdaterSWT.getInstance();
                    if (updater != null) {
                        updater.removeUpdater(updatable);
                    }
                } catch (Exception ex) {
                    Debug.out(ex);
                }
                Object[] views = topbarViews.toArray();
                topbarViews.clear();
                for (int i = 0; i < views.length; i++) {
                    UISWTViewCore view = (UISWTViewCore) views[i];
                    if (view != null) {
                        view.triggerEvent(UISWTViewEvent.TYPE_DESTROY, null);
                    }
                }
            }
        });
        /*
			SWTSkinObject soPrev = skin.getSkinObject("topbar-plugin-prev");
			if (soPrev != null) {
				SWTSkinButtonUtility btnPrev = new SWTSkinButtonUtility(soPrev);
				btnPrev.addSelectionListener(new ButtonListenerAdapter() {
					public void pressed(SWTSkinButtonUtility buttonUtility,
							SWTSkinObject skinObject, int stateMask) {
						//System.out.println("prev click " + activeTopBar + " ; "
						//		+ topbarViews.size());
						if (activeTopBar == null || topbarViews.size() <= 1) {
							return;
						}
						int i = topbarViews.indexOf(activeTopBar) - 1;
						if (i < 0) {
							i = topbarViews.size() - 1;
						}
						activateTopBar((UISWTViewCore) topbarViews.get(i));
					}
				});
			}

			SWTSkinObject soNext = skin.getSkinObject("topbar-plugin-next");
			if (soNext != null) {
				SWTSkinButtonUtility btnNext = new SWTSkinButtonUtility(soNext);
				btnNext.addSelectionListener(new ButtonListenerAdapter() {
					public void pressed(SWTSkinButtonUtility buttonUtility,
							SWTSkinObject skinObject, int stateMask) {
						//System.out.println("next click");
						if (activeTopBar == null || topbarViews.size() <= 1) {
							return;
						}
						int i = topbarViews.indexOf(activeTopBar) + 1;
						if (i >= topbarViews.size()) {
							i = 0;
						}
						activateTopBar((UISWTViewCore) topbarViews.get(i));
					}
				});
			}

			SWTSkinObject soTitle = skin.getSkinObject("topbar-plugin-title");
			if (soTitle != null) {
				final Composite cTitle = (Composite) soTitle.getControl();
				cTitle.addPaintListener(new PaintListener() {
					public void paintControl(PaintEvent e) {
						e.gc.setAdvanced(true);
						//Font font = new Font(e.gc.getDevice(), "Sans", 8, SWT.NORMAL);
						//e.gc.setFont(font);
						if (e.gc.getAdvanced() && activeTopBar != null) {
							try {
								e.gc.setTextAntialias(SWT.ON);
							} catch (Exception ex) {
								// Ignore ERROR_NO_GRAPHICS_LIBRARY error or any others
							}

							try {
								Transform transform = new Transform(e.gc.getDevice());
								transform.rotate(270);
								e.gc.setTransform(transform);

								String s = activeTopBar.getFullTitle();
								Point size = e.gc.textExtent(s);
								e.gc.drawText(s, -size.x, 0, true);
								//e.gc.drawText(s, 0,0, true);
								transform.dispose();
							} catch (Exception ex) {
								// setTransform can trhow a ERROR_NO_GRAPHICS_LIBRARY error
								// no use trying to draw.. it would look weird
							}
							//font.dispose();
						}
					}
				});
			}
			*/
        SWTSkinObject soList = skin.getSkinObject("topbar-plugin-list");
        if (soList != null) {
            final Composite cList = (Composite) soList.getControl();
            listPlugins = new org.eclipse.swt.widgets.List(cList, SWT.V_SCROLL);
            listPlugins.setLayoutData(Utils.getFilledFormData());
            listPlugins.setBackground(cList.getBackground());
            listPlugins.setForeground(cList.getForeground());
            listPlugins.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String[] selection = listPlugins.getSelection();
                    if (selection.length > 0) {
                        String name = selection[0];
                        for (UISWTViewCore view : topbarViews) {
                            if (getViewName(view).equals(name)) {
                                activateTopBar(view);
                            }
                        }
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            Messages.setLanguageTooltip(listPlugins, "label.right.click.for.options.tooltip");
            final Menu menu = new Menu(listPlugins);
            listPlugins.setMenu(menu);
            menu.addMenuListener(new MenuListener() {

                @Override
                public void menuShown(MenuEvent e) {
                    for (MenuItem mi : menu.getItems()) {
                        mi.dispose();
                    }
                    for (final UISWTViewCore view : topbarViews) {
                        final String name = getViewName(view);
                        final MenuItem mi = new MenuItem(menu, SWT.CHECK);
                        mi.setText(name);
                        boolean enabled = isEnabled(view);
                        mi.setSelection(enabled);
                        mi.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                boolean enabled = mi.getSelection();
                                setEnabled(view, enabled);
                                if (enabled) {
                                    activateTopBar(view);
                                } else {
                                    listPlugins.remove(name);
                                    activateTopBar(null);
                                }
                                Utils.relayout(cPluginArea);
                            }
                        });
                    }
                }

                @Override
                public void menuHidden(MenuEvent e) {
                }
            });
        }
        skinObject = skin.getSkinObject(SkinConstants.VIEWID_PLUGINBAR);
        if (skinObject != null) {
            Listener l = new Listener() {

                private int mouseDownAt = 0;

                @Override
                public void handleEvent(Event event) {
                    Composite c = (Composite) event.widget;
                    if (event.type == SWT.MouseDown) {
                        Rectangle clientArea = c.getClientArea();
                        if (event.y > clientArea.height - 10) {
                            mouseDownAt = event.y;
                        }
                    } else if (event.type == SWT.MouseUp && mouseDownAt > 0) {
                        int diff = event.y - mouseDownAt;
                        mouseDownAt = 0;
                        FormData formData = (FormData) c.getLayoutData();
                        formData.height += diff;
                        if (formData.height < 50) {
                            formData.height = 50;
                        } else {
                            Rectangle clientArea = c.getShell().getClientArea();
                            int max = clientArea.height - 350;
                            if (formData.height > max) {
                                formData.height = max;
                            }
                        }
                        COConfigurationManager.setParameter("v3.topbar.height", formData.height);
                        Utils.relayout(c);
                    } else if (event.type == SWT.MouseMove) {
                        Rectangle clientArea = c.getClientArea();
                        boolean draggable = (event.y > clientArea.height - 10);
                        c.setCursor(draggable ? c.getDisplay().getSystemCursor(SWT.CURSOR_SIZENS) : null);
                    } else if (event.type == SWT.MouseExit) {
                        c.setCursor(null);
                    }
                }
            };
            Control control = skinObject.getControl();
            control.addListener(SWT.MouseDown, l);
            control.addListener(SWT.MouseUp, l);
            control.addListener(SWT.MouseMove, l);
            control.addListener(SWT.MouseExit, l);
            skinObject.addListener(new SWTSkinObjectListener() {

                @Override
                public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
                    if (eventType == EVENT_SHOW) {
                        int h = COConfigurationManager.getIntParameter("v3.topbar.height");
                        Control control = skinObject.getControl();
                        FormData formData = (FormData) control.getLayoutData();
                        formData.height = h;
                        control.setLayoutData(formData);
                        Utils.relayout(control);
                    }
                    return null;
                }
            });
        }
        UISWTInstanceImpl uiSWTinstance = (UISWTInstanceImpl) UIFunctionsManagerSWT.getUIFunctionsSWT().getUISWTInstance();
        if (uiSWTinstance != null && !registeredCoreSubViews) {
            uiSWTinstance.addView(UISWTInstance.VIEW_TOPBAR, "ViewDownSpeedGraph", new ViewDownSpeedGraph());
            uiSWTinstance.addView(UISWTInstance.VIEW_TOPBAR, "ViewUpSpeedGraph", new ViewUpSpeedGraph());
            uiSWTinstance.addView(UISWTInstance.VIEW_TOPBAR, "ViewQuickConfig", new ViewQuickConfig());
            uiSWTinstance.addView(UISWTInstance.VIEW_TOPBAR, "ViewQuickNetInfo", new ViewQuickNetInfo());
            uiSWTinstance.addView(UISWTInstance.VIEW_TOPBAR, "ViewQuickNotifications", new ViewQuickNotifications());
            registeredCoreSubViews = true;
        }
        if (uiSWTinstance != null) {
            UISWTViewEventListenerHolder[] pluginViews = uiSWTinstance.getViewListeners(UISWTInstance.VIEW_TOPBAR);
            for (UISWTViewEventListenerHolder l : pluginViews) {
                if (l != null) {
                    try {
                        UISWTViewImpl view = new UISWTViewImpl(l.getViewID(), UISWTInstance.VIEW_TOPBAR, false);
                        view.setEventListener(l, true);
                        addTopBarView(view, cPluginArea);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            }
        }
        String active_view_id = COConfigurationManager.getStringParameter("topbar.active.view.id", "");
        boolean activated = false;
        UISWTViewCore first_enabled = null;
        for (UISWTViewCore view : topbarViews) {
            if (isEnabled(view)) {
                if (first_enabled == null) {
                    first_enabled = view;
                }
                if (active_view_id.equals(view.getViewID())) {
                    activateTopBar(view);
                    activated = true;
                    break;
                }
            }
        }
        if (!activated && first_enabled != null) {
            activateTopBar(first_enabled);
            activated = true;
        }
        if (!activated && topbarViews.size() > 0) {
            UISWTViewCore view = topbarViews.get(0);
            setEnabled(view, true);
            activateTopBar(view);
        }
        if (skinObject != null) {
            skinObject.getControl().getParent().layout(true);
        }
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) Rectangle(org.eclipse.swt.graphics.Rectangle) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) org.eclipse.swt.widgets(org.eclipse.swt.widgets) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIUpdater(com.biglybt.ui.common.updater.UIUpdater)

Example 7 with UIUpdatable

use of com.biglybt.ui.common.updater.UIUpdatable in project BiglyBT by BiglySoftware.

the class SubscriptionWizard method createAvailableSubscriptionComposite.

private Composite createAvailableSubscriptionComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
    Label subtitle1 = new Label(composite, SWT.NONE);
    Label subtitle2 = new Label(composite, SWT.NONE);
    subtitle1.setFont(subTitleFont);
    subtitle2.setFont(subTitleFont);
    subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
    subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
    libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
    torrentColumn.setWidth(Utils.adjustPXForDPI(50));
    final Composite compEmpty = new Composite(composite, SWT.NONE);
    compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
    compEmpty.setBackgroundMode(SWT.INHERIT_DEFAULT);
    FillLayout fl = new FillLayout();
    fl.marginHeight = 15;
    fl.marginWidth = 15;
    compEmpty.setLayout(fl);
    compEmpty.setVisible(false);
    final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
    labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
    labelEmpty.setFont(subTitleFont);
    labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
    labelEmpty.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
                Utils.launch(event.text);
            }
        }
    });
    initColumns();
    final Composite cTV = new Composite(composite, SWT.NONE);
    cTV.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    cTV.setLayout(layout);
    tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    tvSubscriptions.setMenuEnabled(false);
    tvSubscriptions.setHeaderVisible(false);
    tvSubscriptions.setRowDefaultHeightEM(1.4f);
    tvSubscriptions.initialize(cTV);
    tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
            com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
            Rectangle clientArea = ((Composite) event.widget).getClientArea();
            tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
        }
    });
    tvSubscriptions.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] row) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    } else {
                        addButton.setEnabled(true);
                        TableRowCore[] rows = tvSubscriptions.getSelectedRows();
                        Subscription subscription = (Subscription) rows[0].getDataSource();
                        if (subscription.isSubscribed()) {
                            addButton.setEnabled(false);
                        } else {
                            addButton.setEnabled(true);
                        }
                        addButton.setData("subscription", subscription);
                    }
                }
            });
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    }
                }
            });
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
        }
    }, false);
    UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {

        @Override
        public void updateUI() {
            if (tvSubscriptions != null) {
                tvSubscriptions.refreshTable(false);
            }
        }

        @Override
        public String getUpdateUIName() {
            return "SubWiz";
        }
    });
    Listener resizeListener = new Listener() {

        int last_width;

        @Override
        public void handleEvent(Event event) {
            Table table = (Table) event.widget;
            Rectangle rect = table.getClientArea();
            int width = rect.width - 3;
            if (width == last_width) {
                return;
            }
            last_width = width;
            int nbColumns = table.getColumnCount();
            if (nbColumns == 1) {
                table.getColumns()[0].setWidth(width);
            }
            ((Table) event.widget).update();
        }
    };
    // subscriptionTable.addListener(SWT.Resize , resizeListener);
    libraryTable.addListener(SWT.Resize, resizeListener);
    final Listener selectionListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            subscriptions = (Subscription[]) item.getData("subscriptions");
            tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
            if (subscriptions != null) {
                tvSubscriptions.addDataSources(subscriptions);
            }
            tvSubscriptions.processDataSourceQueueSync();
            addButton.setEnabled(false);
            addButton.setData("subscription", null);
            tvSubscriptions.setSelectedRows(new TableRowCore[0]);
            if (subscriptions != null && subscriptions.length > 0) {
                TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
                if (row != null) {
                    row.setSelected(true);
                }
            }
        }
    };
    libraryTable.addListener(SWT.Selection, selectionListener);
    if (availableSubscriptions != null) {
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
                item.setText(subInfo.getDownload().getDisplayName());
                item.setData("subscriptions", subInfo.getSubscriptions());
                boolean isSubscribed = false;
                Subscription[] subs = subInfo.getSubscriptions();
                for (int i = 0; i < subs.length; i++) {
                    if (subs[i].isSubscribed())
                        isSubscribed = true;
                }
                if (isSubscribed) {
                    item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
                }
                if (subInfo.getDownload() == download) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (index == 0 && download == null) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (libraryTable.getSelectionIndex() == index) {
                    // If the item was already selected and we got the SetData afterwards, then let's populate the
                    // subscriptionsTable
                    selectionListener.handleEvent(event);
                }
            }
        });
        libraryTable.setItemCount(availableSubscriptions.length);
        if (availableSubscriptions.length == 0) {
            libraryTable.setVisible(false);
            compEmpty.setVisible(true);
        }
    } else {
        // Test code
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                item.setText("test " + index);
            }
        });
        libraryTable.setItemCount(20);
    }
    addButton.setEnabled(false);
    addButton.setData("subscription", null);
    // final Image rssIcon = imageLoader.getImage("icon_rss");
    libraryTable.addListener(SWT.MeasureItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.height = 20;
        }
    });
    FormLayout formLayout = new FormLayout();
    composite.setLayout(formLayout);
    FormData data;
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(40, 0);
    data.bottom = new FormAttachment(100, 0);
    vsep.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 5);
    subtitle1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(vsep, 5);
    data.right = new FormAttachment(100, 0);
    subtitle2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle1, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    hsep1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle2, 5);
    data.left = new FormAttachment(vsep, -1);
    data.right = new FormAttachment(100, 0);
    hsep2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(hsep1, 0);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    if (availableSubscriptions != null && availableSubscriptions.length > 0) {
        libraryTable.setLayoutData(data);
    } else {
        // hack: dispose libraryTable as it's not needed and draws over controls
        // (makes a white box covering text).  Would be smarter to not
        // create the libraryTable at all..
        libraryTable.dispose();
        cancelButton.setFocus();
        shell.setDefaultButton(cancelButton);
        compEmpty.setLayoutData(data);
    }
    data = new FormData();
    data.top = new FormAttachment(hsep2, 0);
    data.left = new FormAttachment(vsep, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    cTV.setLayoutData(data);
    return composite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) Listener(org.eclipse.swt.widgets.Listener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GridLayout(org.eclipse.swt.layout.GridLayout) Subscription(com.biglybt.core.subs.Subscription) FormAttachment(org.eclipse.swt.layout.FormAttachment) UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableColumn(org.eclipse.swt.widgets.TableColumn) SubscriptionDownloadDetails(com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails) Event(org.eclipse.swt.widgets.Event) Link(org.eclipse.swt.widgets.Link)

Example 8 with UIUpdatable

use of com.biglybt.ui.common.updater.UIUpdatable 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 9 with UIUpdatable

use of com.biglybt.ui.common.updater.UIUpdatable in project BiglyBT by BiglySoftware.

the class SideBarEntrySWT method buildStandAlone.

public static SWTSkinObjectContainer buildStandAlone(SWTSkinObjectContainer soParent, String skinRef, SWTSkin skin, String parentID, String id, Object datasource, int controlType, TreeItem swtItem, UISWTViewEventListener original_event_listener, boolean listener_is_new) {
    Control control = null;
    // SWTSkin skin = soParent.getSkin();
    Composite parent = soParent.getComposite();
    if (skinRef != null) {
        Shell shell = parent.getShell();
        Cursor cursor = shell.getCursor();
        try {
            shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
            // wrap skinRef with a container that we control visibility of
            // (invisible by default)
            SWTSkinObjectContainer soContents = (SWTSkinObjectContainer) skin.createSkinObject("MdiContents." + uniqueNumber++, SO_ID_ENTRY_WRAPPER, soParent, null);
            SWTSkinObject skinObject = skin.createSkinObject(id, skinRef, soContents, datasource);
            control = skinObject.getControl();
            control.setLayoutData(Utils.getFilledFormData());
            control.getParent().layout(true, true);
            soContents.setVisible(true);
            return (soContents);
        } finally {
            shell.setCursor(cursor);
        }
    } else {
        if ((original_event_listener instanceof UISWTViewCoreEventListenerEx && ((UISWTViewCoreEventListenerEx) original_event_listener).isCloneable()) || (original_event_listener instanceof UISWTViewEventListenerEx)) {
            final UISWTViewImpl view = new UISWTViewImpl(id, parentID, true);
            final UISWTViewEventListener event_listener = original_event_listener instanceof UISWTViewEventListenerEx ? ((UISWTViewEventListenerEx) original_event_listener).getClone() : ((UISWTViewCoreEventListenerEx) original_event_listener).getClone();
            try {
                view.setEventListener(event_listener, false);
            } catch (Throwable e) {
                // shouldn't happen as we aren't asking for 'create' to occur which means it can't fail
                Debug.out(e);
            }
            view.setDatasource(datasource);
            try {
                SWTSkinObjectContainer soContents = (SWTSkinObjectContainer) skin.createSkinObject("MdiIView." + uniqueNumber++, SO_ID_ENTRY_WRAPPER, soParent);
                parent.setBackgroundMode(SWT.INHERIT_NONE);
                final Composite viewComposite = soContents.getComposite();
                boolean doGridLayout = true;
                if (controlType == CONTROLTYPE_SKINOBJECT) {
                    doGridLayout = false;
                }
                // SWT.COLOR_WIDGET_FOREGROUND));
                if (doGridLayout) {
                    GridLayout gridLayout = new GridLayout();
                    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
                    viewComposite.setLayout(gridLayout);
                    viewComposite.setLayoutData(Utils.getFilledFormData());
                }
                view.setPluginSkinObject(soContents);
                view.initialize(viewComposite);
                // without this some views get messed up layouts (chat view for example)
                viewComposite.setData(Utils.RELAYOUT_UP_STOP_HERE, true);
                soContents.addListener(new SWTSkinObjectListener() {

                    @Override
                    public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
                        if (eventType == SWTSkinObjectListener.EVENT_OBFUSCATE) {
                            Map data = new HashMap();
                            data.put("image", (Image) params);
                            data.put("obfuscateTitle", false);
                            view.triggerEvent(UISWTViewEvent.TYPE_OBFUSCATE, data);
                        }
                        return null;
                    }
                });
                if (PAINT_BG) {
                    if (swtItem != null) {
                        swtItem.setText(view.getFullTitle());
                    }
                }
                Composite iviewComposite = view.getComposite();
                control = iviewComposite;
                // that instead of form)
                if (doGridLayout) {
                    Object existingLayoutData = iviewComposite.getLayoutData();
                    Object existingParentLayoutData = iviewComposite.getParent().getLayoutData();
                    if (existingLayoutData == null || !(existingLayoutData instanceof GridData) && (existingParentLayoutData instanceof GridLayout)) {
                        GridData gridData = new GridData(GridData.FILL_BOTH);
                        iviewComposite.setLayoutData(gridData);
                    }
                }
                parent.layout(true, true);
                final UIUpdater updater = UIUpdaterSWT.getInstance();
                if (updater != null) {
                    updater.addUpdater(new UIUpdatable() {

                        @Override
                        public void updateUI() {
                            if (viewComposite.isDisposed()) {
                                updater.removeUpdater(this);
                            } else {
                                view.triggerEvent(UISWTViewEvent.TYPE_REFRESH, null);
                            }
                        }

                        @Override
                        public String getUpdateUIName() {
                            return ("popout");
                        }
                    });
                    if (event_listener instanceof IViewRequiresPeriodicUpdates) {
                        updater.addPeriodicUpdater(new UIUpdatable() {

                            @Override
                            public void updateUI() {
                                if (viewComposite.isDisposed()) {
                                    updater.removePeriodicUpdater(this);
                                } else {
                                    event_listener.eventOccurred(new UISWTViewEvent() {

                                        @Override
                                        public UISWTView getView() {
                                            return null;
                                        }

                                        @Override
                                        public int getType() {
                                            return (StatsView.EVENT_PERIODIC_UPDATE);
                                        }

                                        @Override
                                        public Object getData() {
                                            return null;
                                        }
                                    });
                                }
                            }

                            @Override
                            public String getUpdateUIName() {
                                return ("popout");
                            }
                        });
                    }
                }
                soContents.setVisible(true);
                view.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
                iviewComposite.addDisposeListener(new DisposeListener() {

                    @Override
                    public void widgetDisposed(DisposeEvent arg0) {
                        view.triggerEvent(UISWTViewEvent.TYPE_DESTROY, null);
                    }
                });
                return (soContents);
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    }
    return (null);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) GridLayout(org.eclipse.swt.layout.GridLayout) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) UISWTViewEventListenerEx(com.biglybt.ui.swt.pif.UISWTViewEventListenerEx) UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewImpl(com.biglybt.ui.swt.pifimpl.UISWTViewImpl) GridData(org.eclipse.swt.layout.GridData) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) UISWTViewCoreEventListenerEx(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListenerEx) IViewRequiresPeriodicUpdates(com.biglybt.ui.swt.views.IViewRequiresPeriodicUpdates)

Example 10 with UIUpdatable

use of com.biglybt.ui.common.updater.UIUpdatable in project BiglyBT by BiglySoftware.

the class SkinView method skinObjectDestroyed.

// @see SWTSkinObjectAdapter#skinObjectDestroyed(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectDestroyed(SWTSkinObject skinObject, Object params) {
    disposed = true;
    SkinViewManager.remove(this);
    if (this instanceof UIUpdatable) {
        UIUpdatable updateable = (UIUpdatable) this;
        try {
            UIUpdater updater = UIUpdaterSWT.getInstance();
            if (updater != null) {
                updater.removeUpdater(updateable);
            }
        } catch (Exception e) {
            Debug.out(e);
        }
    }
    return null;
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) UIUpdater(com.biglybt.ui.common.updater.UIUpdater)

Aggregations

UIUpdatable (com.biglybt.ui.common.updater.UIUpdatable)10 UIUpdater (com.biglybt.ui.common.updater.UIUpdater)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)3 SWTSkinObjectListener (com.biglybt.ui.swt.skin.SWTSkinObjectListener)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 MdiEntryVitalityImage (com.biglybt.ui.mdi.MdiEntryVitalityImage)2 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)2 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)2 UISWTViewEventListenerEx (com.biglybt.ui.swt.pif.UISWTViewEventListenerEx)2 UISWTViewCoreEventListenerEx (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListenerEx)2 UISWTViewImpl (com.biglybt.ui.swt.pifimpl.UISWTViewImpl)2 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)2 FilesView (com.biglybt.ui.swt.views.FilesView)2 IViewRequiresPeriodicUpdates (com.biglybt.ui.swt.views.IViewRequiresPeriodicUpdates)2