Search in sources :

Example 21 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class TextWithHistory method loadHistory.

private void loadHistory() {
    final ParameterListener listener = new ParameterListener() {

        @Override
        public void parameterChanged(String name) {
            List<String> sl = COConfigurationManager.getStringListParameter(name);
            history = new ArrayList<>();
            if (sl != null) {
                history.addAll(sl);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener(config_prefix + ".data", listener);
    text.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            COConfigurationManager.removeParameterListener(config_prefix + ".data", listener);
        }
    });
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

Example 22 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class Utils method addAndFireParameterListener.

public static void addAndFireParameterListener(Map<String, ParameterListener> mapConfigListeners, final boolean requiresSWTThread, String parameter, final ParameterListener listener) {
    ParameterListener realListener;
    if (requiresSWTThread) {
        realListener = new ParameterListener() {

            @Override
            public void parameterChanged(final String parameterName) {
                execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        listener.parameterChanged(parameterName);
                    }
                });
            }
        };
    } else {
        realListener = listener;
    }
    if (mapConfigListeners != null) {
        mapConfigListeners.put(parameter, realListener);
    }
    COConfigurationManager.addAndFireParameterListener(parameter, realListener);
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

Example 23 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class Utils method initStatic.

static void initStatic() {
    if (DEBUG_SWTEXEC) {
        System.out.println("==== debug.swtexec=1, performance may be affected ====");
        queue = new ArrayList<>();
        diag_logger = AEDiagnostics.getLogger("swt");
        diag_logger.log("\n\nSWT Logging Starts");
        evidenceGenerator = new AEDiagnosticsEvidenceGenerator() {

            @Override
            public void generate(IndentWriter writer) {
                writer.println("SWT Queue:");
                writer.indent();
                for (Runnable r : queue) {
                    if (r == null) {
                        writer.println("NULL");
                    } else {
                        writer.println(r.toString());
                    }
                }
                writer.exdent();
            }
        };
        AEDiagnostics.addEvidenceGenerator(evidenceGenerator);
    } else {
        queue = null;
        diag_logger = null;
    }
    configUserModeListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            userMode = COConfigurationManager.getIntParameter("User Mode");
        }
    };
    configUIListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            isAZ2 = "az2".equals(COConfigurationManager.getStringParameter("ui"));
        }
    };
    COConfigurationManager.addAndFireParameterListener("User Mode", configUserModeListener);
    COConfigurationManager.addAndFireParameterListener("ui", configUIListener);
    // no need to listen, changing param requires restart
    boolean smallOSXControl = COConfigurationManager.getBooleanParameter("enable_small_osx_fonts");
    BUTTON_MARGIN = Constants.isOSX ? (smallOSXControl ? 10 : 12) : 6;
}
Also used : SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 24 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class MenuFactory method addViewToolbarMenuItem.

public static MenuItem addViewToolbarMenuItem(Menu menu) {
    final MenuItem item = addMenuItem(menu, SWT.CHECK, isAZ3 ? MENU_ID_SEARCH_BAR : MENU_ID_TOOLBAR, new Listener() {

        @Override
        public void handleEvent(Event e) {
            UIFunctionsSWT uiFunctions = getUIFunctionSWT();
            if (null != uiFunctions) {
                IMainWindow mainWindow = uiFunctions.getMainWindow();
                boolean isToolbarVisible = mainWindow.isVisible(IMainWindow.WINDOW_ELEMENT_TOOLBAR);
                mainWindow.setVisible(IMainWindow.WINDOW_ELEMENT_TOOLBAR, !isToolbarVisible);
            }
        }
    });
    final ParameterListener listener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            item.setSelection(COConfigurationManager.getBooleanParameter(parameterName));
        }
    };
    COConfigurationManager.addAndFireParameterListener("IconBar.enabled", listener);
    item.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            COConfigurationManager.removeParameterListener("IconBar.enabled", listener);
        }
    });
    return item;
}
Also used : UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) ParameterListener(com.biglybt.core.config.ParameterListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 25 with ParameterListener

use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.

the class TabbedMDI method creatMDI.

private void creatMDI() {
    if (soMain instanceof SWTSkinObjectTabFolder) {
        tabFolder = ((SWTSkinObjectTabFolder) soMain).getTabFolder();
    } else {
        tabFolder = new CTabFolder((Composite) soMain.getControl(), SWT.TOP | SWT.BORDER | SWT.CLOSE);
    }
    iFolderHeightAdj = tabFolder.computeSize(SWT.DEFAULT, 0).y;
    if (isMainMDI) {
        paramFancyTabListener = new ParameterListener() {

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

                    @Override
                    public void runSupport() {
                        boolean simple = !COConfigurationManager.getBooleanParameter("GUI_SWT_bFancyTab");
                        tabFolder.setSimple(simple);
                    }
                });
            }
        };
        COConfigurationManager.addAndFireParameterListener("GUI_SWT_bFancyTab", paramFancyTabListener);
        tabFolder.setSimple(!COConfigurationManager.getBooleanParameter("GUI_SWT_bFancyTab"));
    } else {
        tabFolder.setSimple(true);
        tabFolder.setMaximizeVisible(maximizeVisible);
        tabFolder.setMinimizeVisible(minimizeVisible);
        tabFolder.setUnselectedCloseVisible(false);
    }
    Display display = tabFolder.getDisplay();
    float[] hsb = tabFolder.getBackground().getRGB().getHSB();
    hsb[2] *= (Constants.isOSX) ? 0.9 : 0.97;
    tabFolder.setBackground(ColorCache.getColor(display, hsb));
    hsb = tabFolder.getForeground().getRGB().getHSB();
    hsb[2] *= (Constants.isOSX) ? 1.1 : 0.03;
    tabFolder.setForeground(ColorCache.getColor(display, hsb));
    tabFolder.setSelectionBackground(new Color[] { Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND), Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND), Colors.getSystemColor(display, SWT.COLOR_WIDGET_BACKGROUND) }, new int[] { 10, 90 }, true);
    tabFolder.setSelectionForeground(Colors.getSystemColor(display, SWT.COLOR_LIST_FOREGROUND));
    if (minimumCharacters > 0) {
        tabFolder.setMinimumCharacters(minimumCharacters);
    }
    // XXX TVSWT_Common had SWT.Activate too
    tabFolder.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TabbedEntry entry = (TabbedEntry) event.item.getData("TabbedEntry");
            showEntry(entry);
        }
    });
    tabFolder.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            if (tabFolder.getMinimized()) {
                restore();
                // If the user clicked down on the restore button, and we restore
                // before the CTabFolder does, CTabFolder will minimize us again
                // There's no way that I know of to determine if the mouse is
                // on that button!
                // one of these will tell tabFolder to cancel
                e.button = 0;
                tabFolder.notifyListeners(SWT.MouseExit, null);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            if (!tabFolder.getMinimized() && tabFolder.getMaximizeVisible()) {
                minimize();
            }
        }
    });
    tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {

        @Override
        public void minimize(CTabFolderEvent event) {
            TabbedMDI.this.minimize();
        }

        @Override
        public void maximize(CTabFolderEvent event) {
            if (maximizeListener != null) {
                maximizeListener.maximizePressed();
            }
        }

        @Override
        public void restore(CTabFolderEvent event_maybe_null) {
            TabbedMDI.this.restore();
        }

        @Override
        public void close(CTabFolderEvent event) {
            final TabbedEntry entry = (TabbedEntry) event.item.getData("TabbedEntry");
            if (select_history.remove(entry)) {
                if (select_history.size() > 0) {
                    final MdiEntry next = select_history.getLast();
                    if (!next.isDisposed() && next != entry) {
                        // If tabfolder's selected entry is the one we are closing,
                        // CTabFolder will try to move to next CTabItem.  Disable
                        // this feature by moving tabfolder's selection away from us
                        CTabItem[] items = tabFolder.getItems();
                        for (int i = 0; i < items.length; i++) {
                            CTabItem item = items[i];
                            TabbedEntry scanEntry = getEntryFromTabItem(item);
                            if (scanEntry == next) {
                                tabFolder.setSelection(item);
                                break;
                            }
                        }
                        showEntry(next);
                    }
                }
            }
            // the "next" tab would select.
            if (props_prefix != null) {
                Utils.execSWTThreadLater(0, new AERunnable() {

                    @Override
                    public void runSupport() {
                        String view_id = entry.getViewID();
                        String key = props_prefix + ".closedtabs";
                        Map closedtabs = COConfigurationManager.getMapParameter(key, new HashMap());
                        if (!closedtabs.containsKey(view_id)) {
                            closedtabs.put(view_id, entry.getTitle());
                            // this will trigger listener which will remove the tab
                            COConfigurationManager.setParameter(key, closedtabs);
                        }
                    }
                });
            }
        }
    });
    if (isMainMDI) {
        tabFolder.getDisplay().addFilter(SWT.KeyDown, new Listener() {

            @Override
            public void handleEvent(Event event) {
                if (tabFolder.isDisposed()) {
                    return;
                }
                // Another window has control, skip filter
                Control focus_control = tabFolder.getDisplay().getFocusControl();
                if (focus_control != null && focus_control.getShell() != tabFolder.getShell()) {
                    return;
                }
                int key = event.character;
                if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
                    key += 'a' - 1;
                // ESC or CTRL+F4 closes current Tab
                if (key == SWT.ESC || (event.keyCode == SWT.F4 && event.stateMask == SWT.CTRL)) {
                    MdiEntry entry = getCurrentEntry();
                    if (entry != null) {
                        entry.close(false);
                    }
                    event.doit = false;
                } else if (event.keyCode == SWT.F6 || (event.character == SWT.TAB && (event.stateMask & SWT.CTRL) != 0)) {
                    // what other OSes do, so the code is here in case we get TAB
                    if ((event.stateMask & SWT.SHIFT) == 0) {
                        event.doit = false;
                        selectNextTab(true);
                    // Shift+F6 or Ctrl+Shift+Tab selects previous Tab
                    } else if (event.stateMask == SWT.SHIFT) {
                        selectNextTab(false);
                        event.doit = false;
                    }
                }
            }
        });
    }
    tabFolder.getTabHeight();
    final Menu menu = new Menu(tabFolder);
    tabFolder.setMenu(menu);
    MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuilder() {

        @Override
        public void buildMenu(Menu root_menu, MenuEvent event) {
            Point cursorLocation = event.display.getCursorLocation();
            Point ptOnControl = tabFolder.toControl(cursorLocation.x, cursorLocation.y);
            if (ptOnControl.y > tabFolder.getTabHeight()) {
                return;
            }
            final CTabItem item = tabFolder.getItem(tabFolder.toControl(cursorLocation.x, cursorLocation.y));
            boolean need_sep = false;
            if (item == null) {
                need_sep = mapUserClosedTabs.size() > 0;
                if (need_sep) {
                    for (Object id : mapUserClosedTabs.keySet()) {
                        final String view_id = (String) id;
                        MenuItem mi = new MenuItem(menu, SWT.PUSH);
                        String title;
                        Object oTitle = mapUserClosedTabs.get(id);
                        if (oTitle instanceof String && ((String) oTitle).length() > 0) {
                            title = (String) oTitle;
                        } else {
                            title = MessageText.getString(getViewTitleID(view_id));
                        }
                        mi.setText(title);
                        mi.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                String key = props_prefix + ".closedtabs";
                                Map closedtabs = COConfigurationManager.getMapParameter(key, new HashMap());
                                if (closedtabs.containsKey(view_id)) {
                                    closedtabs.remove(view_id);
                                    COConfigurationManager.setParameter(key, closedtabs);
                                }
                                showEntryByID(view_id);
                            }
                        });
                    }
                }
            }
            if (need_sep) {
                new MenuItem(menu, SWT.SEPARATOR);
            }
            TabbedEntry entry = null;
            if (item != null) {
                entry = getEntryFromTabItem(item);
                showEntry(entry);
            }
            fillMenu(menu, entry, props_prefix);
        }
    });
    if (SWT.getVersion() > 3600) {
        TabbedMDI_Ren.setupTabFolderRenderer(this, tabFolder);
    }
    if (minimizeVisible) {
        boolean toMinimize = ConfigurationManager.getInstance().getBooleanParameter(props_prefix + ".subViews.minimized");
        setMinimized(toMinimize);
    }
}
Also used : UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) ParameterListener(com.biglybt.core.config.ParameterListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) HashMap(java.util.HashMap) MenuBuilder(com.biglybt.ui.swt.MenuBuildUtils.MenuBuilder) MdiEntry(com.biglybt.ui.mdi.MdiEntry) ParameterListener(com.biglybt.core.config.ParameterListener) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ParameterListener (com.biglybt.core.config.ParameterListener)43 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 PriorityParameterListener (com.biglybt.core.config.PriorityParameterListener)4 LogEvent (com.biglybt.core.logging.LogEvent)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)4 ArrayList (java.util.ArrayList)4 Core (com.biglybt.core.Core)3 ConfigurationManager (com.biglybt.core.config.impl.ConfigurationManager)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 AERunnable (com.biglybt.core.util.AERunnable)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 DelayedTask (com.biglybt.pif.utils.DelayedTask)2