Search in sources :

Example 1 with UISWTInstanceImpl

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

the class MainWindowImpl method createWindow.

/**
 * @param uiInitializer
 *
 * called in both delayedCore and !delayedCore
 */
private void createWindow(IUIIntializer uiInitializer) {
    // System.out.println("MainWindow: createWindow)");
    long startTime = SystemTime.getCurrentTime();
    UIFunctionsSWT existing_uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
    uiFunctions = new UIFunctionsImpl(this);
    UIFunctionsManager.setUIFunctions(uiFunctions);
    Utils.disposeComposite(shell);
    increaseProgress(uiInitializer, "splash.initializeGui");
    System.out.println("UIFunctions/ImageLoad took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    shell = existing_uif == null ? new Shell(Utils.getDisplay(), SWT.SHELL_TRIM) : existing_uif.getMainShell();
    if (Constants.isWindows) {
        try {
            Class<?> ehancerClass = Class.forName("com.biglybt.ui.swt.win32.Win32UIEnhancer");
            Method method = ehancerClass.getMethod("initMainShell", Shell.class);
            method.invoke(null, shell);
        } catch (Exception e) {
            Debug.outNoStack(Debug.getCompressedStackTrace(e, 0, 30), true);
        }
    }
    try {
        shell.setData("class", this);
        shell.setText(UIFunctions.MAIN_WINDOW_NAME);
        Utils.setShellIcon(shell);
        Utils.linkShellMetricsToConfig(shell, "window");
        // Shell activeShell = display.getActiveShell();
        // shell.setVisible(true);
        // shell.moveBelow(activeShell);
        System.out.println("new shell took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        skin = SWTSkinFactory.getInstance();
        if (Utils.isAZ2UI()) {
            SWTSkinProperties skinProperties = skin.getSkinProperties();
            String skinPath = SkinPropertiesImpl.PATH_SKIN_DEFS + "skin3_classic";
            ResourceBundle rb = ResourceBundle.getBundle(skinPath);
            skinProperties.addResourceBundle(rb, skinPath);
        }
        /*
			 * KN: passing the skin to the uifunctions so it can be used by UIFunctionsSWT.createMenu()
			 */
        uiFunctions.setSkin(skin);
        System.out.println("new shell setup took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        initSkinListeners();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        // 0ms
        // System.out.println("skinlisteners init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        // startTime = SystemTime.getCurrentTime();
        String startID = Utils.isAZ2UI() ? "classic.shell" : "main.shell";
        skin.initialize(shell, startID, uiInitializer);
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("skin init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        menu = uiFunctions.createMainMenu(shell);
        shell.setData("MainMenu", menu);
        System.out.println("MainMenu init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        skin.layout();
        try {
            Utils.createTorrentDropTarget(shell, false);
        } catch (Throwable e) {
            Logger.log(new LogEvent(LOGID, "Drag and Drop not available", e));
        }
        shell.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (configIconBarEnabledListener != null) {
                    COConfigurationManager.removeParameterListener("IconBar.enabled", configIconBarEnabledListener);
                }
                if (configShowStatusInTitleListener != null) {
                    COConfigurationManager.removeParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
                }
                if (configShowDLBasketListener != null) {
                    COConfigurationManager.removeParameterListener("Show Download Basket", configShowDLBasketListener);
                }
                if (configMonitorClipboardListener != null) {
                    COConfigurationManager.removeParameterListener("Monitor Clipboard For Torrents", configMonitorClipboardListener);
                }
                if (gmListener != null) {
                    GlobalManager gm = core.getGlobalManager();
                    if (gm != null) {
                        gm.removeListener(gmListener);
                    }
                    gmListener = null;
                }
                if (uiFunctions != null) {
                    uiFunctions.dispose();
                }
                if (navigationListener != null) {
                    NavigationHelper.removeListener(navigationListener);
                    navigationListener = null;
                }
                StimulusRPC.unhookListeners();
                UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
                skinnableManagerSWT.removeSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
            // comment out: shell can dispose without us wanting core to be..
            // dispose(false, false);
            }
        });
        shell.addShellListener(new ShellAdapter() {

            @Override
            public void shellClosed(ShellEvent event) {
                if (disposedOrDisposing) {
                    return;
                }
                if (COConfigurationManager.getBooleanParameter("Close To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
                    minimizeToTray(event);
                } else {
                    event.doit = dispose(false, false);
                }
            }

            @Override
            public void shellActivated(ShellEvent e) {
                Shell shellAppModal = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
                if (shellAppModal != null) {
                    shellAppModal.forceActive();
                } else {
                    shell.forceActive();
                }
            }

            @Override
            public void shellIconified(ShellEvent event) {
                if (disposedOrDisposing) {
                    return;
                }
                if (COConfigurationManager.getBooleanParameter("Minimize To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
                    minimizeToTray(event);
                }
            }

            @Override
            public void shellDeiconified(ShellEvent e) {
                if (Constants.isOSX && COConfigurationManager.getBooleanParameter("Password enabled")) {
                    shell.setVisible(false);
                    if (PasswordWindow.showPasswordWindow(Utils.getDisplay())) {
                        shell.setVisible(true);
                    }
                }
            }
        });
        Utils.getDisplay().addFilter(SWT.KeyDown, new Listener() {

            @Override
            public void handleEvent(Event event) {
                // Another window has control, skip filter
                Control focus_control = event.display.getFocusControl();
                if (focus_control != null && focus_control.getShell() != shell)
                    return;
                int key = event.character;
                if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
                    key += 'a' - 1;
                if (key == 'l' && (event.stateMask & SWT.MOD1) != 0) {
                    // Ctrl-L: Open URL
                    if (core == null) {
                        return;
                    }
                    GlobalManager gm = core.getGlobalManager();
                    if (gm != null) {
                        UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
                        event.doit = false;
                    }
                } else if (key == 'd' && (event.stateMask & SWT.MOD1) != 0) {
                    // dump
                    if (Constants.isCVSVersion()) {
                        Utils.dump(shell);
                    }
                } else if (key == 'f' && (event.stateMask & (SWT.MOD1 + SWT.SHIFT)) == SWT.MOD1 + SWT.SHIFT) {
                    shell.setFullScreen(!shell.getFullScreen());
                } else if (event.keyCode == SWT.F1) {
                    Utils.launch(Constants.URL_WIKI);
                }
            }
        });
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("pre skin widgets init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        if (core != null) {
            StimulusRPC.hookListeners(core, this);
        }
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        // 0ms
        // System.out.println("hooks init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        // startTime = SystemTime.getCurrentTime();
        initMDI();
        System.out.println("skin widgets (1/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        initWidgets2();
        increaseProgress(uiInitializer, "v3.splash.initSkin");
        System.out.println("skin widgets (2/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        System.out.println("pre SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
        startTime = SystemTime.getCurrentTime();
        TableColumnCreatorV3.initCoreColumns();
        System.out.println("Init Core Columns took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
        startTime = SystemTime.getCurrentTime();
        // attach the UI to plugins
        // Must be done before initializing views, since plugins may register
        // table columns and other objects
        uiSWTInstanceImpl = new UISWTInstanceImpl();
        uiSWTInstanceImpl.init(uiInitializer);
        System.out.println("SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        increaseProgress(uiInitializer, "splash.initializeGui");
        startTime = SystemTime.getCurrentTime();
    } catch (Throwable t) {
        Debug.out(t);
    } finally {
        String configID = SkinConstants.VIEWID_PLUGINBAR + ".visible";
        if (!ConfigurationDefaults.getInstance().doesParameterDefaultExist(configID)) {
            COConfigurationManager.setBooleanDefault(configID, true);
        }
        setVisible(WINDOW_ELEMENT_TOPBAR, COConfigurationManager.getBooleanParameter(configID) && COConfigurationManager.getIntParameter("User Mode") > 1);
        setVisible(WINDOW_ELEMENT_TOOLBAR, COConfigurationManager.getBooleanParameter("IconBar.enabled"));
        shell.layout(true, true);
        System.out.println("shell.layout took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        showMainWindow();
        // ================
        increaseProgress(uiInitializer, "splash.initializeGui");
        System.out.println("shell.open took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        processStartupDMS();
        System.out.println("processStartupDMS took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        if (core != null) {
            postPluginSetup(core);
        }
        System.out.println("postPluginSetup init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        navigationListener = new navigationListener() {

            @Override
            public void processCommand(final int type, final String[] args) {
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        UIFunctions uif = UIFunctionsManager.getUIFunctions();
                        if (type == NavigationHelper.COMMAND_SWITCH_TO_TAB) {
                            MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                            if (mdi == null) {
                                return;
                            }
                            mdi.showEntryByID(args[0]);
                            if (uif != null) {
                                uif.bringToFront();
                            }
                        } else if (type == NavigationHelper.COMMAND_CONDITION_CHECK) {
                        }
                    }
                });
            }
        };
        NavigationHelper.addListener(navigationListener);
        if (!Constants.isOSX) {
            configShowStatusInTitleListener = new ParameterListener() {

                private TimerEventPeriodic timer;

                private String old_text;

                private String my_last_text;

                @Override
                public void parameterChanged(final String name) {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            boolean enable = COConfigurationManager.getBooleanParameter(name);
                            if (enable) {
                                if (timer == null) {
                                    timer = SimpleTimer.addPeriodicEvent("window.title.updater", 1000, new TimerEventPerformer() {

                                        @Override
                                        public void perform(TimerEvent event) {
                                            Utils.execSWTThread(new AERunnable() {

                                                @Override
                                                public void runSupport() {
                                                    if (shell.isDisposed()) {
                                                        return;
                                                    }
                                                    String current_txt = shell.getText();
                                                    if (current_txt != null && !current_txt.equals(my_last_text)) {
                                                        old_text = current_txt;
                                                    }
                                                    String txt = getCurrentTitleText();
                                                    if (txt != null) {
                                                        if (!txt.equals(current_txt)) {
                                                            shell.setText(txt);
                                                        }
                                                        my_last_text = txt;
                                                    }
                                                }
                                            });
                                        }
                                    });
                                }
                            } else {
                                if (timer != null) {
                                    timer.cancel();
                                    timer = null;
                                }
                                if (old_text != null && !shell.isDisposed()) {
                                    shell.setText(old_text);
                                }
                            }
                        }
                    });
                }
            };
            COConfigurationManager.addAndFireParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
        }
    }
}
Also used : MdiEntryLogIdListener(com.biglybt.ui.mdi.MdiEntryLogIdListener) ParameterListener(com.biglybt.core.config.ParameterListener) MdiListener(com.biglybt.ui.mdi.MdiListener) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) Method(java.lang.reflect.Method) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 2 with UISWTInstanceImpl

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

the class MainWindowImpl method _init.

/**
 * Called only on STARTUP_UIFIRST
 */
private void _init(Core core) {
    // System.out.println("MainWindow: init(core)");
    this.core = core;
    disposedOrDisposing = false;
    StimulusRPC.hookListeners(core, this);
    if (uiSWTInstanceImpl == null) {
        uiSWTInstanceImpl = new UISWTInstanceImpl();
        uiSWTInstanceImpl.init(uiInitializer);
    }
    postPluginSetup(core);
    // When a download is added, check for new meta data and
    // un-"wait state" the rating
    GlobalManager gm = core.getGlobalManager();
    dms_Startup = gm.getDownloadManagers().toArray(new DownloadManager[0]);
    gmListener = new MainWindowGMListener();
    gm.addListener(gmListener, false);
    Alerts.addListener(new MainWindowAlertListener());
    core.triggerLifeCycleComponentCreated(uiFunctions);
    processStartupDMS();
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)

Example 3 with UISWTInstanceImpl

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

the class SideBar method createSideBarPluginViews.

private void createSideBarPluginViews() {
    if (cPluginsArea == null) {
        return;
    }
    UISWTInstanceImpl uiSWTinstance = (UISWTInstanceImpl) UIFunctionsManagerSWT.getUIFunctionsSWT().getUISWTInstance();
    if (uiSWTinstance == null) {
        return;
    }
    UISWTViewEventListenerHolder[] pluginViews = uiSWTinstance.getViewListeners(UISWTInstance.VIEW_SIDEBAR_AREA);
    for (UISWTViewEventListenerHolder l : pluginViews) {
        if (l != null) {
            try {
                UISWTViewImpl view = new UISWTViewImpl(l.getViewID(), UISWTInstance.VIEW_SIDEBAR_AREA, false);
                view.setEventListener(l, true);
                addSideBarView(view, cPluginsArea);
                cPluginsArea.getParent().getParent().layout(true, true);
            } catch (Exception e) {
                e.printStackTrace();
            // skip, plugin probably specifically asked to not be added
            }
        }
    }
    swtViewListener = new SWTViewListener() {

        @Override
        public void setViewAdded(final String parent, final String id, final UISWTViewEventListener l) {
            if (!parent.equals(UISWTInstance.VIEW_SIDEBAR_AREA)) {
                return;
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    try {
                        UISWTViewImpl view = new UISWTViewImpl(id, parent, false);
                        view.setEventListener(l, true);
                        addSideBarView(view, cPluginsArea);
                    } catch (Exception e) {
                        e.printStackTrace();
                    // skip, plugin probably specifically asked to not be added
                    }
                }
            });
        }

        @Override
        public void setViewRemoved(final String parent, final String id, final UISWTViewEventListener l) {
            if (!parent.equals(UISWTInstance.VIEW_SIDEBAR_AREA)) {
                return;
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    try {
                        for (UISWTViewCore view : SideBar.this.pluginViews) {
                            if (l.equals(view.getEventListener())) {
                                view.closeView();
                            } else {
                                if (l instanceof UISWTViewEventListenerHolder) {
                                    UISWTViewEventListener l2 = ((UISWTViewEventListenerHolder) l).getDelegatedEventListener(view);
                                    if (l2 != null && l2.equals(view.getEventListener())) {
                                        view.closeView();
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    // skip, plugin probably specifically asked to not be added
                    }
                }
            });
        }
    };
    uiSWTinstance.addSWTViewListener(swtViewListener);
    cPluginsArea.getParent().getParent().layout(true, true);
}
Also used : UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) UISWTViewImpl(com.biglybt.ui.swt.pifimpl.UISWTViewImpl) SWTViewListener(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)

Example 4 with UISWTInstanceImpl

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

the class SideBar method skinObjectDestroyed.

@Override
public Object skinObjectDestroyed(SWTSkinObject skinObject, Object params) {
    try {
        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
        if (uiFunctions != null) {
            UIUpdater uiUpdater = uiFunctions.getUIUpdater();
            if (uiUpdater != null) {
                uiUpdater.removeUpdater(this);
            }
        }
    } catch (Exception e) {
        Debug.out(e);
    }
    COConfigurationManager.removeParameterListener("Show Side Bar", configShowSideBarListener);
    COConfigurationManager.removeParameterListener("config.skin.color.sidebar.bg", configBGColorListener);
    if (swtViewListener != null) {
        try {
            UISWTInstanceImpl uiSWTinstance = (UISWTInstanceImpl) UIFunctionsManagerSWT.getUIFunctionsSWT().getUISWTInstance();
            uiSWTinstance.removeSWTViewListener(swtViewListener);
        } catch (Throwable ignore) {
        }
    }
    return super.skinObjectDestroyed(skinObject, params);
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)

Aggregations

UISWTInstanceImpl (com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)4 GlobalManager (com.biglybt.core.global.GlobalManager)2 UIFunctions (com.biglybt.ui.UIFunctions)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)1 UIUpdater (com.biglybt.ui.common.updater.UIUpdater)1 MdiEntryLogIdListener (com.biglybt.ui.mdi.MdiEntryLogIdListener)1 MdiListener (com.biglybt.ui.mdi.MdiListener)1 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)1 ObfuscateShell (com.biglybt.ui.swt.debug.ObfuscateShell)1 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)1 SWTViewListener (com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener)1 UISWTViewCore (com.biglybt.ui.swt.pifimpl.UISWTViewCore)1 UISWTViewEventListenerHolder (com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder)1 UISWTViewImpl (com.biglybt.ui.swt.pifimpl.UISWTViewImpl)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 NavigationHelper.navigationListener (com.biglybt.util.NavigationHelper.navigationListener)1 Method (java.lang.reflect.Method)1