Search in sources :

Example 1 with UIUpdatable

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

the class ColumnFileCount method openFilesMiniView.

private void openFilesMiniView(DownloadManager dm, TableCell cell) {
    Shell shell = ShellFactory.createShell(Utils.findAnyShell(), SWT.SHELL_TRIM);
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginHeight = 2;
    fillLayout.marginWidth = 2;
    shell.setLayout(fillLayout);
    Rectangle bounds = ((TableCellSWT) cell).getBoundsOnDisplay();
    bounds.y += bounds.height;
    bounds.width = 630;
    bounds.height = (16 * dm.getNumFileInfos()) + 60;
    Rectangle realBounds = shell.computeTrim(0, 0, bounds.width, bounds.height);
    realBounds.width -= realBounds.x;
    realBounds.height -= realBounds.y;
    realBounds.x = bounds.x;
    realBounds.y = bounds.y;
    if (bounds.height > 500) {
        bounds.height = 500;
    }
    shell.setBounds(realBounds);
    shell.setAlpha(230);
    Utils.verifyShellRect(shell, true);
    final FilesView view = new FilesView(false);
    view.dataSourceChanged(dm);
    view.initialize(shell);
    Composite composite = view.getComposite();
    // composite.setLayoutData(null);
    // shell.setLayout(new FillLayout());
    view.viewActivated();
    view.refresh();
    final UIUpdatable viewUpdater = new UIUpdatable() {

        @Override
        public void updateUI() {
            view.refresh();
        }

        @Override
        public String getUpdateUIName() {
            return view.getFullTitle();
        }
    };
    UIUpdaterSWT.getInstance().addUpdater(viewUpdater);
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            UIUpdaterSWT.getInstance().removeUpdater(viewUpdater);
            view.delete();
        }
    });
    shell.layout(true, true);
    shell.setText(dm.getDisplayName());
    shell.open();
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) DisposeListener(org.eclipse.swt.events.DisposeListener) Shell(org.eclipse.swt.widgets.Shell) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Composite(org.eclipse.swt.widgets.Composite) FilesView(com.biglybt.ui.swt.views.FilesView) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 2 with UIUpdatable

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

the class TagUIUtils method showFilesView.

private static void showFilesView(final TagDownload tag) {
    Shell shell = ShellFactory.createShell(Utils.findAnyShell(), SWT.SHELL_TRIM);
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginHeight = 2;
    fillLayout.marginWidth = 2;
    shell.setLayout(fillLayout);
    final FilesView view = new FilesView(false);
    view.setDisableWhenEmpty(false);
    Set<DownloadManager> dms = tag.getTaggedDownloads();
    view.dataSourceChanged(dms.toArray());
    view.initialize(shell);
    view.viewActivated();
    view.refresh();
    final UIUpdatable viewUpdater = new UIUpdatable() {

        @Override
        public void updateUI() {
            view.refresh();
        }

        @Override
        public String getUpdateUIName() {
            return view.getFullTitle();
        }
    };
    UIUpdaterSWT.getInstance().addUpdater(viewUpdater);
    final TagListener tag_listener = new TagListener() {

        @Override
        public void taggableSync(Tag tag) {
        }

        @Override
        public void taggableRemoved(Tag t, Taggable tagged) {
            Set<DownloadManager> dms = tag.getTaggedDownloads();
            view.dataSourceChanged(dms.toArray());
        }

        @Override
        public void taggableAdded(Tag t, Taggable tagged) {
            Set<DownloadManager> dms = tag.getTaggedDownloads();
            view.dataSourceChanged(dms.toArray());
        }
    };
    tag.addTagListener(tag_listener, false);
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            tag.removeTagListener(tag_listener);
            UIUpdaterSWT.getInstance().removeUpdater(viewUpdater);
            view.delete();
        }
    });
    shell.layout(true, true);
    shell.setText(tag.getTagName(true));
    shell.open();
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) DisposeListener(org.eclipse.swt.events.DisposeListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) FilesView(com.biglybt.ui.swt.views.FilesView) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 3 with UIUpdatable

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

the class SWTSkinObjectBasic method dispose.

// @see SWTSkinObject#dispose()
@Override
public void dispose() {
    Utils.disposeSWTObjects(bgImage);
    if (disposed) {
        return;
    }
    Utils.disposeSWTObjects(control);
    if (skinView != null) {
        removeListener(skinView);
        if (skinView instanceof UIUpdatable) {
            UIUpdatable updateable = (UIUpdatable) skinView;
            try {
                UIUpdater updater = UIUpdaterSWT.getInstance();
                if (updater != null) {
                    updater.removeUpdater(updateable);
                }
            } catch (Exception e) {
                Debug.out(e);
            }
        }
    }
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) UIUpdater(com.biglybt.ui.common.updater.UIUpdater)

Example 4 with UIUpdatable

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

the class TabbedEntry method buildStandAlone.

public static SWTSkinObjectContainer buildStandAlone(SWTSkinObjectContainer soParent, String skinRef, SWTSkin skin, String parentID, String id, Object datasource, int controlType, CTabItem 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 = listener_is_new ? original_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;
                    }
                });
                // 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) HashMap(java.util.HashMap) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) 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) Point(org.eclipse.swt.graphics.Point) 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) HashMap(java.util.HashMap) Map(java.util.Map) UISWTViewCoreEventListenerEx(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListenerEx) IViewRequiresPeriodicUpdates(com.biglybt.ui.swt.views.IViewRequiresPeriodicUpdates)

Example 5 with UIUpdatable

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

the class UIUpdaterSWT method update.

private void update(CopyOnWriteList<UIUpdatable> updateables, boolean is_visible) {
    long start = 0;
    Map<UIUpdatable, Long> mapTimeMap = DEBUG_TIMER ? new HashMap<UIUpdatable, Long>() : null;
    Display display = Utils.getDisplay();
    if (display == null || display.isDisposed()) {
        return;
    }
    for (UIUpdatable updateable : updateables) {
        try {
            if (DEBUG_TIMER) {
                start = SystemTime.getCurrentTime();
            }
            if (updateable instanceof UIUpdatableAlways) {
                ((UIUpdatableAlways) updateable).updateUI(is_visible);
            } else {
                updateable.updateUI();
            }
            if (DEBUG_TIMER) {
                long diff = SystemTime.getCurrentTime() - start;
                if (diff > 0) {
                    mapTimeMap.put(updateable, new Long(diff));
                }
            }
        } catch (Throwable t) {
            Logger.log(new LogEvent(LOGID, "Error while trying to update UI Element " + updateable.getUpdateUIName(), t));
        }
    }
    if (DEBUG_TIMER) {
        makeDebugToolTip(mapTimeMap);
    }
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) LogEvent(com.biglybt.core.logging.LogEvent) UIUpdatableAlways(com.biglybt.ui.common.updater.UIUpdatableAlways) Display(org.eclipse.swt.widgets.Display)

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