Search in sources :

Example 1 with UIUpdater

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

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

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

the class MainStatusBar method initStatusBar.

/**
 * @return composite holding the statusbar
 */
public Composite initStatusBar(final Composite _parent) {
    this.parent = _parent;
    this.display = parent.getDisplay();
    this.uiFunctions = UIFunctionsManager.getUIFunctions();
    ImageLoader imageLoader = ImageLoader.getInstance();
    FormData formData;
    Color fgColor = parent.getForeground();
    statusBar = new Composite(parent, SWT.NONE);
    statusBar.setForeground(fgColor);
    isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
    statusBar.getShell().addListener(SWT.Deiconify, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (!statusBar.isDisposed()) {
                        statusBar.layout();
                    }
                }
            });
        }
    });
    statusBar.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (uiFunctions != null) {
                UIUpdater uiUpdater = uiFunctions.getUIUpdater();
                if (uiUpdater != null) {
                    uiUpdater.removeUpdater(MainStatusBar.this);
                }
            }
            PRManager.removeListener(progressListener);
            Utils.disposeSWTObjects(imgRec, imgSent);
            Utils.removeParameterListeners(mapConfigListeners);
            if (alert_flasher_event != null) {
                alert_flasher_event.cancel();
                alert_flasher_event = null;
            }
            if (alertHistoryListener != null) {
                Alerts.removeMessageHistoryListener(alertHistoryListener);
                alertHistoryListener = null;
            }
        }
    });
    GridLayout layout_status = new GridLayout();
    layout_status.numColumns = 20;
    layout_status.horizontalSpacing = 0;
    layout_status.verticalSpacing = 0;
    layout_status.marginHeight = 0;
    if (Constants.isOSX) {
        // OSX has a resize widget on the bottom right.  It's about 15px wide.
        try {
            layout_status.marginRight = 15;
        } catch (NoSuchFieldError e) {
            // Pre SWT 3.1
            layout_status.marginWidth = 15;
        }
    } else {
        layout_status.marginWidth = 0;
    }
    statusBar.setLayout(layout_status);
    // Either the Status Text
    statusText = new CLabel(statusBar, borderFlag);
    statusText.setForeground(fgColor);
    Utils.setLayoutData(statusText, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    addStatusBarMenu(statusText);
    GC gc = new GC(statusText);
    // add 6, because CLabel forces a 3 pixel indent
    int height = Math.max(16, gc.getFontMetrics().getHeight()) + 6;
    gc.dispose();
    formData = new FormData();
    formData.height = height;
    // 2 params for Pre SWT 3.0
    formData.bottom = new FormAttachment(100, 0);
    // 2 params for Pre SWT 3.0
    formData.left = new FormAttachment(0, 0);
    // 2 params for Pre SWT 3.0
    formData.right = new FormAttachment(100, 0);
    statusBar.setLayoutData(formData);
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (clickListener == null) {
                if (updateWindow != null) {
                    updateWindow.show();
                }
            } else {
                clickListener.UIStatusTextClicked();
            }
        }
    };
    statusText.addListener(SWT.MouseUp, listener);
    statusText.addListener(SWT.MouseDoubleClick, listener);
    // KN: Don't know why OSX is treated differently but this check was already here from the previous code
    if (Constants.isOSX) {
        progressBar = new AZProgressBar(statusBar, true);
    } else {
        progressBar = new AZProgressBar(statusBar, false);
    }
    progressBar.setVisible(false);
    progressGridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    progressGridData.widthHint = 5;
    Utils.setLayoutData(progressBar, progressGridData);
    // addRIP();
    /*
		 * Progress reporting window image label
		 */
    progressViewerImageLabel = new CLabelPadding(statusBar, SWT.NONE);
    // image set below after adding listener
    progressViewerImageLabel.setToolTipText(MessageText.getString("Progress.reporting.statusbar.button.tooltip"));
    progressViewerImageLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            /*
				 * Opens the progress viewer if any of the reporters in the array is NOT already opened
				 * KN: TODO -- This is only a partial solution to minimize the occurrence of the main progress window
				 * opening more than once.  The one remaining case where multiple windows will still open is
				 * when you have one opened already... then run another process such as a torrent file download...
				 * at this point this new process is not in the already opened window so the check would
				 * allow the second window to open.
				 */
            IProgressReporter[] reporters = PRManager.getReportersArray(false);
            if (reporters.length == 0) {
                /*
					 * If there's nothing to see then open the window; the default widow will say there's nothing to see
					 * KN: calling isShowingEmpty return true is there is already a window opened showing the empty panel
					 */
                if (!ProgressReporterWindow.isShowingEmpty()) {
                    ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
                }
            } else {
                for (int i = 0; i < reporters.length; i++) {
                    if (!ProgressReporterWindow.isOpened(reporters[i])) {
                        ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
                        break;
                    }
                }
            }
        }
    });
    progressViewerImageLabel.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            ImageLoader imageLoader = ImageLoader.getInstance();
            imageLoader.releaseImage("progress_error");
            imageLoader.releaseImage("progress_info");
            imageLoader.releaseImage("progress_viewer");
        }
    });
    this.plugin_label_composite = new Composite(statusBar, SWT.NONE);
    this.plugin_label_composite.setForeground(fgColor);
    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    // Something nice and big. :)
    gridLayout.numColumns = 20;
    GridData gridData = new GridData(GridData.FILL_VERTICAL);
    gridData.heightHint = height;
    gridData.minimumHeight = height;
    plugin_label_composite.setLayout(gridLayout);
    plugin_label_composite.setLayoutData(gridData);
    srStatus = new CLabelPadding(statusBar, borderFlag);
    srStatus.setText(MessageText.getString("SpeedView.stats.ratio"));
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show SR", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            srStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    natStatus = new CLabelPadding(statusBar, borderFlag);
    natStatus.setText("");
    final Menu natStatusMenu = new Menu(statusBar.getShell(), SWT.POP_UP);
    natStatus.setMenu(natStatusMenu);
    MenuItem nat_test = new MenuItem(natStatusMenu, SWT.PUSH);
    Messages.setLanguageText(nat_test, "MainWindow.menu.tools.nattest");
    nat_test.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            new NatTestWindow();
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show NAT", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            natStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    dhtStatus = new CLabelPadding(statusBar, borderFlag);
    dhtStatus.setText("");
    dhtStatus.setToolTipText(MessageText.getString("MainWindow.dht.status.tooltip"));
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show DDB", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            dhtStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    // ip filters
    ipBlocked = new CLabelPadding(statusBar, borderFlag);
    // $NON-NLS-1$
    ipBlocked.setText("{} IPs:");
    Messages.setLanguageText(ipBlocked, "MainWindow.IPs.tooltip");
    ipBlocked.addListener(SWT.MouseDoubleClick, new ListenerNeedingCoreRunning() {

        @Override
        public void handleEvent(Core core, Event event) {
            BlockedIpsWindow.showBlockedIps(core, parent.getShell());
        }
    });
    final Menu menuIPFilter = new Menu(statusBar.getShell(), SWT.POP_UP);
    ipBlocked.setMenu(menuIPFilter);
    menuIPFilter.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            MenuItem[] oldItems = menuIPFilter.getItems();
            for (int i = 0; i < oldItems.length; i++) {
                oldItems[i].dispose();
            }
            if (!CoreFactory.isCoreRunning()) {
                return;
            }
            Core core = CoreFactory.getSingleton();
            final IpFilter ip_filter = core.getIpFilterManager().getIPFilter();
            final MenuItem ipfEnable = new MenuItem(menuIPFilter, SWT.CHECK);
            ipfEnable.setSelection(ip_filter.isEnabled());
            Messages.setLanguageText(ipfEnable, "MyTorrentsView.menu.ipf_enable");
            ipfEnable.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ip_filter.setEnabled(ipfEnable.getSelection());
                }
            });
            final MenuItem ipfOptions = new MenuItem(menuIPFilter, SWT.PUSH);
            Messages.setLanguageText(ipfOptions, "ipfilter.options");
            ipfOptions.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    UIFunctions uif = UIFunctionsManager.getUIFunctions();
                    if (uif != null) {
                        uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "ipfilter");
                    }
                }
            });
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show IPF", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            ipBlocked.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
            statusBar.layout();
        }
    });
    // down speed
    statusDown = new CLabelPadding(statusBar, borderFlag);
    statusDown.setImage(imageLoader.getImage("down"));
    // statusDown.setText(/*MessageText.getString("ConfigView.download.abbreviated") +*/"n/a");
    Messages.setLanguageText(statusDown, "MainWindow.status.updowndetails.tooltip");
    Listener lStats = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TransferStatsView");
        }
    };
    statusUp = new CLabelPadding(statusBar, borderFlag);
    statusUp.setImage(imageLoader.getImage("up"));
    // statusUp.setText(/*MessageText.getString("ConfigView.upload.abbreviated") +*/"n/a");
    Messages.setLanguageText(statusUp, "MainWindow.status.updowndetails.tooltip");
    statusDown.addListener(SWT.MouseDoubleClick, lStats);
    statusUp.addListener(SWT.MouseDoubleClick, lStats);
    Listener lDHT = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "DHTView");
        }
    };
    dhtStatus.addListener(SWT.MouseDoubleClick, lDHT);
    Listener lSR = new Listener() {

        @Override
        public void handleEvent(Event e) {
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "SpeedView");
            OverallStats stats = StatsFactory.getStats();
            if (stats == null) {
                return;
            }
            long ratio = (1000 * stats.getUploadedBytes() / (stats.getDownloadedBytes() + 1));
            if (ratio < 900) {
            // Utils.launch(Constants.AZUREUS_WIKI + "Share_Ratio");
            }
        }
    };
    srStatus.addListener(SWT.MouseDoubleClick, lSR);
    Listener lNAT = new ListenerNeedingCoreRunning() {

        @Override
        public void handleEvent(Core core, Event e) {
            uiFunctions.getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, true, false, ConfigSection.SECTION_CONNECTION);
            if (PluginInitializer.getDefaultInterface().getConnectionManager().getNATStatus() != ConnectionManager.NAT_OK) {
                Utils.launch(Constants.AZUREUS_WIKI + "NAT_problem");
            }
        }
    };
    natStatus.addListener(SWT.MouseDoubleClick, lNAT);
    boolean bSpeedMenu = COConfigurationManager.getBooleanParameter("GUI_SWT_bOldSpeedMenu");
    if (bSpeedMenu) {
        // Status Bar Menu construction
        final Menu menuUpSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
        menuUpSpeed.addListener(SWT.Show, new Listener() {

            @Override
            public void handleEvent(Event e) {
                if (!CoreFactory.isCoreRunning()) {
                    return;
                }
                Core core = CoreFactory.getSingleton();
                GlobalManager globalManager = core.getGlobalManager();
                SelectableSpeedMenu.generateMenuItems(menuUpSpeed, core, globalManager, true);
            }
        });
        statusUp.setMenu(menuUpSpeed);
    } else {
        statusUp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
                    return;
                }
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.widget.getDisplay().post(event);
                CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                    @Override
                    public void coreRunning(Core core) {
                        SelectableSpeedMenu.invokeSlider(statusUp, core, true);
                    }
                });
            }
        });
    }
    if (bSpeedMenu) {
        final Menu menuDownSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
        menuDownSpeed.addListener(SWT.Show, new Listener() {

            @Override
            public void handleEvent(Event e) {
                if (!CoreFactory.isCoreRunning()) {
                    return;
                }
                Core core = CoreFactory.getSingleton();
                GlobalManager globalManager = core.getGlobalManager();
                SelectableSpeedMenu.generateMenuItems(menuDownSpeed, core, globalManager, false);
            }
        });
        statusDown.setMenu(menuDownSpeed);
    } else {
        statusDown.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
                    return;
                }
                Event event = new Event();
                event.type = SWT.MouseUp;
                event.widget = e.widget;
                event.stateMask = e.stateMask;
                event.button = e.button;
                e.widget.getDisplay().post(event);
                CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                    @Override
                    public void coreRunning(Core core) {
                        SelectableSpeedMenu.invokeSlider(statusDown, core, false);
                    }
                });
            }
        });
    }
    statusWarnings = new CLabelPadding(statusBar, borderFlag);
    warningIcon = imageLoader.getImage("image.sidebar.vitality.alert");
    warningGreyIcon = imageLoader.getImage("image.sidebar.vitality.alert-gray");
    infoIcon = imageLoader.getImage("image.sidebar.vitality.info");
    updateStatusWarnings(null, false);
    Messages.setLanguageText(statusWarnings, "MainWindow.status.warning.tooltip");
    alertHistoryListener = new AlertHistoryListener() {

        @Override
        public void alertHistoryAdded(LogAlert alert) {
            updateStatusWarnings(alert, true);
        }

        @Override
        public void alertHistoryRemoved(LogAlert alert) {
            updateStatusWarnings(alert, false);
        }
    };
    Alerts.addMessageHistoryListener(alertHistoryListener);
    statusWarnings.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (e.button != 1) {
                return;
            }
            if (SystemWarningWindow.numWarningWindowsOpen > 0) {
                return;
            }
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            if (alerts.size() == 0) {
                return;
            }
            Shell shell = statusWarnings.getShell();
            Rectangle bounds = statusWarnings.getClientArea();
            Point ptBottomRight = statusWarnings.toDisplay(bounds.x + bounds.width, bounds.y);
            new SystemWarningWindow(alerts.get(0), ptBottomRight, shell, 0);
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    Menu menuStatusWarnings = new Menu(statusBar.getShell(), SWT.POP_UP);
    statusWarnings.setMenu(menuStatusWarnings);
    final MenuItem dismissAllItem = new MenuItem(menuStatusWarnings, SWT.PUSH);
    menuStatusWarnings.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            dismissAllItem.setEnabled(Alerts.getUnviewedLogAlerts().size() > 0);
        }
    });
    Messages.setLanguageText(dismissAllItem, "label.dismiss.all");
    dismissAllItem.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            for (LogAlert a : alerts) {
                Alerts.markAlertAsViewed(a);
            }
        }
    });
    Utils.addAndFireParameterListener(mapConfigListeners, true, "status.rategraphs", new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean doRateGraphs = COConfigurationManager.getBooleanParameter("status.rategraphs");
            if (doRateGraphs) {
                if (imgRec == null || imgRec.isDisposed()) {
                    imgRec = new Image(display, 100, 20);
                    GC gc = new GC(imgRec);
                    gc.setBackground(statusDown.getBackground());
                    gc.fillRectangle(0, 0, 100, 20);
                    gc.dispose();
                    statusDown.setBackgroundImage(imgRec);
                }
                if (imgSent == null || imgSent.isDisposed()) {
                    imgSent = new Image(display, 100, 20);
                    GC gc = new GC(imgSent);
                    gc.setBackground(statusUp.getBackground());
                    gc.fillRectangle(0, 0, 100, 20);
                    gc.dispose();
                    statusUp.setBackgroundImage(imgSent);
                }
            } else {
                statusUp.setBackgroundImage(null);
                statusDown.setBackgroundImage(null);
                Utils.disposeSWTObjects(imgRec, imgSent);
                imgRec = imgSent = null;
            }
        }
    });
    // ///////
    progressListener = new ProgressListener();
    PRManager.addListener(progressListener);
    uiFunctions.getUIUpdater().addUpdater(this);
    ArrayList<Runnable> list;
    this_mon.enter();
    try {
        list = listRunAfterInit;
        listRunAfterInit = null;
    } finally {
        this_mon.exit();
    }
    for (Runnable runnable : list) {
        try {
            runnable.run();
        } catch (Exception e) {
            Debug.out(e);
        }
    }
    statusBar.layout(true);
    return statusBar;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) AlertHistoryListener(com.biglybt.ui.swt.Alerts.AlertHistoryListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) FormAttachment(org.eclipse.swt.layout.FormAttachment) Core(com.biglybt.core.Core) FormData(org.eclipse.swt.layout.FormData) LogAlert(com.biglybt.core.logging.LogAlert) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) CLabel(org.eclipse.swt.custom.CLabel) IpFilter(com.biglybt.core.ipfilter.IpFilter) ParameterListener(com.biglybt.core.config.ParameterListener) UIStatusTextClickListener(com.biglybt.ui.UIStatusTextClickListener) AlertHistoryListener(com.biglybt.ui.swt.Alerts.AlertHistoryListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) OverallStats(com.biglybt.core.stats.transfer.OverallStats) GridLayout(org.eclipse.swt.layout.GridLayout) NatTestWindow(com.biglybt.ui.swt.nat.NatTestWindow) GridData(org.eclipse.swt.layout.GridData) ParameterListener(com.biglybt.core.config.ParameterListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 4 with UIUpdater

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

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

the class MiniBarManager method unregister.

public void unregister(MiniBar bar) {
    try {
        minibars_mon.enter();
        minibars.remove(bar);
        if (!global) {
            global_instance.unregister(bar);
        }
    } finally {
        minibars_mon.exit();
    }
    if (minibars.isEmpty()) {
        try {
            UIUpdater updater = UIUpdaterSWT.getInstance();
            if (updater != null) {
                updater.removeUpdater(this);
            }
        } catch (Exception e) {
            Debug.out(e);
        }
    }
}
Also used : UIUpdater(com.biglybt.ui.common.updater.UIUpdater)

Aggregations

UIUpdater (com.biglybt.ui.common.updater.UIUpdater)10 UIUpdatable (com.biglybt.ui.common.updater.UIUpdatable)5 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)3 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)3 SWTSkinObjectListener (com.biglybt.ui.swt.skin.SWTSkinObjectListener)3 GridData (org.eclipse.swt.layout.GridData)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 ParameterListener (com.biglybt.core.config.ParameterListener)2 UIFunctions (com.biglybt.ui.UIFunctions)2 MdiEntryVitalityImage (com.biglybt.ui.mdi.MdiEntryVitalityImage)2 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)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 IViewRequiresPeriodicUpdates (com.biglybt.ui.swt.views.IViewRequiresPeriodicUpdates)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2