Search in sources :

Example 41 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class BuddyPluginView method init.

private void init(BuddyPlugin _plugin, UIInstance _ui_instance, String _VIEW_ID, boolean _main_view) {
    plugin = _plugin;
    ui_instance = (UISWTInstance) _ui_instance;
    VIEW_ID = _VIEW_ID;
    if (_main_view) {
        buddyPluginAZ2Listener = new BuddyPluginAZ2Listener() {

            @Override
            public void chatCreated(final BuddyPluginAZ2.chatInstance chat) {
                final Display display = ui_instance.getDisplay();
                if (!display.isDisposed()) {
                    display.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (!display.isDisposed()) {
                                new BuddyPluginViewChat(plugin, display, chat);
                            }
                        }
                    });
                }
            }

            @Override
            public void chatDestroyed(BuddyPluginAZ2.chatInstance chat) {
            }
        };
        plugin.getAZ2Handler().addListener(buddyPluginAZ2Listener);
        buddyStatusInit = SimpleTimer.addEvent("BuddyStatusInit", SystemTime.getOffsetTime(1000), new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                // UISWTStatusEntry label = ui_instance.createStatusEntry();
                // label.setText(MessageText.getString("azbuddy.tracker.bbb.status.title"));
                statusUpdater = new statusUpdater(ui_instance);
            }
        });
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                iconNLI = imageLoader.getImage("bbb_nli");
                iconIDLE = imageLoader.getImage("bbb_idle");
                iconIN = imageLoader.getImage("bbb_in");
                iconOUT = imageLoader.getImage("bbb_out");
                iconINOUT = imageLoader.getImage("bbb_inout");
            }
        });
    }
    ui_instance.addView(UISWTInstance.VIEW_MAIN, VIEW_ID, this);
    if (_main_view) {
        checkBetaInit();
    }
}
Also used : BuddyPluginAZ2(com.biglybt.plugin.net.buddy.BuddyPluginAZ2) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) BuddyPluginAZ2Listener(com.biglybt.plugin.net.buddy.BuddyPluginAZ2Listener) Display(org.eclipse.swt.widgets.Display)

Example 42 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class ConfigView method _initialize.

private void _initialize(final Composite composite) {
    GridData gridData;
    /*
    /--cConfig-----------------------------------------------------------\
    | ###SashForm#form################################################## |
    | # /--cLeftSide-\ /--cRightSide---------------------------------\ # |
    | # | ##tree#### | | ***cHeader********************************* | # |
    | # | #        # | | * lHeader                    usermodeHint * | # |
    | # | #        # | | ******************************************* | # |
    | # | #        # | | ###Composite cConfigSection################ | # |
    | # | #        # | | #                                         # | # |
    | # | #        # | | #                                         # | # |
    | # | #        # | | #                                         # | # |
    | # | ########## | | #                                         # | # |
    | # |txtFilter X | | ########################################### | # |
    | # \------------/ \---------------------------------------------/ # |
    | ################################################################## |
    |                                                          [Buttons] |
    \--------------------------------------------------------------------/
    */
    try {
        Display d = composite.getDisplay();
        GridLayout configLayout;
        SashForm form = new SashForm(cConfig, SWT.HORIZONTAL);
        gridData = new GridData(GridData.FILL_BOTH);
        Utils.setLayoutData(form, gridData);
        Composite cLeftSide = new Composite(form, SWT.BORDER);
        gridData = new GridData(GridData.FILL_BOTH);
        Utils.setLayoutData(cLeftSide, gridData);
        FormLayout layout = new FormLayout();
        cLeftSide.setLayout(layout);
        Composite cFilterArea = new Composite(cLeftSide, SWT.NONE);
        cFilterArea.setLayout(new FormLayout());
        final Text txtFilter = new Text(cFilterArea, SWT.BORDER);
        txtFilter.setMessage(MessageText.getString("ConfigView.filter"));
        txtFilter.selectAll();
        txtFilter.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                filterTree(txtFilter.getText());
            }
        });
        ImageLoader imageLoader = ImageLoader.getInstance();
        imgSmallXGray = imageLoader.getImage("smallx-gray");
        imgSmallX = imageLoader.getImage("smallx");
        lblX = new Label(cFilterArea, SWT.WRAP);
        Messages.setLanguageTooltip(lblX, "MyTorrentsView.clearFilter.tooltip");
        lblX.setImage(imgSmallXGray);
        lblX.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                txtFilter.setText("");
            }
        });
        lblX.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent arg0) {
                ImageLoader imageLoader = ImageLoader.getInstance();
                imageLoader.releaseImage("smallx-gray");
                imageLoader.releaseImage("smallx");
            }
        });
        Label lblSearch = new Label(cFilterArea, SWT.NONE);
        imageLoader.setLabelImage(lblSearch, "search");
        tree = new Tree(cLeftSide, SWT.NONE);
        FontData[] fontData = tree.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        filterFoundFont = new Font(d, fontData);
        FormData formData;
        formData = new FormData();
        formData.bottom = new FormAttachment(100, -5);
        formData.left = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        Utils.setLayoutData(cFilterArea, formData);
        formData = new FormData();
        formData.top = new FormAttachment(txtFilter, 0, SWT.CENTER);
        formData.left = new FormAttachment(0, 5);
        Utils.setLayoutData(lblSearch, formData);
        formData = new FormData();
        formData.top = new FormAttachment(0, 5);
        formData.left = new FormAttachment(lblSearch, 5);
        formData.right = new FormAttachment(lblX, -3);
        Utils.setLayoutData(txtFilter, formData);
        formData = new FormData();
        formData.top = new FormAttachment(0, 5);
        formData.right = new FormAttachment(100, -5);
        Utils.setLayoutData(lblX, formData);
        formData = new FormData();
        formData.top = new FormAttachment(0, 0);
        formData.left = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(cFilterArea, -1);
        Utils.setLayoutData(tree, formData);
        Composite cRightSide = new Composite(form, SWT.NULL);
        configLayout = new GridLayout();
        configLayout.marginHeight = 3;
        configLayout.marginWidth = 0;
        cRightSide.setLayout(configLayout);
        // Header
        Composite cHeader = new Composite(cRightSide, SWT.BORDER);
        configLayout = new GridLayout();
        configLayout.marginHeight = 3;
        configLayout.marginWidth = 0;
        configLayout.numColumns = 2;
        configLayout.marginRight = 5;
        cHeader.setLayout(configLayout);
        gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
        Utils.setLayoutData(cHeader, gridData);
        cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
        cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
        lHeader = new Label(cHeader, SWT.NULL);
        lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
        lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
        fontData = lHeader.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        int fontHeight = (int) (fontData[0].getHeight() * 1.2);
        fontData[0].setHeight(fontHeight);
        headerFont = new Font(d, fontData);
        lHeader.setFont(headerFont);
        gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_BEGINNING);
        Utils.setLayoutData(lHeader, gridData);
        usermodeHint = new Label(cHeader, SWT.NULL);
        usermodeHint.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
        usermodeHint.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
        gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
        Utils.setLayoutData(usermodeHint, gridData);
        Menu headerMenu = new Menu(cHeader.getShell(), SWT.POP_UP);
        final MenuItem menuShortCut = new MenuItem(headerMenu, SWT.PUSH);
        Messages.setLanguageText(menuShortCut, "label.set.shortcut");
        menuShortCut.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                final TreeItem tree_item = (TreeItem) lHeader.getData("TreeItem");
                if (tree_item != null) {
                    final String id = (String) tree_item.getData("ID");
                    if (id != null) {
                        SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("config.dialog.shortcut.title", "config.dialog.shortcut.text");
                        entryWindow.setPreenteredText(COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, ""), false);
                        entryWindow.setTextLimit(1);
                        entryWindow.prompt(new UIInputReceiverListener() {

                            @Override
                            public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                                if (!entryWindow.hasSubmittedInput()) {
                                    return;
                                }
                                String sReturn = entryWindow.getSubmittedInput();
                                if (sReturn != null) {
                                    sReturn = sReturn.trim();
                                    if (sReturn.length() > 1) {
                                        sReturn = sReturn.substring(0, 1);
                                    }
                                    COConfigurationManager.setParameter("config.section.shortcut.key." + id, sReturn);
                                    updateHeader(tree_item);
                                }
                            }
                        });
                    }
                }
            }
        });
        cHeader.setMenu(headerMenu);
        lHeader.setMenu(headerMenu);
        usermodeHint.setMenu(headerMenu);
        // Config Section
        cConfigSection = new Composite(cRightSide, SWT.NULL);
        layoutConfigSection = new StackLayout();
        cConfigSection.setLayout(layoutConfigSection);
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalIndent = 2;
        Utils.setLayoutData(cConfigSection, gridData);
        form.setWeights(new int[] { 20, 80 });
        tree.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Tree tree = (Tree) e.getSource();
                // and you close its parent.
                if (tree.getSelection().length > 0)
                    showSection(tree.getSelection()[0], false);
            }
        });
        // Double click = expand/contract branch
        tree.addListener(SWT.DefaultSelection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                TreeItem item = (TreeItem) e.item;
                if (item != null)
                    item.setExpanded(!item.getExpanded());
            }
        });
    } catch (Exception e) {
        Logger.log(new LogEvent(LOGID, "Error initializing ConfigView", e));
    }
    scResizeListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            setupSC((ScrolledComposite) event.widget);
        }
    };
    // Add sections
    /**
     * How to add a new section
     * 1) Create a new implementation of ConfigSectionSWT in a new file
     *    (Use the ConfigSectionTMP.java as a template if it's still around)
     * 2) import it into here
     * 3) add it to the internal sections list
     */
    pluginSections = ConfigSectionRepository.getInstance().getList();
    ConfigSection[] internalSections = { new ConfigSectionMode(), new ConfigSectionStartShutdown(), new ConfigSectionBackupRestore(), new ConfigSectionConnection(), new ConfigSectionConnectionProxy(), new ConfigSectionConnectionAdvanced(), new ConfigSectionConnectionEncryption(), new ConfigSectionConnectionDNS(), new ConfigSectionTransfer(), new ConfigSectionTransferAutoSpeedSelect(), new ConfigSectionTransferAutoSpeed(), new ConfigSectionTransferAutoSpeedBeta(), new ConfigSectionTransferLAN(), new ConfigSectionFile(), new ConfigSectionFileMove(), new ConfigSectionFileTorrents(), new ConfigSectionFileTorrentsDecoding(), new ConfigSectionFilePerformance(), new ConfigSectionInterface(), new ConfigSectionInterfaceLanguage(), new ConfigSectionInterfaceStart(), new ConfigSectionInterfaceDisplay(), new ConfigSectionInterfaceTables(), new ConfigSectionInterfaceColor(), new ConfigSectionInterfaceAlerts(), new ConfigSectionInterfacePassword(), new ConfigSectionInterfaceLegacy(), new ConfigSectionIPFilter(), new ConfigSectionPlugins(this), new ConfigSectionStats(), new ConfigSectionTracker(), new ConfigSectionTrackerClient(), new ConfigSectionTrackerServer(), new ConfigSectionSecurity(), new ConfigSectionSharing(), new ConfigSectionLogging() };
    pluginSections.addAll(0, Arrays.asList(internalSections));
    for (int i = 0; i < pluginSections.size(); i++) {
        // slip the non-standard "plugins" initialisation inbetween the internal ones
        // and the plugin ones so plugin ones can be children of it
        boolean plugin_section = i >= internalSections.length;
        ConfigSection section = pluginSections.get(i);
        if (section instanceof UISWTConfigSection) {
            String name;
            try {
                name = section.configSectionGetName();
            } catch (Exception e) {
                Logger.log(new LogEvent(LOGID, "A ConfigSection plugin caused an " + "error while trying to call its " + "configSectionGetName function", e));
                name = "Bad Plugin";
            }
            String section_key = name;
            if (plugin_section) {
                if (!MessageText.keyExists(section_key)) {
                    section_key = sSectionPrefix + name;
                }
            } else {
                section_key = sSectionPrefix + name;
            }
            String section_name = MessageText.getString(section_key);
            try {
                TreeItem treeItem;
                String location = section.configSectionGetParentSection();
                if (location.length() == 0 || location.equalsIgnoreCase(ConfigSection.SECTION_ROOT)) {
                    // int position = findInsertPointFor(section_name, tree);
                    // if ( position == -1 ){
                    treeItem = new TreeItem(tree, SWT.NULL);
                // }else{
                // treeItem = new TreeItem(tree, SWT.NULL, position);
                // }
                } else {
                    TreeItem treeItemFound = findTreeItem(tree, location);
                    if (treeItemFound != null) {
                        if (location.equalsIgnoreCase(ConfigSection.SECTION_PLUGINS)) {
                            // Force ordering by name here.
                            int position = findInsertPointFor(section_name, treeItemFound);
                            if (position == -1) {
                                treeItem = new TreeItem(treeItemFound, SWT.NULL);
                            } else {
                                treeItem = new TreeItem(treeItemFound, SWT.NULL, position);
                            }
                        } else {
                            treeItem = new TreeItem(treeItemFound, SWT.NULL);
                        }
                    } else {
                        treeItem = new TreeItem(tree, SWT.NULL);
                    }
                }
                ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
                sc.setExpandHorizontal(true);
                sc.setExpandVertical(true);
                Utils.setLayoutData(sc, new GridData(GridData.FILL_BOTH));
                sc.getVerticalBar().setIncrement(16);
                sc.addListener(SWT.Resize, scResizeListener);
                if (i == 0) {
                    Composite c = ((UISWTConfigSection) section).configSectionCreate(sc);
                    sectionsCreated.add(section);
                    sc.setContent(c);
                }
                Messages.setLanguageText(treeItem, section_key);
                treeItem.setData("Panel", sc);
                treeItem.setData("ID", name);
                treeItem.setData("ConfigSectionSWT", section);
                sections.put(treeItem, section);
                // PluginConfigModel config pages
                if (section instanceof ConfigSectionPlugins)
                    ((ConfigSectionPlugins) section).initPluginSubSections();
            } catch (Exception e) {
                Logger.log(new LogEvent(LOGID, "ConfigSection plugin '" + name + "' caused an error", e));
            }
        }
    }
    final Display d = composite.getDisplay();
    final Listener shortcut_listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if ((e.stateMask & (SWT.MOD1 | SWT.CONTROL)) != 0 || e.keyCode == SWT.COMMAND) {
                char key = e.character;
                if (key <= 26 && key > 0) {
                    key += 'a' - 1;
                }
                if ((e.stateMask & SWT.SHIFT) != 0) {
                    key = Character.toUpperCase(key);
                }
                if (!Character.isISOControl(key)) {
                    for (TreeItem ti : sections.keySet()) {
                        if (ti.isDisposed()) {
                            continue;
                        }
                        String id = (String) ti.getData("ID");
                        if (id != null) {
                            String shortcut = COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, "");
                            if (shortcut.equals(String.valueOf(key))) {
                                // findFocus( cConfig );
                                selectSection(id, true);
                                e.doit = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
    };
    d.addFilter(SWT.KeyDown, shortcut_listener);
    cConfigSection.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            d.removeFilter(SWT.KeyDown, shortcut_listener);
        }
    });
    if (composite instanceof Shell) {
        initApplyCloseButton();
    } else {
        initSaveButton();
    }
    if (startSection != null) {
        if (selectSection(startSection, false)) {
            return;
        }
    }
    TreeItem selection = getLatestSelection();
    TreeItem[] items = { selection };
    tree.setSelection(items);
    // setSelection doesn't trigger a SelectionListener, so..
    showSection(selection, false);
}
Also used : LinkLabel(com.biglybt.ui.swt.components.LinkLabel) ConfigSection(com.biglybt.pif.ui.config.ConfigSection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) LogEvent(com.biglybt.core.logging.LogEvent) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) StackLayout(org.eclipse.swt.custom.StackLayout) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MessageText(com.biglybt.core.internat.MessageText) SashForm(org.eclipse.swt.custom.SashForm) LogEvent(com.biglybt.core.logging.LogEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 43 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class ConfigSectionIPFilter method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    if (!CoreFactory.isCoreRunning()) {
        Composite cSection = new Composite(parent, SWT.NULL);
        cSection.setLayout(new FillLayout());
        Label lblNotAvail = new Label(cSection, SWT.WRAP);
        Messages.setLanguageText(lblNotAvail, "core.not.available");
        return cSection;
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    String sCurConfigID;
    GridData gridData;
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    final IpFilterManager ipFilterManager = CoreFactory.getSingleton().getIpFilterManager();
    filter = ipFilterManager.getIPFilter();
    Composite gFilter = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    gFilter.setLayout(layout);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gFilter, gridData);
    // start controls
    // row: enable filter + allow/deny
    gridData = new GridData();
    BooleanParameter enabled = new BooleanParameter(gFilter, "Ip Filter Enabled");
    enabled.setLayoutData(gridData);
    Messages.setLanguageText(enabled.getControl(), "ConfigView.section.ipfilter.enable");
    gridData = new GridData();
    BooleanParameter deny = new BooleanParameter(gFilter, "Ip Filter Allow");
    deny.setLayoutData(gridData);
    Messages.setLanguageText(deny.getControl(), "ConfigView.section.ipfilter.allow");
    deny.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            setPercentageBlocked();
        }
    });
    // row persist banning
    gridData = new GridData();
    BooleanParameter persist_bad_data_banning = new BooleanParameter(gFilter, "Ip Filter Banning Persistent");
    persist_bad_data_banning.setLayoutData(gridData);
    Messages.setLanguageText(persist_bad_data_banning.getControl(), "ConfigView.section.ipfilter.persistblocking");
    BooleanParameter disableForUpdates = new BooleanParameter(gFilter, "Ip Filter Disable For Updates");
    Messages.setLanguageText(disableForUpdates.getControl(), "ConfigView.section.ipfilter.disable.for.updates");
    Group gBlockBanning = new Group(gFilter, SWT.NULL);
    Messages.setLanguageText(gBlockBanning, "ConfigView.section.ipfilter.peerblocking.group");
    layout = new GridLayout();
    layout.numColumns = 2;
    gBlockBanning.setLayout(layout);
    // row block bad + group ban
    BooleanParameter enable_bad_data_banning = new BooleanParameter(gBlockBanning, "Ip Filter Enable Banning", "ConfigView.section.ipfilter.enablebanning");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    enable_bad_data_banning.setLayoutData(gridData);
    Label discard_label = new Label(gBlockBanning, SWT.NULL);
    Messages.setLanguageText(discard_label, "ConfigView.section.ipfilter.discardbanning");
    FloatParameter discard_ratio = new FloatParameter(gBlockBanning, "Ip Filter Ban Discard Ratio");
    gridData = new GridData();
    discard_ratio.setLayoutData(gridData);
    Composite cIndent = new Composite(gBlockBanning, SWT.NONE);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 2;
    gridData.horizontalIndent = 15;
    Utils.setLayoutData(cIndent, gridData);
    layout = new GridLayout(3, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cIndent.setLayout(layout);
    Image img = imageLoader.getImage("subitem");
    Label label = new Label(cIndent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    Utils.setLayoutData(label, gridData);
    label.setImage(img);
    Label discard_min_label = new Label(cIndent, SWT.NULL);
    Messages.setLanguageText(discard_min_label, "ConfigView.section.ipfilter.discardminkb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_KB) });
    IntParameter discard_min = new IntParameter(cIndent, "Ip Filter Ban Discard Min KB");
    gridData = new GridData();
    discard_min.setLayoutData(gridData);
    // block banning
    Label block_label = new Label(gBlockBanning, SWT.NULL);
    Messages.setLanguageText(block_label, "ConfigView.section.ipfilter.blockbanning");
    IntParameter block_banning = new IntParameter(gBlockBanning, "Ip Filter Ban Block Limit", 0, 256);
    gridData = new GridData();
    block_banning.setLayoutData(gridData);
    // triggers
    enable_bad_data_banning.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { block_banning.getControl(), block_label, discard_ratio.getControl(), discard_label, discard_min.getControl(), discard_min_label }));
    Group gAutoLoad = new Group(gFilter, SWT.NONE);
    Messages.setLanguageText(gAutoLoad, "ConfigView.section.ipfilter.autoload.group");
    FormLayout flayout = new FormLayout();
    flayout.marginHeight = flayout.marginWidth = 5;
    gAutoLoad.setLayout(flayout);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.widthHint = 500;
    Utils.setLayoutData(gAutoLoad, gridData);
    FormData fd;
    // Load from file
    sCurConfigID = "Ip Filter Autoload File";
    // allConfigIDs.add(sCurConfigID);
    Label lblDefaultDir = new Label(gAutoLoad, SWT.NONE);
    Messages.setLanguageText(lblDefaultDir, "ConfigView.section.ipfilter.autoload.file");
    fd = new FormData();
    Utils.setLayoutData(lblDefaultDir, fd);
    final StringParameter pathParameter = new StringParameter(gAutoLoad, sCurConfigID);
    Button browse = new Button(gAutoLoad, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            dialog.setText(MessageText.getString("ConfigView.section.ipfilter.autoload.file"));
            dialog.setFilterExtensions(new String[] { "*.dat" + File.pathSeparator + "*.p2p" + File.pathSeparator + "*.p2b" + File.pathSeparator + "*.txt", "*.*" });
            dialog.setFileName("ipfilter.dat");
            String file = dialog.open();
            if (file != null) {
                pathParameter.setValue(file);
            }
        }
    });
    final Button btnLoadNow = new Button(gAutoLoad, SWT.PUSH);
    Messages.setLanguageText(btnLoadNow, "ConfigView.section.ipfilter.autoload.loadnow");
    btnLoadNow.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            btnLoadNow.setEnabled(false);
            COConfigurationManager.setParameter(IpFilterAutoLoaderImpl.CFG_AUTOLOAD_LAST, 0);
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    try {
                        filter.reloadSync();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (!btnLoadNow.isDisposed()) {
                                btnLoadNow.setEnabled(true);
                            }
                        }
                    });
                }
            });
        }
    });
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    Utils.setLayoutData(btnLoadNow, fd);
    fd = new FormData();
    fd.right = new FormAttachment(btnLoadNow, -5);
    Utils.setLayoutData(browse, fd);
    fd = new FormData();
    fd.left = new FormAttachment(lblDefaultDir, 5);
    fd.right = new FormAttachment(browse, -5);
    pathParameter.setLayoutData(fd);
    // reload period
    Label l_reload_period = new Label(gAutoLoad, SWT.NULL);
    Messages.setLanguageText(l_reload_period, "ConfigView.section.ipfilter.autoload.period");
    int initial_reload_period = COConfigurationManager.getIntParameter(IpFilterAutoLoaderImpl.CFG_AUTOLOAD_DAYS);
    IntParameter reload_period = new IntParameter(gAutoLoad, IpFilterAutoLoaderImpl.CFG_AUTOLOAD_DAYS, 1, 31);
    reload_period.addChangeListener(new ParameterChangeAdapter() {

        private boolean added_listener = false;

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            if (!added_listener) {
                added_listener = true;
                COConfigurationManager.addListener(new COConfigurationListener() {

                    @Override
                    public void configurationSaved() {
                        COConfigurationManager.removeListener(this);
                        added_listener = false;
                        int period = reload_period.getValue();
                        if (period != initial_reload_period) {
                            Utils.getOffOfSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    try {
                                        ipFilterManager.getIPFilter().reload();
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }
    });
    fd = new FormData();
    fd.top = new FormAttachment(btnLoadNow, 3);
    fd.left = new FormAttachment(0, 20);
    Utils.setLayoutData(l_reload_period, fd);
    fd = new FormData();
    fd.top = new FormAttachment(btnLoadNow, 3);
    fd.left = new FormAttachment(l_reload_period, 5);
    Utils.setLayoutData(reload_period.getControl(), fd);
    // reload info
    Label lblAutoLoadInfo = new Label(gAutoLoad, SWT.WRAP);
    Messages.setLanguageText(lblAutoLoadInfo, "ConfigView.section.ipfilter.autoload.info");
    fd = new FormData();
    fd.top = new FormAttachment(reload_period.getControl(), 3);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    Utils.setLayoutData(lblAutoLoadInfo, fd);
    BooleanParameter clear_on_reload = new BooleanParameter(gAutoLoad, "Ip Filter Clear On Reload");
    fd = new FormData();
    fd.top = new FormAttachment(lblAutoLoadInfo, 3);
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    clear_on_reload.setLayoutData(fd);
    Messages.setLanguageText(clear_on_reload.getControl(), "ConfigView.section.ipfilter.clear.on.reload");
    if (userMode > 0) {
        gridData = new GridData();
        BooleanParameter enableDesc = new BooleanParameter(gFilter, "Ip Filter Enable Description Cache");
        enableDesc.setLayoutData(gridData);
        Messages.setLanguageText(enableDesc.getControl(), "ConfigView.section.ipfilter.enable.descriptionCache");
    }
    // table
    table = new Table(gFilter, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    String[] headers = { "label.description", "ConfigView.section.ipfilter.start", "ConfigView.section.ipfilter.end" };
    int[] sizes = { 110, 110, 110 };
    int[] aligns = { SWT.LEFT, SWT.CENTER, SWT.CENTER };
    for (int i = 0; i < headers.length; i++) {
        TableColumn tc = new TableColumn(table, aligns[i]);
        tc.setText(headers[i]);
        tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
        // $NON-NLS-1$
        Messages.setLanguageText(tc, headers[i]);
    }
    TableColumn[] columns = table.getColumns();
    columns[0].setData(new Integer(FilterComparator.FIELD_NAME));
    columns[1].setData(new Integer(FilterComparator.FIELD_START_IP));
    columns[2].setData(new Integer(FilterComparator.FIELD_END_IP));
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            TableColumn tc = (TableColumn) e.widget;
            int field = ((Integer) tc.getData()).intValue();
            comparator.setField(field);
            if (field == FilterComparator.FIELD_NAME && !bIsCachingDescriptions) {
                ipFilterManager.cacheAllDescriptions();
                bIsCachingDescriptions = true;
            }
            ipRanges = getSortedRanges(filter.getRanges());
            table.setItemCount(ipRanges.length);
            table.clearAll();
            // bug 69398 on Windows
            table.redraw();
        }
    };
    columns[0].addListener(SWT.Selection, listener);
    columns[1].addListener(SWT.Selection, listener);
    columns[2].addListener(SWT.Selection, listener);
    table.setHeaderVisible(true);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = table.getHeaderHeight() * 3;
    gridData.widthHint = 200;
    Utils.setLayoutData(table, gridData);
    Composite cArea = new Composite(gFilter, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 4;
    cArea.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(cArea, gridData);
    Button add = new Button(cArea, SWT.PUSH);
    gridData = new GridData(GridData.CENTER);
    gridData.widthHint = 100;
    Utils.setLayoutData(add, gridData);
    Messages.setLanguageText(add, "Button.add");
    add.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            addRange();
        }
    });
    Button remove = new Button(cArea, SWT.PUSH);
    gridData = new GridData(GridData.CENTER);
    gridData.widthHint = 100;
    Utils.setLayoutData(remove, gridData);
    Messages.setLanguageText(remove, "ConfigView.section.ipfilter.remove");
    remove.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            TableItem[] selection = table.getSelection();
            if (selection.length == 0)
                return;
            removeRange((IpRange) selection[0].getData());
            ipRanges = getSortedRanges(filter.getRanges());
            table.setItemCount(ipRanges.length);
            table.clearAll();
            table.redraw();
        }
    });
    Button edit = new Button(cArea, SWT.PUSH);
    gridData = new GridData(GridData.CENTER);
    gridData.widthHint = 100;
    Utils.setLayoutData(edit, gridData);
    Messages.setLanguageText(edit, "Button.edit");
    edit.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            TableItem[] selection = table.getSelection();
            if (selection.length == 0)
                return;
            editRange((IpRange) selection[0].getData());
        }
    });
    percentage_blocked = new Label(cArea, SWT.WRAP | SWT.RIGHT);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(percentage_blocked, gridData);
    Utils.setLayoutData(percentage_blocked, Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL));
    setPercentageBlocked();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            TableItem[] selection = table.getSelection();
            if (selection.length == 0)
                return;
            editRange((IpRange) selection[0].getData());
        }
    });
    Control[] controls = new Control[3];
    controls[0] = add;
    controls[1] = remove;
    controls[2] = edit;
    IAdditionalActionPerformer enabler = new ChangeSelectionActionPerformer(controls);
    enabled.setAdditionalActionPerformer(enabler);
    ipRanges = getSortedRanges(filter.getRanges());
    table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = table.indexOf(item);
            if (index < 0 || index >= ipRanges.length) {
                return;
            }
            IpRange range = ipRanges[index];
            item.setText(0, range.getDescription());
            item.setText(1, range.getStartIp());
            item.setText(2, range.getEndIp());
            item.setData(range);
        }
    });
    table.setItemCount(ipRanges.length);
    table.clearAll();
    // bug 69398 on Windows
    table.redraw();
    table.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            resizeTable();
        }
    });
    gFilter.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            resizeTable();
        }
    });
    filterListener = new IPFilterListener() {

        @Override
        public void IPFilterEnabledChanged(boolean is_enabled) {
        }

        @Override
        public boolean canIPBeBanned(String ip) {
            return true;
        }

        @Override
        public void IPBanned(BannedIp ip) {
        }

        @Override
        public void IPBlockedListChanged(final IpFilter filter) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (table.isDisposed()) {
                        filter.removeListener(filterListener);
                        return;
                    }
                    ipRanges = getSortedRanges(filter.getRanges());
                    table.setItemCount(ipRanges.length);
                    table.clearAll();
                    table.redraw();
                }
            });
        }

        @Override
        public boolean canIPBeBlocked(String ip, byte[] torrent_hash) {
            return true;
        }
    };
    filter.addListener(filterListener);
    return gFilter;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) COConfigurationListener(com.biglybt.core.config.COConfigurationListener) COConfigurationListener(com.biglybt.core.config.COConfigurationListener) Image(org.eclipse.swt.graphics.Image) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 44 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class ConfigSectionIPFilter method configSectionDelete.

@Override
public void configSectionDelete() {
    if (bIsCachingDescriptions) {
        IpFilterManager ipFilterManager = CoreFactory.getSingleton().getIpFilterManager();
        ipFilterManager.clearDescriptionCache();
        bIsCachingDescriptions = false;
    }
    if (filter != null) {
        filter.removeListener(filterListener);
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.releaseImage("openFolderButton");
    imageLoader.releaseImage("subitem");
}
Also used : ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 45 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class ConfigSectionLogging method configSectionDelete.

@Override
public void configSectionDelete() {
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.releaseImage("openFolderButton");
}
Also used : ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Aggregations

ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)71 Image (org.eclipse.swt.graphics.Image)18 GridData (org.eclipse.swt.layout.GridData)14 GridLayout (org.eclipse.swt.layout.GridLayout)14 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 MessageText (com.biglybt.core.internat.MessageText)5 AERunnable (com.biglybt.core.util.AERunnable)5 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 ArrayList (java.util.ArrayList)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Core (com.biglybt.core.Core)4 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)4 File (java.io.File)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 FormData (org.eclipse.swt.layout.FormData)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3